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.
This commit is contained in:
Norman Jäckel 2014-05-15 20:07:09 +02:00
parent 2cd0a2007d
commit b16641c0dc
27 changed files with 120 additions and 120 deletions

View File

@ -39,6 +39,7 @@ Other:
- Renamed config api classes. Changed permission system for config pages. - Renamed config api classes. Changed permission system for config pages.
- Regrouped config collections and pages. - Regrouped config collections and pages.
- Renamed some classes of the poll api. - Renamed some classes of the poll api.
- Renamed method and attribute of openslides.utils.views.PermissionMixin.
- Added api for absolute urls in models. - Added api for absolute urls in models.
- Inserted command line option to translate config strings during database setup. - Inserted command line option to translate config strings during database setup.
- Enhanced http error pages. - Enhanced http error pages.

View File

@ -10,7 +10,7 @@ class AgendaMainMenuEntry(MainMenuEntry):
Main menu entry for the agenda app. Main menu entry for the agenda app.
""" """
verbose_name = ugettext_lazy('Agenda') verbose_name = ugettext_lazy('Agenda')
permission_required = 'agenda.can_see_agenda' required_permission = 'agenda.can_see_agenda'
default_weight = 20 default_weight = 20
pattern_name = 'item_overview' pattern_name = 'item_overview'
icon_css_class = 'icon-calendar' icon_css_class = 'icon-calendar'

View File

@ -49,7 +49,7 @@ class Overview(TemplateView):
""" """
Show all agenda items, and update their range via post. 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' template_name = 'agenda/overview.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -172,15 +172,15 @@ class AgendaItemView(SingleObjectMixin, FormView):
context_object_name = 'item' context_object_name = 'item'
form_class = AppendSpeakerForm 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. Checks if the user has the required permission.
""" """
if self.get_object().type == Item.ORGANIZATIONAL_ITEM: 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: else:
permission = request.user.has_perm('agenda.can_see_agenda') check_permission = request.user.has_perm('agenda.can_see_agenda')
return permission return check_permission
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
self.object = self.get_object() self.object = self.get_object()
@ -210,7 +210,7 @@ class SetClosed(RedirectView, SingleObjectMixin):
""" """
Close or open an item. Close or open an item.
""" """
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
allow_ajax = True allow_ajax = True
url_name = 'item_overview' url_name = 'item_overview'
model = Item model = Item
@ -237,7 +237,7 @@ class ItemUpdate(UpdateView):
""" """
Update an existing item. Update an existing item.
""" """
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
template_name = 'agenda/edit.html' template_name = 'agenda/edit.html'
model = Item model = Item
context_object_name = 'item' context_object_name = 'item'
@ -256,7 +256,7 @@ class ItemCreate(CreateView):
""" """
Create a new item. Create a new item.
""" """
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
template_name = 'agenda/edit.html' template_name = 'agenda/edit.html'
model = Item model = Item
context_object_name = 'item' context_object_name = 'item'
@ -269,7 +269,7 @@ class ItemDelete(DeleteView):
""" """
Delete an item. Delete an item.
""" """
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
model = Item model = Item
question_url_name = 'item_overview' question_url_name = 'item_overview'
success_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 This view is only for subclassing in views of related apps. You
have to define 'model = ....' have to define 'model = ....'
""" """
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
url_name = 'item_overview' url_name = 'item_overview'
url_name_args = [] url_name_args = []
@ -344,7 +344,7 @@ class CreateRelatedAgendaItemView(SingleObjectMixin, RedirectView):
class AgendaNumberingView(QuestionView): class AgendaNumberingView(QuestionView):
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
question_url_name = 'item_overview' question_url_name = 'item_overview'
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!') 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. Create a full agenda-PDF.
""" """
permission_required = 'agenda.can_see_agenda' required_permission = 'agenda.can_see_agenda'
filename = ugettext_lazy('Agenda') filename = ugettext_lazy('Agenda')
document_title = ugettext_lazy('Agenda') document_title = ugettext_lazy('Agenda')
@ -383,7 +383,7 @@ class SpeakerAppendView(SingleObjectMixin, RedirectView):
""" """
Set the request.user to the speaker list. Set the request.user to the speaker list.
""" """
permission_required = 'agenda.can_be_speaker' required_permission = 'agenda.can_be_speaker'
url_name = 'item_view' url_name = 'item_view'
model = Item model = Item
@ -407,7 +407,7 @@ class SpeakerDeleteView(DeleteView):
success_url_name = 'item_view' success_url_name = 'item_view'
question_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. Check the permission to delete a speaker.
""" """
@ -451,7 +451,7 @@ class SpeakerSpeakView(SingleObjectMixin, RedirectView):
""" """
Mark the speaking person. Mark the speaking person.
""" """
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
url_name = 'item_view' url_name = 'item_view'
model = Item model = Item
@ -478,7 +478,7 @@ class SpeakerEndSpeachView(SingleObjectMixin, RedirectView):
""" """
The speach of the actual speaker is finished. The speach of the actual speaker is finished.
""" """
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
url_name = 'item_view' url_name = 'item_view'
model = Item model = Item
@ -504,7 +504,7 @@ class SpeakerListCloseView(SingleObjectMixin, RedirectView):
""" """
View to close and reopen a list of speakers. View to close and reopen a list of speakers.
""" """
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
model = Item model = Item
reopen = False reopen = False
url_name = 'item_view' 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. 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 model = Item
url_name = 'item_view' url_name = 'item_view'
@ -772,6 +772,6 @@ class ItemCSVImportView(CSVImportView):
Imports agenda items from an uploaded csv file. Imports agenda items from an uploaded csv file.
""" """
import_function = staticmethod(import_agenda_items) import_function = staticmethod(import_agenda_items)
permission_required = 'agenda.can_manage_agenda' required_permission = 'agenda.can_manage_agenda'
success_url_name = 'item_overview' success_url_name = 'item_overview'
template_name = 'agenda/item_form_csv_import.html' template_name = 'agenda/item_form_csv_import.html'

View File

@ -14,7 +14,7 @@ class AgendaWidget(Widget):
""" """
name = 'agenda' name = 'agenda'
verbose_name = ugettext_lazy('Agenda') verbose_name = ugettext_lazy('Agenda')
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
default_column = 1 default_column = 1
default_weight = 20 default_weight = 20
template_name = 'agenda/widget_item.html' template_name = 'agenda/widget_item.html'

View File

@ -10,7 +10,7 @@ class AssignmentMainMenuEntry(MainMenuEntry):
Main menu entry for the assignment app. Main menu entry for the assignment app.
""" """
verbose_name = ugettext_lazy('Elections') verbose_name = ugettext_lazy('Elections')
permission_required = 'assignment.can_see_assignment' required_permission = 'assignment.can_see_assignment'
default_weight = 40 default_weight = 40
pattern_name = 'assignment_list' pattern_name = 'assignment_list'
icon_css_class = 'icon-charts' icon_css_class = 'icon-charts'

View File

@ -28,12 +28,12 @@ from .models import Assignment, AssignmentPoll
class AssignmentListView(ListView): class AssignmentListView(ListView):
"""ListView for all Assignments""" """ListView for all Assignments"""
permission_required = 'assignment.can_see_assignment' required_permission = 'assignment.can_see_assignment'
model = Assignment model = Assignment
class AssignmentDetail(DetailView): class AssignmentDetail(DetailView):
permission_required = 'assignment.can_see_assignment' required_permission = 'assignment.can_see_assignment'
model = Assignment model = Assignment
form_class = AssignmentRunForm form_class = AssignmentRunForm
@ -80,24 +80,24 @@ class AssignmentDetail(DetailView):
class AssignmentCreateView(CreateView): class AssignmentCreateView(CreateView):
model = Assignment model = Assignment
form_class = AssignmentForm form_class = AssignmentForm
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
class AssignmentUpdateView(UpdateView): class AssignmentUpdateView(UpdateView):
model = Assignment model = Assignment
form_class = AssignmentForm form_class = AssignmentForm
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
class AssignmentDeleteView(DeleteView): class AssignmentDeleteView(DeleteView):
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
model = Assignment model = Assignment
success_url_name = 'assignment_list' success_url_name = 'assignment_list'
class AssignmentSetStatusView(SingleObjectMixin, RedirectView): class AssignmentSetStatusView(SingleObjectMixin, RedirectView):
model = Assignment model = Assignment
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
url_name = 'assignment_detail' url_name = 'assignment_detail'
def pre_redirect(self, *args, **kwargs): def pre_redirect(self, *args, **kwargs):
@ -118,7 +118,7 @@ class AssignmentSetStatusView(SingleObjectMixin, RedirectView):
class AssignmentRunView(SingleObjectMixin, PermissionMixin, View): class AssignmentRunView(SingleObjectMixin, PermissionMixin, View):
model = Assignment model = Assignment
permission_required = 'assignment.can_nominate_self' required_permission = 'assignment.can_nominate_self'
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
assignment = self.get_object() assignment = self.get_object()
@ -154,7 +154,7 @@ class AssignmentRunDeleteView(SingleObjectMixin, RedirectView):
class AssignmentRunOtherDeleteView(SingleObjectMixin, QuestionView): class AssignmentRunOtherDeleteView(SingleObjectMixin, QuestionView):
model = Assignment model = Assignment
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
def get_question_message(self): def get_question_message(self):
self._get_person_information() self._get_person_information()
@ -193,7 +193,7 @@ class AssignmentRunOtherDeleteView(SingleObjectMixin, QuestionView):
class PollCreateView(SingleObjectMixin, RedirectView): class PollCreateView(SingleObjectMixin, RedirectView):
model = Assignment model = Assignment
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
url_name = 'assignment_detail' url_name = 'assignment_detail'
def pre_redirect(self, *args, **kwargs): def pre_redirect(self, *args, **kwargs):
@ -224,7 +224,7 @@ class PollUpdateView(PollFormView):
class SetPublishStatusView(SingleObjectMixin, RedirectView): class SetPublishStatusView(SingleObjectMixin, RedirectView):
model = AssignmentPoll model = AssignmentPoll
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
url_name = 'assignment_detail' url_name = 'assignment_detail'
allow_ajax = True allow_ajax = True
@ -246,7 +246,7 @@ class SetPublishStatusView(SingleObjectMixin, RedirectView):
class SetElectedView(SingleObjectMixin, RedirectView): class SetElectedView(SingleObjectMixin, RedirectView):
model = Assignment model = Assignment
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
url_name = 'assignment_detail' url_name = 'assignment_detail'
allow_ajax = True allow_ajax = True
@ -272,7 +272,7 @@ class AssignmentPollDeleteView(DeleteView):
""" """
Delete an assignment poll object. Delete an assignment poll object.
""" """
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
model = AssignmentPoll model = AssignmentPoll
def pre_redirect(self, request, *args, **kwargs): def pre_redirect(self, request, *args, **kwargs):
@ -294,7 +294,7 @@ class AssignmentPollDeleteView(DeleteView):
class AssignmentPDF(PDFView): class AssignmentPDF(PDFView):
permission_required = 'assignment.can_see_assignment' required_permission = 'assignment.can_see_assignment'
top_space = 0 top_space = 0
def get_filename(self): def get_filename(self):
@ -500,7 +500,7 @@ class CreateRelatedAgendaItemView(_CreateRelatedAgendaItemView):
class AssignmentPollPDF(PDFView): class AssignmentPollPDF(PDFView):
permission_required = 'assignment.can_manage_assignment' required_permission = 'assignment.can_manage_assignment'
top_space = 0 top_space = 0
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):

View File

@ -13,7 +13,7 @@ class AssignmentWidget(Widget):
""" """
name = 'assignment' name = 'assignment'
verbose_name = ugettext_lazy('Elections') verbose_name = ugettext_lazy('Elections')
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
default_column = 1 default_column = 1
default_weight = 50 default_weight = 50
template_name = 'assignment/widget_assignment.html' template_name = 'assignment/widget_assignment.html'

View File

@ -10,7 +10,7 @@ class ConfigMainMenuEntry(MainMenuEntry):
Main menu entry for the config app. Main menu entry for the config app.
""" """
verbose_name = ugettext_lazy('Configuration') verbose_name = ugettext_lazy('Configuration')
permission_required = 'config.can_manage' required_permission = 'config.can_manage'
default_weight = 70 default_weight = 70
pattern_name = 'config_first_config_collection_view' pattern_name = 'config_first_config_collection_view'
icon_css_class = 'icon-cog' icon_css_class = 'icon-cog'

View File

@ -15,7 +15,7 @@ class ConfigView(FormView):
""" """
The view for a config collection. The view for a config collection.
""" """
permission_required = 'config.can_manage' required_permission = 'config.can_manage'
template_name = 'config/config_form.html' template_name = 'config/config_form.html'
config_collection = None config_collection = None
form_class = forms.Form form_class = forms.Form

View File

@ -10,7 +10,7 @@ class DashboardMainMenuEntry(MainMenuEntry):
Main menu entry to the dashboard. Main menu entry to the dashboard.
""" """
verbose_name = ugettext_lazy('Dashboard') verbose_name = ugettext_lazy('Dashboard')
permission_required = 'core.can_see_dashboard' required_permission = 'core.can_see_dashboard'
default_weight = 10 default_weight = 10
icon_css_class = 'icon-home' icon_css_class = 'icon-home'
pattern_name = 'core_dashboard' pattern_name = 'core_dashboard'

View File

@ -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 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. 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' template_name = 'core/dashboard.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -49,7 +49,7 @@ class SelectWidgetsView(utils_views.TemplateView):
dashboard. The setting is saved in the session. dashboard. The setting is saved in the session.
""" """
# TODO: Use another base view class here, e. g. a FormView # 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' template_name = 'core/select_widgets.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -187,7 +187,7 @@ class CustomSlideViewMixin(object):
""" """
Mixin for for CustomSlide Views. Mixin for for CustomSlide Views.
""" """
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
template_name = 'core/customslide_update.html' template_name = 'core/customslide_update.html'
model = CustomSlide model = CustomSlide
success_url_name = 'core_dashboard' success_url_name = 'core_dashboard'

View File

@ -14,7 +14,7 @@ class WelcomeWidget(Widget):
Welcome widget with static info for all users. Welcome widget with static info for all users.
""" """
name = 'welcome' name = 'welcome'
permission_required = 'core.can_see_dashboard' required_permission = 'core.can_see_dashboard'
default_column = 1 default_column = 1
default_weight = 10 default_weight = 10
template_name = 'core/widget_welcome.html' template_name = 'core/widget_welcome.html'
@ -30,7 +30,7 @@ class CustonSlideWidget(Widget):
""" """
name = 'custom_slide' name = 'custom_slide'
verbose_name = ugettext_lazy('Custom Slides') verbose_name = ugettext_lazy('Custom Slides')
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
default_column = 2 default_column = 2
default_weight = 30 default_weight = 30
template_name = 'core/widget_customslide.html' template_name = 'core/widget_customslide.html'

View File

@ -18,7 +18,7 @@ class MediafileListView(ListView):
""" """
model = Mediafile 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 return (request.user.has_perm('mediafile.can_see') or
request.user.has_perm('mediafile.can_upload') or request.user.has_perm('mediafile.can_upload') or
request.user.has_perm('mediafile.can_manage')) request.user.has_perm('mediafile.can_manage'))
@ -67,7 +67,7 @@ class MediafileCreateView(MediafileViewMixin, CreateView):
""" """
View to upload a new file. View to upload a new file.
""" """
permission_required = 'mediafile.can_upload' required_permission = 'mediafile.can_upload'
def get_form_kwargs(self, *args, **kwargs): def get_form_kwargs(self, *args, **kwargs):
form_kwargs = super(MediafileCreateView, self).get_form_kwargs(*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. 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 return (request.user.has_perm('mediafile.can_manage') or
(request.user.has_perm('mediafile.can_upload') and self.get_object().uploader == self.request.user)) (request.user.has_perm('mediafile.can_upload') and self.get_object().uploader == self.request.user))
@ -97,7 +97,7 @@ class MediafileDeleteView(DeleteView):
model = Mediafile model = Mediafile
success_url_name = 'mediafile_list' 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 return (request.user.has_perm('mediafile.can_manage') or
(request.user.has_perm('mediafile.can_upload') and self.get_object().uploader == self.request.user)) (request.user.has_perm('mediafile.can_upload') and self.get_object().uploader == self.request.user))

View File

@ -14,7 +14,7 @@ class PDFPresentationWidget(Widget):
""" """
name = 'presentations' name = 'presentations'
verbose_name = ugettext_lazy('Presentations') verbose_name = ugettext_lazy('Presentations')
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
default_column = 1 default_column = 1
default_weight = 75 default_weight = 75
template_name = 'mediafile/widget_pdfpresentation.html' template_name = 'mediafile/widget_pdfpresentation.html'

View File

@ -10,7 +10,7 @@ class MotionMainMenuEntry(MainMenuEntry):
Main menu entry for the motion app. Main menu entry for the motion app.
""" """
verbose_name = ugettext_lazy('Motions') verbose_name = ugettext_lazy('Motions')
permission_required = 'motion.can_see_motion' required_permission = 'motion.can_see_motion'
default_weight = 30 default_weight = 30
pattern_name = 'motion_list' pattern_name = 'motion_list'
icon_css_class = 'icon-file' icon_css_class = 'icon-file'

View File

@ -31,7 +31,7 @@ class MotionListView(ListView):
""" """
View, to list all motions. View, to list all motions.
""" """
permission_required = 'motion.can_see_motion' required_permission = 'motion.can_see_motion'
model = Motion model = Motion
motion_list = MotionListView.as_view() motion_list = MotionListView.as_view()
@ -41,7 +41,7 @@ class MotionDetailView(DetailView):
""" """
Show one motion. Show one motion.
""" """
permission_required = 'motion.can_see_motion' required_permission = 'motion.can_see_motion'
model = Motion model = Motion
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -163,7 +163,7 @@ class MotionCreateView(MotionEditMixin, CreateView):
""" """
model = Motion 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 Checks whether the requesting user can submit a new motion. He needs
at least the permission 'motion.can_create_motion'. If the submitting at least the permission 'motion.can_create_motion'. If the submitting
@ -210,7 +210,7 @@ class MotionUpdateView(MotionEditMixin, UpdateView):
""" """
model = Motion 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. Check if the request.user has the permission to edit the motion.
""" """
@ -279,7 +279,7 @@ class MotionDeleteView(DeleteView):
model = Motion model = Motion
success_url_name = 'motion_list' 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. 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. View to delete a motion version.
""" """
model = MotionVersion model = MotionVersion
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
success_url_name = 'motion_detail' success_url_name = 'motion_detail'
def get_object(self): def get_object(self):
@ -326,7 +326,7 @@ class VersionPermitView(SingleObjectMixin, QuestionView):
""" """
model = Motion model = Motion
final_message = ugettext_lazy('Version successfully permitted.') 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' question_url_name = 'motion_version_detail'
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
@ -372,7 +372,7 @@ class VersionDiffView(DetailView):
""" """
Show diff between two versions of a motion. Show diff between two versions of a motion.
""" """
permission_required = 'motion.can_see_motion' required_permission = 'motion.can_see_motion'
model = Motion model = Motion
template_name = 'motion/motion_diff.html' 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. 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 model = Motion
support = True support = True
@ -481,7 +481,7 @@ class PollCreateView(SingleObjectMixin, RedirectView):
""" """
View to create a poll for a motion. View to create a poll for a motion.
""" """
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
model = Motion model = Motion
url_name = 'motionpoll_detail' url_name = 'motionpoll_detail'
@ -514,7 +514,7 @@ class PollMixin(object):
Mixin for the PollUpdateView and the PollDeleteView. Mixin for the PollUpdateView and the PollDeleteView.
""" """
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
success_url_name = 'motion_detail' success_url_name = 'motion_detail'
def get_object(self): def get_object(self):
@ -598,7 +598,7 @@ class PollPDFView(PollMixin, PDFView):
Generates a ballotpaper. Generates a ballotpaper.
""" """
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
top_space = 0 top_space = 0
def get(self, *args, **kwargs): 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 False, the new state is taken from url.
If self.reset is True, the default state is taken. 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' url_name = 'motion_detail'
model = Motion model = Motion
reset = False 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 If self.print_all_motions is False, the view returns a PDF with only one
motion. motion.
""" """
permission_required = 'motion.can_see_motion' required_permission = 'motion.can_see_motion'
model = Motion model = Motion
top_space = 0 top_space = 0
print_all_motions = False print_all_motions = False
@ -735,14 +735,14 @@ motion_detail_pdf = MotionPDFView.as_view(print_all_motions=False)
class CategoryListView(ListView): class CategoryListView(ListView):
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
model = Category model = Category
category_list = CategoryListView.as_view() category_list = CategoryListView.as_view()
class CategoryCreateView(CreateView): class CategoryCreateView(CreateView):
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
model = Category model = Category
success_url_name = 'motion_category_list' success_url_name = 'motion_category_list'
url_name_args = [] url_name_args = []
@ -751,7 +751,7 @@ category_create = CategoryCreateView.as_view()
class CategoryUpdateView(UpdateView): class CategoryUpdateView(UpdateView):
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
model = Category model = Category
success_url_name = 'motion_category_list' success_url_name = 'motion_category_list'
url_name_args = [] url_name_args = []
@ -760,7 +760,7 @@ category_update = CategoryUpdateView.as_view()
class CategoryDeleteView(DeleteView): class CategoryDeleteView(DeleteView):
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
model = Category model = Category
question_url_name = 'motion_category_list' question_url_name = 'motion_category_list'
url_name_args = [] url_name_args = []
@ -774,7 +774,7 @@ class MotionCSVImportView(CSVImportView):
Imports motions from an uploaded csv file. Imports motions from an uploaded csv file.
""" """
form_class = MotionCSVImportForm form_class = MotionCSVImportForm
permission_required = 'motion.can_manage_motion' required_permission = 'motion.can_manage_motion'
success_url_name = 'motion_list' success_url_name = 'motion_list'
template_name = 'motion/motion_form_csv_import.html' template_name = 'motion/motion_form_csv_import.html'

View File

@ -13,7 +13,7 @@ class MotionWidget(Widget):
""" """
name = 'motion' name = 'motion'
verbose_name = ugettext_lazy('Motions') verbose_name = ugettext_lazy('Motions')
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
default_column = 1 default_column = 1
default_weight = 40 default_weight = 40
icon_css_class = 'icon-file' icon_css_class = 'icon-file'

View File

@ -10,7 +10,7 @@ class ParticipantMainMenuEntry(MainMenuEntry):
Main menu entry for the participant app. Main menu entry for the participant app.
""" """
verbose_name = ugettext_lazy('Participants') verbose_name = ugettext_lazy('Participants')
permission_required = 'participant.can_see_participant' required_permission = 'participant.can_see_participant'
default_weight = 50 default_weight = 50
pattern_name = 'user_overview' pattern_name = 'user_overview'
icon_css_class = 'icon-user' icon_css_class = 'icon-user'

View File

@ -30,7 +30,7 @@ class UserOverview(ListView):
""" """
Show all participants (users). Show all participants (users).
""" """
permission_required = 'participant.can_see_participant' required_permission = 'participant.can_see_participant'
template_name = 'participant/overview.html' template_name = 'participant/overview.html'
context_object_name = 'users' context_object_name = 'users'
@ -56,7 +56,7 @@ class UserDetailView(DetailView, PermissionMixin):
""" """
Classed based view to show a specific user in the interface. 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 model = User
template_name = 'participant/user_detail.html' template_name = 'participant/user_detail.html'
context_object_name = 'shown_user' context_object_name = 'shown_user'
@ -66,7 +66,7 @@ class UserCreateView(CreateView):
""" """
Create a new participant. Create a new participant.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
template_name = 'participant/edit.html' template_name = 'participant/edit.html'
model = User model = User
context_object_name = 'edit_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. 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' template_name = 'participant/user_form_multiple.html'
form_class = UserMultipleCreateForm form_class = UserMultipleCreateForm
success_url_name = 'user_overview' success_url_name = 'user_overview'
@ -124,7 +124,7 @@ class UserUpdateView(UpdateView):
""" """
Update an existing participant. Update an existing participant.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
template_name = 'participant/edit.html' template_name = 'participant/edit.html'
model = User model = User
context_object_name = 'edit_user' context_object_name = 'edit_user'
@ -156,7 +156,7 @@ class UserDeleteView(DeleteView):
""" """
Delete an participant. Delete an participant.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
model = User model = User
success_url_name = 'user_overview' success_url_name = 'user_overview'
url_name_args = [] url_name_args = []
@ -178,7 +178,7 @@ class SetUserStatusView(SingleObjectMixin, RedirectView):
""" """
Activate or deactivate an user. Activate or deactivate an user.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
allow_ajax = True allow_ajax = True
url_name = 'user_overview' url_name = 'user_overview'
url_name_args = [] url_name_args = []
@ -209,7 +209,7 @@ class ParticipantsListPDF(PDFView):
""" """
Generate the userliste as PDF. Generate the userliste as PDF.
""" """
permission_required = 'participant.can_see_participant' required_permission = 'participant.can_see_participant'
filename = ugettext_lazy("Participant-list") filename = ugettext_lazy("Participant-list")
document_title = ugettext_lazy('List of Participants') 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. 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") filename = ugettext_lazy("Participant-access-data")
top_space = 0 top_space = 0
@ -243,7 +243,7 @@ class UserCSVImportView(CSVImportView):
Import users via CSV. Import users via CSV.
""" """
import_function = staticmethod(import_users) import_function = staticmethod(import_users)
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
success_url_name = 'user_overview' success_url_name = 'user_overview'
template_name = 'participant/user_form_csv_import.html' 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. Set the Passwort for a user to his default password.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
model = User model = User
allow_ajax = True allow_ajax = True
question_message = ugettext_lazy('Do you really want to reset the password?') question_message = ugettext_lazy('Do you really want to reset the password?')
@ -275,7 +275,7 @@ class GroupOverview(ListView):
""" """
Overview over all groups. Overview over all groups.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
template_name = 'participant/group_overview.html' template_name = 'participant/group_overview.html'
context_object_name = 'groups' context_object_name = 'groups'
model = Group model = Group
@ -285,7 +285,7 @@ class GroupDetailView(DetailView, PermissionMixin):
""" """
Classed based view to show a specific group in the interface. 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 model = Group
template_name = 'participant/group_detail.html' template_name = 'participant/group_detail.html'
context_object_name = 'group' context_object_name = 'group'
@ -305,7 +305,7 @@ class GroupCreateView(CreateView):
""" """
Create a new group. Create a new group.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
template_name = 'participant/group_edit.html' template_name = 'participant/group_edit.html'
context_object_name = 'group' context_object_name = 'group'
model = Group model = Group
@ -322,7 +322,7 @@ class GroupUpdateView(UpdateView):
""" """
Update an existing group. Update an existing group.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
template_name = 'participant/group_edit.html' template_name = 'participant/group_edit.html'
model = Group model = Group
context_object_name = 'group' context_object_name = 'group'
@ -344,7 +344,7 @@ class GroupDeleteView(DeleteView):
""" """
Delete a group. Delete a group.
""" """
permission_required = 'participant.can_manage_participant' required_permission = 'participant.can_manage_participant'
model = Group model = Group
success_url_name = 'user_group_overview' success_url_name = 'user_group_overview'
url_name_args = [] url_name_args = []

View File

@ -14,7 +14,7 @@ class UserWidget(Widget):
""" """
name = 'user' name = 'user'
verbose_name = ugettext_lazy('Participants') verbose_name = ugettext_lazy('Participants')
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
default_column = 1 default_column = 1
default_weight = 60 default_weight = 60
default_active = False default_active = False
@ -34,7 +34,7 @@ class GroupWidget(Widget):
""" """
name = 'group' name = 'group'
verbose_name = ugettext_lazy('Groups') verbose_name = ugettext_lazy('Groups')
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
default_column = 1 default_column = 1
default_weight = 70 default_weight = 70
default_active = False default_active = False

View File

@ -15,7 +15,7 @@ class ProjectorView(TemplateView):
""" """
The Projector-Page. The Projector-Page.
""" """
permission_required = 'core.can_see_projector' required_permission = 'core.can_see_projector'
template_name = 'projector.html' template_name = 'projector.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -43,7 +43,7 @@ class ActivateView(RedirectView):
""" """
Activate a Slide. Activate a Slide.
""" """
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
url_name = 'core_dashboard' url_name = 'core_dashboard'
allow_ajax = True allow_ajax = True
@ -68,7 +68,7 @@ class ProjectorControllView(RedirectView):
""" """
Scale or scroll the projector. Scale or scroll the projector.
""" """
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
url_name = 'core_dashboard' url_name = 'core_dashboard'
allow_ajax = True allow_ajax = True
@ -102,7 +102,7 @@ class CountdownControllView(RedirectView):
""" """
Start, stop or reset the countdown. Start, stop or reset the countdown.
""" """
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
url_name = 'core_dashboard' url_name = 'core_dashboard'
allow_ajax = True allow_ajax = True
@ -137,7 +137,7 @@ class OverlayMessageView(RedirectView):
""" """
url_name = 'core_dashboard' url_name = 'core_dashboard'
allow_ajax = True allow_ajax = True
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
def pre_post_redirect(self, request, *args, **kwargs): def pre_post_redirect(self, request, *args, **kwargs):
if 'message' in request.POST: if 'message' in request.POST:
@ -158,7 +158,7 @@ class ActivateOverlay(RedirectView):
""" """
url_name = 'core_dashboard' url_name = 'core_dashboard'
allow_ajax = True allow_ajax = True
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
def pre_redirect(self, request, *args, **kwargs): def pre_redirect(self, request, *args, **kwargs):
overlay = get_overlays()[kwargs['name']] overlay = get_overlays()[kwargs['name']]

View File

@ -14,7 +14,7 @@ class ProjectorLiveWidget(Widget):
""" """
name = 'live_view' name = 'live_view'
verbose_name = ugettext_lazy('Projector 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_column = 2
default_weight = 10 default_weight = 10
template_name = 'projector/widget_live_view.html' template_name = 'projector/widget_live_view.html'
@ -27,7 +27,7 @@ class OverlayWidget(Widget):
""" """
name = 'overlays' # TODO: Use singular here name = 'overlays' # TODO: Use singular here
verbose_name = ugettext_lazy('Overlays') verbose_name = ugettext_lazy('Overlays')
permission_required = 'core.can_manage_projector' required_permission = 'core.can_manage_projector'
default_column = 2 default_column = 2
default_weight = 20 default_weight = 20
template_name = 'projector/widget_overlay.html' template_name = 'projector/widget_overlay.html'

View File

@ -18,14 +18,14 @@ class MainMenuEntry(object):
magic. magic.
For the appearance there are some optional attributes and methods like 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, check_permission, get_url, get_default_weight, get_icon_css_class,
get_stylesheets and get_javascript_files. get_stylesheets and get_javascript_files.
""" """
__metaclass__ = SignalConnectMetaClass __metaclass__ = SignalConnectMetaClass
signal = Signal(providing_args=['request']) signal = Signal(providing_args=['request'])
verbose_name = None verbose_name = None
permission_required = None required_permission = None
default_weight = 0 default_weight = 0
pattern_name = None pattern_name = None
icon_css_class = 'icon-home' icon_css_class = 'icon-home'
@ -63,7 +63,7 @@ class MainMenuEntry(object):
""" """
Returns True if the request user is allowed to see the entry. 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): def get_icon_css_class(self):
""" """

View File

@ -24,8 +24,6 @@ from .pdf import firstPage, laterPages
from .signals import template_manipulation from .signals import template_manipulation
from .utils import html_strong from .utils import html_strong
NO_PERMISSION_REQUIRED = 'No permission required'
View = django_views.View View = django_views.View
@ -44,21 +42,22 @@ class LoginMixin(object):
class PermissionMixin(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 check_permission(self, request, *args, **kwargs):
def has_permission(self, request, *args, **kwargs):
""" """
Checks if the user has the required permission. Checks if the user has the required permission.
""" """
if self.permission_required == NO_PERMISSION_REQUIRED: if self.required_permission is None:
return True return True
else: else:
return request.user.has_perm(self.permission_required) return request.user.has_perm(self.required_permission)
def dispatch(self, request, *args, **kwargs): 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 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(): if not request.user.is_authenticated():
path = request.get_full_path() path = request.get_full_path()
return HttpResponseRedirect( return HttpResponseRedirect(

View File

@ -18,7 +18,7 @@ class Widget(object):
(SignalConnectMetaClass) does the rest of the magic. (SignalConnectMetaClass) does the rest of the magic.
For the appearance of the widget there are some attributes and methods 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, default_active, template_name, context, icon_css_class,
more_link_pattern_name, stylesheets, javascript_files, more_link_pattern_name, stylesheets, javascript_files,
get_verbose_name, check_permission, get_html, get_context_data, get_verbose_name, check_permission, get_html, get_context_data,
@ -29,7 +29,7 @@ class Widget(object):
signal = Signal(providing_args=['request']) signal = Signal(providing_args=['request'])
name = None name = None
verbose_name = None verbose_name = None
permission_required = None required_permission = None
default_column = 1 default_column = 1
default_weight = 0 default_weight = 0
default_active = True default_active = True
@ -77,7 +77,7 @@ class Widget(object):
""" """
Returns True if the request user is allowed to see the widget. 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): def is_active(self):
""" """

View File

@ -40,22 +40,22 @@ class PermissionMixinTest(ViewTestCase):
def test_dispatch(self): def test_dispatch(self):
client = Client() client = Client()
# View without permission_required # View without required_permission
response = client.get('/permission_mixin1/') response = client.get('/permission_mixin1/')
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'Well done.') self.assertEqual(response.content, 'Well done.')
# View with permission_required without login # View with required_permission without login
response = client.get('/permission_mixin2/') response = client.get('/permission_mixin2/')
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], 'http://testserver/login/?next=/permission_mixin2/') 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') client.login(username='admin', password='admin')
response = client.get('/permission_mixin2/') response = client.get('/permission_mixin2/')
self.assertEqual(response.status_code, 403) 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/') response = client.get('/permission_mixin3/')
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)

View File

@ -24,8 +24,8 @@ urlpatterns += patterns(
views.PermissionMixinView.as_view()), views.PermissionMixinView.as_view()),
url(r'^permission_mixin2/$', url(r'^permission_mixin2/$',
views.PermissionMixinView.as_view(permission_required='permission_string')), views.PermissionMixinView.as_view(required_permission='permission_string')),
url(r'^permission_mixin3/$', url(r'^permission_mixin3/$',
views.PermissionMixinView.as_view(permission_required='agenda.can_see_agenda')), views.PermissionMixinView.as_view(required_permission='agenda.can_see_agenda')),
) )