mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
Implement reserved group names in Teamspeak3 service module.
Closes #1302
This commit is contained in:
parent
724e0e83f2
commit
d11832913d
@ -4,6 +4,7 @@ from django.conf import settings
|
|||||||
|
|
||||||
from .util.ts3 import TS3Server, TeamspeakError
|
from .util.ts3 import TS3Server, TeamspeakError
|
||||||
from .models import TSgroup
|
from .models import TSgroup
|
||||||
|
from allianceauth.groupmanagement.models import ReservedGroupName
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -270,7 +271,8 @@ class Teamspeak3Manager:
|
|||||||
addgroups.append(ts_groups[ts_group_key])
|
addgroups.append(ts_groups[ts_group_key])
|
||||||
for user_ts_group_key in user_ts_groups:
|
for user_ts_group_key in user_ts_groups:
|
||||||
if user_ts_groups[user_ts_group_key] not in ts_groups.values():
|
if user_ts_groups[user_ts_group_key] not in ts_groups.values():
|
||||||
remgroups.append(user_ts_groups[user_ts_group_key])
|
if not ReservedGroupName.objects.filter(name=user_ts_group_key).exists():
|
||||||
|
remgroups.append(user_ts_groups[user_ts_group_key])
|
||||||
|
|
||||||
for g in addgroups:
|
for g in addgroups:
|
||||||
logger.info(f"Adding Teamspeak user {userid} into group {g}")
|
logger.info(f"Adding Teamspeak user {userid} into group {g}")
|
||||||
|
@ -15,6 +15,7 @@ from .signals import m2m_changed_authts_group, post_save_authts, post_delete_aut
|
|||||||
from .manager import Teamspeak3Manager
|
from .manager import Teamspeak3Manager
|
||||||
from .util.ts3 import TeamspeakError
|
from .util.ts3 import TeamspeakError
|
||||||
from allianceauth.authentication.models import State
|
from allianceauth.authentication.models import State
|
||||||
|
from allianceauth.groupmanagement.models import ReservedGroupName
|
||||||
|
|
||||||
MODULE_PATH = 'allianceauth.services.modules.teamspeak3'
|
MODULE_PATH = 'allianceauth.services.modules.teamspeak3'
|
||||||
DEFAULT_AUTH_GROUP = 'Member'
|
DEFAULT_AUTH_GROUP = 'Member'
|
||||||
@ -316,6 +317,9 @@ class Teamspeak3SignalsTestCase(TestCase):
|
|||||||
|
|
||||||
class Teamspeak3ManagerTestCase(TestCase):
|
class Teamspeak3ManagerTestCase(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.reserved = ReservedGroupName.objects.create(name='reserved', reason='tests', created_by='Bob, praise be!')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def my_side_effect(*args, **kwargs):
|
def my_side_effect(*args, **kwargs):
|
||||||
raise TeamspeakError(1)
|
raise TeamspeakError(1)
|
||||||
@ -339,3 +343,48 @@ class Teamspeak3ManagerTestCase(TestCase):
|
|||||||
|
|
||||||
# perform test
|
# perform test
|
||||||
manager.add_user(user, "Dummy User")
|
manager.add_user(user, "Dummy User")
|
||||||
|
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_get_userid')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_user_group_list')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_add_user_to_group')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_remove_user_from_group')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, 'server')
|
||||||
|
def test_update_groups_add(self, server, remove, add, groups, userid):
|
||||||
|
"""Add to one group"""
|
||||||
|
userid.return_value = 1
|
||||||
|
groups.return_value = {'test': 1}
|
||||||
|
|
||||||
|
Teamspeak3Manager().update_groups(1, {'test': 1, 'dummy': 2})
|
||||||
|
self.assertEqual(add.call_count, 1)
|
||||||
|
self.assertEqual(remove.call_count, 0)
|
||||||
|
self.assertEqual(add.call_args[0][1], 2)
|
||||||
|
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_get_userid')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_user_group_list')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_add_user_to_group')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_remove_user_from_group')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, 'server')
|
||||||
|
def test_update_groups_remove(self, server, remove, add, groups, userid):
|
||||||
|
"""Remove from one group"""
|
||||||
|
userid.return_value = 1
|
||||||
|
groups.return_value = {'test': 1, 'dummy': 2}
|
||||||
|
|
||||||
|
Teamspeak3Manager().update_groups(1, {'test': 1})
|
||||||
|
self.assertEqual(add.call_count, 0)
|
||||||
|
self.assertEqual(remove.call_count, 1)
|
||||||
|
self.assertEqual(remove.call_args[0][1], 2)
|
||||||
|
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_get_userid')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_user_group_list')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_add_user_to_group')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, '_remove_user_from_group')
|
||||||
|
@mock.patch.object(Teamspeak3Manager, 'server')
|
||||||
|
def test_update_groups_remove_reserved(self, server, remove, add, groups, userid):
|
||||||
|
"""Remove from one group, but do not touch reserved group"""
|
||||||
|
userid.return_value = 1
|
||||||
|
groups.return_value = {'test': 1, 'dummy': 2, self.reserved.name: 3}
|
||||||
|
|
||||||
|
Teamspeak3Manager().update_groups(1, {'test': 1})
|
||||||
|
self.assertEqual(add.call_count, 0)
|
||||||
|
self.assertEqual(remove.call_count, 1)
|
||||||
|
self.assertEqual(remove.call_args[0][1], 2)
|
||||||
|
@ -48,7 +48,7 @@ When using Alliance Auth to manage external services like Discord, Auth will aut
|
|||||||
|
|
||||||
```eval_rst
|
```eval_rst
|
||||||
.. note::
|
.. note::
|
||||||
While this feature can help to avoid naming conflicts with groups on external services, the respective service component in Alliance Auth also needs to be build in such a way that it knows how to prevent these conflicts. Currently only the Discord service has this ability.
|
While this feature can help to avoid naming conflicts with groups on external services, the respective service component in Alliance Auth also needs to be build in such a way that it knows how to prevent these conflicts. Currently only the Discord and Teamspeak3 services have this ability.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Managing groups
|
## Managing groups
|
||||||
|
Loading…
x
Reference in New Issue
Block a user