-
Notifications
You must be signed in to change notification settings - Fork 81
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
Fix #1036 -- Add permission check to GeoODK submissions #1047
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given how messy the situation is, this at least works.
Unfortunately, users who are granted permission and then have it revoked (are set to Public User or removed from the organization) are still able to submit, but that's more tied to #1008 than this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of minor requests. Also, I also have no good solution to the all-or-nothing permission problem.
I was thinking that if the user tried to add a specific entity type for which they have no permission, they either get denied outright or those entities are discarded while the rest get accepted. This is still messy.
roles = [superuser, org_admin, prj_manager, data_collector] | ||
assigned_policies = user.assigned_policies() | ||
if not any(role in assigned_policies for role in roles): | ||
raise PermissionDenied(_("You don't have permission do contribute" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misspelling: "do" should be "to".
@@ -53,7 +53,9 @@ def create(self, request, *args, **kwargs): | |||
instance = ModelHelper().upload_submission_data(request) | |||
except InvalidXMLSubmission as e: | |||
logger.debug(str(e)) | |||
return self._sendErrorResponse(request, e) | |||
return self._sendErrorResponse(request, e, 'HTTP_400_BAD_REQUEST') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to send the actual status object instead of a string as shown below? This way, if you misspell the error code, you get a flake error instead of a runtime error.
return self._sendErrorResponse(request, e, status.HTTP_400_BAD_REQUEST)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd still get a runtime error. Flake doesn't check whether the object in an imported module actually exists.
Anyway, I'll change the code to use the status object since this is more clear.
5e9f9d2
to
22f9583
Compare
This is exactly what is currently happening. We're granting permission to create objects based on user roles. Any of the user roles either create all of the entities or none. I discussed with @dpalomino, denying all entities is not an option. Discarding those objects a user is not allowed to create requires more thinking. Through GeoODK users create sets of records, i.e. Location + Relationship + Parties. Some of these sets are 1:n, one location many relationships. How would we handle a case where the user can create a location and a party but no relationship. Do we discard the complete set or do we create both locations and parties without the relationship? How do we communicate what happened back to the user? Is either of the solutions what users would expect or does this contradict their use case? Those questions would have to be answered first before we can implement a more complex solution. Since this is an urgent issue, I suggest to move on with the solution I suggested unless there are issues with the code itself or we find a better solution that can be implemented in a timely manner. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is OK.
22f9583
to
98e9078
Compare
Proposed changes in this pull request
spatial.add
,tenure_rel.add
,party.add
,resource.add
) as users upload everything at once. For our current setup, the proposed solution is sufficient; we need to revisit when we implement fine-grained permission settings. We could then either check if the user has all permissions, which means if one permission is missing they would not be able to add anything. Or we check if one permission is present, which means users could add information they are not supposed to. Both solutions obviously have flaws, and I have no idea how to solve this at this point.PermissionDenied
is raised as expected403
in case the authenticated user is not permitted to upload data.When should this PR be merged
ASAP
Risks
Low
Follow up actions
None
Checklist (for reviewing)
General
migration
label if a new migration is added.Is the risk level assessment sufficient? The risks section should contain all risks that might be introduced with the PR and which actions we need to take to mitigate these risks. Possible risks are database migrations, new libraries that need to be installed or changes to deployment scripts.
Functionality
Code
Tests
Documentation