Skip to content

Commit

Permalink
chore: added remaining docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Jan 17, 2025
1 parent c53963e commit 2cda5b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions course_discovery/apps/tagging/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" This module contains the admin classes for the tagging app models """
from django.conf import settings
from django.contrib import admin
from django.core.exceptions import PermissionDenied
Expand All @@ -15,6 +16,9 @@ class VerticalAdmin(admin.ModelAdmin):
search_fields = ('name',)

def save_model(self, request, obj, form, change):
"""
Override the save_model method to restrict non-superuser from saving the model
"""
if not request.user.is_superuser:
raise PermissionDenied("You are not authorized to perform this action.")
super().save_model(request, obj, form, change)
Expand All @@ -31,6 +35,9 @@ class SubVerticalAdmin(admin.ModelAdmin):
ordering = ('name',)

def save_model(self, request, obj, form, change):
"""
Override the save_model method to restrict non-superuser from saving the model
"""
if not request.user.is_superuser:
raise PermissionDenied("You are not authorized to perform this action.")
super().save_model(request, obj, form, change)
Expand Down Expand Up @@ -60,6 +67,9 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
return super().formfield_for_foreignkey(db_field, request, **kwargs)

def save_model(self, request, obj, form, change):
"""
Override the save_model method to allow only superuser and users in allowed groups to save the model.
"""
allowed_groups = getattr(settings, 'VERTICALS_MANAGEMENT_GROUPS', [])
if not (request.user.is_superuser or request.user.groups.filter(name__in=allowed_groups).exists()):
raise PermissionDenied("You are not authorized to perform this action.")
Expand Down
Empty file.
5 changes: 4 additions & 1 deletion course_discovery/apps/tagging/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def test_list_display(self):
)

def test_vertical_filter_admin_registration(self):
self.assertIn(Vertical, site._registry)
""" Verify that Vertical model is registered on the admin site """
self.assertIn(Vertical, site._registry)


class SubVerticalAdminTests(BaseAdminTestCase):
Expand Down Expand Up @@ -106,6 +107,7 @@ def test_list_display(self):
)

def test_sub_vertical_filter_admin_registration(self):
"""Verify that SubVertical model is registered on the admin site."""
self.assertIn(SubVertical, site._registry)


Expand Down Expand Up @@ -194,4 +196,5 @@ def test_list_display(self):
)

def test_course_vertical_filter_admin_registration(self):
""" Verify that CourseVertical model is registered on the admin site """
self.assertIn(CourseVertical, site._registry)

0 comments on commit 2cda5b8

Please sign in to comment.