export_import: redirect to compare view if compare in GET params (#87653)
This commit is contained in:
parent
393a20b87b
commit
1f23f85b3d
|
@ -42,6 +42,14 @@ klasses_translation = {
|
|||
}
|
||||
klasses_translation_reverse = {v: k for k, v in klasses_translation.items()}
|
||||
|
||||
compare_urls = {
|
||||
'agendas': 'chrono-manager-agenda-history-compare',
|
||||
'categories': 'chrono-manager-category-history-compare',
|
||||
'events_types': 'chrono-manager-events-type-history-compare',
|
||||
'resources': 'chrono-manager-resource-history-compare',
|
||||
'unavailability_calendars': 'chrono-manager-unavailability-calendar-history-compare',
|
||||
}
|
||||
|
||||
|
||||
class Index(GenericAPIView):
|
||||
permission_classes = (permissions.IsAdminUser,)
|
||||
|
@ -184,6 +192,27 @@ component_dependencies = ComponentDependencies.as_view()
|
|||
def component_redirect(request, component_type, slug):
|
||||
klass = klasses[component_type]
|
||||
component = get_object_or_404(klass, slug=slug)
|
||||
|
||||
if component_type not in klasses or component_type == 'roles':
|
||||
raise Http404
|
||||
|
||||
if (
|
||||
'compare' in request.GET
|
||||
and request.GET.get('application')
|
||||
and request.GET.get('version1')
|
||||
and request.GET.get('version2')
|
||||
):
|
||||
component_type = klasses_translation.get(component_type, component_type)
|
||||
return redirect(
|
||||
'%s?version1=%s&version2=%s&application=%s'
|
||||
% (
|
||||
reverse(compare_urls[component_type], args=[component.pk]),
|
||||
request.GET['version1'],
|
||||
request.GET['version2'],
|
||||
request.GET['application'],
|
||||
)
|
||||
)
|
||||
|
||||
if klass == Agenda:
|
||||
return redirect(reverse('chrono-manager-agenda-view', kwargs={'pk': component.pk}))
|
||||
if klass == Category:
|
||||
|
@ -201,13 +230,6 @@ class BundleCheck(GenericAPIView):
|
|||
permission_classes = (permissions.IsAdminUser,)
|
||||
|
||||
def put(self, request, *args, **kwargs):
|
||||
compare_urls = {
|
||||
'agendas': 'chrono-manager-agenda-history-compare',
|
||||
'categories': 'chrono-manager-category-history-compare',
|
||||
'events_types': 'chrono-manager-events-type-history-compare',
|
||||
'resources': 'chrono-manager-resource-history-compare',
|
||||
'unavailability_calendars': 'chrono-manager-unavailability-calendar-history-compare',
|
||||
}
|
||||
tar_io = io.BytesIO(request.read())
|
||||
with tarfile.open(fileobj=tar_io) as tar:
|
||||
manifest = json.loads(tar.extractfile('manifest.json').read().decode())
|
||||
|
|
|
@ -375,22 +375,57 @@ def test_redirect(app, user):
|
|||
redirect_url = f'/api/export-import/agendas/{agenda.slug}/redirect/'
|
||||
resp = app.get(redirect_url, status=302)
|
||||
assert resp.location == f'/manage/agendas/{agenda.pk}/'
|
||||
resp = app.get(redirect_url + '?compare', status=302)
|
||||
assert resp.location == f'/manage/agendas/{agenda.pk}/'
|
||||
resp = app.get(redirect_url + '?compare&version1=bar&version2=bar&application=foo', status=302)
|
||||
assert (
|
||||
resp.location
|
||||
== f'/manage/agendas/{agenda.pk}/history/compare/?version1=bar&version2=bar&application=foo'
|
||||
)
|
||||
|
||||
redirect_url = f'/api/export-import/agendas_categories/{category.slug}/redirect/'
|
||||
resp = app.get(redirect_url, status=302)
|
||||
assert resp.location == '/manage/categories/'
|
||||
resp = app.get(redirect_url + '?compare', status=302)
|
||||
assert resp.location == '/manage/categories/'
|
||||
resp = app.get(redirect_url + '?compare&version1=bar&version2=bar&application=foo', status=302)
|
||||
assert (
|
||||
resp.location
|
||||
== f'/manage/category/{category.pk}/history/compare/?version1=bar&version2=bar&application=foo'
|
||||
)
|
||||
|
||||
redirect_url = f'/api/export-import/resources/{resource.slug}/redirect/'
|
||||
resp = app.get(redirect_url, status=302)
|
||||
assert resp.location == f'/manage/resource/{resource.pk}/'
|
||||
resp = app.get(redirect_url + '?compare', status=302)
|
||||
assert resp.location == f'/manage/resource/{resource.pk}/'
|
||||
resp = app.get(redirect_url + '?compare&version1=bar&version2=bar&application=foo', status=302)
|
||||
assert (
|
||||
resp.location
|
||||
== f'/manage/resource/{resource.pk}/history/compare/?version1=bar&version2=bar&application=foo'
|
||||
)
|
||||
|
||||
redirect_url = f'/api/export-import/events_types/{events_type.slug}/redirect/'
|
||||
resp = app.get(redirect_url, status=302)
|
||||
assert resp.location == '/manage/events-types/'
|
||||
resp = app.get(redirect_url + '?compare', status=302)
|
||||
assert resp.location == '/manage/events-types/'
|
||||
resp = app.get(redirect_url + '?compare&version1=bar&version2=bar&application=foo', status=302)
|
||||
assert (
|
||||
resp.location
|
||||
== f'/manage/events-type/{events_type.pk}/history/compare/?version1=bar&version2=bar&application=foo'
|
||||
)
|
||||
|
||||
redirect_url = f'/api/export-import/unavailability_calendars/{unavailability_calendar.slug}/redirect/'
|
||||
resp = app.get(redirect_url, status=302)
|
||||
assert resp.location == f'/manage/unavailability-calendar/{unavailability_calendar.pk}/'
|
||||
resp = app.get(redirect_url + '?compare', status=302)
|
||||
assert resp.location == f'/manage/unavailability-calendar/{unavailability_calendar.pk}/'
|
||||
resp = app.get(redirect_url + '?compare&version1=bar&version2=bar&application=foo', status=302)
|
||||
assert (
|
||||
resp.location
|
||||
== f'/manage/unavailability-calendar/{unavailability_calendar.pk}/history/compare/?version1=bar&version2=bar&application=foo'
|
||||
)
|
||||
|
||||
|
||||
def create_bundle(app, admin_user, visible=True, version_number='42.0'):
|
||||
|
|
Loading…
Reference in New Issue