Browse Source

added rudimentary "admin" view to allow server admins to configure their servers without being able to alter "hoster only" config options

Natenom/support-murmur-13-1446181288462
Michael Ziegler 16 years ago
parent
commit
f51a52bc13
  1. 9
      pyweb/mumble/forms.py
  2. 8
      pyweb/mumble/models.py
  3. 1
      pyweb/mumble/urls.py
  4. 21
      pyweb/mumble/views.py
  5. 19
      template/mumble/admin.htm
  6. 5
      template/mumble/content.htm

9
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', );

8
pyweb/mumble/models.py

@ -131,6 +131,14 @@ class Mumble( models.Model ):
# Now allow django to save the record set # Now allow django to save the record set
return models.Model.save( self ); 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 ): def deleteServer( self ):
srvid = dbus.Int32( self.srvid ); srvid = dbus.Int32( self.srvid );
murmur = self.getDbusMeta(); murmur = self.getDbusMeta();

1
pyweb/mumble/urls.py

@ -4,6 +4,7 @@ urlpatterns = patterns(
'', '',
( r'savereg', 'mumble.views.savereg' ), ( r'savereg', 'mumble.views.savereg' ),
( r'reg/(?P<server>\d+)', 'mumble.views.register' ), ( r'reg/(?P<server>\d+)', 'mumble.views.register' ),
( r'admin/(?P<serverid>\d+)', 'mumble.views.admin' ),
( r'(?P<server>\d+)', 'mumble.views.show' ), ( r'(?P<server>\d+)', 'mumble.views.show' ),
( r'$', 'mumble.views.mumbles' ), ( r'$', 'mumble.views.mumbles' ),
) )

21
pyweb/mumble/views.py

@ -37,6 +37,7 @@ from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from models import Mumble, MumbleUser from models import Mumble, MumbleUser
from forms import *
from mmobjects import mmServer, mmChannel from mmobjects import mmServer, mmChannel
class Storage( object ): class Storage( object ):
@ -58,7 +59,7 @@ def show( request, server ):
return render_to_response( return render_to_response(
'mumble/mumble.htm', '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) context_instance = RequestContext(request)
); );
@ -153,6 +154,24 @@ def savereg( request ):
@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)
);

19
template/mumble/admin.htm

@ -0,0 +1,19 @@
{% extends "base.htm" %}
{% block content %}
{% if user.is_authenticated %}
{% if CurrentUserIsAdmin %}
<h2>Configure Mumble server</h2>
<p>Here you can configure your Murmur server in detail.</p>
<form action="/mumble/admin/{{Mumble.id}}" method="post">
<table>
{{ Adminform }}
</table>
<input type="submit" />
</form>
{% else %}
<p>Only admins of this server can use this feature.</p>
{% endif %}
{% else %}
<p>Only registered users can use this feature.</p>
{% endif %}
{% endblock %}

5
template/mumble/content.htm

@ -55,5 +55,8 @@
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
<p><a href="/mumble/reg/{{DBaseObject.id}}" class="dingen">Mumble-Account verwalten</a></p>
<p><a href="/mumble/reg/{{DBaseObject.id}}" class="dingen">Manage Account</a></p>
{% if CurrentUserIsAdmin %}
<p><a href="/mumble/admin/{{DBaseObject.id}}" class="dingen">Manage Server settings</a></p>
{% endif %}
</div> </div>
Loading…
Cancel
Save