Refactor update_group to work as update_user
This commit is contained in:
parent
a3bd738b0f
commit
114e661761
3 changed files with 92 additions and 35 deletions
|
@ -14,32 +14,40 @@ use ACU::Process;
|
|||
|
||||
our $ou = "intra";
|
||||
|
||||
my %actions =
|
||||
my %group_actions =
|
||||
(
|
||||
"new" => \&group_new,
|
||||
"add" => \&group_add,
|
||||
"delete" => \&group_delete,
|
||||
"flush" => \&group_flush,
|
||||
"remove" => \&group_remove,
|
||||
"update" => \&group_update,
|
||||
"new" => \&_new,
|
||||
"add" => \&_add,
|
||||
"delete" => \&_delete,
|
||||
"flush" => \&_flush,
|
||||
"remove" => \&_remove,
|
||||
"update" => \&_update,
|
||||
);
|
||||
|
||||
sub group_new($$$)
|
||||
my %user_actions =
|
||||
(
|
||||
"add" => \&_add,
|
||||
"flush" => \&_flush,
|
||||
"remove" => \&_remove,
|
||||
"update" => \&_update,
|
||||
);
|
||||
|
||||
sub _new($$$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
my $args = shift;
|
||||
|
||||
# Add group
|
||||
if (LDAP::add_group($args->{param}{cn}, LDAP::get_year) eq $dn)
|
||||
if (LDAP::add_group($ldap, $args->{param}{cn}, $args->{param}{year}) eq $dn)
|
||||
{
|
||||
if ($args->{param}{type}) {
|
||||
group_add $dn, $args
|
||||
group_add $dn, $args;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub group_add($$$)
|
||||
sub _add($$$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
|
@ -49,16 +57,16 @@ sub group_add($$$)
|
|||
|
||||
# Add content if any
|
||||
for (my $i = $args->{unamed}; $i > 0; $i--) {
|
||||
LDAP::add_attribute($dn, $cnt_type, $args->{param}{$i});
|
||||
LDAP::add_attribute($ldap, $dn, $cnt_type, $args->{param}{$i});
|
||||
}
|
||||
}
|
||||
|
||||
sub group_delete($$$)
|
||||
sub _delete($$$)
|
||||
{
|
||||
return LDAP::delete_entry($_[0], $_[1]);
|
||||
}
|
||||
|
||||
sub group_flush($$)
|
||||
sub _flush($$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
|
@ -69,7 +77,7 @@ sub group_flush($$)
|
|||
return LDAP::flush_attribute($ldap, $dn, $cnt_type);
|
||||
}
|
||||
|
||||
sub group_remove($$)
|
||||
sub _remove($$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
|
@ -85,7 +93,7 @@ sub group_remove($$)
|
|||
return LDAP::delete_attributes($ldap, $dn, $cnt_type, @data);
|
||||
}
|
||||
|
||||
sub group_update($$)
|
||||
sub _update($$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
|
@ -98,45 +106,74 @@ sub group_update($$)
|
|||
push @data, $i;
|
||||
}
|
||||
|
||||
LDAP::update_attribute($ldap, $dn, $cnt_type, @data);
|
||||
return LDAP::update_attribute($ldap, $dn, $cnt_type, @data);
|
||||
}
|
||||
|
||||
|
||||
sub group_get_type($)
|
||||
sub _get_type($)
|
||||
{
|
||||
my $param = shift;
|
||||
|
||||
# Extract data type
|
||||
if ($param{type} eq "members") {
|
||||
if ($param->{type} eq "members") {
|
||||
return "memberUid";
|
||||
}
|
||||
elsif ($param{type} eq "rights") {
|
||||
elsif ($param->{type} eq "rights") {
|
||||
return "intraRights" ;
|
||||
}
|
||||
else {
|
||||
die ("Unknown type to add: ".$param{type});
|
||||
die ("Unknown type to add: ".$param->{type});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub process
|
||||
sub process_group
|
||||
{
|
||||
my ($given_args, $args) = @_;
|
||||
|
||||
my $year = $param{year} // LDAP::get_year;
|
||||
my $dn = "cn=".$param{cn}."ou=$year,ou=$ou,ou=groups,dc=acu,dc=epita,dc=fr";
|
||||
my $action = $param{type} // "update";
|
||||
my $year = $args->{param}{year} // LDAP::get_year;
|
||||
my $dn = "cn=".$args->{param}{cn}."ou=$year,ou=$ou,ou=groups,dc=acu,dc=epita,dc=fr";
|
||||
my $action = $args->{param}{type} // "update";
|
||||
|
||||
# Read action
|
||||
if (! exists $actions{$action}) {
|
||||
if (! exists $group_actions{$action}) {
|
||||
return "Unknown command for update_group: ". $action;
|
||||
}
|
||||
|
||||
my $ldap = LDAP::ldap_connect();
|
||||
|
||||
$actions{$action}($ldap, $dn, $args);
|
||||
$group_actions{$action}($ldap, $dn, $args);
|
||||
|
||||
$ldap->unbind or print "couldn't disconnect correctly";
|
||||
$ldap->unbind or warn "couldn't disconnect correctly";
|
||||
}
|
||||
|
||||
Process::register("update_group", \&process);
|
||||
sub process_user
|
||||
{
|
||||
my ($given_args, $args) = @_;
|
||||
|
||||
my $action = $args->{param}{type} // "update";
|
||||
|
||||
# Read action
|
||||
if (! exists $user_actions{$action}) {
|
||||
return "Unknown command for update_user: ". $action;
|
||||
}
|
||||
|
||||
my $ldap = LDAP::ldap_connect();
|
||||
|
||||
my $dn = LDAP::search_dn($ldap, "ou=users", "uid=".$args->{param}{uid});
|
||||
|
||||
$user_actions{$action}($ldap, $dn, $args);
|
||||
|
||||
$ldap->unbind or warn "couldn't disconnect correctly";
|
||||
}
|
||||
|
||||
|
||||
if ($0 =~ /^update_group/) {
|
||||
Process::register("update_group", \&process_group);
|
||||
}
|
||||
elsif ($0 =~ /^update_user/) {
|
||||
Process::register("update_user", \&process_user);
|
||||
}
|
||||
else {
|
||||
die ("Bad filename.");
|
||||
}
|
||||
|
|
1
process/ldap/update_user.pl
Symbolic link
1
process/ldap/update_user.pl
Symbolic link
|
@ -0,0 +1 @@
|
|||
update_group.pl
|
Reference in a new issue