From 7d98c994c918e5d93ed69da5ba7cb171033c4ba4 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 23 Jan 2015 13:24:50 +0100 Subject: [PATCH] More fixes for the admin interface Make a new get_room_conf API call which does more or less the same as get_room_info but without trying to get our role --- lib/Vroom/Constants.pm | 1 + public/js/vroom.js | 29 +++++++++++++++++++++++++++++ vroom.pl | 18 ++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index e4c2eda..e48592b 100644 --- a/lib/Vroom/Constants.pm +++ b/lib/Vroom/Constants.pm @@ -169,6 +169,7 @@ use constant API_ACTIONS => { ping => 1, authenticate => 1, get_room_info => 1, + get_room_conf => 1, get_peer_role => 1, join => 1, get_padd_session => 1 diff --git a/public/js/vroom.js b/public/js/vroom.js index 2756fbe..4683310 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -319,6 +319,35 @@ function initAdmin(){ }); } + function getRoomConf(roomName){ + $.ajax({ + data: { + req: JSON.stringify({ + action: 'get_room_conf', + param: { + room: roomName, + } + }) + }, + async: false, + error: function(data){ + $.notify(locale.ERROR_OCCURRED, 'error'); + }, + success: function(data){ + // Update config switches + $('#lockedSet').bootstrapSwitch('state', data.locked == 'yes'); + $('#askForNameSet').bootstrapSwitch('state', data.ask_for_name == 'yes'); + $('#joinPassSet').bootstrapSwitch('state', data.join_auth == 'yes'); + $('#ownerPassSet').bootstrapSwitch('state', data.owner_auth == 'yes'); + $('#configureModal').modal('show'); + } + }); + } + + $(document).on('click', '.btn-configure', function(){ + getRoomConf($(this).data('room')); + }); + // Get room list right after loading the page getRooms(); } diff --git a/vroom.pl b/vroom.pl index 9285144..35737ad 100755 --- a/vroom.pl +++ b/vroom.pl @@ -942,6 +942,7 @@ helper make_key_admin => sub { my $self = shift; my ($token) = @_; my $key = $self->get_key_by_token($token); + $self->app->log->debug("making key $token an admin key"); if (!$key){ return 0; } @@ -1031,8 +1032,8 @@ get '/admin/:room' => { room => '' } => sub { my $room = $self->stash('room'); # Someone accessing /admin is considered an admin # For now, the auth is handled outside of VROOM itself - my $token = $self->req->headers->header('X-VROOM-API-Key'); - $self->make_key_admin($token); + $self->login; + $self->make_key_admin($self->session('key')); if ($room eq ''){ $self->purge_rooms; return $self->render('admin'); @@ -1579,6 +1580,19 @@ any '/api' => sub { } ); } + # Return just room config + elsif ($req->{action} eq 'get_room_conf'){ + return $self->render( + json => { + owner_auth => ($room->{owner_password}) ? 'yes' : 'no', + join_auth => ($room->{join_password}) ? 'yes' : 'no', + locked => ($room->{locked}) ? 'yes' : 'no', + ask_for_name => ($room->{ask_for_name}) ? 'yes' : 'no', + notif => $self->get_notification($room->{name}), + status => 'success' + } + ); + } # Return your role and various info about the room elsif ($req->{action} eq 'get_room_info'){ my $peer_id = $req->{param}->{peer_id};