Skip to content

Commit

Permalink
#A20. As Admin, I would like to be able to administrate users better;…
Browse files Browse the repository at this point in the history
… add or remove participants and judges from teams and hackathons (#184)
  • Loading branch information
stefdworschak authored Jun 2, 2021
1 parent ae2a37b commit 42f6aba
Show file tree
Hide file tree
Showing 62 changed files with 1,244 additions and 382 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ COPY ./profiles/ /hackathon-app/profiles/
COPY ./resources/ /hackathon-app/resources/
COPY ./showcase/ /hackathon-app/showcase/
COPY ./static/ /hackathon-app/static/
COPY ./submissions/ /hackathon-app/submissions/
COPY ./teams/ /hackathon-app/teams/
COPY ./templates/ /hackathon-app/templates/
COPY ./hackadmin/ /hackathon-app/hackadmin/
COPY ./manage.py /hackathon-app/manage.py

EXPOSE 8000
Expand Down
23 changes: 13 additions & 10 deletions accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import AdminPasswordChangeForm, \
UserChangeForm, UserCreationForm
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.contrib.auth.decorators import login_required

from .models import CustomUser, Organisation
Expand All @@ -12,10 +11,11 @@ class CustomUserAdmin(BaseUserAdmin):
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': (
'username',
'full_name', 'slack_display_name', 'user_type',
'current_lms_module', 'organisation')}),
'full_name', 'slack_display_name',
'current_lms_module', 'organisation',
'user_type', 'is_external')}),
('Permissions', {'fields': (
'is_active', 'is_staff', 'is_superuser',
'is_active', 'is_staff', 'is_superuser',
'profile_is_public', 'email_is_public',
'groups', 'user_permissions')}),
('Important dates', {'fields': ('last_login', 'date_joined')}),
Expand All @@ -24,7 +24,7 @@ class CustomUserAdmin(BaseUserAdmin):
limited_fieldsets = (
(None, {'fields': ('email',)}),
('Personal info', {'fields': ('full_name',
'slack_display_name', 'user_type',
'slack_display_name',
'organisation')}),
('Important dates', {'fields': ('last_login', 'date_joined')}),
)
Expand All @@ -38,11 +38,14 @@ class CustomUserAdmin(BaseUserAdmin):

form = UserChangeForm
add_form = UserCreationForm
list_display = ('email', 'full_name', 'is_superuser')
list_filter = ('is_staff', 'is_superuser', 'is_active', 'groups')
search_fields = ('full_name', 'email')
list_display = ('email', 'full_name', 'is_superuser', 'user_type',
'is_external')
list_filter = ('is_staff', 'is_superuser', 'is_active', 'groups',
'is_external')
search_fields = ('full_name', 'email', 'slack_display_name')
ordering = ('email',)
readonly_fields = ('last_login', 'date_joined',)

readonly_fields = ('last_login', 'date_joined', 'user_type')


# sign-in via allauth required before accessing the admin panel
Expand Down
28 changes: 28 additions & 0 deletions accounts/decorators.py
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
21 changes: 0 additions & 21 deletions accounts/fixtures/accounts.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"date_joined": "2020-10-26T16:54:30.184Z",
"full_name": "Admin User",
"slack_display_name": "admin_ci",
"user_type": "staff",
"current_lms_module": "staff",
"organisation": 1,
"about": "This is a pre-seeded admin account for development.",
Expand Down Expand Up @@ -57,7 +56,6 @@
"date_joined": "2020-10-26T21:39:10.940Z",
"full_name": "Luke Skywalker",
"slack_display_name": "Luke_Skywalker",
"user_type": "participant",
"current_lms_module": "programme_preliminaries",
"organisation": 1,
"about": "Enthusiastic front-end developer with a passion for React and Angular.",
Expand Down Expand Up @@ -85,7 +83,6 @@
"date_joined": "2020-10-26T21:43:53.334Z",
"full_name": "C-3PO",
"slack_display_name": "C-3PO",
"user_type": "participant",
"current_lms_module": "alumni",
"organisation": 1,
"about": "Interested in general robotics and looking for other developers to work with on projects. Main tech stack is Python",
Expand Down Expand Up @@ -113,7 +110,6 @@
"date_joined": "2020-10-26T21:45:59.264Z",
"full_name": "R2 D2",
"slack_display_name": "R2-D2",
"user_type": "participant",
"current_lms_module": "python_essentials",
"organisation": 1,
"about": "Interested in general robotics and looking for other developers to work with on projects. Main tech stack is Python",
Expand Down Expand Up @@ -141,7 +137,6 @@
"date_joined": "2020-10-26T21:48:44.064Z",
"full_name": "Darth Vader",
"slack_display_name": "Darth_Vader",
"user_type": "staff",
"current_lms_module": "staff",
"organisation": 1,
"about": "Coder with multiple years of experience in front- and backend.",
Expand Down Expand Up @@ -169,7 +164,6 @@
"date_joined": "2020-10-26T21:53:11.458Z",
"full_name": "Leia Organa",
"slack_display_name": "Leia_Organa",
"user_type": "participant",
"current_lms_module": "javascript_essentials",
"organisation": 1,
"about": "Tech evangelist with a wide range of skills. Hoping for a new challenge to do with ML.",
Expand Down Expand Up @@ -197,7 +191,6 @@
"date_joined": "2020-10-26T21:54:54.941Z",
"full_name": "Owen Lars",
"slack_display_name": "Owen_Lars",
"user_type": "participant",
"current_lms_module": "html_essentials",
"organisation": 1,
"about": "Not too much to say about me...I like coding and developing apps.",
Expand Down Expand Up @@ -225,7 +218,6 @@
"date_joined": "2020-10-26T21:57:45.272Z",
"full_name": "Obi-Wan Kenobi",
"slack_display_name": "Obi-Wan_Kenobi",
"user_type": "staff",
"current_lms_module": "staff",
"organisation": 1,
"about": "I have more than 10 years experiencing in developing and deploying enterprise scale applications.",
Expand Down Expand Up @@ -253,7 +245,6 @@
"date_joined": "2020-10-26T22:00:34.989Z",
"full_name": "Anakin Skywalker",
"slack_display_name": "Anakin_Skywalker",
"user_type": "participant",
"current_lms_module": "programming_paradigms",
"organisation": 1,
"about": "Just started programming, but I really like it and am trying to get more and more into it. Looking forward to deploying my first website!!",
Expand Down Expand Up @@ -281,7 +272,6 @@
"date_joined": "2020-10-26T22:02:30.940Z",
"full_name": "Chewbacca",
"slack_display_name": "Chewbacca",
"user_type": "participant",
"current_lms_module": "css_essentials",
"organisation": 1,
"about": "HERRNNNGGGHHHHH!!!",
Expand Down Expand Up @@ -309,7 +299,6 @@
"date_joined": "2020-10-26T22:04:02.107Z",
"full_name": "Han Solo",
"slack_display_name": "Han_Solo",
"user_type": "participant",
"current_lms_module": "data_centric_development",
"organisation": 1,
"about": "Experienced developer; mainly working on shipping applications to production servers. Linux expert!",
Expand Down Expand Up @@ -337,7 +326,6 @@
"date_joined": "2020-10-26T22:05:58.558Z",
"full_name": "Yoda",
"slack_display_name": "Yoda",
"user_type": "admin",
"current_lms_module": "staff",
"organisation": 1,
"about": "Experienced DevOps specialist with about 5 years of web application development as well.",
Expand Down Expand Up @@ -365,7 +353,6 @@
"date_joined": "2020-10-26T22:08:52.279Z",
"full_name": "Senator Palpatine",
"slack_display_name": "Palpatine",
"user_type": "participant",
"current_lms_module": "full_stack_frameworks_with_django",
"organisation": 1,
"about": "",
Expand Down Expand Up @@ -393,7 +380,6 @@
"date_joined": "2020-10-26T22:10:28.037Z",
"full_name": "Boba Fett",
"slack_display_name": "Boba_Fett",
"user_type": "participant",
"current_lms_module": "python_essentials",
"organisation": 1,
"about": "Django is my passion, but Flask is okay too. Not much interested in Frontend.",
Expand Down Expand Up @@ -421,7 +407,6 @@
"date_joined": "2020-10-26T22:13:13.056Z",
"full_name": "Qui-Gon Jinn",
"slack_display_name": "Qui-Gon_Jinn",
"user_type": "staff",
"current_lms_module": "staff",
"organisation": 1,
"about": "",
Expand Down Expand Up @@ -449,7 +434,6 @@
"date_joined": "2020-10-26T22:16:45.860Z",
"full_name": "Padme Amidala",
"slack_display_name": "Padme_Amidala",
"user_type": "participant",
"current_lms_module": "interactive_frontend_development",
"organisation": 1,
"about": "I am an aspiring junior developer with interest in Data Analytics as well.",
Expand Down Expand Up @@ -477,7 +461,6 @@
"date_joined": "2020-10-26T22:20:27.772Z",
"full_name": "Mace Windu",
"slack_display_name": "Mace_Windu",
"user_type": "staff",
"current_lms_module": "staff",
"organisation": 1,
"about": "I have more than 10 years experience in web application development with Java. Trying to upskill and learn Python/Django.",
Expand Down Expand Up @@ -505,7 +488,6 @@
"date_joined": "2020-10-26T22:22:47.130Z",
"full_name": "Count Dooku",
"slack_display_name": "Dooku",
"user_type": "participant",
"current_lms_module": "user_centric_frontend_development",
"organisation": 1,
"about": "Just starting out to learn programming. Really enjoying Bootstrap and working on my website.",
Expand Down Expand Up @@ -533,7 +515,6 @@
"date_joined": "2020-10-26T22:25:11.784Z",
"full_name": "Jango Fett",
"slack_display_name": "Jango_Fett",
"user_type": "participant",
"current_lms_module": "interactive_frontend_development",
"organisation": 1,
"about": "",
Expand Down Expand Up @@ -561,7 +542,6 @@
"date_joined": "2020-10-26T22:28:36.422Z",
"full_name": "Shmi Skywalker",
"slack_display_name": "Shmi_Skywalker",
"user_type": "participant",
"current_lms_module": "practical_python",
"organisation": 1,
"about": "Very experienced Software Developer mainly in the enterprise sector working on HR solutions.",
Expand Down Expand Up @@ -589,7 +569,6 @@
"date_joined": "2021-01-18T21:18:08.530Z",
"full_name": "Admin User 2",
"slack_display_name": "admin2_ci",
"user_type": "staff",
"current_lms_module": "staff",
"organisation": 1,
"about": "",
Expand Down
42 changes: 42 additions & 0 deletions accounts/fixtures/groups.json
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": []
}
}
]
Loading

0 comments on commit 42f6aba

Please sign in to comment.