Skip to content

Commit

Permalink
Merge pull request #35578 from openedx/hamza/ENT-9440-samlprovidercon…
Browse files Browse the repository at this point in the history
…fig-history-tracking

feat: history tracking on SAMLProviderConfig model
  • Loading branch information
hamzawaleed01 authored Oct 7, 2024
2 parents c34ccff + 36a413a commit 14b3178
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions common/djangoapps/third_party_auth/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ class SAMLProviderConfigForm(forms.ModelForm):
class SAMLProviderConfigAdmin(KeyedConfigurationModelAdmin):
""" Django Admin class for SAMLProviderConfig """
form = SAMLProviderConfigForm
search_fields = ['display_name']

def get_queryset(self, request):
"""
Filter the queryset to exclude the archived records.
Filter the queryset to exclude the archived records unless it's the /change/ view.
"""
queryset = super().get_queryset(request).exclude(archived=True)
return queryset
if request.path.endswith('/change/'):
return self.model.objects.all()
return super().get_queryset(request).exclude(archived=True)

def archive_provider_configuration(self, request, queryset):
"""
Expand Down Expand Up @@ -99,7 +101,15 @@ def name_with_update_link(self, instance):
Record name with link for the change view.
"""
if not instance.is_active:
return instance.name
update_url = reverse(
f'admin:{self.model._meta.app_label}_{self.model._meta.model_name}_change',
args=[instance.pk]
)
return format_html(
'<a href="{}" style="color: #999999;">{}</a>',
update_url,
f'{instance.name}'
)

update_url = reverse(f'admin:{self.model._meta.app_label}_{self.model._meta.model_name}_add')
update_url += f'?source={instance.pk}'
Expand Down Expand Up @@ -167,11 +177,11 @@ def upload_csv(self, request, slug):
# Always redirect back to the SAMLProviderConfig listing page
return HttpResponseRedirect(reverse('admin:third_party_auth_samlproviderconfig_changelist'))

def change_view(self, request, object_slug, form_url='', extra_context=None):
def change_view(self, request, object_id, form_url='', extra_context=None):
""" Extend the change view to include CSV upload. """
extra_context = extra_context or {}
extra_context['show_csv_upload'] = True
return super().change_view(request, object_slug, form_url, extra_context)
return super().change_view(request, object_id, form_url, extra_context)

def csv_uuid_update_button(self, obj):
""" Add CSV upload button to the form. """
Expand Down

0 comments on commit 14b3178

Please sign in to comment.