From f51a52bc136031934d03374ee97acc44f047200c Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Fri, 10 Apr 2009 02:19:25 +0200 Subject: [PATCH] added rudimentary "admin" view to allow server admins to configure their servers without being able to alter "hoster only" config options --- pyweb/mumble/forms.py | 9 +++++++++ pyweb/mumble/models.py | 8 ++++++++ pyweb/mumble/urls.py | 1 + pyweb/mumble/views.py | 23 +++++++++++++++++++++-- template/mumble/admin.htm | 19 +++++++++++++++++++ template/mumble/content.htm | 5 ++++- 6 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 pyweb/mumble/forms.py create mode 100644 template/mumble/admin.htm diff --git a/pyweb/mumble/forms.py b/pyweb/mumble/forms.py new file mode 100644 index 0000000..303ab10 --- /dev/null +++ b/pyweb/mumble/forms.py @@ -0,0 +1,9 @@ +from django.forms import ModelForm +from models import * + +class MumbleForm( ModelForm ): + class Meta: + model = Mumble; + exclude = ( 'dbus', 'booted', 'addr', 'port', 'users', 'bwidth', ); + + diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 3d329fb..fcbb1ac 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -131,6 +131,14 @@ class Mumble( models.Model ): # Now allow django to save the record set return models.Model.save( self ); + def isUserAdmin( self, user ): + if user.is_authenticated(): + try: + return self.mumbleuser_set.get( owner=user ).getAdmin(); + except MumbleUser.DoesNotExist: + return False; + return False; + def deleteServer( self ): srvid = dbus.Int32( self.srvid ); murmur = self.getDbusMeta(); diff --git a/pyweb/mumble/urls.py b/pyweb/mumble/urls.py index aafb373..e75c603 100644 --- a/pyweb/mumble/urls.py +++ b/pyweb/mumble/urls.py @@ -4,6 +4,7 @@ urlpatterns = patterns( '', ( r'savereg', 'mumble.views.savereg' ), ( r'reg/(?P\d+)', 'mumble.views.register' ), + ( r'admin/(?P\d+)', 'mumble.views.admin' ), ( r'(?P\d+)', 'mumble.views.show' ), ( r'$', 'mumble.views.mumbles' ), ) diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index a041c3f..147abcb 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -37,6 +37,7 @@ from django.core.urlresolvers import reverse from django.contrib.auth.decorators import login_required from models import Mumble, MumbleUser +from forms import * from mmobjects import mmServer, mmChannel class Storage( object ): @@ -55,10 +56,10 @@ def mumbles( request ): def show( request, server ): "Displays the channel list for the given Server ID." srv, o = createChannelList( server ); - + return render_to_response( 'mumble/mumble.htm', - { 'DBaseObject': srv, 'ServerObject': o, 'ChannelTable': Storage.s }, + { 'DBaseObject': srv, 'ServerObject': o, 'ChannelTable': Storage.s, "CurrentUserIsAdmin": srv.isUserAdmin( request.user ) }, context_instance = RequestContext(request) ); @@ -152,6 +153,24 @@ def savereg( request ): return HttpResponseRedirect( "/mumble/%d" % srv.id ); + +@login_required +def admin( request, serverid ): + murmur = get_object_or_404( Mumble, id=serverid ); + + if request.method == 'POST': + form = MumbleForm( request.POST, instance=murmur ); + if form.is_valid(): + form.save(); + return HttpResponseRedirect( '/mumble/%d' % int(serverid) ); + else: + form = MumbleForm( instance=murmur ); + + return render_to_response( + 'mumble/admin.htm', + { "Mumble": murmur, "Adminform": form, "CurrentUserIsAdmin": murmur.isUserAdmin( request.user ) }, + context_instance = RequestContext(request) + ); diff --git a/template/mumble/admin.htm b/template/mumble/admin.htm new file mode 100644 index 0000000..a326a28 --- /dev/null +++ b/template/mumble/admin.htm @@ -0,0 +1,19 @@ +{% extends "base.htm" %} +{% block content %} +{% if user.is_authenticated %} + {% if CurrentUserIsAdmin %} +

Configure Mumble server

+

Here you can configure your Murmur server in detail.

+
+ + {{ Adminform }} +
+ +
+ {% else %} +

Only admins of this server can use this feature.

+ {% endif %} +{% else %} +

Only registered users can use this feature.

+{% endif %} +{% endblock %} diff --git a/template/mumble/content.htm b/template/mumble/content.htm index d65aea3..d4c7bd5 100644 --- a/template/mumble/content.htm +++ b/template/mumble/content.htm @@ -55,5 +55,8 @@ {% endfor %} -

Mumble-Account verwalten

+

Manage Account

+ {% if CurrentUserIsAdmin %} +

Manage Server settings

+ {% endif %}