Skip to content

Commit

Permalink
style: flake8 linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-pisman committed Oct 11, 2023
1 parent dd7ba5a commit 1be8a1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/unipoll_api/actions/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def add_members(resource: Workspace | Group,
# Check if the user has permission to add members
account = AccountManager.active_user.get()
permissions = await Permissions.get_all_permissions(resource, account)
if resource.resource_type == "workspace":
if resource.resource_type == "workspace":
req_permissions = Permissions.WorkspacePermissions["add_workspace_members"]
default_permissions = Permissions.WORKSPACE_BASIC_PERMISSIONS
elif resource.resource_type == "group":
Expand Down
30 changes: 15 additions & 15 deletions src/unipoll_api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unipoll_api.account_manager import active_user, get_current_active_user
from unipoll_api.documents import ResourceID, Workspace, Group, Account, Poll, Policy
from unipoll_api.utils import permissions as Permissions
from unipoll_api.exceptions import WorkspaceExceptions, GroupExceptions, AccountExceptions, PollExceptions, PolicyExceptions
from unipoll_api import exceptions as Exceptions
from unipoll_api.utils.path_operations import extract_action_from_path, extract_resourceID_from_path


Expand All @@ -14,7 +14,7 @@ async def get_account(account_id: ResourceID) -> Account:
"""
account = await Account.get(account_id)
if not account:
raise AccountExceptions.AccountNotFound(account_id)
raise Exceptions.AccountExceptions.AccountNotFound(account_id)
return account


Expand All @@ -34,7 +34,7 @@ async def get_workspace(workspace_id: ResourceID) -> Workspace:
if workspace:
# await workspace.fetch_all_links()
return workspace
raise WorkspaceExceptions.WorkspaceNotFound(workspace_id)
raise Exceptions.WorkspaceExceptions.WorkspaceNotFound(workspace_id)


# Dependency to get a group by id and verify it exists
Expand All @@ -46,7 +46,7 @@ async def get_group(group_id: ResourceID) -> Group:
if group:
# await group.fetch_all_links()
return group
raise GroupExceptions.GroupNotFound(group_id)
raise Exceptions.GroupExceptions.GroupNotFound(group_id)


# Dependency to get a poll by id and verify it exists
Expand All @@ -57,7 +57,7 @@ async def get_poll(poll_id: ResourceID) -> Poll:
poll = await Poll.get(poll_id, fetch_links=True)
if poll:
return poll
raise GroupExceptions.GroupNotFound(poll_id)
raise Exceptions.GroupExceptions.GroupNotFound(poll_id)


# Dependency to get a policy by id and verify it exists
Expand All @@ -66,7 +66,7 @@ async def get_policy(policy_id: ResourceID) -> Policy:
if policy:
# await policy.parent_resource.fetch_all_links() # type: ignore
return policy
raise PolicyExceptions.PolicyNotFound(policy_id)
raise Exceptions.PolicyExceptions.PolicyNotFound(policy_id)


# Dependency to get a user by id and verify it exists
Expand All @@ -88,7 +88,7 @@ async def check_workspace_permission(request: Request, account: Account = Depend

# Check if workspace exists
if not workspace:
e = WorkspaceExceptions.WorkspaceNotFound(workspaceID)
e = Exceptions.WorkspaceExceptions.WorkspaceNotFound(workspaceID)
raise HTTPException(e.code, str(e))

if account.is_superuser:
Expand All @@ -102,10 +102,10 @@ async def check_workspace_permission(request: Request, account: Account = Depend
required_permission = Permissions.WorkspacePermissions[operationID] # type: ignore
if not Permissions.check_permission(Permissions.WorkspacePermissions(user_permissions), # type: ignore
required_permission):
e = WorkspaceExceptions.UserNotAuthorized(account, workspace, operationID)
e = Exceptions.WorkspaceExceptions.UserNotAuthorized(account, workspace, operationID)
raise HTTPException(e.code, str(e))
except KeyError:
e = WorkspaceExceptions.ActionNotFound(operationID)
e = Exceptions.WorkspaceExceptions.ActionNotFound(operationID)
raise HTTPException(e.code, str(e))


Expand All @@ -119,7 +119,7 @@ async def check_group_permission(request: Request, account: Account = Depends(ge
# Check if group exists
e: Exception
if not group:
e = GroupExceptions.GroupNotFound(groupID)
e = Exceptions.GroupExceptions.GroupNotFound(groupID)
raise HTTPException(e.code, str(e))
# Get the user policy for the group
# print(group.members)
Expand All @@ -130,10 +130,10 @@ async def check_group_permission(request: Request, account: Account = Depends(ge
required_permission = Permissions.GroupPermissions[operationID] # type: ignore
if not Permissions.check_permission(Permissions.GroupPermissions(user_permissions), # type: ignore
required_permission):
e = GroupExceptions.UserNotAuthorized(account, group, operationID)
e = Exceptions.GroupExceptions.UserNotAuthorized(account, group, operationID)
raise HTTPException(e.code, str(e))
except KeyError:
e = GroupExceptions.ActionNotFound(operationID)
e = Exceptions.GroupExceptions.ActionNotFound(operationID)
raise HTTPException(e.code, str(e))


Expand All @@ -147,7 +147,7 @@ async def check_poll_permission(request: Request, account: Account = Depends(get
# Check if poll exists
e: Exception
if not poll:
e = PollExceptions.PollNotFound(pollID)
e = Exceptions.PollExceptions.PollNotFound(pollID)
raise HTTPException(e.code, str(e))

# Check if the poll is public
Expand All @@ -162,8 +162,8 @@ async def check_poll_permission(request: Request, account: Account = Depends(get
required_permission = Permissions.PollPermissions[operationID] # type: ignore
if not Permissions.check_permission(Permissions.PollPermissions(user_permissions), # type: ignore
required_permission):
e = PollExceptions.UserNotAuthorized(account, poll, operationID)
e = Exceptions.PollExceptions.UserNotAuthorized(account, poll, operationID)
raise HTTPException(e.code, str(e))
except KeyError:
e = PollExceptions.ActionNotFound(operationID)
e = Exceptions.PollExceptions.ActionNotFound(operationID)
raise HTTPException(e.code, str(e))

0 comments on commit 1be8a1a

Please sign in to comment.