Skip to content

Commit

Permalink
refactor(permission): Fix type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
DoyunShin committed Jan 9, 2024
1 parent d7f119a commit 4632984
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/user/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __str__(self) -> str:
return self.name

@staticmethod
def search_by_name(name: str) -> list:
def search_by_name(name: str) -> list["Group"]:
return Group.objects.filter(name=name)

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion apps/user/models/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy

from apps.user.models import Group
from ara.db.models import MetaDataModel
from ara.settings import MIN_TIME

Expand Down Expand Up @@ -148,5 +149,5 @@ def is_school_admin(self) -> bool:
return self.group == UserProfile.UserGroup.COMMUNICATION_BOARD_ADMIN

@cached_property
def groups(self) -> list:
def groups(self) -> list[Group]:
return UserGroup.search_by_user(self.user)
16 changes: 12 additions & 4 deletions apps/user/models/usergroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ class Meta:
)

@staticmethod
def search_by_user(self, user: UserProfile):
return UserGroup.objects.filter(user=user)
def search_by_user(self, user: UserProfile) -> list[Group]:
groups = []
for usergroup in UserGroup.objects.filter(user=user):
groups.append(usergroup.group)
return groups

@staticmethod
def search_by_group(self, group: Group): # WARNING: Too many results
return UserGroup.objects.filter(group=group)
def search_by_group(
self, group: Group
) -> list[UserProfile]: # WARNING: Too many results
users = []
for usergroup in UserGroup.objects.filter(group=group):
users.append(usergroup.user)
return users

0 comments on commit 4632984

Please sign in to comment.