Sling/UserUtil.pm

filter: Statementstmt 100% 86 / 86 Branchbran 100% 32 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 100% 10 / 10 totaltotal 100% 144 / 144 CC 17 SCAR 12.0
CC
17
Cov
100%
change_password_setup
6.0
add_setup
5.0
update_setup
4.0
CRAP 3.3
« Sling/AuthzUtil.pm ↑ Summary Sling/ContentUtil.pm »
1 #!/usr/bin/perl -w
2  
3 package Apache::Sling::UserUtil;
4  
5 3 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Apache::Sling::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 require Exporter;
12  
13 3 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 our @EXPORT_OK = ();
16  
17 3 our $VERSION = '0.27';
18  
19 #{{{sub add_setup
20  
21 6 ▶sub add_setup {
Subroutine add_setup: called CC=5 SCAR=16.1
Pod documented
22 6 my ( $base_url, $act_on_user, $act_on_pass, $properties ) = @_;
23 6 ▶ if ( !defined $base_url ) { croak 'No base url defined to add against!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 1 5 6
24 5 ▶ if ( !defined $act_on_user ) { croak 'No user name defined to add!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $act_on_user) 2 3 5
25 3 ▶ if ( !defined $act_on_pass ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $act_on_pass) 1 2 3
26 1 croak "No user password defined to add for user $act_on_user!";
27 }
28 2 my $property_post_vars =
29 Apache::Sling::URL::properties_array_to_string($properties);
30 2 my $post_variables =
31 "\$post_variables = [':name','$act_on_user','pwd','$act_on_pass','pwdConfirm','$act_on_pass'";
32 2 ▶ if ( $property_post_vars ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_post_vars ne "") 1 1 2
33 1 $post_variables .= ",$property_post_vars";
34 }
35 2 $post_variables .= ']';
36 2 return "post $base_url/system/userManager/user.create.html $post_variables";
37 }
38  
39 #}}}
40  
41 #{{{sub add_eval
42 # Return true if the return code is 200 or 201
43 # to support Sakai Nakamura using the more correct
44 # 201 "Created" return code:
45  
46 1 ▶sub add_eval {
Subroutine add_eval: called CC=1 SCAR=0.0
Pod documented
47 1 my ($res) = @_;
48 1 return ( ${$res}->code =~ /^20(0|1)$/x );
49 }
50  
51 #}}}
52  
53 #{{{sub change_password_setup
54  
55 7 ▶sub change_password_setup {
Subroutine change_password_setup: called CC=6 SCAR=17.9
Pod documented
56 7 my ( $base_url, $act_on_user, $act_on_pass, $new_pass, $new_pass_confirm ) =
57 @_;
58 7 ▶ if ( !defined $base_url ) { croak 'No base url defined!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 1 6 7
59 6 ▶ if ( !defined $act_on_user ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $act_on_user) 2 4 6
60 2 croak 'No user name defined to change password for!';
61 }
62 4 ▶ if ( !defined $act_on_pass ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $act_on_pass) 1 3 4
63 1 croak "No current password defined for $act_on_user!";
64 }
65 3 ▶ if ( !defined $new_pass ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_pass) 1 2 3
66 1 croak "No new password defined for $act_on_user!";
67 }
68 2 ▶ if ( !defined $new_pass_confirm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_pass_confirm) 1 1 2
69 1 croak "No confirmation of new password defined for $act_on_user!";
70 }
71 1 my $post_variables =
72 "\$post_variables = ['oldPwd','$act_on_pass','newPwd','$new_pass','newPwdConfirm','$new_pass_confirm']";
73 return
74 1 "post $base_url/system/userManager/user/$act_on_user.changePassword.html $post_variables";
75 }
76  
77 #}}}
78  
79 #{{{sub change_password_eval
80  
81 1 ▶sub change_password_eval {
Subroutine change_password_eval: called CC=1 SCAR=0.0
Pod documented
82 1 my ($res) = @_;
83 1 return ( ${$res}->code eq '200' );
84 }
85  
86 #}}}
87  
88 #{{{sub delete_setup
89  
90 4 ▶sub delete_setup {
Subroutine delete_setup: called CC=3 SCAR=11.0
Pod documented
91 4 my ( $base_url, $act_on_user ) = @_;
92 4 ▶ if ( !defined $base_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 1 3 4
93 1 croak 'No base url defined to delete against!';
94 }
95 3 ▶ if ( !defined $act_on_user ) { croak 'No user name defined to delete!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $act_on_user) 2 1 3
96 1 my $post_variables = '$post_variables = []';
97 return
98 1 "post $base_url/system/userManager/user/$act_on_user.delete.html $post_variables";
99 }
100  
101 #}}}
102  
103 #{{{sub delete_eval
104  
105 1 ▶sub delete_eval {
Subroutine delete_eval: called CC=1 SCAR=0.0
Pod documented
106 1 my ($res) = @_;
107 1 return ( ${$res}->code eq '200' );
108 }
109  
110 #}}}
111  
112 #{{{sub exists_setup
113  
114 4 ▶sub exists_setup {
Subroutine exists_setup: called CC=3 SCAR=11.0
Pod documented
115 4 my ( $base_url, $act_on_user ) = @_;
116 4 ▶ if ( !defined $base_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 1 3 4
117 1 croak 'No base url to check existence against!';
118 }
119 3 ▶ if ( !defined $act_on_user ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $act_on_user) 2 1 3
120 2 croak 'No user to check existence of defined!';
121 }
122 1 return "get $base_url/system/userManager/user/$act_on_user.tidy.json";
123 }
124  
125 #}}}
126  
127 #{{{sub exists_eval
128  
129 2 ▶sub exists_eval {
Subroutine exists_eval: called CC=1 SCAR=0.0
Pod documented
130 2 my ($res) = @_;
131 2 return ( ${$res}->code eq '200' );
132 }
133  
134 #}}}
135  
136 #{{{sub update_setup
137  
138 4 ▶sub update_setup {
Subroutine update_setup: called CC=4 SCAR=13.9
Pod documented
139 4 my ( $base_url, $act_on_user, $properties ) = @_;
140 4 ▶ if ( !defined $base_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 1 3 4
141 1 croak 'No base url defined to update against!';
142 }
143 3 ▶ if ( !defined $act_on_user ) { croak 'No user name defined to update!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $act_on_user) 1 2 3
144 2 my $property_post_vars =
145 Apache::Sling::URL::properties_array_to_string($properties);
146 2 my $post_variables = '$post_variables = [';
147 2 ▶ if ( $property_post_vars ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($property_post_vars ne "") 1 1 2
148 1 $post_variables .= "$property_post_vars";
149 }
150 2 $post_variables .= ']';
151 return
152 2 "post $base_url/system/userManager/user/$act_on_user.update.html $post_variables";
153 }
154  
155 #}}}
156  
157 #{{{sub update_eval
158  
159 1 ▶sub update_eval {
Subroutine update_eval: called CC=1 SCAR=0.0
Pod documented
160 1 my ($res) = @_;
161 1 return ( ${$res}->code eq '200' );
162 }
163  
164 #}}}
165  
166 3 1;
167  
168 __END__
« Sling/AuthzUtil.pm ↑ Summary Sling/ContentUtil.pm »