diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e9e74a6c0c445ff6521fe760bbc46f6d611055d1..823484a9ca45a3328427ec74349e73eb381158ce 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ image: docker:latest variables: DOCKER_TLS_CERTDIR: "/certs" - IMAGE_VER: 0.21.5 + IMAGE_VER: 0.22.0 services: - docker:dind diff --git a/lib/CF2022/Controller/Orders.pm b/lib/CF2022/Controller/Orders.pm index 9f7af472fd3b5cbea5891f8d139c9c848f229028..04ce5f160736bfca996a438858e7219152a2bffa 100644 --- a/lib/CF2022/Controller/Orders.pm +++ b/lib/CF2022/Controller/Orders.pm @@ -13,22 +13,11 @@ no warnings qw{ experimental::signatures }; sub create ($c ) { $c->openapi->valid_input or return; - my $args = $c->req->json; + my $args = $c->req->json; my $claims; my $group; my @products = (); - my $accredited = 0; my $accreditation = 0; - - # clasifikator typu - my $pt = {}; - CLASS: - foreach my $class ( qw(main nonfree subsidy) ) { - foreach my $id ( split /\D+/, $c->config->{"products_$class"} ) { - $pt->{$class}{$id} = 1; - } - } - my $url = sprintf ('%s/organizers/%s/events/%s/orders/', $c->config->{pretix_api}, $c->config->{pretix_organizer}, @@ -42,47 +31,39 @@ sub create ($c ) { # processing tokenu - if ( $args->{token} ) { - $c->oauth_token($args->{token}); + $c->oauth_token($args->{token}); - $claims = $c->oauth_claims; - return $c->error(403, 'Invalid token') if ! $claims; + $claims = $c->oauth_claims; + return $c->error(403, 'Invalid token') if ! $claims; - $group = $c->oauth_main_group; - return $c->error(403, 'Invalid group') if ! $group; + $group = $c->oauth_main_group; + return $c->error(403, 'Invalid group') if ! $group; - $args->{name} = $claims->{name}; + $args->{name} = $claims->{name}; - push @answers, ( - { - question => $c->config->{pretix_qid_sso}, - answer => $claims->{sub}, - }, - { - question => $c->config->{pretix_qid_region}, - answer => $group->{region}, - }, - ); + push @answers, ( + { + question => $c->config->{pretix_qid_sso}, + answer => $claims->{sub}, + }, + { + question => $c->config->{pretix_qid_region}, + answer => $group->{region}, + }, + ); - $accreditation = $c->config->{'products_' . $group->{role}}; + $accreditation = $c->config->{'products_' . $group->{role}}; - if ( $group->{role} eq 'member' ) { - $args->{email} = $claims->{preferred_username} - .'@'. $c->config->{mail_domain}; - } - else { - $args->{email} = $claims->{email}; - } + if ( $group->{role} eq 'member' ) { + $args->{email} = $claims->{preferred_username} + .'@'. $c->config->{mail_domain}; + } + else { + $args->{email} = $claims->{email}; } # kontrola duplicity my $exists = $c->schema->resultset('Order')->search({ - deleted => undef, - email => $args->{email}, - api => $url, - })->count; - - $exists ||= $c->schema->resultset('Order')->search({ deleted => undef, sso_uuid => $claims->{sub}, api => $url, @@ -98,26 +79,10 @@ sub create ($c ) { $product->{id} = $c->mapped_product_id($product->{id}); - next PRODUCT if $pt->{subsidy}{$product->{id}} && ! $product->{price}; - - if ( $pt->{main}{ $product->{id} } ) { - next PRODUCT if $accredited++; # neumoznit dvoji akreditace - - if ( $accreditation ) { - $product->{id} = $accreditation; - } - elsif ( $pt->{nonfree}{ $product->{id} } ) { - $product->{id} = $c->config->{products_fallback}; - } - } - push @products, $product; } - # fallback akreditace - @products = ( { id => $c->config->{products_fallback} }, @products ) if ! $accredited; - my $order = { email => $args->{email}, locale => 'en', @@ -156,6 +121,12 @@ sub create ($c ) { }, ); + @{ $order->{positions} } = ({ + item => $accreditation, + attendee_name => $args->{name}, + answers => \@answers, + }); + PRODUCT: foreach my $product ( @products ) { @@ -167,8 +138,6 @@ sub create ($c ) { company => $args->{company}, }; - $item->{answers} = \@answers if $pt->{main}{$product->{id}}; - push @{ $order->{positions} }, $item; } diff --git a/lib/CF2022/Helpers/Auth.pm b/lib/CF2022/Helpers/Auth.pm index 45b0cb2ffc0eabcc5d948cf1f2ca66eede5e2aa0..28fee8b2593418bcbeb8224f216bb6b0877570de 100644 --- a/lib/CF2022/Helpers/Auth.pm +++ b/lib/CF2022/Helpers/Auth.pm @@ -9,6 +9,7 @@ no warnings qw{ experimental::signatures }; use constant KEY_FORMAT => "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----"; use constant REGIONS => qr{^(jhc|jhm|kvk|lbk|msk|olk|pak|pha|plk|stc|ulk|vys|zlk|khk):(f|regp)$}; +use constant NOREG => qr(^cen:(regp|f)$); sub register ( $class, $self, $conf) { @@ -29,8 +30,9 @@ sub register ( $class, $self, $conf) { eval { $res = $ua->get( $self->cfg->{oauth_url} )->result; }; if (! $@ && $res->is_success) { + my $key = join "\n", unpack("(A64)*", $res->json->{public_key}); $jwt = Mojo::JWT->new( - public => sprintf( KEY_FORMAT, $res->json->{public_key} ) + public => sprintf( KEY_FORMAT, $key ) ); } } @@ -76,7 +78,10 @@ sub register ( $class, $self, $conf) { $self->helper( oauth_main_group => sub ( $c ) { my $claims = $c->oauth_claims // return; - my $cen_regp; + my $default = { + region => '', + role => 'guest', + }; GROUP: foreach my $group ( sort @{ $claims->{groups} } ) { @@ -85,23 +90,20 @@ sub register ( $class, $self, $conf) { my $region = $c->oauth_groups->{ $group }; $region =~ s/^K[SF]\s+//i; + $region =~ s/^RegP\s+//i; return { region => $region, role => $role, }; } - if ( $group =~ /cen:regp/ ) { - $cen_regp = 1; + + if ( $group =~ NOREG ) { + $default->{role} = ( $1 eq 'f') ? 'member':'regp'; } } - if ( $cen_regp ) { - return { - region => 'Praha', - role => 'regp', - }; - } + return $default; });