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

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #10494 passed
Showing
with 1181 additions and 0 deletions
.git
.gitignore
.dockerignore
_work
t
docker-compose.yaml
Dockerfile
_work
docker-compose.yaml
image: docker:20.10.9
variables:
DOCKER_TLS_CERTDIR: "/certs"
services:
- docker:20.10.9-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build:
stage: build
script:
- VERSION=`cat VERSION`
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$VERSION --tag $CI_REGISTRY_IMAGE:latest .
- docker push $CI_REGISTRY_IMAGE:$VERSION
- docker push $CI_REGISTRY_IMAGE:latest
FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y \
wget make gcc libc-dev libpng-dev \
cpanminus \
build-essential \
libxml2-dev \
libcrypt-openssl-rsa-perl \
libcrypt-openssl-x509-perl \
libdata-guid-perl \
libdbix-class-perl \
libdbd-pg-perl \
libdbi-perl \
libio-socket-ssl-perl \
libmodule-build-perl \
libnet-oauth2-perl \
libnet-ssleay-perl \
libredis-perl \
libjson-perl \
libuuid-urandom-perl \
libyaml-dev
RUN cpanm \
Mojolicious \
Mojo::Pg \
Mojo::Redis \
Mojo::JWT \
GraphQL::Client \
Mojolicious::Plugin::Authentication \
Mojolicious::Plugin::I18N \
Mojolicious::Plugin::OpenAPI
ADD . /opt/app
WORKDIR /opt/app
USER nobody
EXPOSE 3000
CMD /opt/app/script/semeet daemon
LICENSE 0 → 100644
The "Artistic License"
Preamble
The intent of this document is to state the conditions under which a
Package may be copied, such that the Copyright Holder maintains some
semblance of artistic control over the development of the package,
while giving the users of the package the right to use and distribute
the Package in a more-or-less customary fashion, plus the right to make
reasonable modifications.
Definitions:
"Package" refers to the collection of files distributed by the
Copyright Holder, and derivatives of that collection of files
created through textual modification.
"Standard Version" refers to such a Package if it has not been
modified, or has been modified in accordance with the wishes
of the Copyright Holder as specified below.
"Copyright Holder" is whoever is named in the copyright or
copyrights for the package.
"You" is you, if you're thinking about copying or distributing
this Package.
"Reasonable copying fee" is whatever you can justify on the
basis of media cost, duplication charges, time of people involved,
and so on. (You will not be required to justify it to the
Copyright Holder, but only to the computing community at large
as a market that must bear the fee.)
"Freely Available" means that no fee is charged for the item
itself, though there may be fees involved in handling the item.
It also means that recipients of the item may redistribute it
under the same conditions they received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications
derived from the Public Domain or from the Copyright Holder. A Package
modified in such a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided
that you insert a prominent notice in each changed file stating how and
when you changed that file, and provided that you do at least ONE of the
following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or
an equivalent medium, or placing the modifications on a major archive
site such as uunet.uu.net, or by allowing the Copyright Holder to include
your modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict
with standard executables, which must also be provided, and provide
a separate manual page for each non-standard executable that clearly
documents how it differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or
executable form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where
to get the Standard Version.
b) accompany the distribution with the machine-readable source of
the Package with your modifications.
c) give non-standard executables non-standard names, and clearly
document the differences in manual pages (or equivalent), together
with instructions on where to get the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this
Package. You may not charge a fee for this Package itself. However,
you may distribute this Package in aggregate with other (possibly
commercial) programs as part of a larger (possibly commercial) software
distribution provided that you do not advertise this Package as a
product of your own. You may embed this Package's interpreter within
an executable of yours (by linking); this shall be construed as a mere
form of aggregation, provided that the complete Standard Version of the
interpreter is so embedded.
6. The scripts and library files supplied as input to or produced as
output from the programs of this Package do not automatically fall
under the copyright of this Package, but belong to whoever generated
them, and may be sold commercially, and may be aggregated with this
Package. If such scripts or library files are aggregated with this
Package via the so-called "undump" or "unexec" methods of producing a
binary executable image, then distribution of such an image shall
neither be construed as a distribution of this Package nor shall it
fall under the restrictions of Paragraphs 3 and 4, provided that you do
not represent such an executable image as a Standard Version of this
Package.
7. C subroutines (or comparably compiled subroutines in other
languages) supplied by you and linked into this Package in order to
emulate subroutines and variables of the language defined by this
Package shall not be considered part of this Package, but are the
equivalent of input as in Paragraph 6, provided these subroutines do
not change the language in any way that would cause it to fail the
regression tests for the language.
8. Aggregation of this Package with a commercial distribution is always
permitted provided that the use of this Package is embedded; that is,
when no overt attempt is made to make this Package's interfaces visible
to the end user of the commercial distribution. Such use shall not be
construed as a distribution of this Package.
9. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
0.1.0
package SeMeet;
use Mojo::Base 'Mojolicious', -signatures;
use Mojo::Pg;
use Mojo::Redis;
use Mojolicious::Plugin::Authentication;
use Mojolicious::Plugin::I18N;
use Net::OAuth2::Profile::WebServer;
use SeMeet::Schema;
use SeMeet::Model::IAPI;
sub startup( $self ) {
# Nacteni konfigurace
my $cfg = $self->plugin('Config' => { file => 'semeet.conf'} );
# Konfigurace z ENV ma prednost
KEY:
foreach my $key ( keys %ENV ) {
if ( $key =~ /^CFG_(.+)/i ) {
$cfg->{lc($1)} = $ENV{$key};
}
}
$self->helper( cfg => sub { return $cfg; } );
# Podpis pro cookies
$self->secrets([$cfg->{session_secret}]);
# Delka session
$self->sessions->default_expiration($cfg->{session_lifetime} // 24 * 3600);
$self->plugin('SeMeet::Helpers::Core');
$self->plugin('SeMeet::Helpers::OIDC');
# migrace schematu
my $pg = Mojo::Pg->new
->dsn($cfg->{database}{dsn})
->username($cfg->{database}{user})
->password($cfg->{database}{password})
;
$pg->migrations->from_file($self->home . '/sql/migrations.sql');
$pg->migrations->migrate();
$self->helper( pg => sub { return $pg; } );
# Spojeni s databazi
my $schema = SeMeet::Schema->connect($cfg->{database});
$self->helper( schema => sub { return $schema; } );
# Redis
my $iapi = SeMeet::Model::IAPI->new( $cfg->{iapi} );
$self->helper( iapi => sub { return $iapi; } );
# Redis
my $redis = Mojo::Redis->new( $cfg->{redis} );
$self->helper( redis => sub { return $redis; } );
# i18n
$self->plugin( I18N => {
namespace => 'SeMeet::I18N',
default => 'cs',
});
$self->plugin('authentication', {
autoload_user => 1,
load_user => sub($c, $uid) {
# $c->trace($c->session->{user});
return $c->session->{user};
},
validate_user => sub($c, $user, $pass, $extradata) {
return $c->session->{user} ? 1 : undef;
},
});
$self->plugin("OpenAPI" => {
url => $self->home->rel_file("openapi.yaml"),
schema => 'v3',
plugins => [qw(+Cors +Security)],
render_specification => 0,
render_specification_for_paths => 0,
default_response_codes => [400, 401, 403, 404, 500, 501],
security => {
Bearer => sub ($c, $definition, $scopes, $cb ){
# my ($c, $definition, $scopes, $cb ) = @_;
my $token = $c->req->headers->authorization || $c->req->param('auth_token');
return $c->$cb('Authorization header not present') if ! $token;
return $c->$cb('Unsupported authorization type') if $token !~ s/Bearer\s+//i;
my $jwt = $c->jwt_token( $token );
return $c->$cb($jwt) if ! ref $jwt;
my $user = $schema->resultset('User')->find({ id => $jwt->{id} } );
return $c->$cb('Invalid user') if ! $user;
$c->stash->{user} = $user;
return $c->$cb();
}
}
});
# defautni globalni promenne ve stash
$self->defaults(
openapi_cors_allowed_origins => ['*'],
);
$self->hook( before_render => sub($c, $args) {
# my ($c, $args) = @_;
if ( $c->req->method eq 'OPTIONS' && exists $args->{json} ) {
delete $args->{json};
$args->{status} = 204;
$args->{text} = '';
}
});
# vypnuti cache templatu pri vyvoji
$self->renderer->cache->max_keys(0) if $cfg->{dev_mode};
# router
my $r = $self->routes;
$r->get('/login')->to('Auth#callback');
$r->get('/logout')->to('Auth#do_logout');
$r->get('/')->requires(authenticated => 1)->to(cb => sub { shift->render('meets'); });
$r->get('/')->to(cb => sub { shift->render('index'); });
$r->get('/meets/:id')->requires(authenticated => 1)->to('Meets#meet');
}
1;
package SeMeet::Controller::Auth;
use Mojo::Base 'Mojolicious::Controller', -signatures;
use YAML;
sub callback ($c) {
my $token = $c->oidc->get_access_token( $c->param("code") );
my $claims = $c->oauth_claims( $token->access_token );
my $octopus_user = $c->iapi->get('octopus/user?username=' . $claims->{preferred_username});
my %user = (
uuid => $claims->{sub},
octid => $octopus_user->{id},
username => $claims->{preferred_username},
displayname => $octopus_user->{displayname} || $claims->{name},
);
my $user = $c->schema->resultset('User')->search({
-or => [
uuid => $claims->{sub},
username => $claims->{preferred_username},
]
})->first;
if ( $user ) {
$user->updata(\%user);
}
else {
$user = $c->schema->resultset('User')->create(\%user);
}
$c->session->{user} = {
$user->get_columns,
token => $user->api_token({ secret => $c->cfg->{jwt_secret}}),
};
my $groups = $c->schema->resultset('Group')->search(
{ octid => { '-in' => $octopus_user->{groups} }},
{ columns => ['id', 'permissions'] }
);
GROUP:
while ( my $group = $groups->next ) {
push @{$c->session->{user}{groups}}, $group->id;
if ( $group->permissions ) {
PERMISSION:
foreach my $permission ( @{ $group->permissions } ) {
$c->session->{user}{permissions}{$permission} = 1;
}
}
}
$c->authenticate();
$c->redirect_to('/');
}
sub do_logout($c) { # nesmi se jmenovat logout - rekurze
$c->logout;
delete $c->session->{user};
$c->redirect_to('/');
}
1;
package SeMeet::Controller::Groups;
use Mojo::Base 'Mojolicious::Controller', -signatures;
sub list($c) {
$c->openapi->valid_input or return;
my $args = $c->validation->output;
my $groups = $c->schema->resultset('Group')->search({
name => { ilike => '%' . $args->{search} . '%' }
},
{
order_by => 'name',
}
);
my @groups = ();
# TODO: filter
GROUP:
while ( my $group = $groups->next()) {
push @groups, $c->spec_filter({
$group->get_columns,
}, 'GroupInList')
}
$c->render( openapi => \@groups );
}
1;
package SeMeet::Controller::Meets;
use Mojo::Base 'Mojolicious::Controller', -signatures;
use UUID::URandom qw(create_uuid_string);
use Mojo::JWT;
use constant AVATAR_SIZE => 320;
use constant JITSI_TOKEN_LIFETIME => 3600 * 24;
sub create($c) {
$c->openapi->valid_input or return;
my $args = $c->req->json;
my $exists = $c->schema->resultset('Meet')->count({
name => $args->{name}
});
return $c->error(400, 'DUPLICTE_NAME') if $exists;
my $guard = $c->schema->txn_scope_guard;
my $meet = $c->schema->resultset('Meet')->create({
uuid => create_uuid_string(),
owner_id => $c->stash->{user}->id,
name => $args->{name},
});
$meet->add_to_meet_users({
user_id => $c->current_user->{id},
is_moderator => 't',
});
$guard->commit;
$c->trace(\'User %s create meet "%s" with id %d',
$c->stash->{user}->username,
$meet->name,
$meet->id,
);
$c->render(
status => 201,
openapi => { id => $meet->id },
);
}
sub get($c) {
$c->openapi->valid_input or return;
my $args = $c->req->json;
my $meet = $c->schema->resultset('Meet')->find({
id => $c->stash->{id}
});
return $c->error(404, 'NOT_FOUND') if ! $meet;
$c->render(openapi => $c->spec_filter({
$meet->get_columns,
groups => $meet->cached_groups,
moderators => $meet->cached_moderators,
is_editable => ( $meet->owner_id == $c->stash->{user}->id),
}, 'Meet'));
}
sub list($c) {
$c->openapi->valid_input or return;
my $args = $c->req->json;
my $meets = $c->schema->resultset('Meet')->search({
deleted => undef,
owner_id => $c->stash->{user}->id,
# PODMINKA PRO UCASTNIKY
},
{
order_by => 'name',
}
);
my @meets = ();
MEET:
while ( my $meet = $meets->next()) {
push @meets, $c->spec_filter({
$meet->get_columns,
groups => $meet->cached_groups,
moderators => $meet->cached_moderators,
is_editable => ( $meet->owner_id == $c->stash->{user}->id),
}, 'Meet')
}
$c->render(
openapi => {
count => scalar( @meets ),
records => \@meets,
},
);
}
sub add_groups($c) {
$c->openapi->valid_input or return;
my $args = $c->req->json;
my $meet = $c->schema->resultset('Meet')->find({
id => $c->stash->{id}
});
return $c->error(404, 'NOT_FOUND') if ! $meet;
return $c->error(403, 'ACCESS_DENIED') if $meet->owner_id != $c->stash->{user}->id;
IDS:
foreach my $id ( @{ $args->{groups} } ) {
$meet->find_or_create_related('meet_groups',
{ group_id => $id }
);
}
$meet->update_groups_cache();
$c->render( status => 204, text => '' );
}
sub add_moderators($c) {
$c->openapi->valid_input or return;
my $args = $c->req->json;
my $meet = $c->schema->resultset('Meet')->find({
id => $c->stash->{id}
});
return $c->error(404, 'NOT_FOUND') if ! $meet;
return $c->error(403, 'ACCESS_DENIED') if $meet->owner_id != $c->stash->{user}->id;
IDS:
foreach my $user ( @{ $args->{users} } ) {
$meet->find_or_create_related('moderators',
{
octid => $user->{id},
name => $user->{name},
}
);
}
$meet->update_moderators_cache();
$c->render( status => 204, text => '' );
}
sub delete_group($c) {
$c->openapi->valid_input or return;
my $meet = $c->schema->resultset('Meet')->find({
id => $c->stash->{id}
});
return $c->error(404, 'NOT_FOUND') if ! $meet;
return $c->error(403, 'ACCESS_DENIED') if $meet->owner_id != $c->stash->{user}->id;
$meet->delete_related('meet_groups',
{ group_id => $c->stash->{group_id} }
);
$meet->update_groups_cache();
$c->render( status => 204, text => '' );
}
sub delete_moderator($c) {
$c->openapi->valid_input or return;
my $meet = $c->schema->resultset('Meet')->find({
id => $c->stash->{id}
});
return $c->error(404, 'NOT_FOUND') if ! $meet;
return $c->error(403, 'ACCESS_DENIED') if $meet->owner_id != $c->stash->{user}->id;
$meet->delete_related('moderators',
{ octid => $c->stash->{user_id} }
);
$meet->update_moderators_cache();
$c->render( status => 204, text => '' );
}
sub delete($c) {
$c->openapi->valid_input or return;
my $meet = $c->schema->resultset('Meet')->find({
id => $c->stash->{id}
});
return $c->error(404, 'NOT_FOUND') if ! $meet;
return $c->error(403, 'ACCESS_DENIED') if $meet->owner_id != $c->stash->{user}->id;
$meet->update({ deleted => \'now()'});
$c->render( status => 204, text => '' );
}
sub meet($c) {
my $meet = $c->schema->resultset('Meet')->find({
id => $c->stash->{id}
});
my $user = $c->schema->resultset('User')->find({
id => $c->current_user->{id}
});
return $c->error(404, 'NOT_FOUND') if ! $meet;
# CHECK MEET ACCESS
$c->stash->{is_editable} = ( $meet->owner_id == $user->id);
$c->stash->{token} = $user->meet_token($meet, $c->config);
$c->stash->{meet} = $meet;
$c->render('meet');
}
1;
__END__
my $avatar = join ('',
$c->config->{piratar},
AVATAR_SIZE, '/',
$user->username,
'.jpg',
);
$c->stash->{token} = Mojo::JWT->new(
secret => $c->config->{jitsi_secret},
claims => {
aud => 'semeet',
iss => 'semeet',
sub => 'meet.pirati.cz',
room => $meet->uuid,
# moderator => $user{moderator} ? \1:\0,
exp => time + JITSI_TOKEN_LIFETIME,
context => {
user => {
avatar => $avatar,
name => $user->displayname,
# email => $user{mail},
}
},
}
)->encode;
package SeMeet::Helpers::Core;
use base 'Mojolicious::Plugin';
use feature 'signatures';
no warnings qw{ experimental::signatures } ;
use YAML;
use Mojo::JWT;
use Mojo::JSON qw(encode_json);
sub register {
my ($class, $self ) = @_;
$self->helper( trace => sub($c, $data, @args) {
if ( ref $data && ref $data eq 'SCALAR') {
$data = sprintf(${ $data }, @args);
}
elsif ( ref $data ) {
$data = Dump $data;
}
$c->app->log->debug($data);
});
$self->helper(error => sub ($c, $status, $msg) {
if ( ref $msg eq 'ARRAY' ) {
$errors = $msg;
}
elsif ( ref $msg eq 'HASH' ) {
$errors = [ $msg ];
}
else {
$errors = [{
message => $c->l($msg),
path => $c->stash('openapi.path'),
}];
}
$c->stash(
status => $status,
openapi => {
status => $status,
errors => $errors,
},
);
return undef;
});
$self->helper( jwt_token => sub {
my $c = shift;
my $token = shift;
my $jwt;
eval {
$jwt = Mojo::JWT->new(
secret => $c->cfg->{jwt_secret}
)->decode($token);
};
if ( $@ ) {
$c->app->log->warn( $@ );
return 'Invalid token';
}
if ( Mojo::JWT->now() > $jwt->{exp} ) {
$c->app->log->warn( $@ );
return 'Token expire'
}
return $jwt;
});
$self->helper( spec_filter => sub ($c, $data, $class) {
if (my $def =$c->openapi->spec("/components/schemas/$class")) {
my $filtered = {};
KEY:
foreach my $key ( keys %{ $def->{properties} } ) {
my $value = $data->{$key};
my $nullable = 0;
my $types = $def->{properties}{$key}{type};
if ( ref $types eq 'ARRAY' ) {
TYPE:
foreach my $type ( @{ $types } ) {
$nullable = 1, last if $type eq 'null';
}
}
$filtered->{$key} = $value;
}
$data = $filtered;
}
return $data;
});
$self->helper( user_by_octid => sub ($c, $octid) {
my $user = $c->schema->resultset('User')->find({
octid => $octid
});
if ( ! $user ) {
my $octopus_user = $c->iapi->get("octopus/users/$octid");
if ( $octopus_user ) {
$user = $c->schema->resultset('User')->find_or_create(
{
octid => $octid,
username => $octopus_user->{username},
displayname => $octopus_user->{displayname},
},
{ key => 'username' }
);
}
}
return $user;
});
}
1;
package SeMeet::Helpers::OIDC;
use strict;
use warnings;
use constant KEY_FORMAT => "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----";
use base 'Mojolicious::Plugin';
use Mojo::JWT;
use Mojo::UserAgent;
use YAML;
sub register {
my ($class, $self) = @_;
my ($jwt, $discovered);
my $ua = Mojo::UserAgent->new();
# get public key
my $tx = $ua->get( $self->cfg->{oidc}{realm_url} );
my $res = $tx->result;
if ($res->is_success) {
$jwt = Mojo::JWT->new(
public => sprintf( KEY_FORMAT, $res->json->{public_key} )
);
}
# get endpoints
$tx = $ua->get( $self->cfg->{oidc}{realm_well_known} );
$res = $tx->result;
if ($res->is_success) {
$discovered = $res->json;
}
my $oidc = Net::OAuth2::Profile::WebServer->new(
%{ $self->cfg->{oidc}},
authorize_url => $discovered->{authorization_endpoint},
access_token_url => $discovered->{token_endpoint},
);
$self->helper( oidc => sub { return $oidc; } );
$self->helper( oauth_claims => sub {
my $c = shift;
my $token = shift // return undef;
return undef if ! $jwt;
my $claims;
eval { $claims = $jwt->decode( $token ); };
if ( $@ ) {
$c->app->log->warn( $@ );
return undef;
}
if ( Mojo::JWT->now() > $claims->{exp} ) {
$c->app->log->warn( 'Token expire' );
return undef;
}
return $claims;
});
$self->helper( oauth_roles => sub {
my $c = shift;
my $claims = shift;
return $claims->{resource_access}{$self->cfg->{oidc}{client_id}}{roles};
});
$self->helper( oauth_groups => sub {
my $c = shift;
my $claims = shift;
return $claims->{groups} // [] ;
});
}
1;
__END__
package SeMeet::I18N;
use base 'Locale::Maketext';
use File::Basename qw(dirname);
#use Locale::Maketext::Lexicon {
# _auto => 1,
# _decode => 1,
# '*' => [Gettext => dirname(__FILE__) . '/I18N/*.po']
#};
1;
package SeMeet::I18N::cs;
use Mojo::Base 'SeMeet::I18N';
use utf8;
our %Lexicon = (
MEET_EDIT => 'Editace místnosti',
MEET_DELETE => 'Smazat místnost',
MEET_DELETE_CONFIRM => 'Opravdu chceš smazat místnost',
INPUT_MEET_NAME_PLACEHOLDER => 'Název nové místnosti',
INPUT_MEET_NAME_LABEL => 'Název místnosti',
INPUT_MEET_DESCRIPTION_PLACEHOLDER => 'Popis místnosti',
INPUT_MEET_DESCRIPTION_LABEL => 'Popis místnosti',
INPUT_MEET_ADD_GROUPS_LABEL => 'Přidat skupiny',
INPUT_MEET_ADD_GROUPS_PLACEHOLDER => 'Začněte psát název skupiny pro hledání',
INPUT_MEET_ADD_USERS_PLACEHOLDER => 'Začněte psát jméno osoby pro hledání',
INPUT_MEET_ADD_GROUPS_LABEL => 'Přidat skupiny',
INPUT_MEET_ADD_GROUPS_PLACEHOLDER => 'Začněte psát název skupiny pro hledání',
BUTTON_GROUPS_ADD => 'Přidat skupiny',
BUTTON_MODERATORS_ADD => 'Přidat moderatory',
BUTTON_SAVE => 'Uložit změny',
ERROR_SERVERSIDE => 'Chyba na straně serveru',
ERROR_MEET_NAME_REQURED => "Název nové místnosti je povinný",
ERROR_MEET_NAME_DUPLICITY => 'Duplicitní název mistnosti',
LABEL_GROUPS_ADD => 'Přidání skupin',
LABEL_USERS_ADD => 'Přidání moderatorů',
ENTER => 'Vstoupit',
COPY_LINK => 'Zkopírovat odkaz',
'Create meet' => 'Vytvořit místnost',
'Base configuration' => 'Základní nastavení',
'Authorized groups' => 'Opravněné skupiny',
'Moderators' => 'Moderatoři',
'Invites' => 'Pozvánky',
);
1;
__END__
package SeMeet::Model::IAPI;
use strict;
use warnings;
use utf8;
use Mojo::UserAgent;
our $VERSION = '0.01';
sub new {
my $classname = shift;
my $base_url = shift;
my $self = {};
$self->{ua} = Mojo::UserAgent->new();
$self->{base_url} = $base_url;
bless ($self, $classname);
return $self;
}
sub ua {
my $self = shift;
return $self->{ua};
}
sub get {
my $self = shift;
my $endpoint = shift;
my $res = $self->ua->get(
$self->{base_url} . $endpoint
)->result();
return undef if ! $res->is_success;
return $res->json;
}
1;
package SeMeet::Schema;
use strict;
use warnings;
use base 'DBIx::Class::Schema';
our $VERSION = 1;
__PACKAGE__->load_namespaces;
1;
package SeMeet::Schema::Result::Group;
use strict;
use warnings;
use base 'DBIx::Class::Core';
our $VERSION = 1;
__PACKAGE__->table('groups');
__PACKAGE__->add_columns(
id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0,
sequence => 'uid_seq'
},
qw(
octid
name
permissions
),
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->add_unique_constraint(
'octid' => [qw(octid)]
);
__PACKAGE__->has_many(
meet_groups => 'SeMeet::Schema::Result::MeetGroup',
{ 'foreign.group_id' => 'self.id', },
);
__PACKAGE__->inflate_column('permissions', {
inflate => sub {
return [ split /\W+/, shift ];
},
});
1;
package SeMeet::Schema::Result::Meet;
use strict;
use warnings;
use feature 'signatures';
no warnings qw{ experimental::signatures } ;
use base 'DBIx::Class::Core';
use Mojo::JWT;
use JSON;
use constant JWT_DEFAULT_LIFETIME => 3600 * 24 * 7;
our $VERSION = 1;
__PACKAGE__->table('meets');
__PACKAGE__->add_columns(
id => {
data_type => 'integer',
is_auto_increment => 1,
is_nullable => 0,
sequence => 'uid_seq'
},
qw(
uuid
owner_id
deleted
name
description
properties
),
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->add_unique_constraint(
'uuid' => [qw(uuid)]
);
__PACKAGE__->belongs_to(
owner => 'SeMeet::Schema::Result::User',
{
'foreign.id' => 'self.owner_id',
},
);
__PACKAGE__->has_many(
meet_groups => 'SeMeet::Schema::Result::MeetGroup',
{ 'foreign.meet_id' => 'self.id', },
);
__PACKAGE__->has_many(
moderators => 'SeMeet::Schema::Result::Moderator',
{ 'foreign.meet_id' => 'self.id', },
);
__PACKAGE__->has_many(
groups => 'SeMeet::Schema::Result::MeetGroup_view',
{ 'foreign.meet_id' => 'self.id', },
);
__PACKAGE__->inflate_column('properties', {
inflate => sub { from_json(shift); },
deflate => sub { to_json(shift); },
});
sub update_groups_cache($self) {
my @groups = ();
foreach my $group ($self->groups) {
push @groups, {
id => $group->group_id,
name => $group->group_name
};
}
my $properties = $self->properties // {};
$properties->{groups} = \@groups;
$self->update({properties => $properties});
}
sub update_moderators_cache($self) {
my @moderators = ();
foreach my $moderator ($self->moderators) {
push @moderators, {
id => $moderator->octid,
name => $moderator->name,
};
}
my $properties = $self->properties // {};
$properties->{moderators} = \@moderators;
$self->update({properties => $properties});
}
sub cached_groups($self) {
my $properties = $self->properties // {};
if (exists $properties->{groups} && ref $properties->{groups} eq 'ARRAY') {
return $properties->{groups};
}
return [];
}
sub cached_moderators($self) {
my $properties = $self->properties // {};
if (exists $properties->{moderators} && ref $properties->{moderators} eq 'ARRAY') {
return $properties->{moderators};
}
return [];
}
1;
package SeMeet::Schema::Result::MeetGroup;
use strict;
use warnings;
use base 'DBIx::Class::Core';
our $VERSION = 1;
__PACKAGE__->table('meets_groups');
__PACKAGE__->add_columns(
qw(
meet_id
group_id
),
);
__PACKAGE__->set_primary_key('meet_id', 'group_id');
1;
package SeMeet::Schema::Result::MeetGroup_view;
use strict;
use warnings;
use base 'SeMeet::Schema::Result::MeetGroup';
our $VERSION = 1;
__PACKAGE__->table('meets_groups_view');
__PACKAGE__->add_columns(
qw(
group_name
),
);
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment