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

Funkcno vytvoreni zakazky

parent 55424275
No related branches found
No related tags found
No related merge requests found
Pipeline #5998 passed
_work
docker-compose.yaml
......@@ -2,7 +2,7 @@ image: docker:20.10.9
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 0.3.0
IMAGE_VER: 0.4.0
services:
- docker:20.10.9-dind
......
{
secrets => ['14283e549647774b17d10e1d75bcf16c2969673e'],
oauth_url => 'https://auth.pirati.cz/auth/realms/pirati',
pretix_api => 'https://pretix.pir-test.eu/api/v1',
pretix_token => 'rxr4dcx9jnyv50jfd8xdamxjwo3j89503y3upiy1830hpv76is9zqd80c27r5gjk',
pretix_organizer => 'pirati',
pretix_event => 'cf2022',
secrets => ['14283e549647774b17d10e1d75bcf16c2969673e'],
oauth_url => 'https://auth.pirati.cz/auth/realms/pirati',
groups_url => 'https://iapi.pirati.cz/v1/groups',
pretix_api => 'https://pretix.pir-test.eu/api/v1',
pretix_token => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
pretix_organizer => 'pirati',
pretix_event => 'cf2022',
pretix_qid_sso => 29, # identifikator otazky SSO UID
pretix_qid_region => 8, # identifikator otazky Kraj
pretix_product_member => 1, # produkt pro cleny
pretix_product_regp => 2, # produkt pro regp
mail_domain => 'pirati.cz',
}
package CF2022::Controller::Orders;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::UserAgent;
use constant MAIN_PRODUCTS => qr/^(1|2|3)$/;
use feature 'signatures';
no warnings qw{ experimental::signatures };
sub create ($c ) {
$c->openapi->valid_input or return;
my $args = $c->req->json;
my @products = @{ $args->{products} };
my @responses = @{ $args->{responses} };
my $group;
my $url = sprintf ('%s/organizers/%s/events/%s/orders/',
$c->config->{pretix_api},
$c->config->{pretix_organizer},
$c->config->{pretix_event},
);
if ( $args->{token} ) {
$c->oauth_token($args->{token});
my $claims = $c->oauth_claims;
return $c->error(403, 'Invalid token') if ! $claims;
$group = $c->oauth_main_group;
return $c->error(403, 'Invalid token') if ! $group;
$args->{name} = $claims->{name};
push @responses, (
{
question_id => $c->config->{pretix_qid_sso},
response => $claims->{sub},
},
{
question_id => $c->config->{pretix_qid_region},
response => $group->{region},
},
);
@products = grep { $_->{id} !~ MAIN_PRODUCTS } @products;
push @products, {
id => $c->config->{'pretix_product_' . $group->{role}}
};
if ( $group->{role} eq 'member' ) {
$args->{email} = $claims->{preferred_username}
.'@'. $c->config->{mail_domain};
}
else {
$args->{email} = $claims->{email};
}
}
my $order = {
email => $args->{email},
locale => 'en',
payment_provider => 'manual',
positions => [],
fees => [],
};
PRODUCT:
foreach my $product ( @products ) {
my $item = {
item => $product->{id},
variation => $product->{variation},
attendee_name => $args->{name},
price => $product->{price},
company => $args->{company},
};
if ( $product->{id} =~ MAIN_PRODUCTS ) {
RESPONSE:
foreach my $response ( @responses ) {
push @{ $item->{answers} }, {
question => $response->{question_id},
answer => $response->{response},
};
}
}
push @{ $order->{positions} }, $item;
}
my $ua = Mojo::UserAgent->new;
###### KONTROLA DUPLICITY
my $rc = $ua->post( $url,
{ Authorization => 'Token ' . $c->config->{pretix_token} },
json => $order
)->result->json;
$c->render(json => $rc);
}
1;
......@@ -74,12 +74,20 @@ sub register ( $class, $self, $conf) {
return $c->stash->{claims};
});
$self->helper( oauth_main_group_name => sub ( $c ) {
$self->helper( oauth_main_group => sub ( $c ) {
my $claims = $c->oauth_claims // return;
GROUP:
foreach my $group ( sort @{ $claims->{groups} } ) {
return $c->oauth_groups->{ $group } if $group =~ REGIONS;
if ( $group =~ REGIONS ) {
my $region = $c->oauth_groups->{ $group };
$region =~ s/^KS\s+//i;
return {
region => $region,
role => ( $2 eq 'f') ? 'member':'regp',
};
}
}
});
......
......@@ -151,12 +151,6 @@ paths:
response: XXXXX
- question_id: 2
response: ZZZZZ
required:
- type
- name
- email
- products
- responses
responses:
201:
description: Order created
......
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