mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
Add button to update TS3 groups to admin page
This commit is contained in:
parent
5a2c9243c4
commit
e4b515c1d5
@ -15,6 +15,7 @@ class Teamspeak3UserAdmin(ServicesUserAdmin):
|
||||
|
||||
@admin.register(AuthTS)
|
||||
class AuthTSgroupAdmin(admin.ModelAdmin):
|
||||
change_list_template = 'admin/teamspeak3/authts/change_list.html'
|
||||
ordering = ('auth_group__name', )
|
||||
list_select_related = True
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
{% extends "admin/change_list.html" %}
|
||||
{% load i18n static %}
|
||||
|
||||
{% block object-tools-items %}
|
||||
{{ block.super }}
|
||||
<li>
|
||||
<a href="{% url 'teamspeak3:admin_update_ts3_groups' %}" class="btn btn-high">
|
||||
Update TS3 groups
|
||||
</a>
|
||||
</li>
|
||||
{% endblock %}
|
@ -216,6 +216,24 @@ class Teamspeak3ViewsTestCase(TestCase):
|
||||
self.assertEqual(ts3_user.perm_key, '123abc')
|
||||
self.assertTrue(tasks_manager.return_value.__enter__.return_value.update_groups.called)
|
||||
|
||||
@mock.patch(MODULE_PATH + '.views.Teamspeak3Tasks')
|
||||
@mock.patch(MODULE_PATH + '.views.messages')
|
||||
def test_should_update_ts_groups(self, messages, Teamspeak3Tasks):
|
||||
# given
|
||||
self.member.is_superuser = True
|
||||
self.member.is_staff = True
|
||||
self.member.save()
|
||||
self.login()
|
||||
# when
|
||||
response = self.client.get(urls.reverse('teamspeak3:admin_update_ts3_groups'))
|
||||
# then
|
||||
self.assertRedirects(
|
||||
response, urls.reverse('admin:teamspeak3_authts_changelist'),
|
||||
target_status_code=200
|
||||
)
|
||||
self.assertTrue(messages.info.called)
|
||||
self.assertTrue(Teamspeak3Tasks.run_ts3_group_update.delay.called)
|
||||
|
||||
|
||||
class Teamspeak3SignalsTestCase(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -6,12 +6,14 @@ app_name = 'teamspeak3'
|
||||
|
||||
module_urls = [
|
||||
# Teamspeak3 service control
|
||||
url(r'^activate/$', views.activate_teamspeak3,
|
||||
name='activate'),
|
||||
url(r'^deactivate/$', views.deactivate_teamspeak3,
|
||||
name='deactivate'),
|
||||
url(r'^reset_perm/$', views.reset_teamspeak3_perm,
|
||||
name='reset_perm'),
|
||||
url(r'^activate/$', views.activate_teamspeak3, name='activate'),
|
||||
url(r'^deactivate/$', views.deactivate_teamspeak3, name='deactivate'),
|
||||
url(r'^reset_perm/$', views.reset_teamspeak3_perm, name='reset_perm'),
|
||||
url(
|
||||
r'^admin_update_ts3_groups/$',
|
||||
views.admin_update_ts3_groups,
|
||||
name='admin_update_ts3_groups'
|
||||
),
|
||||
|
||||
# Teamspeak Urls
|
||||
url(r'^verify/$', views.verify_teamspeak3, name='verify'),
|
||||
|
@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.shortcuts import render, redirect
|
||||
from django.conf import settings
|
||||
@ -99,3 +100,11 @@ def reset_teamspeak3_perm(request):
|
||||
logger.error("Unsuccessful attempt to reset TS3 permission key for user %s" % request.user)
|
||||
messages.error(request, _('An error occurred while processing your TeamSpeak3 account.'))
|
||||
return redirect("services:services")
|
||||
|
||||
|
||||
@login_required
|
||||
@staff_member_required
|
||||
def admin_update_ts3_groups(request):
|
||||
Teamspeak3Tasks.run_ts3_group_update.delay()
|
||||
messages.info(request, "Started updating TS3 server groups...")
|
||||
return redirect("admin:teamspeak3_authts_changelist")
|
||||
|
@ -105,7 +105,9 @@ Click the URL provided to automatically connect to our server. It will prompt yo
|
||||
|
||||
Now we need to make groups. AllianceAuth handles groups in teamspeak differently: instead of creating groups it creates an association between groups in TeamSpeak and groups in AllianceAuth. Go ahead and make the groups you want to associate with auth groups, keeping in mind multiple TeamSpeak groups can be associated with a single auth group.
|
||||
|
||||
Navigate back to the AllianceAuth admin interface (example.com/admin) and under `Services`, select `Auth / TS Groups`. In the top-right corner click `Add`.
|
||||
Navigate back to the AllianceAuth admin interface (example.com/admin) and under `Teamspeak3`, select `Auth / TS Groups`.
|
||||
|
||||
In the top-right corner click, first click on `Update TS3 Groups` to fetch the newly created server groups from TS3 (this may take a minute to complete). Then click on `Add Auth / TS Group` to link Auth groups with TS3 server groups.
|
||||
|
||||
The dropdown box provides all auth groups. Select one and assign TeamSpeak groups from the panels below. If these panels are empty, wait a minute for the database update to run, or see the [troubleshooting section](#ts-group-models-not-populating-on-admin-site) below.
|
||||
|
||||
@ -119,13 +121,23 @@ To enable advanced permissions, on your client go to the `Tools` menu, `Applicat
|
||||
|
||||
### TS group models not populating on admin site
|
||||
|
||||
The method which populates these runs every 30 minutes. To populate manually, start a django shell:
|
||||
The method which populates these runs every 30 minutes. To populate manually you start the process from the admin site or from the Django shell.
|
||||
|
||||
#### Admin Site
|
||||
|
||||
Navigate to the AllianceAuth admin interface and under `Teamspeak3`, select `Auth / TS Groups`.
|
||||
|
||||
Then, in the top-right corner click, click on `Update TS3 Groups` to start the process of fetching the server groups from TS3 (this may take a minute to complete).
|
||||
|
||||
#### Django Shell
|
||||
|
||||
Start a django shell with:
|
||||
|
||||
```bash
|
||||
python manage.py shell
|
||||
```
|
||||
|
||||
And execute the update:
|
||||
And execute the update as follows:
|
||||
|
||||
```python
|
||||
from allianceauth.services.modules.teamspeak3.tasks import Teamspeak3Tasks
|
||||
|
Loading…
x
Reference in New Issue
Block a user