* Added getGroupMembers() to the User data source.

* Fixed a bug in the MySQL implementation of User data source's getGroupName() method. It treated 'row' as an array ref instead of a normal array.
* Made the MySQL User data source automatically add a group with ID 1, named 'Administrators'.
* Special-cased the group with ID 1 in the user object so that if a user is in that group, he automatically is assumed to have all rights.
* Fixed a bug with the saving of the original groups in the user object (the backup object was simply a reference to the original object, which was later changed in place, causing the backup to change too).
* Fixed the handling of rights in the user object constructor to simply set the rights in one line instead of using indirection.
* Fixed the invalidateRights() method of the user object to correctly re-set the rights (previously it was not turning the generated array into a hashref).
* Added a setup.install implementation to the login component. It now queries the user for an administration username and creates the relevant user and puts it in the magic group 1.
* Fixed a call to checkAddress() in the login component.
This commit is contained in:
ian%hixie.ch 2002-02-01 06:48:02 +00:00
Родитель 5e999d163f
Коммит 21b2f6a62d
4 изменённых файлов: 77 добавлений и 13 удалений

Просмотреть файл

@ -258,6 +258,13 @@ sub getGroups {
# return [groupID, name, [rightName]*]*
}
sub getGroupMembers {
my $self = shift;
my($app, $groupID) = @_;
$self->notImplemented();
# return [userID, level]*
}
sub getGroupName {
my $self = shift;
my($app, $groupID) = @_;

Просмотреть файл

@ -263,15 +263,18 @@ sub getGroups {
# return [groupID, name, [rightName]*]*
}
sub getGroupMembers {
my $self = shift;
my($app, $groupID) = @_;
return $self->database($app)->execute('SELECT userGroupsMapping.userID, userGroupsMapping.level
FROM userGroupsMapping
WHERE userGroupsMapping.groupID = ?', $groupID)->rows;
}
sub getGroupName {
my $self = shift;
my($app, $groupID) = @_;
my $row = $self->database($app)->execute('SELECT name FROM groups WHERE groupID = ?', $groupID)->row;
if (defined($row)) {
return $row->[0];
} else {
return undef;
}
return scalar($self->database($app)->execute('SELECT name FROM groups WHERE groupID = ?', $groupID)->row);
# return name or undef
}
@ -500,8 +503,12 @@ sub setupInstall {
# | groupID K1 | auto_increment
# | name K2 | user defined name (can be changed)
# +-------------------+
$self->database($app)->execute('INSERT INTO groups SET groupID=?, name=?', 1, 'Administrators');
} else {
# check its schema is up to date
if (not $self->database($app)->execute('SELECT groupID FROM groups WHERE groupID = ?', 1)->row) {
$self->database($app)->execute('INSERT INTO groups SET groupID=?, name=?', 1, 'Administrators');
}
}
if (not $helper->tableExists($app, $database, 'groupRightsMapping')) {
$app->output->setupProgress('dataSource.user.groupRightsMapping');

Просмотреть файл

@ -43,6 +43,7 @@ sub provides {
$service eq 'dispatcher.commands' or
$service eq 'dispatcher.output.generic' or
$service eq 'dispatcher.output' or
$service eq 'setup.install' or
$class->SUPER::provides($service));
}
@ -250,6 +251,56 @@ sub strings {
);
}
sub setupInstall {
my $self = shift;
my($app) = @_;
# cache the data source service
my $dataSource = $app->getService('dataSource.user');
# look for users in group 1
my $users = $dataSource->getGroupMembers($app, 1);
if (not @$users) {
# no administrators, so ask for one
$app->output->setupProgress('user.login.administrator');
# get the contact method
# XXX should be a way to make sure default contact method is a particular contact method (namely, e-mail)
my $contact = $app->input->getArgument('user.login.administrator.contactMethod', $dataSource->getFieldNamesByCategory($app, 'contact'));
if (not defined($contact)) {
return 'user.login.administrator.contact';
}
# get the address of the administrator user
my $address = $app->input->getArgument('user.login.administrator.adddress');
if (not defined($address)) {
return 'user.login.administrator.address';
}
# cache the user factory
my $userFactory = $app->getService('user.factory');
# get the user in question
my $user = $userFactory->getUserByContactDetails($app, $contact, $address);
# if doesn't exist, create it
if (not defined($user)) {
$app->output->setupProgress('user.login.administrator.creating');
my $password;
($user, $password) = $self->createUser($app, $contact, $address);
if (not defined($user)) {
return 'user.login.administrator.address';
}
$app->output($contact, $user)->loginDetails($address, $password);
}
# add the user to group 1 as an administrator (so he's an administrator of administrators)
$user->joinGroup(1, 2); # XXX HARDCODED CONSTANT ALERT
}
return;
}
# internal routines
@ -264,8 +315,8 @@ sub changePassword {
sub createUser {
my $self = shift;
my($app, $protocol, $address) = @_;
my $validator = $app->getService('protocol.'.$protocol);
if ((defined($validator)) and (not $validator->checkAddress($address))) {
my $validator = $app->getService("protocol.$protocol");
if ((defined($validator)) and (not $validator->checkAddress($app, $address))) {
return (undef, undef);
}
my($crypt, $password) = $app->getService('service.passwords')->newPassword();

Просмотреть файл

@ -129,18 +129,17 @@ sub objectInit {
$groupsByName->{$group->[1]} = {'groupID' => $group->[0], 'level' => $group->[2], }; # name => id, level
}
$self->groupsByID($groupsByID); # authoritative version
$self->originalGroupsByID($groupsByID); # a backup used to make a comparison when saving the groups
$self->originalGroupsByID({%{$groupsByID}}); # a backup used to make a comparison when saving the groups
$self->groupsByName($groupsByName); # helpful version for output purposes only
# rights
my %rights = map {$_ => 1} @$rights;
$self->rights(\%rights); # map a list of strings into a hash for easy access
$self->rights({ map {$_ => 1} @$rights }); # map a list of strings into a hash for easy access
$self->{'_DIRTY'}->{'properties'} = not(defined($userID));
}
sub hasRight {
my $self = shift;
my($right) = @_;
return defined($self->rights->{$right});
return (defined($self->rights->{$right}) or $self->levelInGroup(1)); # group 1 is a magical group
}
sub hasField {
@ -317,7 +316,7 @@ sub insertField {
sub invalidateRights {
my $self = shift;
my $rights = $self->app->getService('dataSource.user')->getRights($self->app, keys(%{$self->{'groupsByID'}}));
$self->rights(map {$_ => 1} @$rights); # map a list of strings into a hash for easy access
$self->rights({ map {$_ => 1} @$rights }); # map a list of strings into a hash for easy access
# don't set a dirty flag, because rights are merely a convenient
# cached expansion of the rights data. Changing this externally
# makes no sense -- what rights one has is dependent on what