File Coverage

blib/lib/WebEditor/OldFeatures/AdminGroup.pm
Criterion Covered Total %
statement 12 77 15.5
branch 0 40 0.0
condition 0 5 0.0
subroutine 4 6 66.6
pod 0 1 0.0
total 16 129 12.4


line stmt bran cond sub pod time code
1             package WebEditor::OldFeatures::AdminGroup;
2              
3 1     1   1171 use strict;
  1         3  
  1         34  
4 1     1   5 use vars qw($VERSION);
  1         3  
  1         89  
5             $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
6              
7 1     1   6 use mixin::with 'WebEditor::OldController';
  1         2  
  1         9  
8              
9 1     1   162 use CGI qw(param);
  1         2  
  1         9  
10              
11             sub groupadmin {
12 0     0 0   my $self = shift;
13              
14 0           $self->check_login;
15 0           my $root = $self->Root;
16              
17 0           my @needed_permissions = qw(admin groupadmin);
18 0 0         if (!$root->is_allowed([@needed_permissions])) {
19 0           print <
20             You are not allowed to call the group administration interface! You
21             ermineed one of the following permissions: @needed_permissions.

22             Back to admin page.
23             EOF
24 0           exit;
25             }
26              
27 0           my $c = $self->C;
28 0           my %tplvars;
29              
30             my $u;
31 0   0       my $useradmindb = param('useradmindb') || '';
32 0           my $userdb_prop;
33 0 0         if ($useradmindb eq '') {
34 0           $u = $root->UserDB;
35 0 0         if ($root->can('get_userdb_prop')) {
36 0           $userdb_prop = $root->get_userdb_prop("");
37             }
38             } else {
39 0           $u = $self->get_custom_userdb($useradmindb);
40             }
41 0 0         if (!$u) {
42 0           $self->error("No userdb for $useradmindb defined");
43             }
44              
45 0           my @message;
46 0           my $useradminaction = param('useradminaction');
47 0           my $useradmingroup = param('useradmingroup');
48 0           my $useradmindelgroup = param('useradmindelgroup');
49              
50             my $groupinfo_update = sub {
51 0     0     my %new;
52 0           foreach my $key (param()) {
53 0 0         next unless $key =~ /^useradmingroup_(.*)/;
54 0           my $fieldkey = $1;
55 0           my $val = param($key);
56 0           $new{$fieldkey} = $val;
57             }
58 0 0         if (keys %new) {
59 0           my $groupobj = $u->get_group_definition($useradmingroup);
60 0           @{$groupobj}{keys %new} = values %new;
  0            
61 0           $u->set_group_definition($useradmingroup, $groupobj);
62             }
63              
64 0 0         if ($c->project->features->{wwwauth}) {
65             # XXX passing -userdb not necessary anymore?
66 0 0 0       $self->update_auth_files(-verbose => 0, -userdb => $u)
67             if $useradmindb && $self->can("update_auth_files");
68             }
69 0           };
70              
71 0 0         $useradminaction = "" if !defined $useradminaction;
72              
73 0 0         if ($useradminaction eq "addgroup") {
    0          
    0          
    0          
74 0 0         if ($useradmingroup =~ /^\s*$/) {
75 0           push @message, qq{Error: no group given!};
76             } else {
77 0 0         if ($u->add_group_definition($useradmingroup) == 1) {
78 0           $groupinfo_update->();
79 0           push @message, "Group $useradmingroup successfully added.";
80             } else {
81 0           push @message, qq{Could not add group $useradmingroup};
82             }
83             }
84             } elsif ($useradminaction eq "updgroup") {
85 0           $groupinfo_update->();
86             } elsif ($useradminaction eq "delgroup") {
87 0 0         if ($u->delete_group_definition($useradmindelgroup) == 1) {
88 0           push @message, "Group $useradmindelgroup successfully deleted.";
89             } else {
90 0           push @message, qq{Could not delete group $useradmindelgroup};
91             }
92             } elsif ($useradminaction eq "editgroup") {
93 0           my $groupobj;
94 0 0         if ($groupobj = $u->get_group_definition($useradmingroup)) {
95 0           push @message, "Please edit group $useradmingroup.";
96 0           $tplvars{'group'} = $groupobj;
97             } else {
98 0           push @message, qq{Could not get group data for $useradmingroup};
99             }
100             }
101             # Other group fetching mechanisms like in the user administration not
102             # possible here.
103 0           my @allgroups = $u->get_all_groups;
104 0           $tplvars{'allgroups'} = \@allgroups;
105              
106 0           my @groupusers;
107 0 0         if ($useradmingroup) {
108 0           @groupusers = $u->get_users_of_group($useradmingroup);
109             }
110              
111             # process Template
112 0           $tplvars{'useradmindb'} = $useradmindb;
113 0           $tplvars{'useradmingroup'} = $useradmingroup;
114 0           $tplvars{'useradmingroupusers'} = \@groupusers;
115 0           $tplvars{'message'} = join "\n", @message;
116 0 0         $tplvars{'headline'} = $self->msg($useradmindb eq 'wwwuser' ? "cap_webgroupadmin" : "cap_groupadmin");
117 0 0         $tplvars{'userheadline'} = $self->msg($useradmindb eq 'wwwuser' ? "cap_webuseradmin" : "cap_useradmin");
118              
119 0           $self->_tpl("bestwe", "we_groupadmin.tpl.html", \%tplvars);
120             }
121              
122             1;