Skip to content

Commit 3ff3cb2

Browse files
committed
permissions for publishing and export action
1 parent 1887ead commit 3ff3cb2

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

django/gsmap/admin.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def make_published(self, request, queryset):
247247
) % updated, messages.SUCCESS)
248248
# todo refactor when upgrading to django 3.2 as action decorator
249249
make_published.short_description = "Publish selected annotations"
250-
make_published.allowed_permissions = ('annotation_publish',)
250+
make_published.allowed_permissions = ('publish',)
251251

252252
# @admin_.action(description='Publish selected annotations')
253253
def make_unpublished(self, request, queryset):
@@ -259,12 +259,12 @@ def make_unpublished(self, request, queryset):
259259
) % updated, messages.SUCCESS)
260260
# todo refactor when upgrading to django 3.2 as action decorator
261261
make_unpublished.short_description = "Unpublish selected annotations"
262-
make_unpublished.allowed_permissions = ('annotation_publish',)
262+
make_unpublished.allowed_permissions = ('publish',)
263263

264-
def has_annotation_publish_permission(self, request):
264+
def has_publish_permission(self, request):
265265
"""Does the user have the publish permission?"""
266266
opts = self.opts
267-
codename = get_permission_codename('annotation_publish', opts)
267+
codename = get_permission_codename('publish', opts)
268268
return request.user.has_perm('%s.%s' % (opts.app_label, codename))
269269

270270
def export_as_csv(self, request, queryset):
@@ -300,11 +300,13 @@ def export_as_csv(self, request, queryset):
300300
r.data
301301
])
302302
return response
303+
export_as_csv.short_description = "Export selected annotations"
304+
export_as_csv.allowed_permissions = ('export',)
303305

304-
def has_annotation_export_permission(self, request):
306+
def has_export_permission(self, request):
305307
"""Does the user have the publish permission?"""
306308
opts = self.opts
307-
codename = get_permission_codename('annotation_export', opts)
309+
codename = get_permission_codename('export', opts)
308310
return request.user.has_perm('%s.%s' % (opts.app_label, codename))
309311

310312
class CategoryAdminForm(TranslatableModelForm):
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 3.1.13 on 2022-02-23 23:31
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('gsmap', '0041_auto_20220223_1850'),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name='annotation',
15+
options={'ordering': ['-created'], 'permissions': [('publish_annotation', 'Can publish annotations'), ('export_annotation', 'Can export annotations')]},
16+
),
17+
]

django/gsmap/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ def __str__(self):
458458
class Annotation(models.Model):
459459
class Meta:
460460
ordering = ['-created']
461+
permissions = [
462+
('publish_annotation', 'Can publish annotations'),
463+
('export_annotation', 'Can export annotations'),
464+
]
461465

462466
created = models.DateTimeField(auto_now_add=True)
463467
modified = models.DateTimeField(auto_now=True)
@@ -515,7 +519,7 @@ def email_hash(self):
515519

516520
@property
517521
def email_hash_short(self):
518-
return self.email_hash[:10]
522+
return self.email_hash[:12]
519523

520524
@property
521525
def description(self):

0 commit comments

Comments
 (0)