From 2cda5b870cf97209810545a0281f18303417c38e Mon Sep 17 00:00:00 2001 From: Muhammad Afaq Shuaib Date: Fri, 17 Jan 2025 15:00:03 +0500 Subject: [PATCH] chore: added remaining docstrings --- course_discovery/apps/tagging/admin.py | 10 ++++++++++ course_discovery/apps/tagging/tests.py | 0 course_discovery/apps/tagging/tests/test_admin.py | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) delete mode 100644 course_discovery/apps/tagging/tests.py diff --git a/course_discovery/apps/tagging/admin.py b/course_discovery/apps/tagging/admin.py index 959b1bf20b..9420d1b81f 100644 --- a/course_discovery/apps/tagging/admin.py +++ b/course_discovery/apps/tagging/admin.py @@ -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 @@ -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) @@ -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) @@ -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.") diff --git a/course_discovery/apps/tagging/tests.py b/course_discovery/apps/tagging/tests.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/course_discovery/apps/tagging/tests/test_admin.py b/course_discovery/apps/tagging/tests/test_admin.py index 5476c02859..0b89ef9724 100644 --- a/course_discovery/apps/tagging/tests/test_admin.py +++ b/course_discovery/apps/tagging/tests/test_admin.py @@ -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): @@ -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) @@ -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)