mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-14 15:00:16 +02:00
Embed authgroup into group admin.
Mirror authgroup admin permissions from group model. Delete authgroup permissions.
This commit is contained in:
parent
9f9cc7ed42
commit
f3c0d05c39
@ -6,11 +6,24 @@ from .models import AuthGroup
|
||||
from .models import GroupRequest
|
||||
|
||||
|
||||
class AuthGroupAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Admin model for AuthGroup
|
||||
"""
|
||||
class AuthGroupInlineAdmin(admin.StackedInline):
|
||||
model = AuthGroup
|
||||
filter_horizontal = ('group_leaders',)
|
||||
fields = ('description', 'group_leaders', 'internal', 'hidden', 'open', 'public')
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return request.user.has_perm('auth.change_group')
|
||||
|
||||
|
||||
class GroupAdmin(admin.ModelAdmin):
|
||||
filter_horizontal = ('permissions',)
|
||||
inlines = (AuthGroupInlineAdmin,)
|
||||
|
||||
|
||||
class Group(BaseGroup):
|
||||
@ -22,11 +35,10 @@ class Group(BaseGroup):
|
||||
try:
|
||||
admin.site.unregister(BaseGroup)
|
||||
finally:
|
||||
admin.site.register(Group)
|
||||
admin.site.register(Group, GroupAdmin)
|
||||
|
||||
|
||||
admin.site.register(GroupRequest)
|
||||
admin.site.register(AuthGroup, AuthGroupAdmin)
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Group)
|
||||
|
@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.10 on 2018-02-23 23:09
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def delete_permissions(apps, schema_editor):
|
||||
AuthGroup = apps.get_model('groupmanagement', 'AuthGroup')
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
Permission = apps.get_model('auth', 'Permission')
|
||||
ct = ContentType.objects.get_for_model(AuthGroup)
|
||||
Permission.objects.filter(content_type=ct).delete()
|
||||
|
||||
|
||||
def recreate_permissions(apps, schema_editor):
|
||||
AuthGroup = apps.get_model('groupmanagement', 'AuthGroup')
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
Permission = apps.get_model('auth', 'Permission')
|
||||
ct = ContentType.objects.get_for_model(AuthGroup)
|
||||
Permission.objects.create(content_type=ct, name='Can add auth group', codename='add_authgroup')
|
||||
Permission.objects.create(content_type=ct, name='Can delete auth group', codename='delete_authgroup')
|
||||
Permission.objects.create(content_type=ct, name='Can change auth group', codename='change_authgroup')
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('groupmanagement', '0007_on_delete'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='authgroup',
|
||||
options={'default_permissions': (), 'permissions': (('request_groups', 'Can request non-public groups'),)},
|
||||
),
|
||||
migrations.RunPython(delete_permissions, recreate_permissions)
|
||||
]
|
@ -74,6 +74,7 @@ class AuthGroup(models.Model):
|
||||
permissions = (
|
||||
("request_groups", u"Can request non-public groups"),
|
||||
)
|
||||
default_permissions = tuple()
|
||||
|
||||
|
||||
@receiver(post_save, sender=Group)
|
||||
|
Loading…
x
Reference in New Issue
Block a user