| 1 | package OpusVL::AppKit::Controller::AppKit::Admin::Users; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use String::MkPasswd qw/mkpasswd/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | BEGIN { extends 'Catalyst::Controller::HTML::FormFu'; }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 8 | with 'OpusVL::AppKit::RolesFor::Controller::GUI'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 8 | __PACKAGE__->config | |||||||||||||||||||||||||||
| 11 | ( | ||||||||||||||||||||||||||||
| 12 | appkit_myclass => 'OpusVL::AppKit', | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub auto | ||||||||||||||||||||||||||||
| 17 | 11 | ▶ | : Action | ||||||||||||||||||||||||||
|
Subroutine
auto: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 19 | { | ||||||||||||||||||||||||||||
| 20 | 11 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # add to the bread crumb.. | ||||||||||||||||||||||||||||
| 23 | 11 | push ( @{ $c->stash->{breadcrumbs} }, { name => 'Users', url => $c->uri_for( $c->controller('AppKit::Admin::Users')->action_for('index') ) } ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # stash all users.. | ||||||||||||||||||||||||||||
| 26 | 11 | my $users_rs = $c->model('AppKitAuthDB::User')->search; | |||||||||||||||||||||||||||
| 27 | 11 | $users_rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); | |||||||||||||||||||||||||||
| 28 | 11 | my @users = $users_rs->all; | |||||||||||||||||||||||||||
| 29 | 11 | $c->stash->{users} = \@users; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub index | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | : Path | ||||||||||||||||||||||||||
|
Subroutine
index: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | : Args(0) | ||||||||||||||||||||||||||||
| 37 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||
| 39 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 40 | 0 | $c->stash->{template} = 'appkit/admin/users/show_user.tt'; | |||||||||||||||||||||||||||
| 41 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub adduser | ||||||||||||||||||||||||||||
| 45 | 5 | ▶ | : Local | ||||||||||||||||||||||||||
|
Subroutine
adduser: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | : Args(0) | ||||||||||||||||||||||||||||
| 47 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 48 | : AppKitForm("appkit/admin/users/user_form.yml") | ||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 5 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 5 | push ( @{ $c->stash->{breadcrumbs} }, { name => 'Add', url => $c->uri_for( $c->controller('AppKit::Admin::Access')->action_for('adduser') ) } ); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 5 | my $form = $c->stash->{form}; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 5 | my $ignore_password = $c->model('AppKitAuthDB')->schema->can('password_check'); | |||||||||||||||||||||||||||
| 57 | 5 | ▶ | if($ignore_password) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 0 | my $password = $form->get_all_element('password'); | |||||||||||||||||||||||||||
| 60 | 0 | $password->parent->remove_element($password); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else | ||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | # add 'Required' constraint to form .. adding means you must have set a password... | ||||||||||||||||||||||||||||
| 65 | 5 | $form->get_all_element('password')->constraint('Required'); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 5 | $form->process(); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 5 | ▶ | if ( $c->stash->{form}->submitted_and_valid ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 2 | ▶ | my $password = $ignore_password ? mkpasswd : $form->param_value('password'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # FIXME: is this a security hole? | ||||||||||||||||||||||||||||
| 74 | # should we be recording the fact we're not using the password field | ||||||||||||||||||||||||||||
| 75 | # really? | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 2 | my $newuser = $c->model('AppKitAuthDB::User')->new_result( { password => $password } ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 2 | $c->stash->{form}->model->update( $newuser ); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | $c->stash->{status_msg} = "User added"; | |||||||||||||||||||||||||||
| 82 | 2 | $c->stash->{thisuser} = $newuser; | |||||||||||||||||||||||||||
| 83 | 2 | $c->res->redirect( $c->uri_for( $c->controller('AppKit::Admin::Users')->action_for('show_user'), [ $c->stash->{thisuser}->id ] ) ) ; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 5 | $c->stash->{template} = "appkit/admin/users/user_form.tt"; | |||||||||||||||||||||||||||
| 86 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub user_specific | ||||||||||||||||||||||||||||
| 90 | 6 | ▶ | : Chained('/') | ||||||||||||||||||||||||||
|
Subroutine
user_specific: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | : PathPart('user') | ||||||||||||||||||||||||||||
| 92 | : CaptureArgs(1) | ||||||||||||||||||||||||||||
| 93 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 6 | my ( $self, $c, $user_id ) = @_; | |||||||||||||||||||||||||||
| 96 | 6 | ( $c->stash->{thisuser} ) = $c->model('AppKitAuthDB::User')->find( $user_id ); | |||||||||||||||||||||||||||
| 97 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub show_user | ||||||||||||||||||||||||||||
| 101 | 5 | ▶ | : Chained('user_specific') | ||||||||||||||||||||||||||
|
Subroutine
show_user: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | : PathPart('show') | ||||||||||||||||||||||||||||
| 103 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 104 | : Args(0) | ||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 5 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 5 | push ( @{ $c->stash->{breadcrumbs} }, { name => $c->stash->{thisuser}->username, url => $c->uri_for( $c->controller('AppKit::Admin::Access')->action_for('show_user'), [ $c->stash->{thisuser}->id ] ) } ); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # test if need to process user submission... | ||||||||||||||||||||||||||||
| 111 | 5 | ▶ | if ( $c->req->method eq 'POST' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||
| 113 | # add related user lookup for the submitted roles... | ||||||||||||||||||||||||||||
| 114 | 1 | my $user_roles = $c->req->params->{user_role}; | |||||||||||||||||||||||||||
| 115 | 1 | ▶ | $user_roles = [ $user_roles ] if defined $user_roles && ! ref $user_roles; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $user_roles and not ref $user_roles
MC/DC0%0/2
defined $user_roles and not ref $user_roles
defined $user_roles
not ref $user_roles
Truth table33%1/3
A and not(B)
A= defined $user_rolesB= not ref $user_roles
| |||||||||||||||||||||||||||||
| 116 | 1 | foreach my $role_id ( @$user_roles ) | |||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||
| 118 | 1 | $c->stash->{thisuser}->find_or_create_related('users_roles', { role_id => $role_id } ); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | #$c->log->debug("************************** SUBMITTED ROLES: $#$user_roles :" . join('|', @$user_roles) ); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | #.. delete any roles not required.. | ||||||||||||||||||||||||||||
| 124 | 1 | $c->stash->{thisuser}->search_related('users_roles', { role_id => { 'NOT IN' => $user_roles } } )->delete; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | $c->stash->{status_msg} = "User Roles updated"; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # capture and stash role information for the user.. | ||||||||||||||||||||||||||||
| 130 | 5 | my @roles; | |||||||||||||||||||||||||||
| 131 | 5 | foreach my $role_rs ( $c->user->roles_modifiable->all ) | |||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||
| 133 | 10 | my $checked = ''; | |||||||||||||||||||||||||||
| 134 | 10 | ▶ | if ( $c->stash->{thisuser}->search_related('users_roles', { role_id => $role_rs->id } )->count > 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||
| 136 | 1 | $checked = 'checked'; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | 10 | push( @roles, { role => $role_rs->role, input => "<INPUT TYPE='checkbox' NAME='user_role' VALUE='".$role_rs->id."' $checked>" } ); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 5 | $c->stash->{roles} = \@roles; | |||||||||||||||||||||||||||
| 141 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | sub reset_password | ||||||||||||||||||||||||||||
| 144 | 0 | ▶ | : Chained('user_specific') | ||||||||||||||||||||||||||
|
Subroutine
reset_password: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | : PathPart('reset') | ||||||||||||||||||||||||||||
| 146 | : AppKitFeature('User Password Administration') | ||||||||||||||||||||||||||||
| 147 | : Args(0) | ||||||||||||||||||||||||||||
| 148 | : AppKitForm | ||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | my $user = $c->stash->{thisuser}; | |||||||||||||||||||||||||||
| 153 | 0 | my $prev_url = $c->uri_for( $self->action_for('show_user'), [ $user->id ] ); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | push ( @{ $c->stash->{breadcrumbs} }, { name => 'Reset password', url => $c->uri_for( $c->controller('AppKit::Admin::Access')->action_for('reset_password'), [ $user->id ] ) } ); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | $c->forward('/appkit/admin/users/reset_password_form', [ $prev_url, $user ] ); | |||||||||||||||||||||||||||
| 158 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # to allow other controllers to forward to this setting their own | ||||||||||||||||||||||||||||
| 161 | # breadcrumbs and passing their own url. | ||||||||||||||||||||||||||||
| 162 | sub reset_password_form | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | : Action | ||||||||||||||||||||||||||
|
Subroutine
reset_password_form: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 164 | : AppKitFeature('User Password Administration,Password Reset') | ||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||
| 166 | 0 | my ($self, $c, $prev_url, $user) = @_; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if ($c->req->param('cancel')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||
| 170 | 0 | $c->response->redirect( $prev_url ); | |||||||||||||||||||||||||||
| 171 | 0 | $c->detach; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | my $form = $c->stash->{form}; | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ( $form->submitted_and_valid ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||
| 177 | 0 | my $password = $form->param_value('newpassword'); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | $user->update( { password => $password } ); | |||||||||||||||||||||||||||
| 180 | 0 | $c->flash->{status_msg} = 'Reset password'; | |||||||||||||||||||||||||||
| 181 | 0 | $c->response->redirect( $prev_url ); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | else | ||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||
| 185 | $c->stash->{form}->default_values( { | ||||||||||||||||||||||||||||
| 186 | 0 | newpassword => mkpasswd, | |||||||||||||||||||||||||||
| 187 | user => $user->username, | ||||||||||||||||||||||||||||
| 188 | }); | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | sub edit_user | ||||||||||||||||||||||||||||
| 194 | 0 | ▶ | : Chained('user_specific') | ||||||||||||||||||||||||||
|
Subroutine
edit_user: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | : PathPart('form') | ||||||||||||||||||||||||||||
| 196 | : Args(0) | ||||||||||||||||||||||||||||
| 197 | : AppKitForm("appkit/admin/users/user_form.yml") | ||||||||||||||||||||||||||||
| 198 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||
| 200 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | my $form = $c->stash->{form}; | |||||||||||||||||||||||||||
| 203 | 0 | my $ignore_password = $c->model('AppKitAuthDB')->schema->can('password_check'); | |||||||||||||||||||||||||||
| 204 | 0 | ▶ | if($ignore_password) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||
| 206 | 0 | my $password = $form->get_all_element('password'); | |||||||||||||||||||||||||||
| 207 | 0 | $password->parent->remove_element($password); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | 0 | push ( @{ $c->stash->{breadcrumbs} }, { name => 'Edit', url => $c->uri_for( $c->controller('AppKit::Admin::Access')->action_for('edit_user'), [ $c->stash->{thisuser}->id ] ) } ); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ( $form->submitted_and_valid ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||
| 213 | # update the user from the form.. | ||||||||||||||||||||||||||||
| 214 | 0 | $form->model->update( $c->stash->{thisuser} ); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | # .. alter password if we have been passed one.. | ||||||||||||||||||||||||||||
| 217 | 0 | ▶ | unless($ignore_password) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||
| 219 | $c->stash->{thisuser}->update( | ||||||||||||||||||||||||||||
| 220 | { password => $c->stash->{form}->param_value('password') } | ||||||||||||||||||||||||||||
| 221 | 0 | ▶ | ) if $c->stash->{form}->param_value('password'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | $c->stash->{status_msg} = "User updated"; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | # set default values.. | ||||||||||||||||||||||||||||
| 228 | 0 | $form->model->default_values( $c->stash->{thisuser} ); | |||||||||||||||||||||||||||
| 229 | 0 | $c->stash->{template} = "appkit/admin/users/user_form.tt"; | |||||||||||||||||||||||||||
| 230 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | sub delete_user | ||||||||||||||||||||||||||||
| 234 | 0 | ▶ | : Chained('user_specific') | ||||||||||||||||||||||||||
|
Subroutine
delete_user: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 235 | : PathPart('delete') | ||||||||||||||||||||||||||||
| 236 | : Args(0) | ||||||||||||||||||||||||||||
| 237 | : AppKitForm("appkit/admin/confirm.yml") | ||||||||||||||||||||||||||||
| 238 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||
| 240 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | $c->stash->{question} = "Are you sure you want to delete the user:" . $c->stash->{thisuser}->username; | |||||||||||||||||||||||||||
| 243 | 0 | $c->stash->{template} = 'appkit/admin/confirm.tt'; | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if ( $c->stash->{form}->submitted_and_valid ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||
| 247 | 0 | $c->stash->{thisuser}->delete; | |||||||||||||||||||||||||||
| 248 | 0 | $c->flash->{status_msg} = "User deleted"; | |||||||||||||||||||||||||||
| 249 | 0 | $c->res->redirect( $c->uri_for( $c->controller('AppKit::Admin::User')->action_for('index') ) ); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | elsif( $c->req->method eq 'POST' ) | ||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||
| 253 | 0 | $c->flash->{status_msg} = "User NOT deleted"; | |||||||||||||||||||||||||||
| 254 | 0 | $c->res->redirect( $c->uri_for( $c->controller('AppKit::Admin::User')->action_for('index') ) ); | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | sub delete_parameter | ||||||||||||||||||||||||||||
| 261 | 0 | ▶ | : Chained('user_specific') | ||||||||||||||||||||||||||
|
Subroutine
delete_parameter: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 262 | : PathPart('deleteparameter') | ||||||||||||||||||||||||||||
| 263 | : Args(1) | ||||||||||||||||||||||||||||
| 264 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 265 | { | ||||||||||||||||||||||||||||
| 266 | 0 | my ( $self, $c, $param_id ) = @_; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | $c->stash->{thisuser}->delete_related('users_parameters', { parameter_id => $param_id } ); | |||||||||||||||||||||||||||
| 269 | 0 | $c->flash->{status_msg} = "Parameter deleted"; | |||||||||||||||||||||||||||
| 270 | 0 | $c->res->redirect( $c->uri_for( $c->controller('AppKit::Admin::User')->action_for('show_user'), [ $c->stash->{thisuser}->id ] ) ); | |||||||||||||||||||||||||||
| 271 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | sub add_parameter | ||||||||||||||||||||||||||||
| 275 | 0 | ▶ | : Chained('user_specific') | ||||||||||||||||||||||||||
|
Subroutine
add_parameter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 276 | : PathPart('addparameter') | ||||||||||||||||||||||||||||
| 277 | : Args(0) | ||||||||||||||||||||||||||||
| 278 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||
| 280 | 0 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if ( $c->req->method eq 'POST' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||
| 284 | 0 | my $parameter_id = $c->req->param('parameter_id'); | |||||||||||||||||||||||||||
| 285 | 0 | my $parameter_value = $c->req->param('parameter_value'); | |||||||||||||||||||||||||||
| 286 | 0 | $c->stash->{thisuser}->update_or_create_related('users_parameters', { parameter_id => $parameter_id, value => $parameter_value } ); | |||||||||||||||||||||||||||
| 287 | 0 | $c->stash->{status_msg} = "Parameter updated"; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # refresh show page.. | ||||||||||||||||||||||||||||
| 291 | 0 | $c->res->redirect( $c->uri_for( $c->controller('AppKit::Admin::User')->action_for('show_user'), [ $c->stash->{thisuser}->id ] ) ) ; | |||||||||||||||||||||||||||
| 292 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | sub get_parameter_input | ||||||||||||||||||||||||||||
| 296 | 0 | ▶ | : Chained('user_specific') | ||||||||||||||||||||||||||
|
Subroutine
get_parameter_input: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 297 | : PathPart('addparaminput') | ||||||||||||||||||||||||||||
| 298 | : Args(1) | ||||||||||||||||||||||||||||
| 299 | : AppKitFeature('User Administration') | ||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||
| 301 | 0 | my ( $self, $c, $param_id ) = @_; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | my $param = $c->model('AppKitAuthDB::Parameter')->find( $param_id ); | |||||||||||||||||||||||||||
| 304 | 0 | ▶ | return undef unless $param; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | # get and values ther might be (for the user in the stash)... | ||||||||||||||||||||||||||||
| 307 | 0 | my $up = $c->stash->{thisuser}->find_related('users_parameters', { parameter_id => $param_id } ); | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | my $value = $up->value if ( $up ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | # output correct HTML.. | ||||||||||||||||||||||||||||
| 311 | 0 | my $html = ''; | |||||||||||||||||||||||||||
| 312 | 0 | ▶ | if ( $param->data_type eq 'boolean' ) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 313 | { | ||||||||||||||||||||||||||||
| 314 | 0 | $html .= '<div class="radio label">'; | |||||||||||||||||||||||||||
| 315 | 0 | ▶ | $html .= "<label for='parameter_value_true'>True</label><input type='radio' name='parameter_value' value='1' id='parameter_value_true' " . ( $value ? "checked='1'" : '') . ">"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | 0 | $html .= '</div><div class="radio label">'; | |||||||||||||||||||||||||||
| 317 | 0 | ▶ | $html .= "<label for='parameter_value_false'>False</label><input type='radio' name='parameter_value' value='0' id='parameter_value_false' " . ( $value ? '' : "checked='1'") . ">"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 0 | $html .= "</div>"; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | elsif ( $param->data_type eq 'select' ) | ||||||||||||||||||||||||||||
| 321 | { | ||||||||||||||||||||||||||||
| 322 | 0 | $html .= "<select name='parameter_value'> \n"; | |||||||||||||||||||||||||||
| 323 | 0 | foreach my $pdef ( $param->parameter_defaults ) | |||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||
| 325 | 0 | my $thisval = $pdef->data; | |||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $selected = $thisval eq $value ? 'selected' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | 0 | $html .= "<option $selected value='$thisval'> $thisval</option>\n"; | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | 0 | $html .= "</select> \n"; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | elsif ( $param->data_type eq 'integer' ) | ||||||||||||||||||||||||||||
| 332 | { | ||||||||||||||||||||||||||||
| 333 | 0 | $html .= "<input type='text' name='parameter_value' value='$value' id='parameter_value' size='5'>"; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | else | ||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||
| 337 | 0 | $html .= "<input type='text' name='parameter_value' value='$value' id='parameter_value'>"; | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | $c->stash->{no_wrapper} = 1; | |||||||||||||||||||||||||||
| 341 | 0 | $c->stash->{html} = $html; | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 8 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | __END__ | ||||||||||||||||||||||||||||