Automatically set email and display names for users

tags/0.1.9
Daniel Berteaud 11 years ago
parent 2a621eada1
commit 29b3215d65
  1. 13
      root/etc/e-smith/events/actions/ajaxplorer-user-rights

@ -29,6 +29,8 @@ use PHP::Serialization qw(serialize unserialize);
my $c = esmith::ConfigDB->open_ro; my $c = esmith::ConfigDB->open_ro;
my $a = esmith::AccountsDB->open_ro; my $a = esmith::AccountsDB->open_ro;
my $domain = $c->get('DomainName')->value;
# Remove all the permissions # Remove all the permissions
unlink(</var/lib/ajaxplorer/plugins/auth.serial/*/rights.ser>); unlink(</var/lib/ajaxplorer/plugins/auth.serial/*/rights.ser>);
@ -41,6 +43,8 @@ unlink(</var/cache/ajaxplorer/i18n/*.ser>);
foreach my $user (($a->users),$a->get('admin')){ foreach my $user (($a->users),$a->get('admin')){
my $name = $user->key; my $name = $user->key;
my $first = $user->prop('FirstName') || '';
my $last = $user->prop('LastName') || $name;
my $data; my $data;
mkpath('/var/lib/ajaxplorer/plugins/auth.serial/' . $name); mkpath('/var/lib/ajaxplorer/plugins/auth.serial/' . $name);
chmod 0770, "/var/lib/ajaxplorer/plugins/auth.serial/$name"; chmod 0770, "/var/lib/ajaxplorer/plugins/auth.serial/$name";
@ -56,7 +60,6 @@ foreach my $user (($a->users),$a->get('admin')){
else{ else{
$data->{"\0*\0groupPath"} = undef; $data->{"\0*\0groupPath"} = undef;
$data->{"\0*\0autoApplies"} = []; $data->{"\0*\0autoApplies"} = [];
$data->{"\0*\0parameters"} = [];
$data->{"\0*\0roleLabel"} = undef; $data->{"\0*\0roleLabel"} = undef;
$data->{"\0*\0actions"} = []; $data->{"\0*\0actions"} = [];
$data->{"\0*\0roleId"} = "AJXP_USR_/$name"; $data->{"\0*\0roleId"} = "AJXP_USR_/$name";
@ -85,6 +88,14 @@ foreach my $user (($a->users),$a->get('admin')){
$data->{"\0*\0acls"}->{$sharename} = 'rw' if ( $_ eq $name ); $data->{"\0*\0acls"}->{$sharename} = 'rw' if ( $_ eq $name );
} }
} }
# As we're here, lets update the email address and the display name
# First, delete parameter if it's an array (meaning it's empty
delete $data->{"\0*\0parameters"} unless(
defined $data->{"\0*\0parameters"}->{'AJXP_REPO_SCOPE_ALL'}->{'core.conf'}->{'email'} ||
defined $data->{"\0*\0parameters"}->{'AJXP_REPO_SCOPE_ALL'}->{'core.conf'}->{'USER_DISPLAY_NAME'}
);
$data->{"\0*\0parameters"}->{'AJXP_REPO_SCOPE_ALL'}->{'core.conf'}->{'email'} = "$name\@$domain";
$data->{"\0*\0parameters"}->{'AJXP_REPO_SCOPE_ALL'}->{'core.conf'}->{'USER_DISPLAY_NAME'} = "$first $last";
open WROLE, '+>', "/var/lib/ajaxplorer/plugins/auth.serial/$name/role.ser"; open WROLE, '+>', "/var/lib/ajaxplorer/plugins/auth.serial/$name/role.ser";
print WROLE serialize($data); print WROLE serialize($data);

Loading…
Cancel
Save