mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-10 09:06:21 +01:00
New view_state_corpstats permission
Cleanup CorpStats permissions
This commit is contained in:
@@ -19,6 +19,7 @@ PERMISSIONS = {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def user_permissions_dict(apps):
|
||||
Permission = apps.get_model('auth', 'Permission')
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
@@ -33,14 +34,17 @@ def user_permissions_dict(apps):
|
||||
'corpstats': {x: Permission.objects.get_or_create(codename=x, name=y, content_type=corpstats_ct)[0] for x, y in PERMISSIONS['corpstats'].items()},
|
||||
}
|
||||
|
||||
|
||||
def users_with_permission(apps, perm):
|
||||
User = apps.get_model('auth', 'User')
|
||||
return User.objects.filter(user_permissions=perm.pk)
|
||||
|
||||
|
||||
def groups_with_permission(apps, perm):
|
||||
Group = apps.get_model('auth', 'Group')
|
||||
return Group.objects.filter(permissions=perm.pk)
|
||||
|
||||
|
||||
def forward(apps, schema_editor):
|
||||
perm_dict = user_permissions_dict(apps)
|
||||
|
||||
@@ -66,8 +70,9 @@ def forward(apps, schema_editor):
|
||||
|
||||
for name, perm in perm_dict['user'].items():
|
||||
perm.delete()
|
||||
|
||||
def reverse(apps, schema_editor):
|
||||
|
||||
|
||||
def reverse(apps, schema_editor):
|
||||
perm_dict = user_permissions_dict(apps)
|
||||
|
||||
corp_users = users_with_permission(apps, perm_dict['corpstats']['view_corp_corpstats'])
|
||||
@@ -79,7 +84,6 @@ def reverse(apps, schema_editor):
|
||||
u.user_permissions.remove(perm_dict['corpstats']['view_corp_corpstats'].pk)
|
||||
for u in corp_api_users:
|
||||
u.user_permissions.remove(perm_dict['corpstats']['corp_apis'].pk)
|
||||
|
||||
|
||||
alliance_users = users_with_permission(apps, perm_dict['corpstats']['view_alliance_corpstats'])
|
||||
alliance_api_users = users_with_permission(apps, perm_dict['corpstats']['alliance_apis'])
|
||||
@@ -93,7 +97,6 @@ def reverse(apps, schema_editor):
|
||||
|
||||
corp_groups = groups_with_permission(apps, perm_dict['corpstats']['view_corp_corpstats'])
|
||||
corp_api_groups = groups_with_permission(apps, perm_dict['corpstats']['corp_apis'])
|
||||
corp_gs = corp_groups | corp_api_groups
|
||||
for g in corp_groups.distinct():
|
||||
g.permissions.add(perm_dict['user']['corp_apis'].pk)
|
||||
for g in corp_groups:
|
||||
|
||||
@@ -27,7 +27,7 @@ def convert_members_to_json(apps, schema_editor):
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('corputils', '0003_make_strings_more_stringy'),
|
||||
('corputils', '0003_granular_permissions'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
||||
40
corputils/migrations/0005_cleanup_permissions.py
Normal file
40
corputils/migrations/0005_cleanup_permissions.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.2 on 2017-06-10 15:34
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def delete_permissions(apps, schema_editor):
|
||||
CorpStats = apps.get_model('corputils', 'CorpStats')
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
Permission = apps.get_model('auth', 'Permission')
|
||||
ct = ContentType.objects.get_for_model(CorpStats)
|
||||
perms = Permission.objects.filter(content_type=ct)
|
||||
perms.filter(codename__contains='api').delete()
|
||||
perms.filter(codename='view_corpstats').delete()
|
||||
perms.filter(codename__contains='blue').delete()
|
||||
perms.filter(codename__contains='remove').delete()
|
||||
|
||||
g = perms.get(codename='view_corp_corpstats')
|
||||
g.name = 'Can view corp stats of their corporation.'
|
||||
g.save()
|
||||
|
||||
g = perms.get(codename='view_alliance_corpstats')
|
||||
g.name = 'Can view corp stats of members of their alliance.'
|
||||
g.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('corputils', '0004_member_models'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='corpstats',
|
||||
options={'permissions': (('view_corp_corpstats', 'Can view corp stats of their corporation.'), ('view_alliance_corpstats', 'Can view corp stats of members of their alliance.'), ('view_state_corpstats', 'Can view corp stats of members of their auth state.')), 'verbose_name': 'corp stats', 'verbose_name_plural': 'corp stats'},
|
||||
),
|
||||
migrations.RunPython(delete_permissions, migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user