mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-11 21:40:17 +02:00
Merge branch 'group_leads' into 'master'
Add option to add groups as group leaders Closes #1062 See merge request allianceauth/allianceauth!1146
This commit is contained in:
commit
13f523679c
@ -8,8 +8,8 @@ from .models import GroupRequest
|
|||||||
|
|
||||||
class AuthGroupInlineAdmin(admin.StackedInline):
|
class AuthGroupInlineAdmin(admin.StackedInline):
|
||||||
model = AuthGroup
|
model = AuthGroup
|
||||||
filter_horizontal = ('group_leaders', 'states',)
|
filter_horizontal = ('group_leaders', 'group_leader_groups', 'states',)
|
||||||
fields = ('description', 'group_leaders', 'states', 'internal', 'hidden', 'open', 'public')
|
fields = ('description', 'group_leaders', 'group_leader_groups', 'states', 'internal', 'hidden', 'open', 'public')
|
||||||
verbose_name_plural = 'Auth Settings'
|
verbose_name_plural = 'Auth Settings'
|
||||||
verbose_name = ''
|
verbose_name = ''
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ class GroupManager:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_group_leaders_groups(user):
|
def get_group_leaders_groups(user):
|
||||||
return Group.objects.select_related('authgroup').filter(authgroup__group_leaders__in=[user])
|
return Group.objects.select_related('authgroup').filter(authgroup__group_leaders__in=[user]) | \
|
||||||
|
Group.objects.select_related('authgroup').filter(authgroup__group_leader_groups__in=user.groups.all())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def joinable_group(group, state):
|
def joinable_group(group, state):
|
||||||
@ -66,7 +67,7 @@ class GroupManager:
|
|||||||
:return: bool True if user can manage groups, False otherwise
|
:return: bool True if user can manage groups, False otherwise
|
||||||
"""
|
"""
|
||||||
if user.is_authenticated:
|
if user.is_authenticated:
|
||||||
return cls.has_management_permission(user) or user.leads_groups.all()
|
return cls.has_management_permission(user) or cls.get_group_leaders_groups(user)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
19
allianceauth/groupmanagement/migrations/0012_group_leads.py
Normal file
19
allianceauth/groupmanagement/migrations/0012_group_leads.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 2.2.8 on 2020-01-06 11:00
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('auth', '0011_update_proxy_permissions'),
|
||||||
|
('groupmanagement', '0011_requestlog_date'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='authgroup',
|
||||||
|
name='group_leader_groups',
|
||||||
|
field=models.ManyToManyField(blank=True, help_text='Group leaders can process group requests for this group specifically. Use the auth.group_management permission to allow a user to manage all groups.', related_name='leads_group_groups', to='auth.Group'),
|
||||||
|
)
|
||||||
|
]
|
@ -98,6 +98,11 @@ class AuthGroup(models.Model):
|
|||||||
help_text="Group leaders can process group requests for this group "
|
help_text="Group leaders can process group requests for this group "
|
||||||
"specifically. Use the auth.group_management permission to allow "
|
"specifically. Use the auth.group_management permission to allow "
|
||||||
"a user to manage all groups.")
|
"a user to manage all groups.")
|
||||||
|
# allow groups to be *group leads*
|
||||||
|
group_leader_groups = models.ManyToManyField(Group, related_name='leads_group_groups', blank=True,
|
||||||
|
help_text="Group leaders can process group requests for this group "
|
||||||
|
"specifically. Use the auth.group_management permission to allow "
|
||||||
|
"a user to manage all groups.")
|
||||||
|
|
||||||
states = models.ManyToManyField(State, related_name='valid_states', blank=True,
|
states = models.ManyToManyField(State, related_name='valid_states', blank=True,
|
||||||
help_text="States listed here will have the ability to join this group provided "
|
help_text="States listed here will have the ability to join this group provided "
|
||||||
|
46
allianceauth/groupmanagement/tests.py
Normal file
46
allianceauth/groupmanagement/tests.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from allianceauth.tests.auth_utils import AuthUtils
|
||||||
|
from allianceauth.eveonline.models import EveCorporationInfo, EveAllianceInfo, EveCharacter
|
||||||
|
from django.contrib.auth.models import User, Group
|
||||||
|
from allianceauth.groupmanagement.managers import GroupManager
|
||||||
|
|
||||||
|
class GroupManagementVisibilityTestCase(TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
cls.user = AuthUtils.create_user('test')
|
||||||
|
AuthUtils.add_main_character(cls.user, 'test character', '1', corp_id='2', corp_name='test_corp', corp_ticker='TEST', alliance_id='3', alliance_name='TEST')
|
||||||
|
cls.user.profile.refresh_from_db()
|
||||||
|
cls.alliance = EveAllianceInfo.objects.create(alliance_id='3', alliance_name='test alliance', alliance_ticker='TEST', executor_corp_id='2')
|
||||||
|
cls.corp = EveCorporationInfo.objects.create(corporation_id='2', corporation_name='test corp', corporation_ticker='TEST', alliance=cls.alliance, member_count=1)
|
||||||
|
cls.group1 = Group.objects.create(name='group1')
|
||||||
|
cls.group2 = Group.objects.create(name='group2')
|
||||||
|
cls.group3 = Group.objects.create(name='group3')
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.user.refresh_from_db()
|
||||||
|
|
||||||
|
def _refresh_user(self):
|
||||||
|
self.user = User.objects.get(pk=self.user.pk)
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_manage_group(self):
|
||||||
|
|
||||||
|
|
||||||
|
self.group1.authgroup.group_leaders.add(self.user)
|
||||||
|
self.group2.authgroup.group_leader_groups.add(self.group1)
|
||||||
|
self._refresh_user()
|
||||||
|
groups = GroupManager.get_group_leaders_groups(self.user)
|
||||||
|
|
||||||
|
self.assertIn(self.group1, groups) #avail due to user
|
||||||
|
self.assertNotIn(self.group2, groups) #not avail due to group
|
||||||
|
self.assertNotIn(self.group3, groups) #not avail at all
|
||||||
|
|
||||||
|
self.user.groups.add(self.group1)
|
||||||
|
self._refresh_user()
|
||||||
|
groups = GroupManager.get_group_leaders_groups(self.user)
|
||||||
|
|
||||||
|
self.assertIn(self.group1, groups) #avail due to user
|
||||||
|
self.assertIn(self.group2, groups) #avail due to group1
|
||||||
|
self.assertNotIn(self.group3, groups) #not avail at all
|
Loading…
x
Reference in New Issue
Block a user