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

Prisna kontrola typu registrace

parent e2c3d22c
No related branches found
No related tags found
No related merge requests found
Pipeline #6037 passed
...@@ -2,7 +2,7 @@ image: docker:20.10.9 ...@@ -2,7 +2,7 @@ image: docker:20.10.9
variables: variables:
DOCKER_TLS_CERTDIR: "/certs" DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 0.5.2 IMAGE_VER: 0.6.0
services: services:
- docker:20.10.9-dind - docker:20.10.9-dind
......
...@@ -2,7 +2,10 @@ package CF2022::Controller::Orders; ...@@ -2,7 +2,10 @@ package CF2022::Controller::Orders;
use Mojo::Base 'Mojolicious::Controller'; use Mojo::Base 'Mojolicious::Controller';
use Mojo::UserAgent; use Mojo::UserAgent;
use constant MAIN_PRODUCTS => qr/^(1|2|3)$/; use constant MAIN_PRODUCTS => qr/^(1|2|3)$/; # typy akreditace
use constant NONFREE_PRODUCTS => qr/^(1)$/; # akreditace vyzadujici token
use constant SUBSIDY_PRUDUCTS => qr/^(58)$/; # prispevkove polozky
use constant FALLBACK_PRODUCT => 2; # fallback akreditace
use feature 'signatures'; use feature 'signatures';
no warnings qw{ experimental::signatures }; no warnings qw{ experimental::signatures };
...@@ -11,10 +14,11 @@ sub create ($c ) { ...@@ -11,10 +14,11 @@ sub create ($c ) {
$c->openapi->valid_input or return; $c->openapi->valid_input or return;
my $args = $c->req->json; my $args = $c->req->json;
my @products = @{ $args->{products} };
my @responses = @{ $args->{responses} };
my $claims; my $claims;
my $group; my $group;
my @products = ();
my $accredited = 0;
my $accreditation = 0;
my $url = sprintf ('%s/organizers/%s/events/%s/orders/', my $url = sprintf ('%s/organizers/%s/events/%s/orders/',
$c->config->{pretix_api}, $c->config->{pretix_api},
...@@ -22,6 +26,13 @@ sub create ($c ) { ...@@ -22,6 +26,13 @@ sub create ($c ) {
$c->config->{pretix_event}, $c->config->{pretix_event},
); );
my @answers = map {{
question => $_->{question_id},
answer => $_->{response},
}} @{ $args->{responses} };
# processing tokenu
if ( $args->{token} ) { if ( $args->{token} ) {
$c->oauth_token($args->{token}); $c->oauth_token($args->{token});
...@@ -33,7 +44,7 @@ sub create ($c ) { ...@@ -33,7 +44,7 @@ sub create ($c ) {
$args->{name} = $claims->{name}; $args->{name} = $claims->{name};
push @responses, ( push @answers, (
{ {
question_id => $c->config->{pretix_qid_sso}, question_id => $c->config->{pretix_qid_sso},
response => $claims->{sub}, response => $claims->{sub},
...@@ -44,10 +55,7 @@ sub create ($c ) { ...@@ -44,10 +55,7 @@ sub create ($c ) {
}, },
); );
@products = grep { $_->{id} !~ MAIN_PRODUCTS } @products; $accreditation = $c->config->{'pretix_product_' . $group->{role}};
@products = ({
id => $c->config->{'pretix_product_' . $group->{role}}
}, @products);
if ( $group->{role} eq 'member' ) { if ( $group->{role} eq 'member' ) {
$args->{email} = $claims->{preferred_username} $args->{email} = $claims->{preferred_username}
...@@ -58,6 +66,31 @@ sub create ($c ) { ...@@ -58,6 +66,31 @@ sub create ($c ) {
} }
} }
# korekce akreditace
PRODUCT:
foreach my $product ( @{ $args->{products} } ) {
next PRODUCT if $product->{id} =~ SUBSIDY_PRUDUCTS && ! $product->{price};
if ( $product->{id} =~ MAIN_PRODUCTS ) {
next PRODUCT if $accredited++; # neumoznit dvoji akreditace
if ( $accreditation ) {
$product->{id} = $accreditation;
}
elsif ($product->{id} =~ NONFREE_PRODUCTS) {
$product->{id} = FALLBACK_PRODUCT;
}
}
push @products, $product;
}
# fallback akreditace
@products = ( { id => FALLBACK_PRODUCT}, @products ) if ! $accredited;
my $order = { my $order = {
email => $args->{email}, email => $args->{email},
locale => 'en', locale => 'en',
...@@ -69,23 +102,16 @@ sub create ($c ) { ...@@ -69,23 +102,16 @@ sub create ($c ) {
PRODUCT: PRODUCT:
foreach my $product ( @products ) { foreach my $product ( @products ) {
my $item = { my $item = {
item => $product->{id}, item => $product->{id},
variation => $product->{variation}, variation => $product->{variation},
attendee_name => $args->{name}, attendee_name => $args->{name},
price => $product->{price}, price => $product->{price},
company => $args->{company}, company => $args->{company},
}; };
if ( $product->{id} =~ MAIN_PRODUCTS ) { $item->{answers} = \@answers if $product->{id} =~ MAIN_PRODUCTS;
RESPONSE:
foreach my $response ( @responses ) {
push @{ $item->{answers} }, {
question => $response->{question_id},
answer => $response->{response},
};
}
}
push @{ $order->{positions} }, $item; push @{ $order->{positions} }, $item;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment