Skip to content
Snippets Groups Projects
Verified Commit 9846dbd1 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Manipulace s jitsi tokenem

parent 9f13a4b1
Branches
Tags
No related merge requests found
...@@ -7,7 +7,23 @@ no warnings qw{ experimental::signatures }; ...@@ -7,7 +7,23 @@ no warnings qw{ experimental::signatures };
sub me ($c){ sub me ($c){
my $user = $c->_get( $c->user->{id} ) // return; my $user = $c->_get( $c->user->{id} ) // return;
$c->render(openapi => $c->spec_filter($user->formatted, 'User'));
my $formatted = $user->formatted;
if (
( $user->jitsi_allowed || $user->roles =~ /chairman/ )
&& $c->cfg->{jitsi_base_url}
&& $c->cfg->{jitsi_room}
) {
$formatted->{jitsi_url} = join ('',
$c->cfg->{jitsi_base_url},
$c->cfg->{jitsi_room},
'?jwt=',
$c->jitsi_token($c->cfg->{jitsi_room}),
);
}
$c->render(openapi => $c->spec_filter($formatted, 'User'));
} }
sub ban ($c){ sub ban ($c){
...@@ -45,6 +61,18 @@ sub unban ($c){ ...@@ -45,6 +61,18 @@ sub unban ($c){
$c->render(status => 204, text => ''); $c->render(status => 204, text => '');
} }
sub jitsi ($c){
$c->openapi->valid_input or return;
my $args = $c->req->json;
my $user = $c->_get( $c->stash->{id} ) // return;
my $guard = $c->schema->txn_scope_guard;
$user->update({ jitsi_allowed => $args->{allowed} });
$guard->commit;
$c->render(status => 204, text => '');
}
sub _get ($c, $id ) { sub _get ($c, $id ) {
my $user; my $user;
......
...@@ -24,19 +24,22 @@ sub main { ...@@ -24,19 +24,22 @@ sub main {
$c->on(json => sub( $c, $message ) { $c->on(json => sub( $c, $message ) {
if ( $message->{event} eq 'KEEPALIVE' ) { if ( $message->{event} eq 'KEEPALIVE' ) {
my $user_id; my $user;
if ($message->{payload} =~ /^(\d+)$/) { if ($message->{payload} =~ /^(\d+)$/) {
# TODO: check signtaure # TODO: check signtaure
$user_id = $1;
$user = $c->schema->resultset('User')->find(
{ id => $1 }
);
} }
$c->schema->resultset('Socket')->update_or_create({ $c->schema->resultset('Socket')->update_or_create({
id => $c->req->headers->header('Sec-WebSocket-Key'), id => $c->req->headers->header('Sec-WebSocket-Key'),
ip => $ip, ip => $ip,
keepalive => \'now()', keepalive => \'now()',
user_id => $user_id, user_id => $user ? $user->id : undef,
}, { key => $user_id ? 'user':'primary'} ); }, { key => $user ? 'user':'primary'} );
my $all = $c->schema->resultset('Socket_view')->count( my $all = $c->schema->resultset('Socket_view')->count(
{ is_alive => 't', } { is_alive => 't', }
...@@ -49,6 +52,15 @@ sub main { ...@@ -49,6 +52,15 @@ sub main {
all => $all, all => $all,
members => $members, members => $members,
}}}); }}});
if ( $user ) {
my $jitsi = $user->jitsi_allowed || $user->roles =~ /chairman/;
$c->send({json => { event => 'user_status', payload => {
jitsi_allowed => $jitsi ? \1:\0,
# is_banned => $user->banned_until ? 1:0,
}}});
}
} }
}); });
......
...@@ -28,6 +28,7 @@ __PACKAGE__->add_columns( ...@@ -28,6 +28,7 @@ __PACKAGE__->add_columns(
main_group_name main_group_name
keepalive keepalive
banned_until banned_until
jitsi_allowed
), ),
); );
......
...@@ -116,6 +116,8 @@ components: ...@@ -116,6 +116,8 @@ components:
type: string type: string
secret: secret:
type: string type: string
jitsi_url:
type: string
is_banned: is_banned:
type: boolean type: boolean
Announcement: Announcement:
...@@ -462,7 +464,7 @@ paths: ...@@ -462,7 +464,7 @@ paths:
enum: [0, 1, 2, 3, 4] enum: [0, 1, 2, 3, 4]
content: content:
type: string type: string
isr_archived: is_archived:
type: boolean type: boolean
responses: responses:
204: 204:
...@@ -564,3 +566,25 @@ paths: ...@@ -564,3 +566,25 @@ paths:
responses: responses:
204: 204:
description: User banned description: User banned
/users/{id}/jitsi:
patch:
security:
- Bearer: ['chairman']
x-mojo-to: users#jitsi
tags:
- users
summary: Set jitsi access
operationId: jitsi
requestBody:
content:
application/json:
schema:
type: object
properties:
allowed:
type: boolean
responses:
204:
description: Status changed
alter table "users" add "roles" text; alter table "users" add "roles" text;
alter table "users" add "jitsi_allowed" bool not null default false;
create table "sockets" ( create table "sockets" (
"id" varchar(64), "id" varchar(64),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment