Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorUserPreferencesQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
private $phids;
|
|
|
|
private $userPHIDs;
|
2016-06-05 21:38:04 +02:00
|
|
|
private $builtinKeys;
|
|
|
|
private $hasUserPHID;
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
private $users = array();
|
Fix several issues with email-related global preferences
Summary:
Ref T11098. Mixture of issues here:
- Similar problem to D16112, where users with no settings at all could fail to fall back to the global defaults.
- I made `UserPreferencesQuery` responsible for building defaults instead to simplify this, since we have 4 or 5 callsites which need to do it and they aren't easily reducible.
- Handle cases where `metamta.one-mail-per-recipient` is off (and thus users can not have any custom settings) more explicitly.
- When `metamta.one-mail-per-recipient` is off, remove the "Email Format" panel for users only -- administrators can still access it in global preferences.
Test Plan:
- Deleted a user's preferences, changed globals, purged cache, made sure defaults reflected global defaults.
- Changed global mail tags, sent mail to the user, verified it was dropped in accordinace with global settings.
- Changed user's settings to get the mail instead, verified mail was sent.
- Toggled user's Re / Vary settings, verified mail subject lines reflected user settings.
- Disabled `metamta.one-mail-per-recipient`, verified user "Email Format" panel vanished.
- Edited "Email Format" in single-mail-mode in global prefs as an administrator.
- Sent more mail, verified mail respected new global settings.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11098
Differential Revision: https://secure.phabricator.com/D16118
2016-06-14 20:49:59 +02:00
|
|
|
private $synthetic;
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
public function withHasUserPHID($is_user) {
|
|
|
|
$this->hasUserPHID = $is_user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
public function withUserPHIDs(array $phids) {
|
|
|
|
$this->userPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withUsers(array $users) {
|
|
|
|
assert_instances_of($users, 'PhabricatorUser');
|
|
|
|
$this->users = mpull($users, null, 'getPHID');
|
|
|
|
$this->withUserPHIDs(array_keys($this->users));
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
public function withBuiltinKeys(array $keys) {
|
|
|
|
$this->builtinKeys = $keys;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Fix several issues with email-related global preferences
Summary:
Ref T11098. Mixture of issues here:
- Similar problem to D16112, where users with no settings at all could fail to fall back to the global defaults.
- I made `UserPreferencesQuery` responsible for building defaults instead to simplify this, since we have 4 or 5 callsites which need to do it and they aren't easily reducible.
- Handle cases where `metamta.one-mail-per-recipient` is off (and thus users can not have any custom settings) more explicitly.
- When `metamta.one-mail-per-recipient` is off, remove the "Email Format" panel for users only -- administrators can still access it in global preferences.
Test Plan:
- Deleted a user's preferences, changed globals, purged cache, made sure defaults reflected global defaults.
- Changed global mail tags, sent mail to the user, verified it was dropped in accordinace with global settings.
- Changed user's settings to get the mail instead, verified mail was sent.
- Toggled user's Re / Vary settings, verified mail subject lines reflected user settings.
- Disabled `metamta.one-mail-per-recipient`, verified user "Email Format" panel vanished.
- Edited "Email Format" in single-mail-mode in global prefs as an administrator.
- Sent more mail, verified mail respected new global settings.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11098
Differential Revision: https://secure.phabricator.com/D16118
2016-06-14 20:49:59 +02:00
|
|
|
/**
|
|
|
|
* Always return preferences for every queried user.
|
|
|
|
*
|
|
|
|
* If no settings exist for a user, a new empty settings object with
|
|
|
|
* appropriate defaults is returned.
|
|
|
|
*
|
2017-10-09 19:48:01 +02:00
|
|
|
* @param bool True to generate synthetic preferences for missing users.
|
Fix several issues with email-related global preferences
Summary:
Ref T11098. Mixture of issues here:
- Similar problem to D16112, where users with no settings at all could fail to fall back to the global defaults.
- I made `UserPreferencesQuery` responsible for building defaults instead to simplify this, since we have 4 or 5 callsites which need to do it and they aren't easily reducible.
- Handle cases where `metamta.one-mail-per-recipient` is off (and thus users can not have any custom settings) more explicitly.
- When `metamta.one-mail-per-recipient` is off, remove the "Email Format" panel for users only -- administrators can still access it in global preferences.
Test Plan:
- Deleted a user's preferences, changed globals, purged cache, made sure defaults reflected global defaults.
- Changed global mail tags, sent mail to the user, verified it was dropped in accordinace with global settings.
- Changed user's settings to get the mail instead, verified mail was sent.
- Toggled user's Re / Vary settings, verified mail subject lines reflected user settings.
- Disabled `metamta.one-mail-per-recipient`, verified user "Email Format" panel vanished.
- Edited "Email Format" in single-mail-mode in global prefs as an administrator.
- Sent more mail, verified mail respected new global settings.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11098
Differential Revision: https://secure.phabricator.com/D16118
2016-06-14 20:49:59 +02:00
|
|
|
*/
|
|
|
|
public function needSyntheticPreferences($synthetic) {
|
|
|
|
$this->synthetic = $synthetic;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
public function newResultObject() {
|
|
|
|
return new PhabricatorUserPreferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadPage() {
|
Fix several issues with email-related global preferences
Summary:
Ref T11098. Mixture of issues here:
- Similar problem to D16112, where users with no settings at all could fail to fall back to the global defaults.
- I made `UserPreferencesQuery` responsible for building defaults instead to simplify this, since we have 4 or 5 callsites which need to do it and they aren't easily reducible.
- Handle cases where `metamta.one-mail-per-recipient` is off (and thus users can not have any custom settings) more explicitly.
- When `metamta.one-mail-per-recipient` is off, remove the "Email Format" panel for users only -- administrators can still access it in global preferences.
Test Plan:
- Deleted a user's preferences, changed globals, purged cache, made sure defaults reflected global defaults.
- Changed global mail tags, sent mail to the user, verified it was dropped in accordinace with global settings.
- Changed user's settings to get the mail instead, verified mail was sent.
- Toggled user's Re / Vary settings, verified mail subject lines reflected user settings.
- Disabled `metamta.one-mail-per-recipient`, verified user "Email Format" panel vanished.
- Edited "Email Format" in single-mail-mode in global prefs as an administrator.
- Sent more mail, verified mail respected new global settings.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T11098
Differential Revision: https://secure.phabricator.com/D16118
2016-06-14 20:49:59 +02:00
|
|
|
$preferences = $this->loadStandardPage($this->newResultObject());
|
|
|
|
|
|
|
|
if ($this->synthetic) {
|
|
|
|
$user_map = mpull($preferences, null, 'getUserPHID');
|
|
|
|
foreach ($this->userPHIDs as $user_phid) {
|
|
|
|
if (isset($user_map[$user_phid])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$preferences[] = $this->newResultObject()
|
|
|
|
->setUserPHID($user_phid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $preferences;
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function willFilterPage(array $prefs) {
|
|
|
|
$user_phids = mpull($prefs, 'getUserPHID');
|
|
|
|
$user_phids = array_filter($user_phids);
|
|
|
|
|
|
|
|
// If some of the preferences are attached to users, try to use any objects
|
|
|
|
// we were handed first. If we're missing some, load them.
|
|
|
|
|
|
|
|
if ($user_phids) {
|
|
|
|
$users = $this->users;
|
|
|
|
|
|
|
|
$user_phids = array_fuse($user_phids);
|
|
|
|
$load_phids = array_diff_key($user_phids, $users);
|
|
|
|
$load_phids = array_keys($load_phids);
|
|
|
|
|
|
|
|
if ($load_phids) {
|
|
|
|
$load_users = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($load_phids)
|
|
|
|
->execute();
|
|
|
|
$load_users = mpull($load_users, null, 'getPHID');
|
|
|
|
$users += $load_users;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$users = array();
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
$need_global = array();
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
foreach ($prefs as $key => $pref) {
|
|
|
|
$user_phid = $pref->getUserPHID();
|
|
|
|
if (!$user_phid) {
|
|
|
|
$pref->attachUser(null);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
$need_global[] = $pref;
|
|
|
|
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
$user = idx($users, $user_phid);
|
|
|
|
if (!$user) {
|
|
|
|
$this->didRejectResult($pref);
|
|
|
|
unset($prefs[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$pref->attachUser($user);
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
// If we loaded any user preferences, load the global defaults and attach
|
|
|
|
// them if they exist.
|
|
|
|
if ($need_global) {
|
|
|
|
$global = id(new self())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withBuiltinKeys(
|
|
|
|
array(
|
|
|
|
PhabricatorUserPreferences::BUILTIN_GLOBAL_DEFAULT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if ($global) {
|
|
|
|
foreach ($need_global as $pref) {
|
|
|
|
$pref->attachDefaultSettings($global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
return $prefs;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
|
|
|
|
|
|
|
if ($this->ids !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->phids !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->userPHIDs !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'userPHID IN (%Ls)',
|
|
|
|
$this->userPHIDs);
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
if ($this->builtinKeys !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'builtinKey IN (%Ls)',
|
|
|
|
$this->builtinKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->hasUserPHID !== null) {
|
|
|
|
if ($this->hasUserPHID) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'userPHID IS NOT NULL');
|
|
|
|
} else {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'userPHID IS NULL');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Prepare UserPreferences for transactions
Summary:
Ref T4103. This give preferences a PHID, policy/transaction interfaces, a transaction table, and a Query class.
This doesn't actually change how they're edited, yet.
Test Plan:
- Ran migrations.
- Inspected database for date created, date modified, PHIDs.
- Changed some of my preferences.
- Deleted a user's preferences, verified they reset properly.
- Set some preferences as a new user, got a new row.
- Destroyed a user, verified their preferences were destroyed.
- Sent Conpherence messages.
- Send mail.
- Tried to edit another user's settings.
- Tried to edit a bot's settings as a non-admin.
- Edited a bot's settings as an admin (technically, none of the editable settings are actually stored in the settings table, currently).
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4103
Differential Revision: https://secure.phabricator.com/D15991
2016-05-27 14:58:46 +02:00
|
|
|
return $where;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
return 'PhabricatorSettingsApplication';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|