|
|
@ -438,27 +438,29 @@ helper set_peer_role => sub { |
|
|
|
# Return the role of a peer, from it's signaling ID |
|
|
|
# Return the role of a peer, from it's signaling ID |
|
|
|
helper get_peer_role => sub { |
|
|
|
helper get_peer_role => sub { |
|
|
|
my $self = shift; |
|
|
|
my $self = shift; |
|
|
|
my ($room,$id) = @_; |
|
|
|
my ($data) = @_; |
|
|
|
my $data = $self->get_room_by_name($room)->{data} || return undef; |
|
|
|
|
|
|
|
if (!$data){ |
|
|
|
|
|
|
|
return undef; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
my $sth = eval { |
|
|
|
my $sth = eval { |
|
|
|
$self->db->prepare('SELECT `role` |
|
|
|
$self->db->prepare('SELECT `p`.`role` |
|
|
|
FROM `room_participants` |
|
|
|
FROM `room_participants` `p` |
|
|
|
WHERE `peer_id`=? |
|
|
|
LEFT JOIN `rooms` `r` ON `p`.`room_id`=`r`.`id` |
|
|
|
AND `room_id`=? |
|
|
|
WHERE `p`.`peer_id`=? |
|
|
|
|
|
|
|
AND `r`.`name`=? |
|
|
|
LIMIT 1'); |
|
|
|
LIMIT 1'); |
|
|
|
} || return undef; |
|
|
|
}; |
|
|
|
# TODO: replace with bind_columns |
|
|
|
if ($@){ |
|
|
|
$sth->execute($id,$data->{id}) || return undef; |
|
|
|
return {msg => $@}; |
|
|
|
if ($sth->rows == 1){ |
|
|
|
|
|
|
|
my ($role) = $sth->fetchrow_array(); |
|
|
|
|
|
|
|
return $role; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
$sth->execute($data->{peer_id},$data->{room}); |
|
|
|
return 'participant'; |
|
|
|
if ($sth->err){ |
|
|
|
|
|
|
|
return {msg => "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
my $role; |
|
|
|
|
|
|
|
$sth->bind_columns(\$role); |
|
|
|
|
|
|
|
$sth->fetch; |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
ok => 1, |
|
|
|
|
|
|
|
data => $role |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
# Promote a peer to owner |
|
|
|
# Promote a peer to owner |
|
|
@ -1529,7 +1531,7 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub { |
|
|
|
my $id = $self->param('id'); |
|
|
|
my $id = $self->param('id'); |
|
|
|
my %emailNotif; |
|
|
|
my %emailNotif; |
|
|
|
if ($self->session($room) && $self->session($room)->{role}){ |
|
|
|
if ($self->session($room) && $self->session($room)->{role}){ |
|
|
|
if ($self->session($room)->{role} ne 'owner' && $self->get_peer_role($room,$id) eq 'owner'){ |
|
|
|
if ($self->session($room)->{role} ne 'owner' && $self->get_peer_role({room => $room, peer_id => $id})->{data} eq 'owner'){ |
|
|
|
$self->session($room)->{role} = 'owner'; |
|
|
|
$self->session($room)->{role} = 'owner'; |
|
|
|
} |
|
|
|
} |
|
|
|
my $res = $self->set_peer_role({ |
|
|
|
my $res = $self->set_peer_role({ |
|
|
@ -1567,7 +1569,7 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub { |
|
|
|
# Return the role of a peer |
|
|
|
# Return the role of a peer |
|
|
|
elsif ($action eq 'getPeerRole'){ |
|
|
|
elsif ($action eq 'getPeerRole'){ |
|
|
|
my $id = $self->param('id'); |
|
|
|
my $id = $self->param('id'); |
|
|
|
my $role = $self->get_peer_role($room,$id); |
|
|
|
my $role = $self->get_peer_role({room => $room, peer_id => $id}); |
|
|
|
return $self->render( |
|
|
|
return $self->render( |
|
|
|
json => { |
|
|
|
json => { |
|
|
|
role => $role, |
|
|
|
role => $role, |
|
|
|