Commit 0d0b8c2f authored by Francesc Guasch's avatar Francesc Guasch
Browse files

refactor(frontend): add and remove group

parent 904aac61
......@@ -337,6 +337,7 @@ Add a group to the LDAP
=cut
sub add_group($name, $base=_dc_base(), $class=['groupOfUniqueNames','nsMemberOf','posixGroup','top' ]) {
my $ldap = _init_ldap_admin();
$base = _dc_base() if !defined $base;
$name = escape_filter_value($name);
my $oc_posix_group;
......@@ -344,7 +345,6 @@ sub add_group($name, $base=_dc_base(), $class=['groupOfUniqueNames','nsMemberOf'
my @attrs =( cn=>$name
,objectClass => $class
,ou => 'Groups'
,description => "Group for $name"
);
push @attrs, (gidNumber => _search_new_gid()) if $oc_posix_group;
......@@ -354,7 +354,7 @@ sub add_group($name, $base=_dc_base(), $class=['groupOfUniqueNames','nsMemberOf'
, cn => $name
, attrs => \@attrs
);
my $mesg = $LDAP_ADMIN->add(@data);
my $mesg = $ldap->add(@data);
if ($mesg->code) {
die "Error creating group $name : ".$mesg->error."\n".Dumper(\@data);
}
......
......@@ -1708,7 +1708,7 @@ post '/ldap/group/remove_member' => sub($c) {
};
get '/ldap/group/remove/(:group)' => sub($c) {
get '/ldap/group/remove/(#group)' => sub($c) {
return access_denied($c) if !$USER->can_manage_groups;
eval { Ravada::Auth::LDAP::remove_group($c->stash('group')) };
return $c->render( json => { error => ($@ or '') });
......@@ -2642,7 +2642,13 @@ sub new_group($c) {
my $groupname = ($c->param('groupname') or '');
my $object_class = $c->every_param('object_class');
push @$object_class,('top' , 'groupOfUniqueNames');
my $object_class_checkbox;
for (@$object_class) {
$object_class_checkbox->{$_} = 'checked';
}
$c->stash(object_class => $object_class_checkbox);
$object_class = ['top',@$object_class];
if ($groupname) {
if ($groupname =~ /^[0-9a-zA-Z._-]+$/) {
......@@ -2654,6 +2660,8 @@ sub new_group($c) {
push @error,("Error: group name '$groupname' invalid."
,"Group name can only contain words, numbers, dashes, dots and underscores" );
}
} else {
$c->stash(object_class => { posixGroup => 'checked' });
}
$c->render(template => 'bootstrap/new_group', error => \@error
,groupname => $groupname);
......
......@@ -5,11 +5,11 @@
>
<div class="from-group">
<label for="groupname"><%=l 'Group name' %></label><%= $groupname %>
<input class="form-control" ng-model-onblur placeholder="<%=l 'Enter group name' %>" type="text" ng-maxlength="80" ng-minlength="5" name="groupname" ng-pattern="/^[a-zA-Z0-9_.-]*$/" id="groupname" required="" value="<%= $groupname %>"><br/>
<input class="form-control" ng-model-onblur placeholder="<%=l 'Enter group name' %>" type="text" ng-maxlength="80" ng-minlength="5" name="groupname" ng-pattern="/^[a-zA-Z0-9_.-]*$/" id="groupname" required="true" value="<%= $groupname %>"><br/>
</div>
<div class="form-group">
% for (sort ('nsMemberOf','posixGroup') ) {
<input type="checkbox" checked="true" name="object_class" value="<%= $_ %>"> <%= $_ %><br/>
% for (sort ('nsMemberOf','posixGroup','groupOfUniqueNames') ) {
<input type="checkbox" <%= ($object_class->{$_} or '') %> name="object_class" value="<%= $_ %>"> <%= $_ %><br/>
% }
</div>
<div class="card-text" ng-show="new_userForm.$submitted || (new_userForm.groupname.$touched && new_userForm.groupname.$dirty)">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment