django22: rename permissions(#49188)
to avoid conflicts with new _view permissions introduced in django 2.1 https://docs.djangoproject.com/en/3.1/releases/2.1/#model-view-permission
This commit is contained in:
parent
19ce0c4f2a
commit
e8250824b1
|
@ -19,7 +19,7 @@ class Migration(migrations.Migration):
|
|||
('resource_pk', models.PositiveIntegerField()),
|
||||
],
|
||||
options={
|
||||
'permissions': (('view_accessright', 'Can view access right'),),
|
||||
'permissions': (('see_accessright', 'Can see access right'),),
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
|
|
|
@ -25,7 +25,7 @@ class Migration(migrations.Migration):
|
|||
('extra', django.contrib.postgres.fields.jsonb.JSONField(default={}, verbose_name=b'extras')),
|
||||
],
|
||||
options={
|
||||
'permissions': (('view_resourcelog', 'Can view resource logs'),),
|
||||
'permissions': (('see_resourcelog', 'Can see resource logs'),),
|
||||
},
|
||||
),
|
||||
]
|
||||
|
|
|
@ -14,6 +14,6 @@ class Migration(migrations.Migration):
|
|||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='resourcelog',
|
||||
options={'ordering': ('id',), 'permissions': (('view_resourcelog', 'Can view resource logs'),)},
|
||||
options={'ordering': ('id',), 'permissions': (('see_resourcelog', 'Can see resource logs'),)},
|
||||
),
|
||||
]
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def rename_permissions(apps, schema_editor):
|
||||
Permission = apps.get_model('auth', 'Permission')
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
|
||||
try:
|
||||
ct = ContentType.objects.get(app_label='base', model='accessright')
|
||||
except ContentType.DoesNotExist:
|
||||
# db from scratch: contenttypes are created on post_migrate signal
|
||||
return
|
||||
|
||||
if not Permission.objects.filter(content_type=ct, codename='see_accessright').exists():
|
||||
# old schema, rename view_accessright permission
|
||||
p = Permission.objects.get(content_type=ct, codename='view_accessright')
|
||||
p.codename = 'see_accessright'
|
||||
p.name = 'Can see access right'
|
||||
p.save()
|
||||
|
||||
ct = ContentType.objects.get(app_label='base', model='resourcelog')
|
||||
if not Permission.objects.filter(content_type=ct, codename='see_resourcelog').exists():
|
||||
# old schema, rename view_resourcelog permission
|
||||
p = Permission.objects.get(content_type=ct, codename='view_resourcelog')
|
||||
p.codename = 'see_resourcelog'
|
||||
p.name = 'Can see resource log'
|
||||
p.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0027_transaction_id'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(rename_permissions, reverse_code=migrations.RunPython.noop),
|
||||
]
|
|
@ -11,6 +11,7 @@ import base64
|
|||
import itertools
|
||||
import uuid
|
||||
|
||||
from django import VERSION
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
|
@ -642,7 +643,7 @@ class AccessRight(models.Model):
|
|||
|
||||
class Meta:
|
||||
permissions = (
|
||||
('view_accessright', 'Can view access right'),
|
||||
('see_accessright', 'Can see access right'),
|
||||
)
|
||||
unique_together = (
|
||||
('codename', 'resource_type', 'resource_pk', 'apiuser'),
|
||||
|
@ -810,7 +811,7 @@ class ResourceLog(models.Model):
|
|||
class Meta:
|
||||
ordering = ('id',)
|
||||
permissions = (
|
||||
('view_resourcelog', 'Can view resource logs'),
|
||||
('see_resourcelog', 'Can see resource logs'),
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
{% block endpoints %}
|
||||
{{ block.super }}
|
||||
{% if perms.base.view_accessright %}
|
||||
{% if perms.base.see_accessright %}
|
||||
<div>
|
||||
<a rel="popup" href="/manage{{ object.get_absolute_url }}test-send/">
|
||||
{% trans 'Send a test message' %}
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
{% endblock %}
|
||||
|
||||
<div id="security" class="section">
|
||||
{% if perms.base.view_accessright %}
|
||||
{% if perms.base.see_accessright %}
|
||||
<h3>{% trans "Security" %}</h3>
|
||||
<div>
|
||||
{% block security %}
|
||||
|
@ -123,7 +123,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if perms.base.view_resourcelog %}
|
||||
{% if perms.base.see_resourcelog %}
|
||||
<div id="logs" class="section">
|
||||
<h3>{% trans "Logs" %}
|
||||
<a class="button" href="{% url 'view-logs-connector' connector=object.get_connector_slug slug=object.slug %}">{% trans "Full page & filter" %}</a>
|
||||
|
|
Loading…
Reference in New Issue