| 1 | package WebEditor::OldFeatures::AdminGroup; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use vars qw($VERSION); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/); | ||
| 6 | |||
| 7 | 1 | ▶ | use mixin::with 'WebEditor::OldController'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 0 | ▶ | use CGI qw(param); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | sub groupadmin { | ||
| 12 | my $self = shift; | ||
| 13 | |||
| 14 | $self->check_login; | ||
| 15 | my $root = $self->Root; | ||
| 16 | |||
| 17 | my @needed_permissions = qw(admin groupadmin); | ||
| 18 | if (!$root->is_allowed([@needed_permissions])) { | ||
| 19 | print <<EOF; | ||
| 20 | You are not allowed to call the group administration interface! You | ||
| 21 | ermineed one of the following permissions: @needed_permissions.<p> | ||
| 22 | Back to <a href='javascript:history.back()'>admin</a> page. | ||
| 23 | EOF | ||
| 24 | exit; | ||
| 25 | } | ||
| 26 | |||
| 27 | my $c = $self->C; | ||
| 28 | my %tplvars; | ||
| 29 | |||
| 30 | my $u; | ||
| 31 | my $useradmindb = param('useradmindb') || ''; | ||
| 32 | my $userdb_prop; | ||
| 33 | if ($useradmindb eq '') { | ||
| 34 | $u = $root->UserDB; | ||
| 35 | if ($root->can('get_userdb_prop')) { | ||
| 36 | $userdb_prop = $root->get_userdb_prop(""); | ||
| 37 | } | ||
| 38 | } else { | ||
| 39 | $u = $self->get_custom_userdb($useradmindb); | ||
| 40 | } | ||
| 41 | if (!$u) { | ||
| 42 | $self->error("No userdb for $useradmindb defined"); | ||
| 43 | } | ||
| 44 | |||
| 45 | my @message; | ||
| 46 | my $useradminaction = param('useradminaction'); | ||
| 47 | my $useradmingroup = param('useradmingroup'); | ||
| 48 | my $useradmindelgroup = param('useradmindelgroup'); | ||
| 49 | |||
| 50 | my $groupinfo_update = sub { | ||
| 51 | my %new; | ||
| 52 | foreach my $key (param()) { | ||
| 53 | next unless $key =~ /^useradmingroup_(.*)/; | ||
| 54 | my $fieldkey = $1; | ||
| 55 | my $val = param($key); | ||
| 56 | $new{$fieldkey} = $val; | ||
| 57 | } | ||
| 58 | if (keys %new) { | ||
| 59 | my $groupobj = $u->get_group_definition($useradmingroup); | ||
| 60 | @{$groupobj}{keys %new} = values %new; | ||
| 61 | $u->set_group_definition($useradmingroup, $groupobj); | ||
| 62 | } | ||
| 63 | |||
| 64 | if ($c->project->features->{wwwauth}) { | ||
| 65 | # XXX passing -userdb not necessary anymore? | ||
| 66 | $self->update_auth_files(-verbose => 0, -userdb => $u) | ||
| 67 | if $useradmindb && $self->can("update_auth_files"); | ||
| 68 | } | ||
| 69 | }; | ||
| 70 | |||
| 71 | $useradminaction = "" if !defined $useradminaction; | ||
| 72 | |||
| 73 | if ($useradminaction eq "addgroup") { | ||
| 74 | if ($useradmingroup =~ /^\s*$/) { | ||
| 75 | push @message, qq{<span class="alert">Error: no group given!</span>}; | ||
| 76 | } else { | ||
| 77 | if ($u->add_group_definition($useradmingroup) == 1) { | ||
| 78 | $groupinfo_update->(); | ||
| 79 | push @message, "Group $useradmingroup successfully added."; | ||
| 80 | } else { | ||
| 81 | push @message, qq{<span class="alert">Could not add group $useradmingroup</span>}; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } elsif ($useradminaction eq "updgroup") { | ||
| 85 | $groupinfo_update->(); | ||
| 86 | } elsif ($useradminaction eq "delgroup") { | ||
| 87 | if ($u->delete_group_definition($useradmindelgroup) == 1) { | ||
| 88 | push @message, "Group $useradmindelgroup successfully deleted."; | ||
| 89 | } else { | ||
| 90 | push @message, qq{<span class="alert">Could not delete group $useradmindelgroup</span>}; | ||
| 91 | } | ||
| 92 | } elsif ($useradminaction eq "editgroup") { | ||
| 93 | my $groupobj; | ||
| 94 | if ($groupobj = $u->get_group_definition($useradmingroup)) { | ||
| 95 | push @message, "Please edit group $useradmingroup."; | ||
| 96 | $tplvars{'group'} = $groupobj; | ||
| 97 | } else { | ||
| 98 | push @message, qq{<span class="alert">Could not get group data for $useradmingroup</span>}; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | # Other group fetching mechanisms like in the user administration not | ||
| 102 | # possible here. | ||
| 103 | my @allgroups = $u->get_all_groups; | ||
| 104 | $tplvars{'allgroups'} = \@allgroups; | ||
| 105 | |||
| 106 | my @groupusers; | ||
| 107 | if ($useradmingroup) { | ||
| 108 | @groupusers = $u->get_users_of_group($useradmingroup); | ||
| 109 | } | ||
| 110 | |||
| 111 | # process Template | ||
| 112 | $tplvars{'useradmindb'} = $useradmindb; | ||
| 113 | $tplvars{'useradmingroup'} = $useradmingroup; | ||
| 114 | $tplvars{'useradmingroupusers'} = \@groupusers; | ||
| 115 | $tplvars{'message'} = join "\n", @message; | ||
| 116 | $tplvars{'headline'} = $self->msg($useradmindb eq 'wwwuser' ? "cap_webgroupadmin" : "cap_groupadmin"); | ||
| 117 | $tplvars{'userheadline'} = $self->msg($useradmindb eq 'wwwuser' ? "cap_webuseradmin" : "cap_useradmin"); | ||
| 118 | |||
| 119 | $self->_tpl("bestwe", "we_groupadmin.tpl.html", \%tplvars); | ||
| 120 | } | ||
| 121 | |||
| 122 | 1; | ||