зеркало из https://github.com/mozilla/pjs.git
Minor fixes to make the previous checkin actually compile...
This commit is contained in:
Родитель
87e2811f81
Коммит
0d7332f336
|
@ -118,7 +118,7 @@ sub removeUserField {
|
||||||
sub setUserGroups {
|
sub setUserGroups {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my($app, $userID, $groupIDs) = @_;
|
my($app, $userID, $groupIDs) = @_;
|
||||||
$groupIDs is a hashref in the form { groupID => level }*
|
# $groupIDs is a hashref in the form { groupID => level }*
|
||||||
foreach my $groupID (keys(%$groupIDs)) {
|
foreach my $groupID (keys(%$groupIDs)) {
|
||||||
$self->assert($groupIDs->{$groupID} > 0, 1, 'Invalid group membership level passed to setUserGroups');
|
$self->assert($groupIDs->{$groupID} > 0, 1, 'Invalid group membership level passed to setUserGroups');
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,6 @@ sub getUserByID {
|
||||||
FROM groups, userGroupsMapping
|
FROM groups, userGroupsMapping
|
||||||
WHERE userGroupsMapping.userID = ?
|
WHERE userGroupsMapping.userID = ?
|
||||||
AND userGroupsMapping.groupID = groups.groupID', $id)->rows;
|
AND userGroupsMapping.groupID = groups.groupID', $id)->rows;
|
||||||
my %groupData = map { $$_[0] => $$_[1] } @$groupData;
|
|
||||||
# rights
|
# rights
|
||||||
my $rightsData = $self->database($app)->execute('SELECT rights.name
|
my $rightsData = $self->database($app)->execute('SELECT rights.name
|
||||||
FROM rights, userGroupsMapping, groupRightsMapping
|
FROM rights, userGroupsMapping, groupRightsMapping
|
||||||
|
@ -90,7 +89,7 @@ sub getUserByID {
|
||||||
AND groupRightsMapping.rightID = rights.rightID', $id)->rows;
|
AND groupRightsMapping.rightID = rights.rightID', $id)->rows;
|
||||||
my @rightsData = map { $$_[0] } @$rightsData;
|
my @rightsData = map { $$_[0] } @$rightsData;
|
||||||
# bake it all up and send it to the customer
|
# bake it all up and send it to the customer
|
||||||
return (@userData, \%fieldData, \%groupData, \@rightsData);
|
return (@userData, \%fieldData, $groupData, \@rightsData);
|
||||||
} else {
|
} else {
|
||||||
return ();
|
return ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,8 @@ sub cmdUserPrefs {
|
||||||
} else {
|
} else {
|
||||||
# one or more users selected
|
# one or more users selected
|
||||||
# let's get rid of the duplicates
|
# let's get rid of the duplicates
|
||||||
@userIDs = keys(map { $_ => 1 } @userIDs);
|
my %userIDs = map { $_ => 1 } @userIDs;
|
||||||
|
@userIDs = keys(%userIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
# cache rights (for efficiently reasons)
|
# cache rights (for efficiently reasons)
|
||||||
|
@ -70,12 +71,17 @@ sub cmdUserPrefs {
|
||||||
|
|
||||||
# get a handle to some useful services (also for efficiently reasons)
|
# get a handle to some useful services (also for efficiently reasons)
|
||||||
my $userFactory = $app->getService('user.factory');
|
my $userFactory = $app->getService('user.factory');
|
||||||
my $userDataSource = $app->getService('user.dataSource');
|
my $userDataSource = $app->getService('dataSource.user');
|
||||||
|
|
||||||
# get the data for each user being edited
|
# get the data for each user being edited
|
||||||
my $userData = {};
|
my $userData = {};
|
||||||
foreach my $userID (@userIDs) {
|
foreach my $userID (@userIDs) {
|
||||||
$userData->{$userID} = $self->populateUserPrefsHash($app, $userDataSource, $user, $userFactory->getUserByID($userID), $userID, $userID == $user->userID, @rights);
|
my $targetUser = $userFactory->getUserByID($app, $userID);
|
||||||
|
if (defined($targetUser)) {
|
||||||
|
$userData->{$userID} = $self->populateUserPrefsHash($app, $userDataSource, $user, $targetUser, $userID, $userID == $user->userID, @rights);
|
||||||
|
} else {
|
||||||
|
$self->warn(2, "someone tried to get the details of invalid user $userID");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# put it all together
|
# put it all together
|
||||||
|
@ -116,9 +122,9 @@ sub populateUserPrefsHash {
|
||||||
|
|
||||||
# XXX there is probably a more generic way of doing this...
|
# XXX there is probably a more generic way of doing this...
|
||||||
$userData->{'fields'} = {};
|
$userData->{'fields'} = {};
|
||||||
$self->populateUserPrefsHashFieldCategory($app, $rightContactMethods, 'contact', $editingUserIsTargetUser, $userData);
|
$self->populateUserPrefsHashFieldCategory($app, $targetUser, $rightContactMethods, 'contact', $editingUserIsTargetUser, $userData);
|
||||||
$self->populateUserPrefsHashFieldCategory($app, $rightPersonalDetails, 'personal', $editingUserIsTargetUser, $userData);
|
$self->populateUserPrefsHashFieldCategory($app, $targetUser, $rightPersonalDetails, 'personal', $editingUserIsTargetUser, $userData);
|
||||||
$self->populateUserPrefsHashFieldCategory($app, $rightSettings, 'settings', $editingUserIsTargetUser, $userData);
|
$self->populateUserPrefsHashFieldCategory($app, $targetUser, $rightSettings, 'settings', $editingUserIsTargetUser, $userData);
|
||||||
|
|
||||||
$userData->{'groups'} = {};
|
$userData->{'groups'} = {};
|
||||||
if ($rightGroups) {
|
if ($rightGroups) {
|
||||||
|
@ -144,7 +150,7 @@ sub populateUserPrefsHash {
|
||||||
|
|
||||||
sub populateUserPrefsHashFieldCategory {
|
sub populateUserPrefsHashFieldCategory {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my($app, $right, $category, $editingUserIsTargetUser, $userData) = @_;
|
my($app, $targetUser, $right, $category, $editingUserIsTargetUser, $userData) = @_;
|
||||||
if ($right or $editingUserIsTargetUser) {
|
if ($right or $editingUserIsTargetUser) {
|
||||||
# give user ${category}s
|
# give user ${category}s
|
||||||
$userData->{'fields'}->{$category} = {};
|
$userData->{'fields'}->{$category} = {};
|
||||||
|
@ -180,7 +186,8 @@ sub cmdUserPrefsSet {
|
||||||
} else {
|
} else {
|
||||||
# one or more users selected
|
# one or more users selected
|
||||||
# let's get rid of the duplicates
|
# let's get rid of the duplicates
|
||||||
@userIDs = keys(map { $_ => 1 } @userIDs);
|
my %userIDs = map { $_ => 1 } @userIDs;
|
||||||
|
@userIDs = keys(%userIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
# cache rights (for efficiently reasons as well as to protect
|
# cache rights (for efficiently reasons as well as to protect
|
||||||
|
@ -238,13 +245,13 @@ sub applyUserPrefsChanges {
|
||||||
my @notifications = ();
|
my @notifications = ();
|
||||||
|
|
||||||
# first, get a lists of all the relevant arguments
|
# first, get a lists of all the relevant arguments
|
||||||
my $arguments = $app->input->getArgumentsBranch("userPrefs.$userID");
|
my $arguments = $app->input->getArgumentsBranch("userPrefs.$targetUserID");
|
||||||
|
|
||||||
if (defined($arguments('password'))) {
|
if (defined($arguments->{'password'})) {
|
||||||
if ($editingUserIsTargetUser) {
|
if ($editingUserIsTargetUser) {
|
||||||
if (defined($arguments('password.old')) and ($user->checkPassword($arguments('password.old')))) {
|
if (defined($arguments->{'password.old'}) and ($targetUser->checkPassword($arguments->{'password.old'}))) {
|
||||||
if (defined($arguments('password.confirmation')) and
|
if (defined($arguments->{'password.confirmation'}) and
|
||||||
$arguments('password.confirmation') eq $arguments('password')) {
|
$arguments->{'password.confirmation'} eq $arguments->{'password'}) {
|
||||||
$targetUser->password($app->getService('service.passwords')->encryptPassword(arguments('password')));
|
$targetUser->password($app->getService('service.passwords')->encryptPassword(arguments('password')));
|
||||||
} else {
|
} else {
|
||||||
# new passwords don't match
|
# new passwords don't match
|
||||||
|
@ -263,16 +270,16 @@ sub applyUserPrefsChanges {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $userDataSource = $app->getService('user.dataSource');
|
my $userDataSource = $app->getService('dataSource.user');
|
||||||
foreach my $fieldRow ($userDataSource->getFields($app)) {
|
foreach my $fieldRow ($userDataSource->getFields($app)) {
|
||||||
# $field contains [type, fieldID, category, name, typeData]*
|
# $field contains [type, fieldID, category, name, typeData]*
|
||||||
my $fieldID = $fieldRow->[1];
|
my $fieldID = $fieldRow->[1];
|
||||||
my $fieldCategory = $fieldRow->[2];
|
my $fieldCategory = $fieldRow->[2];
|
||||||
my $fieldName = $fieldRow->[3];
|
my $fieldName = $fieldRow->[3];
|
||||||
my $newValue = $arguments("fields.$category.$name");
|
my $newValue = $arguments->{"fields.$fieldCategory.$fieldName"};
|
||||||
if (defined($newValue)) {
|
if (defined($newValue)) {
|
||||||
my $field = $targetUser->getFieldByID($fieldID);
|
my $field = $targetUser->getFieldByID($fieldID);
|
||||||
$oldValue = $field->data;
|
my $oldValue = $field->data;
|
||||||
if (not defined($oldValue)) {
|
if (not defined($oldValue)) {
|
||||||
$oldValue = '';
|
$oldValue = '';
|
||||||
}
|
}
|
||||||
|
@ -284,9 +291,9 @@ sub applyUserPrefsChanges {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($arguments('adminMessage'))) {
|
if (defined($arguments->{'adminMessage'})) {
|
||||||
if ($rightAdminMessage) {
|
if ($rightAdminMessage) {
|
||||||
$targetUser->adminMessage($arguments('adminMessage'));
|
$targetUser->adminMessage($arguments->{'adminMessage'});
|
||||||
} else {
|
} else {
|
||||||
my $userID = $user->userID;
|
my $userID = $user->userID;
|
||||||
$self->warn(2, "user $userID tried to change user $targetUserID's admin message: denied");
|
$self->warn(2, "user $userID tried to change user $targetUserID's admin message: denied");
|
||||||
|
@ -294,9 +301,9 @@ sub applyUserPrefsChanges {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($arguments('mode'))) {
|
if (defined($arguments->('mode'))) {
|
||||||
if ($rightAdminMessage) {
|
if ($rightAdminMessage) {
|
||||||
$targetUser->Mode($arguments('mode'));
|
$targetUser->mode($arguments->{'mode'});
|
||||||
} else {
|
} else {
|
||||||
my $userID = $user->userID;
|
my $userID = $user->userID;
|
||||||
$self->warn(2, "user $userID tried to change user $targetUserID's user mode: denied");
|
$self->warn(2, "user $userID tried to change user $targetUserID's user mode: denied");
|
||||||
|
@ -307,7 +314,7 @@ sub applyUserPrefsChanges {
|
||||||
foreach my $group (@{$userDataSource->getGroups($app)}) {
|
foreach my $group (@{$userDataSource->getGroups($app)}) {
|
||||||
# $group contains [groupID, name, [rightName]*]
|
# $group contains [groupID, name, [rightName]*]
|
||||||
my $groupID = $group->[0];
|
my $groupID = $group->[0];
|
||||||
my $newValue = $arguments("groups.$groupID");
|
my $newValue = $arguments->{"groups.$groupID"};
|
||||||
if (defined($newValue)) {
|
if (defined($newValue)) {
|
||||||
if ($newValue =~ /^\d+$/o) {
|
if ($newValue =~ /^\d+$/o) {
|
||||||
my $userLevel = $user->levelInGroup($groupID);
|
my $userLevel = $user->levelInGroup($groupID);
|
||||||
|
@ -337,7 +344,7 @@ sub applyUserPrefsChanges {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return @notificatons;
|
return @notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
# descendants should only call this once they have tried to handle field changes
|
# descendants should only call this once they have tried to handle field changes
|
||||||
|
|
|
@ -85,7 +85,7 @@ sub getUserByContactDetails {
|
||||||
sub getUserByID {
|
sub getUserByID {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my($app, $userID) = @_;
|
my($app, $userID) = @_;
|
||||||
my(@data) = $app->getService('dataSource.user')->getUserByUserID($app, $userID);
|
my(@data) = $app->getService('dataSource.user')->getUserByID($app, $userID);
|
||||||
if (@data) {
|
if (@data) {
|
||||||
return $self->objectCreate($app, @data);
|
return $self->objectCreate($app, @data);
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,6 +108,7 @@ sub objectProvides {
|
||||||
sub objectInit {
|
sub objectInit {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my($app, $userID, $mode, $password, $adminMessage, $newFieldID, $newFieldValue, $newFieldPassword, $fields, $groups, $rights) = @_;
|
my($app, $userID, $mode, $password, $adminMessage, $newFieldID, $newFieldValue, $newFieldPassword, $fields, $groups, $rights) = @_;
|
||||||
|
|
||||||
$self->{'_DIRTY'} = {}; # make sure propertySet is happy
|
$self->{'_DIRTY'} = {}; # make sure propertySet is happy
|
||||||
$self->SUPER::objectInit(@_);
|
$self->SUPER::objectInit(@_);
|
||||||
$self->userID($userID);
|
$self->userID($userID);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче