Browse Source

finish user admin thingy. fixes #15

Natenom/support-murmur-13-1446181288462
Michael Ziegler 16 years ago
parent
commit
2c9ad43f2a
  1. 3
      pyweb/mumble/urls.py
  2. 25
      pyweb/mumble/views.py
  3. 41
      template/mumble/mumble.htm

3
pyweb/mumble/urls.py

@ -18,7 +18,8 @@ from django.conf.urls.defaults import *
urlpatterns = patterns( urlpatterns = patterns(
'mumble.views', 'mumble.views',
( r'(?P<server>\d+)/users', 'users' ),
( r'djangousers', 'djangousers' ),
( r'(?P<server>\d+)/users', 'users' ),
( r'(?P<server>\d+)/(?P<userid>\d+)texture.png', 'showTexture' ), ( r'(?P<server>\d+)/(?P<userid>\d+)texture.png', 'showTexture' ),
( r'(?P<server>\d+)/texture.png', 'showTexture' ), ( r'(?P<server>\d+)/texture.png', 'showTexture' ),
( r'(?P<server>\d+)', 'show' ), ( r'(?P<server>\d+)', 'show' ),

25
pyweb/mumble/views.py

@ -188,7 +188,6 @@ def users( request, server ):
if request.method == 'POST': if request.method == 'POST':
data = simplejson.loads( request.POST['data'] ); data = simplejson.loads( request.POST['data'] );
print "Json: ", data;
for record in data: for record in data:
if record['id'] == -1: if record['id'] == -1:
if record['delete']: if record['delete']:
@ -204,25 +203,22 @@ def users( request, server ):
mu.password = record['password']; mu.password = record['password'];
mu.isAdmin = record['admin']; mu.isAdmin = record['admin'];
if record['owner_id']:
mu.owner = User.objects.get( id=int(record['owner_id']) );
if record['owner']:
mu.owner = User.objects.get( id=int(record['owner']) );
mu.save(); mu.save();
users = []; users = [];
for mu in srv.mumbleuser_set.all(): for mu in srv.mumbleuser_set.all():
owner = None; owner = None;
owner_id = None;
if mu.owner is not None: if mu.owner is not None:
owner = unicode( mu.owner );
owner_id = mu.owner.id
owner = mu.owner.id
users.append( { users.append( {
'id': mu.id, 'id': mu.id,
'name': mu.name, 'name': mu.name,
'password': None, 'password': None,
'owner': owner, 'owner': owner,
'owner_id': owner_id,
'admin': mu.getAdmin(), 'admin': mu.getAdmin(),
} ); } );
@ -232,6 +228,19 @@ def users( request, server ):
); );
@login_required
def djangousers( request ):
"Return a list of all Django users' names and IDs."
users = [ { 'uid': '', 'uname': '------' } ];
for du in User.objects.all():
users.append( {
'uid': du.id,
'uname': unicode( du ),
} );
return HttpResponse(
simplejson.dumps( { 'success': True, 'objects': users } ),
mimetype='text/javascript'
);

41
template/mumble/mumble.htm

@ -149,8 +149,7 @@
{ name: 'id', type: 'int' }, { name: 'id', type: 'int' },
{ name: 'name', type: 'string' }, { name: 'name', type: 'string' },
{ name: 'password', type: 'string' }, { name: 'password', type: 'string' },
{ name: 'owner', type: 'string' },
{ name: 'owner_id', type: 'int' },
{ name: 'owner', type: 'int' },
{ name: 'admin', type: 'bool' }, { name: 'admin', type: 'bool' },
{ name: 'delete', type: 'bool' }, { name: 'delete', type: 'bool' },
]); ]);
@ -167,11 +166,30 @@
adminColumn = new Ext.grid.CheckColumn({ adminColumn = new Ext.grid.CheckColumn({
header: '{% trans "Admin on root channel" %}', header: '{% trans "Admin on root channel" %}',
dataIndex: 'admin', dataIndex: 'admin',
width: 50,
}); });
deleteColumn = new Ext.grid.CheckColumn({ deleteColumn = new Ext.grid.CheckColumn({
header: '{% trans "Delete" %}', header: '{% trans "Delete" %}',
dataIndex: 'delete', dataIndex: 'delete',
width: 50,
});
ownerCombo = new Ext.form.ComboBox({
name: 'owner',
hiddenName: 'owner_id',
forceSelection: true,
triggerAction: 'all',
valueField: 'uid',
displayField: 'uname',
store: new Ext.data.Store({
url: '/mumble/djangousers',
reader: new Ext.data.JsonReader({
fields: [ 'uid', 'uname' ],
root: 'objects',
}),
autoLoad: true,
}),
}); });
{% endif %} {% endif %}
@ -210,13 +228,25 @@
}, { }, {
header: '{% trans "Account owner" %}', header: '{% trans "Account owner" %}',
dataIndex: 'owner', dataIndex: 'owner',
editor: new Ext.form.TextField(),
editor: ownerCombo,
renderer: function( value ){
if( value == '' ) return '';
idx = ownerCombo.store.find( 'uid', value );
rec = ownerCombo.store.getAt( idx );
return rec.get( 'uname' );
},
}, adminColumn, { }, adminColumn, {
header: '{% trans "Change password" %}', header: '{% trans "Change password" %}',
dataIndex: 'password', dataIndex: 'password',
editor: new Ext.form.TextField({ editor: new Ext.form.TextField({
inputType: 'password', inputType: 'password',
}), }),
renderer: function( value ){
ret = '';
for( i = 0; i < value.length; i++ )
ret += '*';
return ret;
},
}, deleteColumn ] ), }, deleteColumn ] ),
tbar: [{ tbar: [{
text: '{% trans "Add" %}', text: '{% trans "Add" %}',
@ -225,9 +255,8 @@
id: -1, id: -1,
name: 'New User', name: 'New User',
admin: false, admin: false,
owner: null,
owner_id: null,
password: null,
owner: '',
password: '',
'delete': false, 'delete': false,
} ) ); } ) );
} }

Loading…
Cancel
Save