Repository: DDMAL/CantusDB

Issue:
Promote people to superuser in Django admin
Replace the current `is_staff` checkbox with a `is_superuser` checkbox. This way, the project manager can give superuser access (access to Django admin interface) to people without touching the command line. 

Project managers can access the Cantus editing functionalities (within the Cantus DB website, not the Admin interface). 
Superusers can access the Django admin interface. 
If we want someone to have access to both, they need to be in the `project manager` group and have `is_superuser` as `True`.


Discussion:
Also, there needs to be both boolean fields (`is_staff` and `is_superuser`) present as checkboxes in the admin interface.

`is_staff` determines whether a user is able to access the admin interface at all in the first place, and `is_superuser` determines if a user is given the permission to do anything in the admin interface.
This means that if a user is superuser but not staff, they won't be able to access the admin interface.


Resolving patch:
diff --git a/django/cantusdb_project/main_app/admin.py b/django/cantusdb_project/main_app/admin.py
--- a/django/cantusdb_project/main_app/admin.py
+++ b/django/cantusdb_project/main_app/admin.py
@@ -1,6 +1,15 @@
 from django.contrib import admin
 from main_app.models import *
+from django.contrib.auth import get_user_model
 # Register your models here.
+
+class SourcesUserCanEditInline(admin.TabularInline):
+    model = get_user_model().sources_user_can_edit.through
+
+class SourceAdmin(admin.ModelAdmin):
+    inlines = [SourcesUserCanEditInline]
+    filter_horizontal = ('century', 'notation', 'current_editors', 'inventoried_by', 'full_text_entered_by', 'melodies_entered_by', 'proofreaders', 'other_editors')
+
 admin.site.register(Chant)
 admin.site.register(Feast)
 admin.site.register(Genre)
@@ -10,4 +19,4 @@
 admin.site.register(Provenance)
 admin.site.register(Segment)
 admin.site.register(Sequence)
-admin.site.register(Source)
+admin.site.register(Source, SourceAdmin)
diff --git a/django/cantusdb_project/users/admin.py b/django/cantusdb_project/users/admin.py
--- a/django/cantusdb_project/users/admin.py
+++ b/django/cantusdb_project/users/admin.py
@@ -5,42 +5,19 @@
 
 # Register your models here.
 
-class CustomUserCreationForm(UserCreationForm):
-
-    class Meta:
-        model = User
-        fields = (
-            'email', 'password', 'is_active', 'date_joined', 'last_login', 
-            'full_name', 'first_name', 'last_name', 'institution', 'city', 
-            'country', 'website', 'is_staff', 'groups', 'sources_user_can_edit',
-        )
-
-
-class CustomUserChangeForm(UserChangeForm):
-
-    class Meta:
-        model = User
-        fields = (
-            'email', 'password', 'is_active', 'date_joined', 'last_login', 
-            'full_name', 'first_name', 'last_name', 'institution', 'city', 
-            'country', 'website', 'is_staff', 'groups', 'sources_user_can_edit',
-        )
-
-
 class UserAdmin(BaseUserAdmin):
-    form = CustomUserChangeForm
-    add_form = CustomUserCreationForm 
+    readonly_fields = ('date_joined', 'last_login',)
     list_display = ('email', 'first_name', 'last_name', 'institution',)
     list_filter = ('groups',)
     fieldsets = (
         ('Account info', {'fields': (('email', 'password'), 'is_active', ('date_joined', 'last_login'))}),
         ('Personal info', {'fields': ('full_name', ('first_name', 'last_name'), 'institution', ('city', 'country'), 'website',)}),
-        ('Permissions', {'fields': ('is_staff', 'groups', 'sources_user_can_edit',)}),
+        ('Permissions', {'fields': ('is_staff', 'is_superuser', 'groups', 'sources_user_can_edit',)}),
     )
     add_fieldsets = (
         ('Account info', {'fields': ('email', ('password1', 'password2'),)}),
         ('Personal info', {'fields': ('full_name', ('first_name', 'last_name'), 'institution', ('city', 'country'), 'website',)}),
-        ('Permissions', {'fields': ('is_staff', 'groups', 'sources_user_can_edit',)}),
+        ('Permissions', {'fields': ('is_staff', 'is_superuser', 'groups', 'sources_user_can_edit',)}),
     )
     search_fields = ('email', 'first_name', 'last_name', 'institution',)
     ordering = ('email',)


Test patch: