Skip to content

Commit

Permalink
style: Fixed resource spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-pisman committed Oct 17, 2023
1 parent ddfe048 commit 6ffa917
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/unipoll_api/actions/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def get_policies(policy_holder: Account | Group | None = None,

async def get_policy(policy: Policy, permission_check: bool = True) -> PolicySchemas.PolicyShort:
# Get the parent resource of the policy
parent_resource = await policy.get_parent_recource(fetch_links=True)
parent_resource = await policy.get_parent_resource(fetch_links=True)
await check_permissions(parent_resource, "get_policies", permission_check)

# Get the policy holder
Expand All @@ -75,7 +75,7 @@ async def update_policy(policy: Policy,
new_permissions: list[str],
check_permissions: bool = True) -> PolicySchemas.PolicyOutput:

parent_resource = await policy.get_parent_recource(fetch_links=True)
parent_resource = await policy.get_parent_resource(fetch_links=True)

# Check if the user has the required permissions to update the policy
await Permissions.check_permissions(parent_resource, "update_policies", check_permissions)
Expand Down
19 changes: 13 additions & 6 deletions src/unipoll_api/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class AccessToken(BeanieBaseAccessToken, Document): # type: ignore
class Resource(Document):
id: ResourceID = Field(default_factory=ResourceID, alias="_id")
resource_type: Literal["workspace", "group", "poll"]
name: str = Field(title="Name", description="Name of the resource", min_length=3, max_length=50)
name: str = Field(
title="Name", description="Name of the resource", min_length=3, max_length=50)
description: str = Field(default="", title="Description", max_length=1000)
policies: list[Link["Policy"]] = []

Expand Down Expand Up @@ -101,7 +102,9 @@ async def remove_member(self, account, save: bool = True) -> bool:
for i, member in enumerate(self.members):
if account.id == member.id: # type: ignore
self.members.remove(member)
Debug.info(f"Removed member {member.id} from {self.resource_type} {self.id}") # type: ignore
# type: ignore
Debug.info(
f"Removed member {member.id} from {self.resource_type} {self.id}")
break

# Remove the policy from the workspace
Expand All @@ -128,7 +131,8 @@ class Group(Resource):
async def add_member(self, account: "Account", permissions, save: bool = True) -> "Account":
if account not in self.workspace.members: # type: ignore
from unipoll_api.exceptions import WorkspaceExceptions
raise WorkspaceExceptions.UserNotMember(self.workspace, account) # type: ignore
raise WorkspaceExceptions.UserNotMember(
self.workspace, account) # type: ignore

# Add the account to the group
self.members.append(account) # type: ignore
Expand All @@ -143,7 +147,9 @@ async def remove_member(self, account, save: bool = True) -> bool:
for i, member in enumerate(self.members):
if account.id == member.id: # type: ignore
self.members.remove(member)
Debug.info(f"Removed member {member.id} from {self.resource_type} {self.id}") # type: ignore
# type: ignore
Debug.info(
f"Removed member {member.id} from {self.resource_type} {self.id}")
break

# Remove the policy from the group
Expand Down Expand Up @@ -171,12 +177,13 @@ class Policy(Document):
policy_holder: Link["Group"] | Link["Account"]
permissions: int

async def get_parent_recource(self, fetch_links: bool = False) -> Workspace | Group | Poll:
async def get_parent_resource(self, fetch_links: bool = False) -> Workspace | Group | Poll:
from unipoll_api.exceptions.resource import ResourceNotFound
parent = await eval(self.parent_resource.ref.collection).get(self.parent_resource.ref.id,
fetch_links=fetch_links)
if not parent:
ResourceNotFound(self.parent_resource.ref.collection, self.parent_resource.ref.id)
ResourceNotFound(self.parent_resource.ref.collection,
self.parent_resource.ref.id)
return parent

async def get_policy_holder(self, fetch_links: bool = False) -> Group | Account:
Expand Down

0 comments on commit 6ffa917

Please sign in to comment.