tombreit
tombreit

Reputation: 1349

Lost some wagtail group permissions after remove_stale_contenttypes - how to get them back?

After refactoring some models in my Django/Wagtail project I had some stale contenttypes, triggering errors in the wagtail search app.

These errors could be fixed by running a contenttypes management command:

./manage.py remove_stale_contenttypes

Ok, I got warned about what will be deleted and there were indeed some group permission objects listed. Anyway, remove_stale_contenttypes did it's job and the wagtail search was back.

But now some permissions are missing: e.g. the "Can access wagtail admin" Group permission is completely missing, even for new Group instances.

How do I get the default permissions back (some were migrated once via wagtail/admin/migration)? Ideally, I would like to restore all "default" permissions on my production site...

Upvotes: 1

Views: 352

Answers (1)

gasman
gasman

Reputation: 25227

The following code (to be run on the ./manage.py shell command line) should to it:

from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission
wagtailadmin_content_type, created = ContentType.objects.get_or_create(app_label='wagtailadmin', model='admin')
admin_permission, created = Permission.objects.get_or_create(content_type=wagtailadmin_content_type, codename='access_admin', name='Can access Wagtail admin')

This is a bug specifically affecting the "Can access wagtail admin" permission type, and no other permissions should be affected.

Upvotes: 2

Related Questions