Automatically set email and display names for users

This commit is contained in:
Daniel Berteaud 2013-10-03 09:48:37 +02:00
parent 2a621eada1
commit 29b3215d65
1 changed files with 12 additions and 1 deletions

View File

@ -29,6 +29,8 @@ use PHP::Serialization qw(serialize unserialize);
my $c = esmith::ConfigDB->open_ro;
my $a = esmith::AccountsDB->open_ro;
my $domain = $c->get('DomainName')->value;
# Remove all the permissions
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')){
my $name = $user->key;
my $first = $user->prop('FirstName') || '';
my $last = $user->prop('LastName') || $name;
my $data;
mkpath('/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{
$data->{"\0*\0groupPath"} = undef;
$data->{"\0*\0autoApplies"} = [];
$data->{"\0*\0parameters"} = [];
$data->{"\0*\0roleLabel"} = undef;
$data->{"\0*\0actions"} = [];
$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 );
}
}
# 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";
print WROLE serialize($data);