Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions django_rq/migrations/0003_alter_dashboard_permission_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from __future__ import annotations

from collections.abc import Callable

from django.db import migrations
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps

def permission_migration(
*, old: str, new: str
) -> Callable[[StateApps, BaseDatabaseSchemaEditor], None]:
def migrate(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
try:
ContentType = apps.get_model("contenttypes", "ContentType")
Permission = apps.get_model("auth", "Permission")
Dashboard = apps.get_model("django_rq", "Dashboard")
except LookupError:
return

Permission._default_manager.filter(
content_type=ContentType._default_manager.get_for_model(Dashboard),
codename=old,
).update(codename=new)

return migrate


class Migration(migrations.Migration):
dependencies = [('django_rq', '0002_delete_queue_create_dashboard')]

operations = [
migrations.AlterModelOptions(
name='dashboard',
options={
'default_permissions': (),
'managed': False,
'permissions': (('admin', 'Access admin page'),),
'verbose_name': 'Django-RQ',
'verbose_name_plural': 'Django-RQ',
},
),
migrations.RunPython(
permission_migration(old="view", new="admin"),
permission_migration(old="admin", new="view"),
)
]
4 changes: 3 additions & 1 deletion django_rq/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Dashboard(models.Model):
class Meta:
managed = False # No database table - admin integration only
default_permissions = ()
permissions = [['view', 'Access admin page']]
permissions = (
('admin', 'Access admin page'),
)
verbose_name = 'Django-RQ'
verbose_name_plural = 'Django-RQ'
Loading