-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#A20. As Admin, I would like to be able to administrate users better;…
… add or remove participants and judges from teams and hackathons (#184)
- Loading branch information
1 parent
ae2a37b
commit 42f6aba
Showing
62 changed files
with
1,244 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from functools import wraps | ||
|
||
from django.contrib import messages | ||
from django.core.exceptions import PermissionDenied | ||
from django.shortcuts import reverse, redirect | ||
|
||
from accounts.models import UserType | ||
|
||
|
||
def can_access(allowed_types, redirect_url=None, redirect_kwargs={}): | ||
def decorator(view_function): | ||
@wraps(view_function) | ||
def wrapped_view(request, *args, **kwargs): | ||
print(request.user.user_type) | ||
authorized = (request.user.user_type in allowed_types | ||
or request.user.user_type is UserType.SUPERUSER) | ||
|
||
if not authorized and redirect_url: | ||
messages.error(request, 'You do not have access to this page!') | ||
return redirect(reverse(redirect_url, kwargs=redirect_kwargs)) | ||
elif not authorized: | ||
raise PermissionDenied('You do not have access to this page!') | ||
|
||
return view_function(request, *args, **kwargs) | ||
|
||
return wrapped_view | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
{ | ||
"model": "auth.group", | ||
"pk": 1, | ||
"fields": { | ||
"name": "FACILITATOR_ADMIN", | ||
"permissions": [] | ||
} | ||
}, | ||
{ | ||
"model": "auth.group", | ||
"pk": 2, | ||
"fields": { | ||
"name": "FACILITATOR_JUDGE", | ||
"permissions": [] | ||
} | ||
}, | ||
{ | ||
"model": "auth.group", | ||
"pk": 3, | ||
"fields": { | ||
"name": "FACILITATOR", | ||
"permissions": [] | ||
} | ||
}, | ||
{ | ||
"model": "auth.group", | ||
"pk": 4, | ||
"fields": { | ||
"name": "STUDENT", | ||
"permissions": [] | ||
} | ||
}, | ||
{ | ||
"model": "auth.group", | ||
"pk": 5, | ||
"fields": { | ||
"name": "EXTERNAL_USER", | ||
"permissions": [] | ||
} | ||
} | ||
] |
Oops, something went wrong.