saxix / django-adminactions

Compare 96ce649 ... +2 ... 250d9e2

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -83,7 +83,8 @@
Loading
83 83
    """
84 84
85 85
    opts = modeladmin.model._meta
86 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_merge', opts))
86 +
    perm = "{0}.{1}".format(opts.app_label,
87 +
                            get_permission_codename(merge.base_permission, opts))
87 88
    if not request.user.has_perm(perm):
88 89
        messages.error(request, _('Sorry you do not have rights to execute this action'))
89 90
        return
@@ -212,3 +213,4 @@
Loading
212 213
213 214
214 215
merge.short_description = _("Merge selected %(verbose_name_plural)s")
216 +
merge.base_permission = 'adminactions_merge'

@@ -250,7 +250,8 @@
Loading
250 250
                             updated=updated)
251 251
252 252
    opts = modeladmin.model._meta
253 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_massupdate', opts))
253 +
    perm = "{0}.{1}".format(opts.app_label,
254 +
                            get_permission_codename(mass_update.base_permission, opts))
254 255
    if not request.user.has_perm(perm):
255 256
        messages.error(request, _('Sorry you do not have rights to execute this action'))
256 257
        return
@@ -382,3 +383,4 @@
Loading
382 383
383 384
384 385
mass_update.short_description = _("Mass update")
386 +
mass_update.base_permission = 'adminactions_massupdate'

@@ -18,13 +18,17 @@
Loading
18 18
def create_extra_permissions():
19 19
    from django.contrib.auth.models import Permission
20 20
    from django.contrib.contenttypes.models import ContentType
21 +
22 +
    from .actions import actions as aa
23 +
24 +
    #  ('adminactions_export', 'adminactions_massupdate',
25 +
    #                        'adminactions_merge', 'adminactions_chart',
26 +
    #                        'adminactions_byrowsupdate')
21 27
    for model in apps.get_models():
22 -
        for action in ('adminactions_export', 'adminactions_massupdate',
23 -
                       'adminactions_merge', 'adminactions_chart',
24 -
                       'adminactions_byrowsupdate'):
28 +
        for action in aa:
25 29
            opts = model._meta
26 -
            codename = get_permission_codename(action, opts)
27 -
            label = 'Can {} {} (adminactions)'.format(action.replace('adminactions_', ""),
30 +
            codename = get_permission_codename(action.base_permission, opts)
31 +
            label = 'Can {} {} (adminactions)'.format(action.base_permission.replace('adminactions_', ""),
28 32
                                                      opts.verbose_name_raw)
29 33
            ct = ContentType.objects.get_for_model(model)
30 34
            params = dict(codename=codename,

@@ -4,6 +4,8 @@
Loading
4 4
from django.core.exceptions import ValidationError
5 5
from django.template.response import TemplateResponse
6 6
7 +
from .perms import get_permission_codename
8 +
7 9
8 10
class ImportFixtureForm(forms.Form):
9 11
    fixture_file = forms.FileField(required=False)
@@ -51,4 +53,17 @@
Loading
51 53
    return TemplateResponse(request, "adminactions/helpers/import_fixture.html", context)
52 54
53 55
54 -
56 +
class AdminActionPermMixin:
57 +
    def _filter_actions_by_permissions(self, request, actions):
58 +
        opts = self.model._meta
59 +
        filtered_actions = []
60 +
        actions = super()._filter_actions_by_permissions(request, actions)
61 +
        from .actions import actions as aa
62 +
        for action in actions:
63 +
            if action[0] in aa:
64 +
                perm = "{0}.{1}".format(opts.app_label,
65 +
                                        get_permission_codename(action[0].base_permission, opts))
66 +
                if not request.user.has_perm(perm):
67 +
                    continue
68 +
            filtered_actions.append(action)
69 +
        return filtered_actions

@@ -35,7 +35,8 @@
Loading
35 35
        export a queryset to csv file
36 36
    """
37 37
    opts = modeladmin.model._meta
38 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_export', opts))
38 +
    perm = "{0}.{1}".format(opts.app_label,
39 +
                            get_permission_codename(base_export.base_permission, opts))
39 40
    if not request.user.has_perm(perm):
40 41
        messages.error(request, _('Sorry you do not have rights to execute this action'))
41 42
        return
@@ -118,6 +119,9 @@
Loading
118 119
    return render(request, template, ctx)
119 120
120 121
122 +
base_export.base_permission = 'adminactions_export'
123 +
124 +
121 125
def export_as_csv(modeladmin, request, queryset):
122 126
    return base_export(modeladmin, request, queryset,
123 127
                       impl=_export_as_csv,
@@ -132,6 +136,7 @@
Loading
132 136
133 137
134 138
export_as_csv.short_description = _("Export as CSV")
139 +
export_as_csv.base_permission = 'adminactions_export'
135 140
136 141
137 142
def export_as_xls(modeladmin, request, queryset):
@@ -148,6 +153,7 @@
Loading
148 153
149 154
150 155
export_as_xls.short_description = _("Export as XLS")
156 +
export_as_xls.base_permission = 'adminactions_export'
151 157
152 158
153 159
class FlatCollector:
@@ -233,7 +239,8 @@
Loading
233 239
               'serializer': 'json',
234 240
               'indent': 4}
235 241
    opts = modeladmin.model._meta
236 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_export', opts))
242 +
    perm = "{0}.{1}".format(opts.app_label,
243 +
                            get_permission_codename(export_as_fixture.base_permission, opts))
237 244
    if not request.user.has_perm(perm):
238 245
        messages.error(request, _('Sorry you do not have rights to execute this action'))
239 246
        return
@@ -307,6 +314,7 @@
Loading
307 314
308 315
309 316
export_as_fixture.short_description = _("Export as fixture")
317 +
export_as_fixture.base_permission = 'adminactions_export'
310 318
311 319
312 320
def export_delete_tree(modeladmin, request, queryset):  # noqa
@@ -315,7 +323,8 @@
Loading
315 323
    That mean that dump what will be deleted if the queryset was deleted
316 324
    """
317 325
    opts = modeladmin.model._meta
318 -
    perm = "{0}.{1}".format(opts.app_label, get_permission_codename('adminactions_export', opts))
326 +
    perm = "{0}.{1}".format(opts.app_label,
327 +
                            get_permission_codename(export_delete_tree.base_permission, opts))
319 328
    if not request.user.has_perm(perm):
320 329
        messages.error(request, _('Sorry you do not have rights to execute this action'))
321 330
        return
@@ -399,3 +408,4 @@
Loading
399 408
400 409
401 410
export_delete_tree.short_description = _("Export delete tree")
411 +
export_delete_tree.base_permission = 'adminactions_export'

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 1 files with coverage changes found.

Changes in src/adminactions/helpers.py
-8
+8
Loading file...
Files Coverage
src/adminactions 0.38% 84.75%
Project Totals (23 files) 84.75%
Loading