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

being able to call do_action with super powers using the utility #1175

Merged
merged 2 commits into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -4,7 +4,9 @@ CHANGELOG
6.4.2 (unreleased)
------------------

- Nothing changed yet.
- Being able to call do_action with super powers in the Workflow
utility
[nilbacardit26]


6.4.1 (2022-07-27)
Expand Down
13 changes: 7 additions & 6 deletions guillotina/contrib/workflows/utility.py
Expand Up @@ -60,17 +60,18 @@ async def available_actions(self, request):
def initial_state(self):
return self._initial_state

async def do_action(self, action, comments):
async def do_action(self, action, comments, bypass_permission_check=False):
available_actions = self.actions
if action not in available_actions:
raise HTTPPreconditionFailed(content={"reason": "Unavailable action"})

action_def = available_actions[action]
policy = get_security_policy()
if "check_permission" in action_def and not policy.check_permission(
action_def["check_permission"], self.context
):
raise HTTPUnauthorized()
if bypass_permission_check is False:
policy = get_security_policy()
if "check_permission" in action_def and not policy.check_permission(
action_def["check_permission"], self.context
):
raise HTTPUnauthorized()

# Change permission
new_state = action_def["to"]
Expand Down