Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions issue: user changed from DC to PU in a project is still able to add/edit/delete records #1008

Closed
dpalomino opened this issue Dec 15, 2016 · 9 comments · Fixed by #1062
Assignees
Milestone

Comments

@dpalomino
Copy link

Steps to reproduce the error

(tested in demo)

  1. Have a regular member of the organization with public user permissions to several projects. Some of these projects have been created before the release of Sprint 11 and others after the release of Sprint 11.
  2. Access to a project created before release of Sprint 11. Apart from the issue Permissions issue: Public user role within an organization #961 already known, otherwise the behaviour is "correct"
  3. Access to a project created after release of Sprint 11, where that user has only Public User permissions
  4. You will see that for that project user is able to:

Actual behaviour

See above

Expected behaviour

User is not able to submit, edit or delete any record

@amplifi
Copy link
Contributor

amplifi commented Dec 15, 2016

Note: This occurs after a user has been made Data Collector for a project, then changed back to a Public User.

@bjohare
Copy link
Contributor

bjohare commented Dec 15, 2016

Affects permissions for form downloads to ODK also.

@dpalomino
Copy link
Author

Thanks really a lot @amplifi and @bjohare! Now that we know that is indeed related to changing user profile and not happening with all PU, we can move this to medium priority for now I think.

@dpalomino dpalomino changed the title Permissions issue: public user within an organization able to add/edit/delete records Permissions issue: user changed from DC to PU in a project is still able to add/edit/delete records Dec 15, 2016
@seav
Copy link
Contributor

seav commented Jan 4, 2017

Note: PU = Project User role. This is not the same as a Public User role which uses the code Pb. A Project User has access to the project's records but cannot manipulate it, while a Public User only has access to the project's overview page, and not any of the records.

I've investigated this for a bit and I think this bug is because the method that reassigns a user's project policy is never called when the user becomes a public user of the project. This method is called whenever the ProjectRole object relating the user to the project is saved (due to the models.signals.post_save signal). But because Public User is not a real role (it is not in ROLE_CHOICES), the user's ProjectRole object for the project is deleted instead. Since deletion is not equal to saving it, the policy reassigning method is not called because there is no post_save signal. (There will be pre_delete and post_delete signals instead.) So when a user becomes a project Public User, the user still retains the previous policy they had for the project.

Our permissioning and roles functionality is quite a mess to be honest.

I guess the quickest way to fix this bug is to call the policy reassigning method with the pre_delete signal too and adding code to check that the ProjectRole is being deleted and delete the user's project policies accordingly.

Alternatively, we can make Public User be a real role at the expense of having N×M ProjectRole instances for N projects and M users per organization. This seems cleaner to me.

Any thoughts from the other developers?

@wonderchook
Copy link
Contributor

@seav could you expand a bit on which parts are making it a mess?

@seav
Copy link
Contributor

seav commented Jan 4, 2017

@wonderchook: I feel that how we have implemented our permissioning, policies, and roles is not consistent or as clean as it can be. The Public User pseudo-role, for instance, was bolted on when before we set that all org members are Project Users by default.

As another example of inconsistency, we have code that checks a user's role in the organization or project before allowing some features when we should be really checking whether the user has the specific tutelary permission. I have already filed #815 and #816 before for this.

If we try to check tutelary permissions all the time, then if ever we decide to, say, allow data collectors to download the project's data instead of just project managers, then we only need to update the data collector policy file instead of refactoring our code to provide an additional exception to data collectors. Right now, we check that the user is a project manager before showing the link to download the project's data.

@wonderchook
Copy link
Contributor

@seav is it worth writing out a decision record for this so we could plan to make things work better?

@seav
Copy link
Contributor

seav commented Jan 6, 2017

I guess that can help. I was also thinking we can approach this in the same manner that Oliver approached cleaning up the API (#880).

@oliverroick oliverroick modified the milestone: Sprint 13 Jan 6, 2017
@oliverroick oliverroick self-assigned this Jan 9, 2017
@linzjax
Copy link
Contributor

linzjax commented Jan 10, 2017

Adding to this: Removing a user from an organization isn't changing their permissions. I deleted a data collector and they can still add/edit/delete records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants