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
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 0.5.2
IMAGE_VER: 0.6.0
services:
- docker:20.10.9-dind
......
......@@ -2,7 +2,10 @@ package CF2022::Controller::Orders;
use Mojo::Base 'Mojolicious::Controller';
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';
no warnings qw{ experimental::signatures };
......@@ -11,10 +14,11 @@ sub create ($c ) {
$c->openapi->valid_input or return;
my $args = $c->req->json;
my @products = @{ $args->{products} };
my @responses = @{ $args->{responses} };
my $claims;
my $group;
my @products = ();
my $accredited = 0;
my $accreditation = 0;
my $url = sprintf ('%s/organizers/%s/events/%s/orders/',
$c->config->{pretix_api},
......@@ -22,6 +26,13 @@ sub create ($c ) {
$c->config->{pretix_event},
);
my @answers = map {{
question => $_->{question_id},
answer => $_->{response},
}} @{ $args->{responses} };
# processing tokenu
if ( $args->{token} ) {
$c->oauth_token($args->{token});
......@@ -33,7 +44,7 @@ sub create ($c ) {
$args->{name} = $claims->{name};
push @responses, (
push @answers, (
{
question_id => $c->config->{pretix_qid_sso},
response => $claims->{sub},
......@@ -44,10 +55,7 @@ sub create ($c ) {
},
);
@products = grep { $_->{id} !~ MAIN_PRODUCTS } @products;
@products = ({
id => $c->config->{'pretix_product_' . $group->{role}}
}, @products);
$accreditation = $c->config->{'pretix_product_' . $group->{role}};
if ( $group->{role} eq 'member' ) {
$args->{email} = $claims->{preferred_username}
......@@ -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 = {
email => $args->{email},
locale => 'en',
......@@ -69,23 +102,16 @@ sub create ($c ) {
PRODUCT:
foreach my $product ( @products ) {
my $item = {
item => $product->{id},
variation => $product->{variation},
item => $product->{id},
variation => $product->{variation},
attendee_name => $args->{name},
price => $product->{price},
company => $args->{company},
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},
};
}
}
$item->{answers} = \@answers if $product->{id} =~ MAIN_PRODUCTS;
push @{ $order->{positions} }, $item;
}
......
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