« Workflow/Activities/Authorities/Activity.pm
↑ Summary
Workflow/Activities/Authorities/Standard/Base.pm »
| 1 | package Daje::Workflow::Activities::Authorities::Standard::AdminRole; | ||
| 2 | use Mojo::Base 'Daje::Workflow::Activities::Authorities::Standard::Base', -base; | ||
| 3 | use v5.42; | ||
| 4 | |||
| 5 | # NAME | ||
| 6 | # ==== | ||
| 7 | # | ||
| 8 | # Daje::Workflow::Activities::Authorities::Standard::AdminRole - Daje helper, | ||
| 9 | # creates a new admin role and attach it to user and company | ||
| 10 | # | ||
| 11 | # SYNOPSIS | ||
| 12 | # ======== | ||
| 13 | # | ||
| 14 | # | ||
| 15 | # DESCRIPTION | ||
| 16 | # =========== | ||
| 17 | # | ||
| 18 | # Daje::Workflow::Activities::Authorities::Standard::AdminRole a helper clas | ||
| 19 | # | ||
| 20 | # METHODS | ||
| 21 | # ======= | ||
| 22 | # | ||
| 23 | # | ||
| 24 | # | ||
| 25 | # | ||
| 26 | # SEE ALSO | ||
| 27 | # ======== | ||
| 28 | # | ||
| 29 | # Mojolicious, Mojolicious::Guides, https://mojolicious.org. | ||
| 30 | # | ||
| 31 | # LICENSE | ||
| 32 | # ======= | ||
| 33 | # | ||
| 34 | # Copyright (C) janeskil1525. | ||
| 35 | # | ||
| 36 | # This library is free software; you can redistribute it and/or modify | ||
| 37 | # it under the same terms as Perl itself. | ||
| 38 | # | ||
| 39 | # AUTHOR | ||
| 40 | # ====== | ||
| 41 | # | ||
| 42 | # janeskil1525 E<lt>janeskil1525@gmail.com | ||
| 43 | # | ||
| 44 | |||
| 45 | |||
| 46 | use Daje::Database::View::vAuthoritiesPluginList; | ||
| 47 | use Daje::Database::View::vAuthoritiesFunction; | ||
| 48 | use Daje::Database::View::vAuthoritiesPermissionsList; | ||
| 49 | use Daje::Database::Model::UsersUsers; | ||
| 50 | |||
| 51 | sub create_admin($self) { | ||
| 52 | $self->model->insert_history( | ||
| 53 | "Admin role for new client", | ||
| 54 | "Daje::Workflow::Activities::Authorities::Standard::AdminRole::create_admin", | ||
| 55 | 1 | ||
| 56 | ); | ||
| 57 | |||
| 58 | my $authorities_role_pkey = $self->createRole('Administrator', 1); | ||
| 59 | |||
| 60 | my $plugins = Daje::Database::View::vAuthoritiesPluginList->new( | ||
| 61 | db => $self->db | ||
| 62 | )->load_all_authorities_plugin()->{data}; | ||
| 63 | |||
| 64 | my $permissions = Daje::Database::View::vAuthoritiesPermissionsList->new( | ||
| 65 | db => $self->db | ||
| 66 | )->load_all_authorities_permissions()->{data}; | ||
| 67 | |||
| 68 | my $length = scalar @{$plugins}; | ||
| 69 | for(my $i = 0; $i < $length; $i++) { | ||
| 70 | my $authorities_plugin_role_pkey = $self->create_role_plugin( | ||
| 71 | $authorities_role_pkey, | ||
| 72 | @{$plugins}[$i]->{authorities_plugin_pkey}, | ||
| 73 | "Autogenerated" | ||
| 74 | ); | ||
| 75 | my $functions = Daje::Database::View::vAuthoritiesFunction->new( | ||
| 76 | db => $self->db | ||
| 77 | )->load_authorities_plugin_fkey( | ||
| 78 | @{$plugins}[$i]->{authorities_plugin_pkey} | ||
| 79 | )->{data}; | ||
| 80 | |||
| 81 | my $len = scalar @{$functions}; | ||
| 82 | for(my $j = 0; $j < $len; $j++) { | ||
| 83 | my $authorities_function_plugin_role_pkey = $self->create_function_plugin_role( | ||
| 84 | $authorities_role_pkey, | ||
| 85 | @{$functions}[$j]->{authorities_function_pkey}, | ||
| 86 | @{$plugins}[$i]->{authorities_plugin_pkey}, | ||
| 87 | "Autogenerated" | ||
| 88 | ); | ||
| 89 | |||
| 90 | my $le = scalar @{$permissions}; | ||
| 91 | for(my $k = 0; $k < $le; $k++) { | ||
| 92 | $self->create_role_permissions( | ||
| 93 | @{$permissions}[$k]->{authorities_permissions_pkey}, | ||
| 94 | $authorities_role_pkey, | ||
| 95 | @{$functions}[$j]->{authorities_function_pkey}, | ||
| 96 | @{$plugins}[$i]->{authorities_plugin_pkey} | ||
| 97 | ); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | Daje::Database::Model::UsersUsers->new(db => $self->db)->update({ | ||
| 102 | users_users_pkey => $self->context->{context}->{users_fkey}, | ||
| 103 | authorities_role_fkey => $authorities_role_pkey, | ||
| 104 | }); | ||
| 105 | } | ||
| 106 | 1; |