Skip to content

Conversation

@timyates
Copy link
Contributor

@timyates timyates commented May 22, 2024

See #2350

Added 1 new permission:

  • CAN_VIEW_ALL_PULSE_RESPONSES

create and update check

  1. If not, are they the user in the teamMemberId field for the report
  2. If not, does the teamMemberId in the supervisory tree of the current user?

And view checks the permission exists, and if not then performs the 2 above checks

@timyates timyates linked an issue May 22, 2024 that may be closed by this pull request
4 tasks
@timyates timyates self-assigned this May 22, 2024
@timyates timyates changed the title Requires hierarchy check and tests Implement Pulse Survey report permissions May 22, 2024
@timyates timyates marked this pull request as ready for review May 23, 2024 12:39
@timyates timyates requested review from mjperry91 and mkimberlin May 23, 2024 12:39
@timyates timyates added enhancement New feature or request server labels May 23, 2024
@timyates
Copy link
Contributor Author

I removed the service test, the coverage is almost exactly the same, and the mocking was getting excessive. The controller test does a better job of exercising the paths with real services and actual data (IMO)

ORDER BY level""",
nativeQuery = true
)
List<MemberProfile> findSubordinatesForId(UUID id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤘

List<MemberProfile> subordinatesForId = memberProfileRepository.findSubordinatesForId(id);
if (!currentUserServices.isAdmin()) {
for (MemberProfile memberProfile : subordinatesForId) {
memberProfile.clearBirthYear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to clear the birth year of the subordinates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the pattern for supervisors in the getSupervisorsForId method above 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to expose folks ages to everyone, so we clear them for those who don't need to know.

@Cacheable
public List<MemberProfile> getSubordinatesForId(UUID id) {
List<MemberProfile> subordinatesForId = memberProfileRepository.findSubordinatesForId(id);
if (!currentUserServices.isAdmin()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit makes me sad, but I think it's the right choice for this PR. I'll create a spike to identify any usages of the roles for security (we should be using permissions) so that we can break out stories to address those.

CAN_VIEW_SETTINGS("View settings", "Settings"),
CAN_VIEW_ALL_PULSE_RESPONSES("View all pulse responses", "Pulse"),
CAN_CREATE_ALL_PULSE_RESPONSES("Create pulse responses for anyone", "Pulse"),
CAN_UPDATE_ALL_PULSE_RESPONSES("Update pulse responses for anyone", "Pulse");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a use case for these bottom two. This is probably a failure of the AC, so, my bad.

We want to control whether a role can create/update pulse responses, but in either case, they should only be able to enter a response for themselves, not edit or enter them for others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fingers crossed this fixes it 🤞 7d08d3b

I removed the CREATE and UPDATE permissions, but still check the memberId so only the member themselves (or a "logical company superior") can create, edit or update a report for a given memberId

List<MemberProfile> subordinatesForId = memberProfileRepository.findSubordinatesForId(id);
if (!currentUserServices.isAdmin()) {
for (MemberProfile memberProfile : subordinatesForId) {
memberProfile.clearBirthYear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to expose folks ages to everyone, so we clear them for those who don't need to know.

PulseResponse pulseResponseRet = null;
if(pulseResponse!=null){
if (pulseResponse != null) {
final UUID memberId = pulseResponse.getTeamMemberId();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given my comment about only being able to create/update your own responses. It might be worthwhile to turn the teammemberid field into one that is annotated with and populated via @CreatedBy. Thoughts?

Copy link
Contributor Author

@timyates timyates May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look, but I am unsure as to how to get the tests working with @CreatedBy 🤔

Should I change

            } else if (!currentUserId.equals(memberId) && !isSubordinateTo(memberId, currentUserId)) {

in save and update to

            } else if (!currentUserId.equals(memberId)) {

To more closely match your comment? We can then raise a card to investigate @CreatedBy and I can pick it up when I return on the 3rd?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works, yes. Sorry for the slow reply. I missed yours completely.

@timyates timyates merged commit caef515 into develop Jun 3, 2024
@timyates timyates deleted the feature-2350/pulse-survey-report-permissions branch June 3, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Pulse Survey report permissions

5 participants