Skip to content

Commit

Permalink
fix: Updated set policy routes
Browse files Browse the repository at this point in the history
Added case when user does not provide account_id in update_policy request, with the else statement, the route will find current user's policy
  • Loading branch information
mike-pisman committed Oct 13, 2023
1 parent edccfa9 commit f072769
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/unipoll_api/routes/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ async def set_group_policy(group: Group = Depends(Dependencies.get_group),
policy_list = await PolicyActions.get_policies(resource=group, policy_holder=group) # type: ignore
policy = policy_list.policies[0] # type: ignore
policy = await Policy.get(policy.id, fetch_links=True) # type: ignore
else:
account = AccountManager.active_user.get()
policy_list = await PolicyActions.get_policies(resource=group, policy_holder=account)
policy = policy_list.policies[0]
policy = await Policy.get(policy.id, fetch_links=True)

if not policy:
raise APIException(404, "Policy not found 404")
Expand Down
5 changes: 5 additions & 0 deletions src/unipoll_api/routes/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ async def set_workspace_policy(workspace: Workspace = Depends(Dependencies.get_w
policy_list = await actions.PolicyActions.get_policies(resource=workspace, policy_holder=group)
policy = policy_list.policies[0] # type: ignore
policy = await Policy.get(policy.id, fetch_links=True) # type: ignore
else:
account = AccountManager.active_user.get()
policy_list = await actions.PolicyActions.get_policies(resource=workspace, policy_holder=account)
policy = policy_list.policies[0] # type: ignore
policy = await Policy.get(policy.id, fetch_links=True) # type: ignore

if not policy:
raise APIException(404, "Policy not found 404")
Expand Down

0 comments on commit f072769

Please sign in to comment.