TNL-8080 ][: Use module mixin and fix permissions for proxy models. (#27811)
* chore: Update Python requirements via pip-tools. Needed the newest edx-django-utils version. * refactor: Use the newly-added ReadOnlyAdminMixin from the updated module and remove the existing implementation. * fix: edx-platform now has a Django proxy model - CourseOutlineRegenerate. Without this fix, the permissions to the model's admin interface cannot be added to a group and successfully granted to users.
This commit is contained in:
@@ -8,6 +8,7 @@ from config_models.admin import ConfigurationModelAdmin
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
|
||||
from django.utils.translation import ugettext as _
|
||||
from edx_django_utils.admin.mixins import ReadOnlyAdminMixin
|
||||
|
||||
from cms.djangoapps.contentstore.models import VideoUploadConfig
|
||||
from cms.djangoapps.contentstore.outlines_regenerate import CourseOutlineRegenerate
|
||||
@@ -19,37 +20,6 @@ from .tasks import update_outline_from_modulestore_task, update_all_outlines_fro
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ReadOnlyAdminMixin(object):
|
||||
"""
|
||||
Disables all editing capabilities for the admin's model.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.list_display_links = None
|
||||
self.readonly_fields = [f.name for f in self.model._meta.get_fields()]
|
||||
|
||||
def get_actions(self, request):
|
||||
actions = super().get_actions(request)
|
||||
if 'delete_selected' in actions:
|
||||
del actions["delete_selected"]
|
||||
return actions
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None): # pylint: disable=unused-argument
|
||||
return False
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
pass
|
||||
|
||||
def delete_model(self, request, obj):
|
||||
pass
|
||||
|
||||
def save_related(self, request, form, formsets, change):
|
||||
pass
|
||||
|
||||
|
||||
def regenerate_course_outlines_subset(modeladmin, request, queryset):
|
||||
"""
|
||||
Create a celery task to regenerate a single course outline for each passed-in course key.
|
||||
|
||||
@@ -103,7 +103,8 @@ class Command(BaseCommand): # lint-amnesty, pylint: disable=missing-class-docst
|
||||
except LookupError as exc:
|
||||
raise CommandError(str(exc)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
content_type = ContentType.objects.get_for_model(model_class)
|
||||
# Fetch content type for model, including proxy models.
|
||||
content_type = ContentType.objects.get_for_model(model_class, for_concrete_model=False)
|
||||
try:
|
||||
new_permission = Permission.objects.get(
|
||||
content_type=content_type,
|
||||
|
||||
@@ -62,7 +62,6 @@ numpy==1.16.5
|
||||
# chem
|
||||
# matplotlib
|
||||
# openedx-calc
|
||||
# scipy
|
||||
openedx-calc==1.0.9
|
||||
# via -r requirements/edx-sandbox/py35.in
|
||||
pycparser==2.20
|
||||
|
||||
Reference in New Issue
Block a user