| 1 | #!/usr/bin/perl -w | ||||||||||
| 2 | |||||||||||
| 3 | package Sakai::Nakamura::UserUtil; | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use 5.008008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | require Exporter; | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | our @EXPORT_OK = (); | |||||||||
| 15 | |||||||||||
| 16 | 2 | our $VERSION = '0.13'; | |||||||||
| 17 | |||||||||||
| 18 | #{{{sub exists_setup | ||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub exists_setup { | ||||||||
|
Subroutine
exists_setup: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 21 | 0 | my ( $base_url, $act_on_user ) = @_; | |||||||||
| 22 | 0 | ▶ | if ( !defined $base_url ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | croak 'No base url to check existence against!'; | |||||||||
| 24 | } | ||||||||||
| 25 | 0 | ▶ | if ( !defined $act_on_user ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | croak 'No user to check existence of defined!'; | |||||||||
| 27 | } | ||||||||||
| 28 | return | ||||||||||
| 29 | 0 | "get $base_url/system/userManager/user.exists.html?userid=$act_on_user"; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | #}}} | ||||||||||
| 33 | |||||||||||
| 34 | #{{{sub exists_eval | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub exists_eval { | ||||||||
|
Subroutine
exists_eval: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 37 | 0 | my ($res) = @_; | |||||||||
| 38 | 0 | return ( ${$res}->code eq '204' ); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | #}}} | ||||||||||
| 42 | |||||||||||
| 43 | #{{{sub me_setup | ||||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | sub me_setup { | ||||||||
|
Subroutine
me_setup: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 46 | 2 | my ($base_url) = @_; | |||||||||
| 47 | 2 | ▶ | if ( !defined $base_url ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 1 | croak 'No base url to run me against!'; | |||||||||
| 49 | } | ||||||||||
| 50 | 1 | return "get $base_url/system/me"; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | #}}} | ||||||||||
| 54 | |||||||||||
| 55 | #{{{sub me_eval | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub me_eval { | ||||||||
|
Subroutine
me_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | 1 | my ($res) = @_; | |||||||||
| 59 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | #}}} | ||||||||||
| 63 | |||||||||||
| 64 | #{{{sub profile_update_setup | ||||||||||
| 65 | |||||||||||
| 66 | 7 | ▶ | sub profile_update_setup { | ||||||||
|
Subroutine
profile_update_setup: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 67 | 7 | my ( $base_url, $field, $value, $act_on_user, $profile_section ) = @_; | |||||||||
| 68 | 7 | ▶ | if ( !defined $base_url ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 1 | croak 'No base url to run profile update against!'; | |||||||||
| 70 | } | ||||||||||
| 71 | 6 | ▶ | if ( !defined $field ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 2 | croak 'No profile field to update specified!'; | |||||||||
| 73 | } | ||||||||||
| 74 | 4 | ▶ | if ( !defined $value ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 1 | croak 'No value specified to set profile field to!'; | |||||||||
| 76 | } | ||||||||||
| 77 | 3 | ▶ | if ( !defined $act_on_user ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 1 | croak 'No user specified to update profile for!'; | |||||||||
| 79 | } | ||||||||||
| 80 | 2 | ▶ | if ( !defined $profile_section ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 1 | $profile_section = 'basic'; | |||||||||
| 82 | } | ||||||||||
| 83 | 2 | my $profile_update_json = | |||||||||
| 84 | "{\"elements\":{\"$field\":{\"value\":\"$value\"}}}"; | ||||||||||
| 85 | 2 | my $post_variables = | |||||||||
| 86 | "\$post_variables = [':content','$profile_update_json',':contentType','json',':operation','import',':removeTree','true',':replace','true',':replaceProperties','true']"; | ||||||||||
| 87 | return | ||||||||||
| 88 | 2 | "post $base_url/~$act_on_user/public/authprofile/$profile_section.profile.json $post_variables"; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | #}}} | ||||||||||
| 92 | |||||||||||
| 93 | #{{{sub profile_update_eval | ||||||||||
| 94 | |||||||||||
| 95 | 1 | ▶ | sub profile_update_eval { | ||||||||
|
Subroutine
profile_update_eval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 96 | 1 | my ($res) = @_; | |||||||||
| 97 | 1 | return ( ${$res}->code eq '200' ); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | #}}} | ||||||||||
| 101 | |||||||||||
| 102 | 2 | 1; | |||||||||
| 103 | |||||||||||
| 104 | __END__ | ||||||||||