mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-03 02:18:24 +01:00
b256f2d7b2
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
118 lines
2.7 KiB
PHP
118 lines
2.7 KiB
PHP
<?php
|
|
|
|
final class PhabricatorUserPreferencesQuery
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
private $ids;
|
|
private $phids;
|
|
private $userPHIDs;
|
|
private $users = array();
|
|
|
|
public function withIDs(array $ids) {
|
|
$this->ids = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public function newResultObject() {
|
|
return new PhabricatorUserPreferences();
|
|
}
|
|
|
|
protected function loadPage() {
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
foreach ($prefs as $key => $pref) {
|
|
$user_phid = $pref->getUserPHID();
|
|
if (!$user_phid) {
|
|
$pref->attachUser(null);
|
|
continue;
|
|
}
|
|
|
|
$user = idx($users, $user_phid);
|
|
if (!$user) {
|
|
$this->didRejectResult($pref);
|
|
unset($prefs[$key]);
|
|
continue;
|
|
}
|
|
|
|
$pref->attachUser($user);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
return $where;
|
|
}
|
|
|
|
public function getQueryApplicationClass() {
|
|
return 'PhabricatorSettingsApplication';
|
|
}
|
|
|
|
}
|