Consolidate user editing code

Summary:
  - We currently have some bugs in account creation due to nontransactional user/email editing.
    - We save $user, then try to save $email. This may fail for various reasons, commonly because the email isn't unique.
    - This leaves us with a $user with no email.
  - Also, logging of edits is somewhat inconsistent across various edit mechanisms.
  - Move all editing to a `PhabricatorUserEditor` class.
  - Handle some broken-data cases more gracefully.

Test Plan:
  - Created and edited a user with `accountadmin`.
  - Created a user with `add_user.php`
  - Created and edited a user with People editor.
  - Created a user with OAuth.
  - Edited user information via Settings.
  - Tried to create an OAuth user with a duplicate email address, got a proper error.
  - Tried to create a user via People with a duplicate email address, got a proper error.

Reviewers: btrahan, vrana, jungejason

Reviewed By: btrahan

CC: tberman, aran

Maniphest Tasks: T1184

Differential Revision: https://secure.phabricator.com/D2569
This commit is contained in:
epriestley
2012-05-25 07:30:44 -07:00
parent eb310888e5
commit 70fd96037b
16 changed files with 502 additions and 87 deletions

View File

@@ -61,14 +61,14 @@ if ($existing_email) {
$user = new PhabricatorUser();
$user->setUsername($username);
$user->setRealname($realname);
$user->save();
$email_object = id(new PhabricatorUserEmail())
->setUserPHID($user->getPHID())
->setAddress($email)
->setIsVerified(1)
->setIsPrimary(1)
->save();
->setIsVerified(1);
id(new PhabricatorUserEditor())
->setActor($admin)
->createNewUser($user, $email_object);
$user->sendWelcomeEmail($admin);