diff options
author | Buchan Milne <buchan@mageia.org> | 2011-02-20 14:25:32 +0000 |
---|---|---|
committer | Buchan Milne <buchan@mageia.org> | 2011-02-20 14:25:32 +0000 |
commit | 1d0a1ce05e26011e76bb317b9e011ca3536b9743 (patch) | |
tree | 1074db37ff1fdb980ed305af2395cac3e486d68f /lib | |
parent | d7e655bab45c3d52cbc1a34555bf2bb9d08972b9 (diff) | |
download | identity-1d0a1ce05e26011e76bb317b9e011ca3536b9743.tar identity-1d0a1ce05e26011e76bb317b9e011ca3536b9743.tar.gz identity-1d0a1ce05e26011e76bb317b9e011ca3536b9743.tar.bz2 identity-1d0a1ce05e26011e76bb317b9e011ca3536b9743.tar.xz identity-1d0a1ce05e26011e76bb317b9e011ca3536b9743.zip |
Initial group editing, still needs some work, but functional for adding/removing group members, by admin or group owner
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CatDap/Controller/admin.pm | 76 |
1 files changed, 60 insertions, 16 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; } |