From 805c4faf8e3f3991198d53d74255ffbb9fbd5bb5 Mon Sep 17 00:00:00 2001 From: Carlos Vega <carlos.vega@uni.lu> Date: Thu, 22 Nov 2018 19:12:26 +0100 Subject: [PATCH] added decorators properly in class-based views --- smash/web/views/language.py | 19 ++++++++++++++++--- smash/web/views/study.py | 2 +- smash/web/views/voucher.py | 14 ++++++++++++-- smash/web/views/voucher_type.py | 15 +++++++++++++-- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/smash/web/views/language.py b/smash/web/views/language.py index d024f10a..e971d7ed 100644 --- a/smash/web/views/language.py +++ b/smash/web/views/language.py @@ -15,7 +15,10 @@ class LanguageListView(ListView, WrappedView): context_object_name = "languages" template_name = 'languages/list.html' -@PermissionDecorator('change_language', 'configuration') + @PermissionDecorator('change_language', 'configuration') + def dispatch(self, *args, **kwargs): + return super(LanguageListView, self).dispatch(*args, **kwargs) + class LanguageCreateView(CreateView, WrappedView): model = Language template_name = "languages/add.html" @@ -23,7 +26,10 @@ class LanguageCreateView(CreateView, WrappedView): success_url = reverse_lazy('web.views.languages') success_message = "Language created" -@PermissionDecorator('change_language', 'configuration') + @PermissionDecorator('change_language', 'configuration') + def dispatch(self, *args, **kwargs): + return super(LanguageCreateView, self).dispatch(*args, **kwargs) + class LanguageDeleteView(DeleteView, WrappedView): model = Language success_url = reverse_lazy('web.views.languages') @@ -33,7 +39,10 @@ class LanguageDeleteView(DeleteView, WrappedView): messages.success(request, "Language deleted") return super(LanguageDeleteView, self).delete(request, *args, **kwargs) -@PermissionDecorator('change_language', 'configuration') + @PermissionDecorator('change_language', 'configuration') + def dispatch(self, *args, **kwargs): + return super(LanguageDeleteView, self).dispatch(*args, **kwargs) + class LanguageEditView(UpdateView, WrappedView): model = Language success_url = reverse_lazy('web.views.languages') @@ -41,3 +50,7 @@ class LanguageEditView(UpdateView, WrappedView): success_message = "Language edited" template_name = "languages/edit.html" context_object_name = "language" + + @PermissionDecorator('change_language', 'configuration') + def dispatch(self, *args, **kwargs): + return super(LanguageEditView, self).dispatch(*args, **kwargs) \ No newline at end of file diff --git a/smash/web/views/study.py b/smash/web/views/study.py index 82756ed8..e2a37152 100644 --- a/smash/web/views/study.py +++ b/smash/web/views/study.py @@ -11,7 +11,7 @@ from web.decorators import PermissionDecorator logger = logging.getLogger(__name__) -PermissionDecorator('change_study', 'configuration') +@PermissionDecorator('change_study', 'configuration') def study_edit(request, study_id): study = get_object_or_404(Study, id=study_id) if request.method == 'POST': diff --git a/smash/web/views/voucher.py b/smash/web/views/voucher.py index e08023d7..e68918f6 100644 --- a/smash/web/views/voucher.py +++ b/smash/web/views/voucher.py @@ -24,11 +24,14 @@ class VoucherListView(ListView, WrappedView): context_object_name = "vouchers" template_name = 'vouchers/list.html' + @PermissionDecorator('change_voucher', 'configuration') + def dispatch(self, *args, **kwargs): + return super(VoucherListView, self).dispatch(*args, **kwargs) + def voucher_types_for_study_subject(study_subject_id): return StudySubject.objects.get(id=study_subject_id).voucher_types.all() -PermissionDecorator('change_voucher', 'configuration') class VoucherCreateView(CreateView, WrappedView): form_class = VoucherForm model = Voucher @@ -61,7 +64,10 @@ class VoucherCreateView(CreateView, WrappedView): kwargs['voucher_types'] = voucher_types_for_study_subject(self.request.GET.get("study_subject_id", -1)) return kwargs -PermissionDecorator('change_voucher', 'configuration') + @PermissionDecorator('change_voucher', 'configuration') + def dispatch(self, *args, **kwargs): + return super(VoucherCreateView, self).dispatch(*args, **kwargs) + class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView): form_class = VoucherForm model = Voucher @@ -83,6 +89,10 @@ class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView): context['mail_templates'] = MailTemplate.get_voucher_mail_templates([]) return context + @PermissionDecorator('change_voucher', 'configuration') + def dispatch(self, *args, **kwargs): + return super(VoucherEditView, self).dispatch(*args, **kwargs) + class ExpireVouchersJob(CronJobBase): RUN_EVERY_MINUTES = 120 diff --git a/smash/web/views/voucher_type.py b/smash/web/views/voucher_type.py index 82df7343..1c47a8e6 100644 --- a/smash/web/views/voucher_type.py +++ b/smash/web/views/voucher_type.py @@ -15,7 +15,10 @@ class VoucherTypeListView(ListView, WrappedView): context_object_name = "voucher_types" template_name = 'voucher_types/list.html' -PermissionDecorator('change_vouchertype', 'configuration') + @PermissionDecorator('change_vouchertype', 'configuration') + def dispatch(self, *args, **kwargs): + return super(VoucherTypeListView, self).dispatch(*args, **kwargs) + class VoucherTypeCreateView(CreateView, WrappedView): form_class = VoucherTypeForm model = VoucherType @@ -28,7 +31,11 @@ class VoucherTypeCreateView(CreateView, WrappedView): form.instance.study_id = GLOBAL_STUDY_ID return super(VoucherTypeCreateView, self).form_valid(form) -PermissionDecorator('change_vouchertype', 'configuration') + @PermissionDecorator('change_vouchertype', 'configuration') + def dispatch(self, *args, **kwargs): + return super(VoucherTypeCreateView, self).dispatch(*args, **kwargs) + +#@PermissionDecorator('change_vouchertype', 'configuration') class VoucherTypeEditView(UpdateView, WrappedView): form_class = VoucherTypeForm model = VoucherType @@ -37,3 +44,7 @@ class VoucherTypeEditView(UpdateView, WrappedView): success_message = "Voucher type edited" template_name = "voucher_types/edit.html" context_object_name = "voucher_type" + + @PermissionDecorator('change_vouchertype', 'configuration') + def dispatch(self, *args, **kwargs): + return super(VoucherTypeEditView, self).dispatch(*args, **kwargs) -- GitLab