Some fundamental fixes for the admin interface

Now rooms get listed and displayed on the page, but a lot is still missing
- Pagination
- Filter as you type
- Action on utton press (only join which is a simple a href works)
- Bypass password when joining a room through the admin page (push in the room_partitipant table)
- Probably more
master
Daniel Berteaud 10 years ago
parent 944f121ae4
commit 222f77d5ff
  1. 2
      lib/Vroom/Constants.pm
  2. 18
      public/js/vroom.js
  3. 41
      vroom.pl

@ -149,7 +149,7 @@ use constant JS_STRINGS => qw(
# API actions # API actions
use constant API_ACTIONS => { use constant API_ACTIONS => {
admin => { admin => {
list_rooms => 1, get_room_list => 1,
set_persistent => 1 set_persistent => 1
}, },
owner => { owner => {

@ -257,7 +257,7 @@ function initAdmin(){
var matches = 0; var matches = 0;
// Update display of room list // Update display of room list
function updateDeviceList(filter, min, max){ function updateRoomList(filter, min, max){
$('#deviceList').html(''); $('#deviceList').html('');
var filterRe = new RegExp(filter, "gi"); var filterRe = new RegExp(filter, "gi");
var i = 0; var i = 0;
@ -266,7 +266,7 @@ function initAdmin(){
if (filter === '' || obj.name.match(filterRe)){ if (filter === '' || obj.name.match(filterRe)){
matches++; matches++;
if (i >= min && i < max){ if (i >= min && i < max){
$('#deviceList').append($('<tr>') $('#roomList').append($('<tr>')
.append($('<td>').html(stringEscape(obj.name))) .append($('<td>').html(stringEscape(obj.name)))
.append($('<td>') .append($('<td>')
.append($('<div>').addClass('btn-group') .append($('<div>').addClass('btn-group')
@ -275,6 +275,16 @@ function initAdmin(){
$('<span>').addClass('glyphicon glyphicon-log-in') $('<span>').addClass('glyphicon glyphicon-log-in')
) )
) )
.append($('<button>').addClass('btn btn-default btn-configure').data('room', obj.name)
.html(
$('<span>').addClass('glyphicon glyphicon-cog')
)
)
.append($('<a>').addClass('btn btn-default btn-remove').data('room', obj.name)
.html(
$('<span>').addClass('glyphicon glyphicon-trash')
)
)
) )
) )
); );
@ -298,8 +308,8 @@ function initAdmin(){
}, },
success: function(data){ success: function(data){
if (data.status === 'success'){ if (data.status === 'success'){
deviceList = data.data; roomList = data.rooms;
matches = Object.keys(deviceList).length; matches = Object.keys(roomList).length;
updateRoomList($('searchRoom').val(), 0, matches); updateRoomList($('searchRoom').val(), 0, matches);
} }
else{ else{

@ -937,6 +937,23 @@ helper associate_key_to_room => sub {
return 1; return 1;
}; };
# Make an API key admin of every rooms
helper make_key_admin => sub {
my $self = shift;
my ($token) = @_;
my $key = $self->get_key_by_token($token);
if (!$key){
return 0;
}
my $sth = eval {
$self->db->prepare('UPDATE `api_keys`
SET `admin`=\'1\'
WHERE `id`=?');
};
$sth->execute($key->{id});
return 1;
};
# Check if a key can perform an action against a room # Check if a key can perform an action against a room
helper key_can_do_this => sub { helper key_can_do_this => sub {
my $self = shift; my $self = shift;
@ -1012,6 +1029,10 @@ get '/help' => 'help';
get '/admin/:room' => { room => '' } => sub { get '/admin/:room' => { room => '' } => sub {
my $self = shift; my $self = shift;
my $room = $self->stash('room'); 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);
if ($room eq ''){ if ($room eq ''){
$self->purge_rooms; $self->purge_rooms;
return $self->render('admin'); return $self->render('admin');
@ -1261,6 +1282,24 @@ any '/api' => sub {
action => $req->{action}, action => $req->{action},
param => $req->{param} param => $req->{param}
); );
# Here are mthod not tied to a room
if ($req->{action} eq 'get_room_list'){
my $rooms = $self->get_room_list;
# Blank out a few param we don't need
foreach my $r (keys %{$rooms}){
foreach my $p (qw/join_password owner_password owner token etherpad_group/){
delete $rooms->{$r}->{$p};
}
}
return $self->render(
json => {
status => 'success',
rooms => $rooms
}
);
}
$room = $self->get_room_by_name($req->{param}->{room}); $room = $self->get_room_by_name($req->{param}->{room});
if (!$res || (!$room && $req->{param}->{room})){ if (!$res || (!$room && $req->{param}->{room})){
return $self->render( return $self->render(
@ -1312,7 +1351,7 @@ any '/api' => sub {
); );
} }
# Handle room lock/unlock # Handle room lock/unlock
if ($req->{action} =~ m/(un)?lock_room/){ elsif ($req->{action} =~ m/(un)?lock_room/){
$room->{locked} = ($req->{action} eq 'lock_room') ? '1':'0'; $room->{locked} = ($req->{action} eq 'lock_room') ? '1':'0';
if ($self->modify_room($room)){ if ($self->modify_room($room)){
return $self->render( return $self->render(

Loading…
Cancel
Save