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

Pokrocilejsi seznam osob

parent b109b8f6
No related branches found
No related tags found
No related merge requests found
Pipeline #10521 passed
0.4.0 0.5.0
...@@ -14,7 +14,7 @@ sub list($c) { ...@@ -14,7 +14,7 @@ sub list($c) {
); );
my @groups = (); my @groups = ();
# TODO: filter
GROUP: GROUP:
while ( my $group = $groups->next()) { while ( my $group = $groups->next()) {
push @groups, $c->spec_filter({ push @groups, $c->spec_filter({
......
package SeMeet::Controller::Users;
use Mojo::Base 'Mojolicious::Controller', -signatures;
use utf8;
use JSON;
use constant REDIS_CACHE_LIFETIME => 60;
sub list($c) {
$c->openapi->valid_input or return;
my $args = $c->validation->output;
my $cache_key = sprintf('USERS %s', $args->{search} || 'ALL');
if ($c->redis->db->exists( $cache_key )) {
$c->render(openapi => from_json($c->redis->db->get( $cache_key )));
return;
}
my $groups = $c->schema->resultset('Group')->search(
{ permissions => { ilike => 'org-%' }}, # TODO: samostatny priznak?
{ order_by => 'name', }
);
my %groups = ();
GROUP:
while ( my $group = $groups->next()) {
my $name = $group->name;
next GROUP if $name !~ s/^(KS|MS)\s+//i;
my $type = $1;
$name =~ s/\s+členové a RegP//i;
$groups{$type}->{$group->octid} = $name;
}
my $users = $c->iapi->get('octopus/users?search=' . $args->{search});
my @users = ();
USER:
foreach my $user ( @{ $users } ) {
my ($ks, $ms);
GROUP:
foreach my $id (@{ $user->{groups} }) {
if ( my $group = $groups{KS}->{$id} ) {
$ks //= $group;
}
if ( my $group = $groups{MS}->{$id} ) {
$ms //= $group;
}
}
push @users, $c->spec_filter({
id => $user->{id},
name => $user->{displayname},
username => $user->{username},
region => join ' - ', grep { defined } ($ks, $ms),
}, 'UserInList')
}
$c->redis->db->set( $cache_key, to_json(\@users), 'EX', REDIS_CACHE_LIFETIME );
$c->render( openapi => \@users );
}
1;
...@@ -66,6 +66,14 @@ components: ...@@ -66,6 +66,14 @@ components:
name: name:
type: string type: string
readOnly: true readOnly: true
username:
type: string
readOnly: true
nullable: true
region:
type: string
nullable: true
readOnly: true
paths: paths:
/meets: /meets:
...@@ -216,14 +224,13 @@ paths: ...@@ -216,14 +224,13 @@ paths:
204: 204:
description: Mistnost je smazana description: Mistnost je smazana
/meets/{id}/unauthorized_groups: /groups:
get: get:
x-mojo-to: groups#list x-mojo-to: groups#list
tags: tags:
- meets
- groups - groups
summary: "Seznam nezarazenych skupin" summary: "Hledani skupin"
operationId: searchUnauthorizeGroups operationId: searchGroups
parameters: parameters:
- name: search - name: search
in: query in: query
...@@ -241,6 +248,30 @@ paths: ...@@ -241,6 +248,30 @@ paths:
items: items:
$ref: '#/components/schemas/GroupInList' $ref: '#/components/schemas/GroupInList'
/users:
get:
x-mojo-to: users#list
tags:
- users
summary: "Hledani osob"
operationId: searchUsers
parameters:
- name: search
in: query
description: Search query
schema:
type: string
example: 'Ivan'
responses:
200:
description: Seznam osob
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UserInList'
/meets/{id}/group: /meets/{id}/group:
post: post:
x-mojo-to: meets#add_groups x-mojo-to: meets#add_groups
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<div class="overflow-y-auto h-64 mb-4 border p-2 text-sm" v-if="users.length > 0"> <div class="overflow-y-auto h-64 mb-4 border p-2 text-sm" v-if="users.length > 0">
<div v-for="user in users" class="checkbox form-field__control mb-1" > <div v-for="user in users" class="checkbox form-field__control mb-1" >
<input name="users" type="checkbox" v-bind:title="user.id" v-bind:value="user.id" v-model="selected_users" > <input name="users" type="checkbox" v-bind:title="user.id" v-bind:value="user.id" v-model="selected_users" >
<label>{{user.name}}</label> <label style="max-width: 100%">{{user.name}} ({{ user.username }})<span v-if="user.region.length > 0" class="text-grey-300 text-xs"> | {{ user.region }}</span></label>
</div> </div>
</div> </div>
<div class="form-field" v-if="selected_users.length > 0"> <div class="form-field" v-if="selected_users.length > 0">
......
...@@ -31,8 +31,9 @@ ...@@ -31,8 +31,9 @@
<script type="module"> <script type="module">
import { createApp } from 'https://cdn-unpkg.pirati.cz/petite-vue@0.2.2/dist/petite-vue.es.js' import { createApp } from 'https://cdn-unpkg.pirati.cz/petite-vue@0.2.2/dist/petite-vue.es.js'
const GROUPS_URL = '/api/meets/<%= stash->{id} %>/unauthorized_groups'; const GROUPS_URL = '/api/groups';
const USERS_URL = '<%= config->{iapi} %>octopus/users'; const USERS_URL = '/api/users';
//const USERS_URL = '<%= config->{iapi} %>octopus/users';
const MEET_URL = '/api/meets/<%= stash->{id} %>'; const MEET_URL = '/api/meets/<%= stash->{id} %>';
const ADD_GROUPS_URL = '/api/meets/<%= stash->{id} %>/group'; const ADD_GROUPS_URL = '/api/meets/<%= stash->{id} %>/group';
const ADD_USERS_URL = '/api/meets/<%= stash->{id} %>/moderator'; const ADD_USERS_URL = '/api/meets/<%= stash->{id} %>/moderator';
......
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