From b16641c0dc62efe3b24fd7c27ccec51decfafa75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Thu, 15 May 2014 20:07:09 +0200 Subject: [PATCH] Renamed 'permission_required' to 'required_permission' etc. Renamed method and attribute of openslides.utils.views.PermissionMixin. Renamed attribute of widgets and main menu entries. Fixed #1160. --- CHANGELOG | 1 + openslides/agenda/main_menu.py | 2 +- openslides/agenda/views.py | 38 ++++++++++++++--------------- openslides/agenda/widgets.py | 2 +- openslides/assignment/main_menu.py | 2 +- openslides/assignment/views.py | 28 ++++++++++----------- openslides/assignment/widgets.py | 2 +- openslides/config/main_menu.py | 2 +- openslides/config/views.py | 2 +- openslides/core/main_menu.py | 2 +- openslides/core/views.py | 6 ++--- openslides/core/widgets.py | 4 +-- openslides/mediafile/views.py | 8 +++--- openslides/mediafile/widgets.py | 2 +- openslides/motion/main_menu.py | 2 +- openslides/motion/views.py | 38 ++++++++++++++--------------- openslides/motion/widgets.py | 2 +- openslides/participant/main_menu.py | 2 +- openslides/participant/views.py | 32 ++++++++++++------------ openslides/participant/widgets.py | 4 +-- openslides/projector/views.py | 12 ++++----- openslides/projector/widgets.py | 4 +-- openslides/utils/main_menu.py | 6 ++--- openslides/utils/views.py | 19 +++++++-------- openslides/utils/widgets.py | 6 ++--- tests/utils/test_views.py | 8 +++--- tests/utils/urls.py | 4 +-- 27 files changed, 120 insertions(+), 120 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5ec25703f..4d3e68750 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -39,6 +39,7 @@ Other: - Renamed config api classes. Changed permission system for config pages. - Regrouped config collections and pages. - Renamed some classes of the poll api. +- Renamed method and attribute of openslides.utils.views.PermissionMixin. - Added api for absolute urls in models. - Inserted command line option to translate config strings during database setup. - Enhanced http error pages. diff --git a/openslides/agenda/main_menu.py b/openslides/agenda/main_menu.py index 4a4324d7b..cee93ab96 100644 --- a/openslides/agenda/main_menu.py +++ b/openslides/agenda/main_menu.py @@ -10,7 +10,7 @@ class AgendaMainMenuEntry(MainMenuEntry): Main menu entry for the agenda app. """ verbose_name = ugettext_lazy('Agenda') - permission_required = 'agenda.can_see_agenda' + required_permission = 'agenda.can_see_agenda' default_weight = 20 pattern_name = 'item_overview' icon_css_class = 'icon-calendar' diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index 4af70752a..c0db84ec9 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -49,7 +49,7 @@ class Overview(TemplateView): """ Show all agenda items, and update their range via post. """ - permission_required = 'agenda.can_see_agenda' + required_permission = 'agenda.can_see_agenda' template_name = 'agenda/overview.html' def get_context_data(self, **kwargs): @@ -172,15 +172,15 @@ class AgendaItemView(SingleObjectMixin, FormView): context_object_name = 'item' form_class = AppendSpeakerForm - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): """ Checks if the user has the required permission. """ if self.get_object().type == Item.ORGANIZATIONAL_ITEM: - permission = request.user.has_perm('agenda.can_see_orga_items') + check_permission = request.user.has_perm('agenda.can_see_orga_items') else: - permission = request.user.has_perm('agenda.can_see_agenda') - return permission + check_permission = request.user.has_perm('agenda.can_see_agenda') + return check_permission def get_context_data(self, **kwargs): self.object = self.get_object() @@ -210,7 +210,7 @@ class SetClosed(RedirectView, SingleObjectMixin): """ Close or open an item. """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' allow_ajax = True url_name = 'item_overview' model = Item @@ -237,7 +237,7 @@ class ItemUpdate(UpdateView): """ Update an existing item. """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' template_name = 'agenda/edit.html' model = Item context_object_name = 'item' @@ -256,7 +256,7 @@ class ItemCreate(CreateView): """ Create a new item. """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' template_name = 'agenda/edit.html' model = Item context_object_name = 'item' @@ -269,7 +269,7 @@ class ItemDelete(DeleteView): """ Delete an item. """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' model = Item question_url_name = 'item_overview' success_url_name = 'item_overview' @@ -325,7 +325,7 @@ class CreateRelatedAgendaItemView(SingleObjectMixin, RedirectView): This view is only for subclassing in views of related apps. You have to define 'model = ....' """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' url_name = 'item_overview' url_name_args = [] @@ -344,7 +344,7 @@ class CreateRelatedAgendaItemView(SingleObjectMixin, RedirectView): class AgendaNumberingView(QuestionView): - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' question_url_name = 'item_overview' url_name = 'item_overview' question_message = ugettext_lazy('Do you really want to generate agenda numbering? Manually added item numbers will be overwritten!') @@ -363,7 +363,7 @@ class AgendaPDF(PDFView): """ Create a full agenda-PDF. """ - permission_required = 'agenda.can_see_agenda' + required_permission = 'agenda.can_see_agenda' filename = ugettext_lazy('Agenda') document_title = ugettext_lazy('Agenda') @@ -383,7 +383,7 @@ class SpeakerAppendView(SingleObjectMixin, RedirectView): """ Set the request.user to the speaker list. """ - permission_required = 'agenda.can_be_speaker' + required_permission = 'agenda.can_be_speaker' url_name = 'item_view' model = Item @@ -407,7 +407,7 @@ class SpeakerDeleteView(DeleteView): success_url_name = 'item_view' question_url_name = 'item_view' - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): """ Check the permission to delete a speaker. """ @@ -451,7 +451,7 @@ class SpeakerSpeakView(SingleObjectMixin, RedirectView): """ Mark the speaking person. """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' url_name = 'item_view' model = Item @@ -478,7 +478,7 @@ class SpeakerEndSpeachView(SingleObjectMixin, RedirectView): """ The speach of the actual speaker is finished. """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' url_name = 'item_view' model = Item @@ -504,7 +504,7 @@ class SpeakerListCloseView(SingleObjectMixin, RedirectView): """ View to close and reopen a list of speakers. """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' model = Item reopen = False url_name = 'item_view' @@ -524,7 +524,7 @@ class SpeakerChangeOrderView(SingleObjectMixin, RedirectView): Has to be called as post-request with the new order of the speaker ids. """ - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' model = Item url_name = 'item_view' @@ -772,6 +772,6 @@ class ItemCSVImportView(CSVImportView): Imports agenda items from an uploaded csv file. """ import_function = staticmethod(import_agenda_items) - permission_required = 'agenda.can_manage_agenda' + required_permission = 'agenda.can_manage_agenda' success_url_name = 'item_overview' template_name = 'agenda/item_form_csv_import.html' diff --git a/openslides/agenda/widgets.py b/openslides/agenda/widgets.py index 81eccbe1f..f3de6de6d 100644 --- a/openslides/agenda/widgets.py +++ b/openslides/agenda/widgets.py @@ -14,7 +14,7 @@ class AgendaWidget(Widget): """ name = 'agenda' verbose_name = ugettext_lazy('Agenda') - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' default_column = 1 default_weight = 20 template_name = 'agenda/widget_item.html' diff --git a/openslides/assignment/main_menu.py b/openslides/assignment/main_menu.py index 6313ab88e..b5a17393a 100644 --- a/openslides/assignment/main_menu.py +++ b/openslides/assignment/main_menu.py @@ -10,7 +10,7 @@ class AssignmentMainMenuEntry(MainMenuEntry): Main menu entry for the assignment app. """ verbose_name = ugettext_lazy('Elections') - permission_required = 'assignment.can_see_assignment' + required_permission = 'assignment.can_see_assignment' default_weight = 40 pattern_name = 'assignment_list' icon_css_class = 'icon-charts' diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 5e6e8bde4..aa35f712b 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -28,12 +28,12 @@ from .models import Assignment, AssignmentPoll class AssignmentListView(ListView): """ListView for all Assignments""" - permission_required = 'assignment.can_see_assignment' + required_permission = 'assignment.can_see_assignment' model = Assignment class AssignmentDetail(DetailView): - permission_required = 'assignment.can_see_assignment' + required_permission = 'assignment.can_see_assignment' model = Assignment form_class = AssignmentRunForm @@ -80,24 +80,24 @@ class AssignmentDetail(DetailView): class AssignmentCreateView(CreateView): model = Assignment form_class = AssignmentForm - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' class AssignmentUpdateView(UpdateView): model = Assignment form_class = AssignmentForm - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' class AssignmentDeleteView(DeleteView): - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' model = Assignment success_url_name = 'assignment_list' class AssignmentSetStatusView(SingleObjectMixin, RedirectView): model = Assignment - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' url_name = 'assignment_detail' def pre_redirect(self, *args, **kwargs): @@ -118,7 +118,7 @@ class AssignmentSetStatusView(SingleObjectMixin, RedirectView): class AssignmentRunView(SingleObjectMixin, PermissionMixin, View): model = Assignment - permission_required = 'assignment.can_nominate_self' + required_permission = 'assignment.can_nominate_self' def get(self, *args, **kwargs): assignment = self.get_object() @@ -154,7 +154,7 @@ class AssignmentRunDeleteView(SingleObjectMixin, RedirectView): class AssignmentRunOtherDeleteView(SingleObjectMixin, QuestionView): model = Assignment - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' def get_question_message(self): self._get_person_information() @@ -193,7 +193,7 @@ class AssignmentRunOtherDeleteView(SingleObjectMixin, QuestionView): class PollCreateView(SingleObjectMixin, RedirectView): model = Assignment - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' url_name = 'assignment_detail' def pre_redirect(self, *args, **kwargs): @@ -224,7 +224,7 @@ class PollUpdateView(PollFormView): class SetPublishStatusView(SingleObjectMixin, RedirectView): model = AssignmentPoll - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' url_name = 'assignment_detail' allow_ajax = True @@ -246,7 +246,7 @@ class SetPublishStatusView(SingleObjectMixin, RedirectView): class SetElectedView(SingleObjectMixin, RedirectView): model = Assignment - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' url_name = 'assignment_detail' allow_ajax = True @@ -272,7 +272,7 @@ class AssignmentPollDeleteView(DeleteView): """ Delete an assignment poll object. """ - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' model = AssignmentPoll def pre_redirect(self, request, *args, **kwargs): @@ -294,7 +294,7 @@ class AssignmentPollDeleteView(DeleteView): class AssignmentPDF(PDFView): - permission_required = 'assignment.can_see_assignment' + required_permission = 'assignment.can_see_assignment' top_space = 0 def get_filename(self): @@ -500,7 +500,7 @@ class CreateRelatedAgendaItemView(_CreateRelatedAgendaItemView): class AssignmentPollPDF(PDFView): - permission_required = 'assignment.can_manage_assignment' + required_permission = 'assignment.can_manage_assignment' top_space = 0 def get(self, request, *args, **kwargs): diff --git a/openslides/assignment/widgets.py b/openslides/assignment/widgets.py index accbe9733..c59f5aff6 100644 --- a/openslides/assignment/widgets.py +++ b/openslides/assignment/widgets.py @@ -13,7 +13,7 @@ class AssignmentWidget(Widget): """ name = 'assignment' verbose_name = ugettext_lazy('Elections') - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' default_column = 1 default_weight = 50 template_name = 'assignment/widget_assignment.html' diff --git a/openslides/config/main_menu.py b/openslides/config/main_menu.py index 220a26459..e7402ef9d 100644 --- a/openslides/config/main_menu.py +++ b/openslides/config/main_menu.py @@ -10,7 +10,7 @@ class ConfigMainMenuEntry(MainMenuEntry): Main menu entry for the config app. """ verbose_name = ugettext_lazy('Configuration') - permission_required = 'config.can_manage' + required_permission = 'config.can_manage' default_weight = 70 pattern_name = 'config_first_config_collection_view' icon_css_class = 'icon-cog' diff --git a/openslides/config/views.py b/openslides/config/views.py index bfe0f9c05..82e03dfc5 100644 --- a/openslides/config/views.py +++ b/openslides/config/views.py @@ -15,7 +15,7 @@ class ConfigView(FormView): """ The view for a config collection. """ - permission_required = 'config.can_manage' + required_permission = 'config.can_manage' template_name = 'config/config_form.html' config_collection = None form_class = forms.Form diff --git a/openslides/core/main_menu.py b/openslides/core/main_menu.py index e040ab165..3b409e5b1 100644 --- a/openslides/core/main_menu.py +++ b/openslides/core/main_menu.py @@ -10,7 +10,7 @@ class DashboardMainMenuEntry(MainMenuEntry): Main menu entry to the dashboard. """ verbose_name = ugettext_lazy('Dashboard') - permission_required = 'core.can_see_dashboard' + required_permission = 'core.can_see_dashboard' default_weight = 10 icon_css_class = 'icon-home' pattern_name = 'core_dashboard' diff --git a/openslides/core/views.py b/openslides/core/views.py index aa29fb08f..b172a4279 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -28,7 +28,7 @@ class DashboardView(utils_views.AjaxMixin, utils_views.TemplateView): Dashboard of OpenSlides. This main view uses the widget api to collect all widgets from all apps. See openslides.utils.widgets.Widget for more details. """ - permission_required = 'core.can_see_dashboard' + required_permission = 'core.can_see_dashboard' template_name = 'core/dashboard.html' def get_context_data(self, **kwargs): @@ -49,7 +49,7 @@ class SelectWidgetsView(utils_views.TemplateView): dashboard. The setting is saved in the session. """ # TODO: Use another base view class here, e. g. a FormView - permission_required = 'core.can_see_dashboard' + required_permission = 'core.can_see_dashboard' template_name = 'core/select_widgets.html' def get_context_data(self, **kwargs): @@ -187,7 +187,7 @@ class CustomSlideViewMixin(object): """ Mixin for for CustomSlide Views. """ - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' template_name = 'core/customslide_update.html' model = CustomSlide success_url_name = 'core_dashboard' diff --git a/openslides/core/widgets.py b/openslides/core/widgets.py index 17897439d..db39f39ba 100644 --- a/openslides/core/widgets.py +++ b/openslides/core/widgets.py @@ -14,7 +14,7 @@ class WelcomeWidget(Widget): Welcome widget with static info for all users. """ name = 'welcome' - permission_required = 'core.can_see_dashboard' + required_permission = 'core.can_see_dashboard' default_column = 1 default_weight = 10 template_name = 'core/widget_welcome.html' @@ -30,7 +30,7 @@ class CustonSlideWidget(Widget): """ name = 'custom_slide' verbose_name = ugettext_lazy('Custom Slides') - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' default_column = 2 default_weight = 30 template_name = 'core/widget_customslide.html' diff --git a/openslides/mediafile/views.py b/openslides/mediafile/views.py index cee2c91f6..cfe27bd24 100644 --- a/openslides/mediafile/views.py +++ b/openslides/mediafile/views.py @@ -18,7 +18,7 @@ class MediafileListView(ListView): """ model = Mediafile - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): return (request.user.has_perm('mediafile.can_see') or request.user.has_perm('mediafile.can_upload') or request.user.has_perm('mediafile.can_manage')) @@ -67,7 +67,7 @@ class MediafileCreateView(MediafileViewMixin, CreateView): """ View to upload a new file. """ - permission_required = 'mediafile.can_upload' + required_permission = 'mediafile.can_upload' def get_form_kwargs(self, *args, **kwargs): form_kwargs = super(MediafileCreateView, self).get_form_kwargs(*args, **kwargs) @@ -80,7 +80,7 @@ class MediafileUpdateView(MediafileViewMixin, UpdateView): """ View to edit the entry of an uploaded file. """ - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): return (request.user.has_perm('mediafile.can_manage') or (request.user.has_perm('mediafile.can_upload') and self.get_object().uploader == self.request.user)) @@ -97,7 +97,7 @@ class MediafileDeleteView(DeleteView): model = Mediafile success_url_name = 'mediafile_list' - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): return (request.user.has_perm('mediafile.can_manage') or (request.user.has_perm('mediafile.can_upload') and self.get_object().uploader == self.request.user)) diff --git a/openslides/mediafile/widgets.py b/openslides/mediafile/widgets.py index b1a0d4011..a7ba64b59 100644 --- a/openslides/mediafile/widgets.py +++ b/openslides/mediafile/widgets.py @@ -14,7 +14,7 @@ class PDFPresentationWidget(Widget): """ name = 'presentations' verbose_name = ugettext_lazy('Presentations') - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' default_column = 1 default_weight = 75 template_name = 'mediafile/widget_pdfpresentation.html' diff --git a/openslides/motion/main_menu.py b/openslides/motion/main_menu.py index 05bbd9c4b..e84e64c57 100644 --- a/openslides/motion/main_menu.py +++ b/openslides/motion/main_menu.py @@ -10,7 +10,7 @@ class MotionMainMenuEntry(MainMenuEntry): Main menu entry for the motion app. """ verbose_name = ugettext_lazy('Motions') - permission_required = 'motion.can_see_motion' + required_permission = 'motion.can_see_motion' default_weight = 30 pattern_name = 'motion_list' icon_css_class = 'icon-file' diff --git a/openslides/motion/views.py b/openslides/motion/views.py index 7b1432780..9baacfbd1 100644 --- a/openslides/motion/views.py +++ b/openslides/motion/views.py @@ -31,7 +31,7 @@ class MotionListView(ListView): """ View, to list all motions. """ - permission_required = 'motion.can_see_motion' + required_permission = 'motion.can_see_motion' model = Motion motion_list = MotionListView.as_view() @@ -41,7 +41,7 @@ class MotionDetailView(DetailView): """ Show one motion. """ - permission_required = 'motion.can_see_motion' + required_permission = 'motion.can_see_motion' model = Motion def get_context_data(self, **kwargs): @@ -163,7 +163,7 @@ class MotionCreateView(MotionEditMixin, CreateView): """ model = Motion - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): """ Checks whether the requesting user can submit a new motion. He needs at least the permission 'motion.can_create_motion'. If the submitting @@ -210,7 +210,7 @@ class MotionUpdateView(MotionEditMixin, UpdateView): """ model = Motion - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): """ Check if the request.user has the permission to edit the motion. """ @@ -279,7 +279,7 @@ class MotionDeleteView(DeleteView): model = Motion success_url_name = 'motion_list' - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): """ Check if the request.user has the permission to delete the motion. """ @@ -296,7 +296,7 @@ class VersionDeleteView(DeleteView): View to delete a motion version. """ model = MotionVersion - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' success_url_name = 'motion_detail' def get_object(self): @@ -326,7 +326,7 @@ class VersionPermitView(SingleObjectMixin, QuestionView): """ model = Motion final_message = ugettext_lazy('Version successfully permitted.') - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' question_url_name = 'motion_version_detail' def get(self, *args, **kwargs): @@ -372,7 +372,7 @@ class VersionDiffView(DetailView): """ Show diff between two versions of a motion. """ - permission_required = 'motion.can_see_motion' + required_permission = 'motion.can_see_motion' model = Motion template_name = 'motion/motion_diff.html' @@ -414,7 +414,7 @@ class SupportView(SingleObjectMixin, QuestionView): If self.support is False, the view will remove a request.user from the supporter list. """ - permission_required = 'motion.can_support_motion' + required_permission = 'motion.can_support_motion' model = Motion support = True @@ -481,7 +481,7 @@ class PollCreateView(SingleObjectMixin, RedirectView): """ View to create a poll for a motion. """ - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' model = Motion url_name = 'motionpoll_detail' @@ -514,7 +514,7 @@ class PollMixin(object): Mixin for the PollUpdateView and the PollDeleteView. """ - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' success_url_name = 'motion_detail' def get_object(self): @@ -598,7 +598,7 @@ class PollPDFView(PollMixin, PDFView): Generates a ballotpaper. """ - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' top_space = 0 def get(self, *args, **kwargs): @@ -635,7 +635,7 @@ class MotionSetStateView(SingleObjectMixin, RedirectView): If self.reset is False, the new state is taken from url. If self.reset is True, the default state is taken. """ - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' url_name = 'motion_detail' model = Motion reset = False @@ -694,7 +694,7 @@ class MotionPDFView(SingleObjectMixin, PDFView): If self.print_all_motions is False, the view returns a PDF with only one motion. """ - permission_required = 'motion.can_see_motion' + required_permission = 'motion.can_see_motion' model = Motion top_space = 0 print_all_motions = False @@ -735,14 +735,14 @@ motion_detail_pdf = MotionPDFView.as_view(print_all_motions=False) class CategoryListView(ListView): - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' model = Category category_list = CategoryListView.as_view() class CategoryCreateView(CreateView): - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' model = Category success_url_name = 'motion_category_list' url_name_args = [] @@ -751,7 +751,7 @@ category_create = CategoryCreateView.as_view() class CategoryUpdateView(UpdateView): - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' model = Category success_url_name = 'motion_category_list' url_name_args = [] @@ -760,7 +760,7 @@ category_update = CategoryUpdateView.as_view() class CategoryDeleteView(DeleteView): - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' model = Category question_url_name = 'motion_category_list' url_name_args = [] @@ -774,7 +774,7 @@ class MotionCSVImportView(CSVImportView): Imports motions from an uploaded csv file. """ form_class = MotionCSVImportForm - permission_required = 'motion.can_manage_motion' + required_permission = 'motion.can_manage_motion' success_url_name = 'motion_list' template_name = 'motion/motion_form_csv_import.html' diff --git a/openslides/motion/widgets.py b/openslides/motion/widgets.py index 73eb42c93..3873f3bd5 100644 --- a/openslides/motion/widgets.py +++ b/openslides/motion/widgets.py @@ -13,7 +13,7 @@ class MotionWidget(Widget): """ name = 'motion' verbose_name = ugettext_lazy('Motions') - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' default_column = 1 default_weight = 40 icon_css_class = 'icon-file' diff --git a/openslides/participant/main_menu.py b/openslides/participant/main_menu.py index 443588563..f6d5e0818 100644 --- a/openslides/participant/main_menu.py +++ b/openslides/participant/main_menu.py @@ -10,7 +10,7 @@ class ParticipantMainMenuEntry(MainMenuEntry): Main menu entry for the participant app. """ verbose_name = ugettext_lazy('Participants') - permission_required = 'participant.can_see_participant' + required_permission = 'participant.can_see_participant' default_weight = 50 pattern_name = 'user_overview' icon_css_class = 'icon-user' diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 330462637..aa02bbfad 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -30,7 +30,7 @@ class UserOverview(ListView): """ Show all participants (users). """ - permission_required = 'participant.can_see_participant' + required_permission = 'participant.can_see_participant' template_name = 'participant/overview.html' context_object_name = 'users' @@ -56,7 +56,7 @@ class UserDetailView(DetailView, PermissionMixin): """ Classed based view to show a specific user in the interface. """ - permission_required = 'participant.can_see_participant' + required_permission = 'participant.can_see_participant' model = User template_name = 'participant/user_detail.html' context_object_name = 'shown_user' @@ -66,7 +66,7 @@ class UserCreateView(CreateView): """ Create a new participant. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' template_name = 'participant/edit.html' model = User context_object_name = 'edit_user' @@ -97,7 +97,7 @@ class UserMultipleCreateView(FormView): """ View to create multiple users at once using a big text field. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' template_name = 'participant/user_form_multiple.html' form_class = UserMultipleCreateForm success_url_name = 'user_overview' @@ -124,7 +124,7 @@ class UserUpdateView(UpdateView): """ Update an existing participant. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' template_name = 'participant/edit.html' model = User context_object_name = 'edit_user' @@ -156,7 +156,7 @@ class UserDeleteView(DeleteView): """ Delete an participant. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' model = User success_url_name = 'user_overview' url_name_args = [] @@ -178,7 +178,7 @@ class SetUserStatusView(SingleObjectMixin, RedirectView): """ Activate or deactivate an user. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' allow_ajax = True url_name = 'user_overview' url_name_args = [] @@ -209,7 +209,7 @@ class ParticipantsListPDF(PDFView): """ Generate the userliste as PDF. """ - permission_required = 'participant.can_see_participant' + required_permission = 'participant.can_see_participant' filename = ugettext_lazy("Participant-list") document_title = ugettext_lazy('List of Participants') @@ -224,7 +224,7 @@ class ParticipantsPasswordsPDF(PDFView): """ Generate the access data welcome paper for all participants as PDF. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' filename = ugettext_lazy("Participant-access-data") top_space = 0 @@ -243,7 +243,7 @@ class UserCSVImportView(CSVImportView): Import users via CSV. """ import_function = staticmethod(import_users) - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' success_url_name = 'user_overview' template_name = 'participant/user_form_csv_import.html' @@ -252,7 +252,7 @@ class ResetPasswordView(SingleObjectMixin, QuestionView): """ Set the Passwort for a user to his default password. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' model = User allow_ajax = True question_message = ugettext_lazy('Do you really want to reset the password?') @@ -275,7 +275,7 @@ class GroupOverview(ListView): """ Overview over all groups. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' template_name = 'participant/group_overview.html' context_object_name = 'groups' model = Group @@ -285,7 +285,7 @@ class GroupDetailView(DetailView, PermissionMixin): """ Classed based view to show a specific group in the interface. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' model = Group template_name = 'participant/group_detail.html' context_object_name = 'group' @@ -305,7 +305,7 @@ class GroupCreateView(CreateView): """ Create a new group. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' template_name = 'participant/group_edit.html' context_object_name = 'group' model = Group @@ -322,7 +322,7 @@ class GroupUpdateView(UpdateView): """ Update an existing group. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' template_name = 'participant/group_edit.html' model = Group context_object_name = 'group' @@ -344,7 +344,7 @@ class GroupDeleteView(DeleteView): """ Delete a group. """ - permission_required = 'participant.can_manage_participant' + required_permission = 'participant.can_manage_participant' model = Group success_url_name = 'user_group_overview' url_name_args = [] diff --git a/openslides/participant/widgets.py b/openslides/participant/widgets.py index d5f8f2fa4..65b6879a7 100644 --- a/openslides/participant/widgets.py +++ b/openslides/participant/widgets.py @@ -14,7 +14,7 @@ class UserWidget(Widget): """ name = 'user' verbose_name = ugettext_lazy('Participants') - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' default_column = 1 default_weight = 60 default_active = False @@ -34,7 +34,7 @@ class GroupWidget(Widget): """ name = 'group' verbose_name = ugettext_lazy('Groups') - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' default_column = 1 default_weight = 70 default_active = False diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 945004223..8bcb59437 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -15,7 +15,7 @@ class ProjectorView(TemplateView): """ The Projector-Page. """ - permission_required = 'core.can_see_projector' + required_permission = 'core.can_see_projector' template_name = 'projector.html' def get_context_data(self, **kwargs): @@ -43,7 +43,7 @@ class ActivateView(RedirectView): """ Activate a Slide. """ - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' url_name = 'core_dashboard' allow_ajax = True @@ -68,7 +68,7 @@ class ProjectorControllView(RedirectView): """ Scale or scroll the projector. """ - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' url_name = 'core_dashboard' allow_ajax = True @@ -102,7 +102,7 @@ class CountdownControllView(RedirectView): """ Start, stop or reset the countdown. """ - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' url_name = 'core_dashboard' allow_ajax = True @@ -137,7 +137,7 @@ class OverlayMessageView(RedirectView): """ url_name = 'core_dashboard' allow_ajax = True - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' def pre_post_redirect(self, request, *args, **kwargs): if 'message' in request.POST: @@ -158,7 +158,7 @@ class ActivateOverlay(RedirectView): """ url_name = 'core_dashboard' allow_ajax = True - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' def pre_redirect(self, request, *args, **kwargs): overlay = get_overlays()[kwargs['name']] diff --git a/openslides/projector/widgets.py b/openslides/projector/widgets.py index c9de0dbd1..707567134 100644 --- a/openslides/projector/widgets.py +++ b/openslides/projector/widgets.py @@ -14,7 +14,7 @@ class ProjectorLiveWidget(Widget): """ name = 'live_view' verbose_name = ugettext_lazy('Projector live view') - permission_required = 'core.can_see_projector' + required_permission = 'core.can_see_projector' default_column = 2 default_weight = 10 template_name = 'projector/widget_live_view.html' @@ -27,7 +27,7 @@ class OverlayWidget(Widget): """ name = 'overlays' # TODO: Use singular here verbose_name = ugettext_lazy('Overlays') - permission_required = 'core.can_manage_projector' + required_permission = 'core.can_manage_projector' default_column = 2 default_weight = 20 template_name = 'projector/widget_overlay.html' diff --git a/openslides/utils/main_menu.py b/openslides/utils/main_menu.py index 49df3078a..90a3fcb2b 100644 --- a/openslides/utils/main_menu.py +++ b/openslides/utils/main_menu.py @@ -18,14 +18,14 @@ class MainMenuEntry(object): magic. For the appearance there are some optional attributes and methods like - permission_required, default_weight, stylesheets, javascript_files, + required_permission, default_weight, stylesheets, javascript_files, check_permission, get_url, get_default_weight, get_icon_css_class, get_stylesheets and get_javascript_files. """ __metaclass__ = SignalConnectMetaClass signal = Signal(providing_args=['request']) verbose_name = None - permission_required = None + required_permission = None default_weight = 0 pattern_name = None icon_css_class = 'icon-home' @@ -63,7 +63,7 @@ class MainMenuEntry(object): """ Returns True if the request user is allowed to see the entry. """ - return self.permission_required is None or self.request.user.has_perm(self.permission_required) + return self.required_permission is None or self.request.user.has_perm(self.required_permission) def get_icon_css_class(self): """ diff --git a/openslides/utils/views.py b/openslides/utils/views.py index 87cda5e07..36be0eb21 100644 --- a/openslides/utils/views.py +++ b/openslides/utils/views.py @@ -24,8 +24,6 @@ from .pdf import firstPage, laterPages from .signals import template_manipulation from .utils import html_strong -NO_PERMISSION_REQUIRED = 'No permission required' - View = django_views.View @@ -44,21 +42,22 @@ class LoginMixin(object): class PermissionMixin(object): """ - Mixin for views, that only can be visited from users with special rights. + Mixin for views, that only can be visited from users with special + permissions. - Set the attribute 'permission_required' to the required permission string. + Set the attribute 'required_permission' to the required permission + string or override the method 'check_permission'. """ - permission_required = NO_PERMISSION_REQUIRED + required_permission = None - # TODO: Rename this to check_permission - def has_permission(self, request, *args, **kwargs): + def check_permission(self, request, *args, **kwargs): """ Checks if the user has the required permission. """ - if self.permission_required == NO_PERMISSION_REQUIRED: + if self.required_permission is None: return True else: - return request.user.has_perm(self.permission_required) + return request.user.has_perm(self.required_permission) def dispatch(self, request, *args, **kwargs): """ @@ -66,7 +65,7 @@ class PermissionMixin(object): If the user is not logged in, redirect the user to the login page. """ - if not self.has_permission(request, *args, **kwargs): + if not self.check_permission(request, *args, **kwargs): if not request.user.is_authenticated(): path = request.get_full_path() return HttpResponseRedirect( diff --git a/openslides/utils/widgets.py b/openslides/utils/widgets.py index 620ed1a01..115c49a83 100644 --- a/openslides/utils/widgets.py +++ b/openslides/utils/widgets.py @@ -18,7 +18,7 @@ class Widget(object): (SignalConnectMetaClass) does the rest of the magic. For the appearance of the widget there are some attributes and methods - like verbose_name, permission_required, default_column, default_weight, + like verbose_name, required_permission, default_column, default_weight, default_active, template_name, context, icon_css_class, more_link_pattern_name, stylesheets, javascript_files, get_verbose_name, check_permission, get_html, get_context_data, @@ -29,7 +29,7 @@ class Widget(object): signal = Signal(providing_args=['request']) name = None verbose_name = None - permission_required = None + required_permission = None default_column = 1 default_weight = 0 default_active = True @@ -77,7 +77,7 @@ class Widget(object): """ Returns True if the request user is allowed to see the widget. """ - return self.permission_required is None or self.request.user.has_perm(self.permission_required) + return self.required_permission is None or self.request.user.has_perm(self.required_permission) def is_active(self): """ diff --git a/tests/utils/test_views.py b/tests/utils/test_views.py index 55ab9ab17..fe468538c 100644 --- a/tests/utils/test_views.py +++ b/tests/utils/test_views.py @@ -40,22 +40,22 @@ class PermissionMixinTest(ViewTestCase): def test_dispatch(self): client = Client() - # View without permission_required + # View without required_permission response = client.get('/permission_mixin1/') self.assertEqual(response.status_code, 200) self.assertEqual(response.content, 'Well done.') - # View with permission_required without login + # View with required_permission without login response = client.get('/permission_mixin2/') self.assertEqual(response.status_code, 302) self.assertEqual(response['Location'], 'http://testserver/login/?next=/permission_mixin2/') - # View with permission_required, with login, without permission + # View with required_permission, with login, without permission client.login(username='admin', password='admin') response = client.get('/permission_mixin2/') self.assertEqual(response.status_code, 403) - # View with permission_required, with login, with permission + # View with required_permission, with login, with permission response = client.get('/permission_mixin3/') self.assertEqual(response.status_code, 200) diff --git a/tests/utils/urls.py b/tests/utils/urls.py index 83b0e55d3..c31d30303 100644 --- a/tests/utils/urls.py +++ b/tests/utils/urls.py @@ -24,8 +24,8 @@ urlpatterns += patterns( views.PermissionMixinView.as_view()), url(r'^permission_mixin2/$', - views.PermissionMixinView.as_view(permission_required='permission_string')), + views.PermissionMixinView.as_view(required_permission='permission_string')), url(r'^permission_mixin3/$', - views.PermissionMixinView.as_view(permission_required='agenda.can_see_agenda')), + views.PermissionMixinView.as_view(required_permission='agenda.can_see_agenda')), )