【问题标题】:Lost some wagtail group permissions after remove_stale_contenttypes - how to get them back?在 remove_stale_contenttypes 之后丢失了一些 wagtail 组权限 - 如何找回它们?
【发布时间】:2018-06-15 11:34:40
【问题描述】:

在我的 Django/Wagtail 项目中重构了一些模型后,我有一些过时的内容类型,在 wagtail 搜索应用程序中触发了错误。

可以通过运行contenttypes 管理命令来修复这些错误:

./manage.py remove_stale_contenttypes

好的,我收到了关于哪些内容将被删除的警告,并且确实列出了一些组权限对象。不管怎样,remove_stale_contenttypes 完成了它的工作,鹡鸰搜索又回来了。

但现在缺少一些权限:例如“Can access wagtail admin”组权限完全缺失,即使对于新的组实例也是如此。

如何取回默认权限(有些是通过wagtail/admin/migration 迁移一次)?理想情况下,我想恢复生产站点上的所有“默认”权限...

【问题讨论】:

    标签: django wagtail


    【解决方案1】:

    下面的代码(在./manage.py shell 命令行上运行)应该是它:

    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')
    

    这是a bug specifically affecting the "Can access wagtail admin" permission type,应该不会影响其他权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多