diff options
-rw-r--r-- | lib/CatDap/Controller/admin.pm | 76 | ||||
-rw-r--r-- | root/admin/group.tt | 1 | ||||
-rw-r--r-- | root/admin/group_modify.tt | 12 |
3 files changed, 69 insertions, 20 deletions
diff --git a/lib/CatDap/Controller/admin.pm b/lib/CatDap/Controller/admin.pm index 7fd5539..5838028 100644 --- a/lib/CatDap/Controller/admin.pm +++ b/lib/CatDap/Controller/admin.pm @@ -565,39 +565,80 @@ sub password : Local { sub group : Local { my ( $self, $c ) = @_; $c->detach('/user/login') if not $c->user; - $c->assert_user_roles('Account Admins'); - $c->stash( subpages => gensubpages('account') ); + my $mainrole; + if ( $c->check_user_roles('Account Admins') ) { + $mainrole = 'account'; + } + elsif ( $c->check_user_roles('Group Admins') ) { + $mainrole = 'group'; + } + else { + $c->res->forward('/user'); + } + #$c->assert_any_user_role({['Account Admins','Group Admins']}); + #$mainrole = 'account' if $c->check_user_roles('Account Admins'); + $c->stash( subpages => gensubpages($mainrole) ); my @errors; - return if not $c->req->param('attribute') and not $c->req->param('value'); - my $attribute = $c->req->param('attribute'); - $attribute =~ s/[^\w\d]//g; - my $value = $c->req->param('value'); - $value =~ s/[^\w\d\* ]//g; + my ($attribute,$value); + if ( not $c->req->param('attribute') and not $c->req->param('value') ) { + $attribute = 'owner'; + $value = $c->user->ldap_entry->dn; + $c->stash( heading => 'Groups you manage'); + } + else { + $attribute = $c->req->param('attribute'); + $attribute =~ s/[^\w\d]//g; + $value = $c->req->param('value'); + $value =~ s/[^\w\d\* ]//g; + $c->stash( heading => 'Groups matching search criteria'); + } my $mesg = $c->model('user') - ->search("(&(objectclass=posixGroup)($attribute=$value))"); + ->search("(&(objectclass=groupOfNames)($attribute=$value))"); push @errors, $mesg->error if $mesg->code; - my @entries = $mesg->entries; + my @entries = $mesg->entries if ($mesg->entries ge 1); push @errors, $mesg->error if $mesg->code; - $c->stash( - entries => \@entries, - errors => \@errors, - ); + $c->stash( entries => \@entries ) if (@entries); + $c->stash( errors => \@errors); } sub group_modify : Local { - my ( $self, $c, $group ) = @_; + my ( $self, $c, $group, $op, $attr, $value ) = @_; $c->detach('/user/login') if not $c->user; $c->assert_user_roles('Account Admins'); $c->stash( subpages => gensubpages('account') ); my @errors; + my @entries; + my $mesg; $c->detach('/admin/group') if $group eq ''; if ( $group !~ /^[\w\d ]*$/ ) { push @errors, "Group contains illegal characters"; $c->detach('/admin/group'); } - my $mesg = - $c->model('user')->search("(&(objectClass=posixGroup)(cn=$group))"); + if ($op eq 'delete') { + $mesg = $c->model('user')->search("(&(objectClass=groupOfNames)(cn=$group))"); + @entries = $mesg->entries; + @entries[0]->delete( $attr => $value)->update; + $c->res->redirect("/admin/group_modify/$group"); + } + if ( $op eq 'add' ) { + my $member = $c->req->param('member'); + $mesg = $c->model('user')->search("(uid=$member)"); + if ( $mesg->code ) { + $c->stash({ errors => $mesg->error}); + $c->detach('/admin/group'); + } + if ( $mesg->entries ne 1 ) { + $c->detach('/admin/group'); + } + @entries = $mesg->entries; + my $dn = @entries[0]->dn; + $mesg = $c->model('user')->search("(&(objectClass=groupOfNames)(cn=$group))"); + @entries = $mesg->entries; + @entries[0]->add( 'member' => $dn )->update; + $c->res->redirect("/admin/group_modify/$group"); + } + $mesg = $c->model('user')->search("(&(objectClass=groupOfNames)(cn=$group))"); if ( $mesg->entries gt 1 ) { push @errors, 'More than one entry matched'; $c->detach('/admin/group'); @@ -641,6 +682,9 @@ sub gensubpages : Private { { page => 'group', title => "Groups" }, ); } + if ( $type eq 'group' ) { + { page => 'group', title => "Groups" }, + } return \@subpagenames; } diff --git a/root/admin/group.tt b/root/admin/group.tt index d7f258a..7264ef6 100644 --- a/root/admin/group.tt +++ b/root/admin/group.tt @@ -22,6 +22,7 @@ </table> </form> [% IF entries %] +[% heading %] <table border=0> <tr> <th>[% l('Group Name') %]</th> diff --git a/root/admin/group_modify.tt b/root/admin/group_modify.tt index 99ebff7..7bb412d 100644 --- a/root/admin/group_modify.tt +++ b/root/admin/group_modify.tt @@ -1,5 +1,5 @@ -<form method="post" action=""> - <input type='hidden' name='dn' value='[% group.dn %]'> +<form method="post" action="[% c.req.uri %]/add"> + <input type='hidden' name='cn' value='[% group.cn %]'> <table> <tr> <th>[% l('Attribute') %]</th> @@ -11,13 +11,17 @@ <td> [% FOREACH value IN group.get_value(attr) %] [% value %] - <a href="[% c.uri_for('/admin/group_modify') %]/delete/[% group.dn %]/[% attr %]/[% value %]">[% l('delete') %]</a> + [% IF attr == "member" OR attr =="owner" %] + <a href="[% c.uri_for('/admin/group_modify') %]/[% group.cn %]/delete/[% attr %]/[% value %]">[% l('delete') %]</a> + [% END %] <br/> [% END %] + [% IF attr == "member" OR attr == "owner" %] <input name="[% attr %]" value="" /> <input type="submit" value="[% l('Add') %]" /> + [% END %] </td> </tr> [% END %] </table> -</form>
\ No newline at end of file +</form> |