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

Add raise_exception arg to @group_required #10658 #10659

Merged
merged 4 commits into from
Mar 19, 2024

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Mar 6, 2024

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description of Change

Allows raising a 403 Forbidden for API-style requests, instead of a 302 redirect to nowhere.

More info about the use case in the linked issue.

Issues Solved

Closes #10658

Checklist

  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Ticket Background

  • Sponsored by:
  • Found by: @
  • Tested by: @
  • Designed by: @

Allows raising a 403 PermissionDenied for API-style
requests, instead of a 302 redirect to nowhere.
@jacobtylerwalls jacobtylerwalls requested a review from apeters March 6, 2024 14:51
@jacobtylerwalls jacobtylerwalls changed the title Raise exception arg Add raise_exception arg to @group_required #10658 Mar 6, 2024
Comment on lines -86 to -87
self.client.force_login(self.anonymous)
response = self.client.post(reverse("workflow_history", kwargs={"workflowid": str(self.history.workflowid)}))
Copy link
Member Author

Choose a reason for hiding this comment

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

Noticed this wasn't testing what it I had intended (because the user wasn't even a resource editor), so I added a comment and adjusted the request so that it's an editor user and actually has some data.

@jacobtylerwalls
Copy link
Member Author

I borrowed the idea from @permission_required.

@@ -60,8 +58,8 @@ def post(self, request, workflowid):
workflowid = workflowid,
)
else:
return JSONErrorResponse(_("Request Failed"), _("Permission Denied"), status=403)

raise PermissionDenied
Copy link
Member

Choose a reason for hiding this comment

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

Will the UI be able to handle the fact that we used to return a JSON object and are now returning a python exception?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I just retested. No change on the frontend because the frontend doesn't even check the response for success:

Notice no try/catch here:

await fetch(arches.urls.workflow_history + workflowid, {

This is probably because you shouldn't be able to end up in this scenario (editing someone else's workflow) through the UI. You'd need to be trying to hack the endpoint with your own POST requests to reach this. I tested by leaving the UI open and then changing the owner of the workflow in the database.

In terms of the motivation for this change, I figured it was better to have all the permission failure cases return the same shape of a response so that we don't expose any information about what workflows exist.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Retested this one also. Same. Both 7.6 and this PR show the same in the UI:

Screenshot 2024-03-14 at 8 26 02 PM

The fact that the response changes from:

dev/7.6.x

{
    "message": "Permission Denied",
    "status": "false",
    "success": false,
    "title": "Request Failed"
}

to

<!doctype html>
<html lang="en">
<head>
  <title>403 Forbidden</title>
</head>
<body>
  <h1>403 Forbidden</h1><p></p>
</body>
</html>

doesn't seem to matter.

Copy link
Member Author

Choose a reason for hiding this comment

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

All we're using is the statusText which remains the same.

Copy link
Member

@apeters apeters left a comment

Choose a reason for hiding this comment

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

can we add the line at the top of the workflow_tests.py file that specifies the command to run this test file individually?

@jacobtylerwalls jacobtylerwalls linked an issue Mar 18, 2024 that may be closed by this pull request
Copy link
Member

@apeters apeters left a comment

Choose a reason for hiding this comment

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

looks good to me

@apeters apeters merged commit b5d64c0 into dev/7.6.x Mar 19, 2024
4 checks passed
@apeters apeters deleted the raise-exception-arg branch March 19, 2024 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add raise_exception arg to @group_required
2 participants