def index(self, request):
        context = dict(self.admin_site.each_context(request))

        context.update({
            'views': get_views(),
            'group_by': request.GET.get('group_by', 'module')
        })
        return TemplateResponse(request, "permissions_auditor/admin/views_index.html", context)
    def test_get_views_results(self):
        blacklist = {
            'namespaces': [],
            'view_names': [],
            'modules': [],
        }

        with self.settings(PERMISSIONS_AUDITOR_BLACKLIST=blacklist):
            self.reload_blacklist()
            views = core.get_views()
            self.assertSequenceEqual(views, self.views_results)
    def test_module_blacklist(self):
        blacklist = {
            'namespaces': [],
            'view_names': [],
            'modules': [self.module],
        }

        with self.settings(PERMISSIONS_AUDITOR_BLACKLIST=blacklist):
            self.reload_blacklist()
            views = core.get_views()
            self.assertEqual(views, [])
    def test_view_name_blacklist(self):
        blacklist = {
            'namespaces': [],
            'view_names': ['{}.BaseView'.format(self.module)],
            'modules': [],
        }

        with self.settings(PERMISSIONS_AUDITOR_BLACKLIST=blacklist):
            self.reload_blacklist()
            views = core.get_views()
            self.assertNotIn(views, self.views_results[0])  # BaseView
    def test_namespace_blacklist(self):
        blacklist = {
            'namespaces': ['admin'],
            'view_names': [],
            'modules': [],
        }

        with self.settings(PERMISSIONS_AUDITOR_BLACKLIST=blacklist):
            self.reload_blacklist()
            views = core.get_views()
            self.assertNotIn(
                views, self.views_results[3])  # staff_member_required_view
    def permission_detail(self, request, permission, obj=None):
        try:
            obj = self.get_object(request, permission)
        except Permission.MultipleObjectsReturned:
            return self._get_obj_multiple_exist_redirect(request, permission)

        if obj is None:
            return self._get_obj_does_not_exist_redirect(request, self.model._meta, permission)

        opts = self.model._meta

        adminForm = helpers.AdminForm(
            self.get_form(request, obj),
            list(self.get_fieldsets(request, obj)),
            {},
            model_admin=self
        )
        media = self.media + adminForm.media

        if (request.method == 'POST' and
                adminForm.form.is_valid() and
                self.has_auditor_change_permission(request)):
            obj.user_set.set(adminForm.form.cleaned_data['users'])
            obj.group_set.set(adminForm.form.cleaned_data['groups'])
            return self.response_change(request, obj)

        context = {
            **self.admin_site.each_context(request),
            'adminform': adminForm,
            'errors': helpers.AdminErrorList(adminForm.form, []),
            'media': media,

            'views': get_views(),
            'permission': '{}.{}'.format(obj.content_type.app_label, obj.codename),

            'opts': opts,
            'add': False,
            'change': True,
            'is_popup': False,
            'save_as': self.save_as,
            'has_editable_inline_admin_formsets': False,
            'has_view_permission': self.has_view_permission(request, obj),
            'has_add_permission': self.has_add_permission(request, obj),
            'has_change_permission': self.has_auditor_change_permission(request),
            'has_delete_permission': self.has_delete_permission(request, obj),
            'app_label': opts.app_label,
        }

        return TemplateResponse(
            request, "permissions_auditor/admin/permission_detail.html", context
        )
示例#7
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['views'] = get_views()
     return context
def permissions_index(request):
    context = {'views': get_views()}
    return render(request, 'permissions_list.html', context)