Skip to content

Commit

Permalink
fix(utils): refactor access_for_all
Browse files Browse the repository at this point in the history
This makes this function a lot easier to read

Closes: #582
  • Loading branch information
b1rger committed Feb 23, 2024
1 parent b3d2cbe commit b021696
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions apis_core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@
def access_for_all(self, viewtype="list"):
if self.request.user.is_authenticated:
return self.request.user.is_authenticated
elif viewtype == "list":
try:
access = settings.APIS_LIST_VIEWS_ALLOWED
except AttributeError:
access = False
return access
return access
else:
try:
access = settings.APIS_DETAIL_VIEWS_ALLOWED
except AttributeError:
access = False
return access
return access
match viewtype:
case "list":
return getattr(settings, "APIS_LIST_VIEWS_ALLOWED", False)
case "detail":
return getattr(settings, "APIS_DETAIL_VIEWS_ALLOWED", False)
return False


def access_for_all_function(user):
Expand Down

0 comments on commit b021696

Please sign in to comment.