repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/management/PhabricatorPeopleManagementEmpowerWorkflow.php | src/applications/people/management/PhabricatorPeopleManagementEmpowerWorkflow.php | <?php
final class PhabricatorPeopleManagementEmpowerWorkflow
extends PhabricatorPeopleManagementWorkflow {
protected function didConstruct() {
$arguments = array_merge(
$this->getUserSelectionArguments(),
array());
$this
->setName('empower')
->setExamples('**empower** --user __username__')
->setSynopsis(pht('Turn a user account into an administrator account.'))
->setArguments($arguments);
}
public function execute(PhutilArgumentParser $args) {
$user = $this->selectUser($args);
$display_name = $user->getUsername();
if ($user->getIsAdmin()) {
throw new PhutilArgumentUsageException(
pht(
'User account "%s" is already an administrator. You can only '.
'empower accounts that are not yet administrators.',
$display_name));
}
$xactions = array();
$xactions[] = $user->getApplicationTransactionTemplate()
->setTransactionType(PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE)
->setNewValue(true);
$this->applyTransactions($user, $xactions);
$this->logOkay(
pht('DONE'),
pht('Empowered user account "%s".', $display_name));
return 0;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/management/PhabricatorPeopleManagementWorkflow.php | src/applications/people/management/PhabricatorPeopleManagementWorkflow.php | <?php
abstract class PhabricatorPeopleManagementWorkflow
extends PhabricatorManagementWorkflow {
final protected function getUserSelectionArguments() {
return array(
array(
'name' => 'user',
'param' => 'username',
'help' => pht('User account to act on.'),
),
);
}
final protected function selectUser(PhutilArgumentParser $argv) {
$username = $argv->getArg('user');
if (!strlen($username)) {
throw new PhutilArgumentUsageException(
pht(
'Select a user account to act on with "--user <username>".'));
}
$user = id(new PhabricatorPeopleQuery())
->setViewer($this->getViewer())
->withUsernames(array($username))
->executeOne();
if (!$user) {
throw new PhutilArgumentUsageException(
pht(
'No user with username "%s" exists.',
$username));
}
return $user;
}
final protected function applyTransactions(
PhabricatorUser $user,
array $xactions) {
assert_instances_of($xactions, 'PhabricatorUserTransaction');
$viewer = $this->getViewer();
$application = id(new PhabricatorPeopleApplication())->getPHID();
$content_source = $this->newContentSource();
$editor = $user->getApplicationTransactionEditor()
->setActor($viewer)
->setActingAsPHID($application)
->setContentSource($content_source)
->setContinueOnMissingFields(true);
return $editor->applyTransactions($user, $xactions);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/management/PhabricatorPeopleManagementApproveWorkflow.php | src/applications/people/management/PhabricatorPeopleManagementApproveWorkflow.php | <?php
final class PhabricatorPeopleManagementApproveWorkflow
extends PhabricatorPeopleManagementWorkflow {
protected function didConstruct() {
$arguments = array_merge(
$this->getUserSelectionArguments(),
array());
$this
->setName('approve')
->setExamples('**approve** --user __username__')
->setSynopsis(pht('Approves a user.'))
->setArguments($arguments);
}
public function execute(PhutilArgumentParser $args) {
$user = $this->selectUser($args);
$display_name = $user->getUsername();
if ($user->getIsApproved()) {
throw new PhutilArgumentUsageException(
pht(
'User account "%s" is already approved. You can only '.
'approve accounts that are not yet approved.',
$display_name));
}
$xactions = array();
$xactions[] = $user->getApplicationTransactionTemplate()
->setTransactionType(PhabricatorUserApproveTransaction::TRANSACTIONTYPE)
->setNewValue(true);
$this->applyTransactions($user, $xactions);
$this->logOkay(
pht('DONE'),
pht('Approved user account "%s".', $display_name));
return 0;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/icon/PhabricatorPeopleIconSet.php | src/applications/people/icon/PhabricatorPeopleIconSet.php | <?php
final class PhabricatorPeopleIconSet
extends PhabricatorIconSet {
const ICONSETKEY = 'people';
public function getSelectIconTitleText() {
return pht('Choose User Icon');
}
protected function newIcons() {
$specifications = self::getIconSpecifications();
$icons = array();
foreach ($specifications as $spec) {
$icons[] = id(new PhabricatorIconSetIcon())
->setKey($spec['key'])
->setIcon($spec['icon'])
->setLabel($spec['name']);
}
return $icons;
}
public static function getDefaultIconKey() {
$specifications = self::getIconSpecifications();
foreach ($specifications as $spec) {
if (idx($spec, 'default')) {
return $spec['key'];
}
}
return null;
}
public static function getIconIcon($key) {
$specifications = self::getIconSpecifications();
$map = ipull($specifications, 'icon', 'key');
return idx($map, $key);
}
public static function getIconName($key) {
$specifications = self::getIconSpecifications();
$map = ipull($specifications, 'name', 'key');
return idx($map, $key);
}
private static function getIconSpecifications() {
return self::getDefaultSpecifications();
}
private static function getDefaultSpecifications() {
return array(
array(
'key' => 'person',
'icon' => 'fa-user',
'name' => pht('User'),
'default' => true,
),
array(
'key' => 'engineering',
'icon' => 'fa-code',
'name' => pht('Engineering'),
),
array(
'key' => 'operations',
'icon' => 'fa-space-shuttle',
'name' => pht('Operations'),
),
array(
'key' => 'resources',
'icon' => 'fa-heart',
'name' => pht('Resources'),
),
array(
'key' => 'camera',
'icon' => 'fa-camera-retro',
'name' => pht('Design'),
),
array(
'key' => 'music',
'icon' => 'fa-headphones',
'name' => pht('Musician'),
),
array(
'key' => 'spy',
'icon' => 'fa-user-secret',
'name' => pht('Spy'),
),
array(
'key' => 'android',
'icon' => 'fa-android',
'name' => pht('Bot'),
),
array(
'key' => 'relationships',
'icon' => 'fa-glass',
'name' => pht('Relationships'),
),
array(
'key' => 'administration',
'icon' => 'fa-fax',
'name' => pht('Administration'),
),
array(
'key' => 'security',
'icon' => 'fa-shield',
'name' => pht('Security'),
),
array(
'key' => 'logistics',
'icon' => 'fa-truck',
'name' => pht('Logistics'),
),
array(
'key' => 'research',
'icon' => 'fa-flask',
'name' => pht('Research'),
),
array(
'key' => 'analysis',
'icon' => 'fa-bar-chart-o',
'name' => pht('Analysis'),
),
array(
'key' => 'executive',
'icon' => 'fa-angle-double-up',
'name' => pht('Executive'),
),
array(
'key' => 'animal',
'icon' => 'fa-paw',
'name' => pht('Animal'),
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/query/PhabricatorPeopleLogSearchEngine.php | src/applications/people/query/PhabricatorPeopleLogSearchEngine.php | <?php
final class PhabricatorPeopleLogSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Account Activity');
}
public function getApplicationClassName() {
return 'PhabricatorPeopleApplication';
}
public function getPageSize(PhabricatorSavedQuery $saved) {
return 500;
}
public function newQuery() {
$query = new PhabricatorPeopleLogQuery();
// NOTE: If the viewer isn't an administrator, always restrict the query to
// related records. This echoes the policy logic of these logs. This is
// mostly a performance optimization, to prevent us from having to pull
// large numbers of logs that the user will not be able to see and filter
// them in-process.
$viewer = $this->requireViewer();
if (!$viewer->getIsAdmin()) {
$query->withRelatedPHIDs(array($viewer->getPHID()));
}
return $query;
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['userPHIDs']) {
$query->withUserPHIDs($map['userPHIDs']);
}
if ($map['actorPHIDs']) {
$query->withActorPHIDs($map['actorPHIDs']);
}
if ($map['actions']) {
$query->withActions($map['actions']);
}
if (strlen($map['ip'])) {
$query->withRemoteAddressPrefix($map['ip']);
}
if ($map['sessions']) {
$query->withSessionKeys($map['sessions']);
}
if ($map['createdStart'] || $map['createdEnd']) {
$query->withDateCreatedBetween(
$map['createdStart'],
$map['createdEnd']);
}
return $query;
}
protected function buildCustomSearchFields() {
$types = PhabricatorUserLogType::getAllLogTypes();
$types = mpull($types, 'getLogTypeName', 'getLogTypeKey');
return array(
id(new PhabricatorUsersSearchField())
->setKey('userPHIDs')
->setAliases(array('users', 'user', 'userPHID'))
->setLabel(pht('Users'))
->setDescription(pht('Search for activity affecting specific users.')),
id(new PhabricatorUsersSearchField())
->setKey('actorPHIDs')
->setAliases(array('actors', 'actor', 'actorPHID'))
->setLabel(pht('Actors'))
->setDescription(pht('Search for activity by specific users.')),
id(new PhabricatorSearchDatasourceField())
->setKey('actions')
->setLabel(pht('Actions'))
->setDescription(pht('Search for particular types of activity.'))
->setDatasource(new PhabricatorUserLogTypeDatasource()),
id(new PhabricatorSearchTextField())
->setKey('ip')
->setLabel(pht('Filter IP'))
->setDescription(pht('Search for actions by remote address.')),
id(new PhabricatorSearchStringListField())
->setKey('sessions')
->setLabel(pht('Sessions'))
->setDescription(pht('Search for activity in particular sessions.')),
id(new PhabricatorSearchDateField())
->setLabel(pht('Created After'))
->setKey('createdStart'),
id(new PhabricatorSearchDateField())
->setLabel(pht('Created Before'))
->setKey('createdEnd'),
);
}
protected function getURI($path) {
return '/people/logs/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $logs,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($logs, 'PhabricatorUserLog');
$viewer = $this->requireViewer();
$table = id(new PhabricatorUserLogView())
->setUser($viewer)
->setLogs($logs);
if ($viewer->getIsAdmin()) {
$table->setSearchBaseURI($this->getApplicationURI('logs/'));
}
return id(new PhabricatorApplicationSearchResultView())
->setTable($table);
}
protected function newExportFields() {
$viewer = $this->requireViewer();
$fields = array(
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('actorPHID')
->setLabel(pht('Actor PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('actor')
->setLabel(pht('Actor')),
$fields[] = id(new PhabricatorPHIDExportField())
->setKey('userPHID')
->setLabel(pht('User PHID')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('user')
->setLabel(pht('User')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('action')
->setLabel(pht('Action')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('actionName')
->setLabel(pht('Action Name')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('session')
->setLabel(pht('Session')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('old')
->setLabel(pht('Old Value')),
$fields[] = id(new PhabricatorStringExportField())
->setKey('new')
->setLabel(pht('New Value')),
);
if ($viewer->getIsAdmin()) {
$fields[] = id(new PhabricatorStringExportField())
->setKey('remoteAddress')
->setLabel(pht('Remote Address'));
}
return $fields;
}
protected function newExportData(array $logs) {
$viewer = $this->requireViewer();
$phids = array();
foreach ($logs as $log) {
$phids[] = $log->getUserPHID();
$phids[] = $log->getActorPHID();
}
$handles = $viewer->loadHandles($phids);
$types = PhabricatorUserLogType::getAllLogTypes();
$types = mpull($types, 'getLogTypeName', 'getLogTypeKey');
$export = array();
foreach ($logs as $log) {
$user_phid = $log->getUserPHID();
if ($user_phid) {
$user_name = $handles[$user_phid]->getName();
} else {
$user_name = null;
}
$actor_phid = $log->getActorPHID();
if ($actor_phid) {
$actor_name = $handles[$actor_phid]->getName();
} else {
$actor_name = null;
}
$action = $log->getAction();
$action_name = idx($types, $action, pht('Unknown ("%s")', $action));
$map = array(
'actorPHID' => $actor_phid,
'actor' => $actor_name,
'userPHID' => $user_phid,
'user' => $user_name,
'action' => $action,
'actionName' => $action_name,
'session' => substr($log->getSession(), 0, 6),
'old' => $log->getOldValue(),
'new' => $log->getNewValue(),
);
if ($viewer->getIsAdmin()) {
$map['remoteAddress'] = $log->getRemoteAddr();
}
$export[] = $map;
}
return $export;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/query/PhabricatorPeopleQuery.php | src/applications/people/query/PhabricatorPeopleQuery.php | <?php
final class PhabricatorPeopleQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $usernames;
private $realnames;
private $emails;
private $phids;
private $ids;
private $dateCreatedAfter;
private $dateCreatedBefore;
private $isAdmin;
private $isSystemAgent;
private $isMailingList;
private $isDisabled;
private $isApproved;
private $nameLike;
private $nameTokens;
private $namePrefixes;
private $isEnrolledInMultiFactor;
private $needPrimaryEmail;
private $needProfile;
private $needProfileImage;
private $needAvailability;
private $needBadgeAwards;
private $cacheKeys = array();
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withEmails(array $emails) {
$this->emails = $emails;
return $this;
}
public function withRealnames(array $realnames) {
$this->realnames = $realnames;
return $this;
}
public function withUsernames(array $usernames) {
$this->usernames = $usernames;
return $this;
}
public function withDateCreatedBefore($date_created_before) {
$this->dateCreatedBefore = $date_created_before;
return $this;
}
public function withDateCreatedAfter($date_created_after) {
$this->dateCreatedAfter = $date_created_after;
return $this;
}
public function withIsAdmin($admin) {
$this->isAdmin = $admin;
return $this;
}
public function withIsSystemAgent($system_agent) {
$this->isSystemAgent = $system_agent;
return $this;
}
public function withIsMailingList($mailing_list) {
$this->isMailingList = $mailing_list;
return $this;
}
public function withIsDisabled($disabled) {
$this->isDisabled = $disabled;
return $this;
}
public function withIsApproved($approved) {
$this->isApproved = $approved;
return $this;
}
public function withNameLike($like) {
$this->nameLike = $like;
return $this;
}
public function withNameTokens(array $tokens) {
$this->nameTokens = array_values($tokens);
return $this;
}
public function withNamePrefixes(array $prefixes) {
$this->namePrefixes = $prefixes;
return $this;
}
public function withIsEnrolledInMultiFactor($enrolled) {
$this->isEnrolledInMultiFactor = $enrolled;
return $this;
}
public function needPrimaryEmail($need) {
$this->needPrimaryEmail = $need;
return $this;
}
public function needProfile($need) {
$this->needProfile = $need;
return $this;
}
public function needProfileImage($need) {
$cache_key = PhabricatorUserProfileImageCacheType::KEY_URI;
if ($need) {
$this->cacheKeys[$cache_key] = true;
} else {
unset($this->cacheKeys[$cache_key]);
}
return $this;
}
public function needAvailability($need) {
$this->needAvailability = $need;
return $this;
}
public function needUserSettings($need) {
$cache_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES;
if ($need) {
$this->cacheKeys[$cache_key] = true;
} else {
unset($this->cacheKeys[$cache_key]);
}
return $this;
}
public function needBadgeAwards($need) {
$cache_key = PhabricatorUserBadgesCacheType::KEY_BADGES;
if ($need) {
$this->cacheKeys[$cache_key] = true;
} else {
unset($this->cacheKeys[$cache_key]);
}
return $this;
}
public function newResultObject() {
return new PhabricatorUser();
}
protected function didFilterPage(array $users) {
if ($this->needProfile) {
$user_list = mpull($users, null, 'getPHID');
$profiles = new PhabricatorUserProfile();
$profiles = $profiles->loadAllWhere(
'userPHID IN (%Ls)',
array_keys($user_list));
$profiles = mpull($profiles, null, 'getUserPHID');
foreach ($user_list as $user_phid => $user) {
$profile = idx($profiles, $user_phid);
if (!$profile) {
$profile = PhabricatorUserProfile::initializeNewProfile($user);
}
$user->attachUserProfile($profile);
}
}
if ($this->needAvailability) {
$rebuild = array();
foreach ($users as $user) {
$cache = $user->getAvailabilityCache();
if ($cache !== null) {
$user->attachAvailability($cache);
} else {
$rebuild[] = $user;
}
}
if ($rebuild) {
$this->rebuildAvailabilityCache($rebuild);
}
}
$this->fillUserCaches($users);
return $users;
}
protected function shouldGroupQueryResultRows() {
if ($this->nameTokens) {
return true;
}
return parent::shouldGroupQueryResultRows();
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = parent::buildJoinClauseParts($conn);
if ($this->emails) {
$email_table = new PhabricatorUserEmail();
$joins[] = qsprintf(
$conn,
'JOIN %T email ON email.userPHID = user.PHID',
$email_table->getTableName());
}
if ($this->nameTokens) {
foreach ($this->nameTokens as $key => $token) {
$token_table = 'token_'.$key;
$joins[] = qsprintf(
$conn,
'JOIN %T %T ON %T.userID = user.id AND %T.token LIKE %>',
PhabricatorUser::NAMETOKEN_TABLE,
$token_table,
$token_table,
$token_table,
$token);
}
}
return $joins;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->usernames !== null) {
$where[] = qsprintf(
$conn,
'user.userName IN (%Ls)',
$this->usernames);
}
if ($this->namePrefixes) {
$parts = array();
foreach ($this->namePrefixes as $name_prefix) {
$parts[] = qsprintf(
$conn,
'user.username LIKE %>',
$name_prefix);
}
$where[] = qsprintf($conn, '%LO', $parts);
}
if ($this->emails !== null) {
$where[] = qsprintf(
$conn,
'email.address IN (%Ls)',
$this->emails);
}
if ($this->realnames !== null) {
$where[] = qsprintf(
$conn,
'user.realName IN (%Ls)',
$this->realnames);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'user.phid IN (%Ls)',
$this->phids);
}
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'user.id IN (%Ld)',
$this->ids);
}
if ($this->dateCreatedAfter) {
$where[] = qsprintf(
$conn,
'user.dateCreated >= %d',
$this->dateCreatedAfter);
}
if ($this->dateCreatedBefore) {
$where[] = qsprintf(
$conn,
'user.dateCreated <= %d',
$this->dateCreatedBefore);
}
if ($this->isAdmin !== null) {
$where[] = qsprintf(
$conn,
'user.isAdmin = %d',
(int)$this->isAdmin);
}
if ($this->isDisabled !== null) {
$where[] = qsprintf(
$conn,
'user.isDisabled = %d',
(int)$this->isDisabled);
}
if ($this->isApproved !== null) {
$where[] = qsprintf(
$conn,
'user.isApproved = %d',
(int)$this->isApproved);
}
if ($this->isSystemAgent !== null) {
$where[] = qsprintf(
$conn,
'user.isSystemAgent = %d',
(int)$this->isSystemAgent);
}
if ($this->isMailingList !== null) {
$where[] = qsprintf(
$conn,
'user.isMailingList = %d',
(int)$this->isMailingList);
}
if ($this->nameLike !== null) {
$where[] = qsprintf(
$conn,
'user.username LIKE %~ OR user.realname LIKE %~',
$this->nameLike,
$this->nameLike);
}
if ($this->isEnrolledInMultiFactor !== null) {
$where[] = qsprintf(
$conn,
'user.isEnrolledInMultiFactor = %d',
(int)$this->isEnrolledInMultiFactor);
}
return $where;
}
protected function getPrimaryTableAlias() {
return 'user';
}
public function getQueryApplicationClass() {
return 'PhabricatorPeopleApplication';
}
public function getOrderableColumns() {
return parent::getOrderableColumns() + array(
'username' => array(
'table' => 'user',
'column' => 'username',
'type' => 'string',
'reverse' => true,
'unique' => true,
),
);
}
protected function newPagingMapFromPartialObject($object) {
return array(
'id' => (int)$object->getID(),
'username' => $object->getUsername(),
);
}
private function rebuildAvailabilityCache(array $rebuild) {
$rebuild = mpull($rebuild, null, 'getPHID');
// Limit the window we look at because far-future events are largely
// irrelevant and this makes the cache cheaper to build and allows it to
// self-heal over time.
$min_range = PhabricatorTime::getNow();
$max_range = $min_range + phutil_units('72 hours in seconds');
// NOTE: We don't need to generate ghosts here, because we only care if
// the user is attending, and you can't attend a ghost event: RSVP'ing
// to it creates a real event.
$events = id(new PhabricatorCalendarEventQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withInvitedPHIDs(array_keys($rebuild))
->withIsCancelled(false)
->withDateRange($min_range, $max_range)
->execute();
// Group all the events by invited user. Only examine events that users
// are actually attending.
$map = array();
$invitee_map = array();
foreach ($events as $event) {
foreach ($event->getInvitees() as $invitee) {
if (!$invitee->isAttending()) {
continue;
}
// If the user is set to "Available" for this event, don't consider it
// when computing their away status.
if (!$invitee->getDisplayAvailability($event)) {
continue;
}
$invitee_phid = $invitee->getInviteePHID();
if (!isset($rebuild[$invitee_phid])) {
continue;
}
$map[$invitee_phid][] = $event;
$event_phid = $event->getPHID();
$invitee_map[$invitee_phid][$event_phid] = $invitee;
}
}
// We need to load these users' timezone settings to figure out their
// availability if they're attending all-day events.
$this->needUserSettings(true);
$this->fillUserCaches($rebuild);
foreach ($rebuild as $phid => $user) {
$events = idx($map, $phid, array());
// We loaded events with the omnipotent user, but want to shift them
// into the user's timezone before building the cache because they will
// be unavailable during their own local day.
foreach ($events as $event) {
$event->applyViewerTimezone($user);
}
$cursor = $min_range;
$next_event = null;
if ($events) {
// Find the next time when the user has no meetings. If we move forward
// because of an event, we check again for events after that one ends.
while (true) {
foreach ($events as $event) {
$from = $event->getStartDateTimeEpochForCache();
$to = $event->getEndDateTimeEpochForCache();
if (($from <= $cursor) && ($to > $cursor)) {
$cursor = $to;
if (!$next_event) {
$next_event = $event;
}
continue 2;
}
}
break;
}
}
if ($cursor > $min_range) {
$invitee = $invitee_map[$phid][$next_event->getPHID()];
$availability_type = $invitee->getDisplayAvailability($next_event);
$availability = array(
'until' => $cursor,
'eventPHID' => $next_event->getPHID(),
'availability' => $availability_type,
);
// We only cache this availability until the end of the current event,
// since the event PHID (and possibly the availability type) are only
// valid for that long.
// NOTE: This doesn't handle overlapping events with the greatest
// possible care. In theory, if you're attending multiple events
// simultaneously we should accommodate that. However, it's complex
// to compute, rare, and probably not confusing most of the time.
$availability_ttl = $next_event->getEndDateTimeEpochForCache();
} else {
$availability = array(
'until' => null,
'eventPHID' => null,
'availability' => null,
);
// Cache that the user is available until the next event they are
// invited to starts.
$availability_ttl = $max_range;
foreach ($events as $event) {
$from = $event->getStartDateTimeEpochForCache();
if ($from > $cursor) {
$availability_ttl = min($from, $availability_ttl);
}
}
}
// Never TTL the cache to longer than the maximum range we examined.
$availability_ttl = min($availability_ttl, $max_range);
$user->writeAvailabilityCache($availability, $availability_ttl);
$user->attachAvailability($availability);
}
}
private function fillUserCaches(array $users) {
if (!$this->cacheKeys) {
return;
}
$user_map = mpull($users, null, 'getPHID');
$keys = array_keys($this->cacheKeys);
$hashes = array();
foreach ($keys as $key) {
$hashes[] = PhabricatorHash::digestForIndex($key);
}
$types = PhabricatorUserCacheType::getAllCacheTypes();
// First, pull any available caches. If we wanted to be particularly clever
// we could do this with JOINs in the main query.
$cache_table = new PhabricatorUserCache();
$cache_conn = $cache_table->establishConnection('r');
$cache_data = queryfx_all(
$cache_conn,
'SELECT cacheKey, userPHID, cacheData, cacheType FROM %T
WHERE cacheIndex IN (%Ls) AND userPHID IN (%Ls)',
$cache_table->getTableName(),
$hashes,
array_keys($user_map));
$skip_validation = array();
// After we read caches from the database, discard any which have data that
// invalid or out of date. This allows cache types to implement TTLs or
// versions instead of or in addition to explicit cache clears.
foreach ($cache_data as $row_key => $row) {
$cache_type = $row['cacheType'];
if (isset($skip_validation[$cache_type])) {
continue;
}
if (empty($types[$cache_type])) {
unset($cache_data[$row_key]);
continue;
}
$type = $types[$cache_type];
if (!$type->shouldValidateRawCacheData()) {
$skip_validation[$cache_type] = true;
continue;
}
$user = $user_map[$row['userPHID']];
$raw_data = $row['cacheData'];
if (!$type->isRawCacheDataValid($user, $row['cacheKey'], $raw_data)) {
unset($cache_data[$row_key]);
continue;
}
}
$need = array();
$cache_data = igroup($cache_data, 'userPHID');
foreach ($user_map as $user_phid => $user) {
$raw_rows = idx($cache_data, $user_phid, array());
$raw_data = ipull($raw_rows, 'cacheData', 'cacheKey');
foreach ($keys as $key) {
if (isset($raw_data[$key]) || array_key_exists($key, $raw_data)) {
continue;
}
$need[$key][$user_phid] = $user;
}
$user->attachRawCacheData($raw_data);
}
// If we missed any cache values, bulk-construct them now. This is
// usually much cheaper than generating them on-demand for each user
// record.
if (!$need) {
return;
}
$writes = array();
foreach ($need as $cache_key => $need_users) {
$type = PhabricatorUserCacheType::getCacheTypeForKey($cache_key);
if (!$type) {
continue;
}
$data = $type->newValueForUsers($cache_key, $need_users);
foreach ($data as $user_phid => $raw_value) {
$data[$user_phid] = $raw_value;
$writes[] = array(
'userPHID' => $user_phid,
'key' => $cache_key,
'type' => $type,
'value' => $raw_value,
);
}
foreach ($need_users as $user_phid => $user) {
if (isset($data[$user_phid]) || array_key_exists($user_phid, $data)) {
$user->attachRawCacheData(
array(
$cache_key => $data[$user_phid],
));
}
}
}
PhabricatorUserCache::writeCaches($writes);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/query/PhabricatorPeopleSearchEngine.php | src/applications/people/query/PhabricatorPeopleSearchEngine.php | <?php
final class PhabricatorPeopleSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Users');
}
public function getApplicationClassName() {
return 'PhabricatorPeopleApplication';
}
public function newQuery() {
return id(new PhabricatorPeopleQuery())
->needPrimaryEmail(true)
->needProfileImage(true);
}
protected function buildCustomSearchFields() {
$fields = array(
id(new PhabricatorSearchStringListField())
->setLabel(pht('Usernames'))
->setKey('usernames')
->setAliases(array('username'))
->setDescription(pht('Find users by exact username.')),
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('nameLike')
->setDescription(
pht('Find users whose usernames contain a substring.')),
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Administrators'))
->setKey('isAdmin')
->setOptions(
pht('(Show All)'),
pht('Show Only Administrators'),
pht('Hide Administrators'))
->setDescription(
pht(
'Pass true to find only administrators, or false to omit '.
'administrators.')),
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Disabled'))
->setKey('isDisabled')
->setOptions(
pht('(Show All)'),
pht('Show Only Disabled Users'),
pht('Hide Disabled Users'))
->setDescription(
pht(
'Pass true to find only disabled users, or false to omit '.
'disabled users.')),
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Bots'))
->setKey('isBot')
->setAliases(array('isSystemAgent'))
->setOptions(
pht('(Show All)'),
pht('Show Only Bots'),
pht('Hide Bots'))
->setDescription(
pht(
'Pass true to find only bots, or false to omit bots.')),
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Mailing Lists'))
->setKey('isMailingList')
->setOptions(
pht('(Show All)'),
pht('Show Only Mailing Lists'),
pht('Hide Mailing Lists'))
->setDescription(
pht(
'Pass true to find only mailing lists, or false to omit '.
'mailing lists.')),
id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Needs Approval'))
->setKey('needsApproval')
->setOptions(
pht('(Show All)'),
pht('Show Only Unapproved Users'),
pht('Hide Unapproved Users'))
->setDescription(
pht(
'Pass true to find only users awaiting administrative approval, '.
'or false to omit these users.')),
);
$viewer = $this->requireViewer();
if ($viewer->getIsAdmin()) {
$fields[] = id(new PhabricatorSearchThreeStateField())
->setLabel(pht('Has MFA'))
->setKey('mfa')
->setOptions(
pht('(Show All)'),
pht('Show Only Users With MFA'),
pht('Hide Users With MFA'))
->setDescription(
pht(
'Pass true to find only users who are enrolled in MFA, or false '.
'to omit these users.'));
}
$fields[] = id(new PhabricatorSearchDateField())
->setKey('createdStart')
->setLabel(pht('Joined After'))
->setDescription(
pht('Find user accounts created after a given time.'));
$fields[] = id(new PhabricatorSearchDateField())
->setKey('createdEnd')
->setLabel(pht('Joined Before'))
->setDescription(
pht('Find user accounts created before a given time.'));
return $fields;
}
protected function getDefaultFieldOrder() {
return array(
'...',
'createdStart',
'createdEnd',
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
$viewer = $this->requireViewer();
// If the viewer can't browse the user directory, restrict the query to
// just the user's own profile. This is a little bit silly, but serves to
// restrict users from creating a dashboard panel which essentially just
// contains a user directory anyway.
$can_browse = PhabricatorPolicyFilter::hasCapability(
$viewer,
$this->getApplication(),
PeopleBrowseUserDirectoryCapability::CAPABILITY);
if (!$can_browse) {
$query->withPHIDs(array($viewer->getPHID()));
}
if ($map['usernames']) {
$query->withUsernames($map['usernames']);
}
if ($map['nameLike']) {
$query->withNameLike($map['nameLike']);
}
if ($map['isAdmin'] !== null) {
$query->withIsAdmin($map['isAdmin']);
}
if ($map['isDisabled'] !== null) {
$query->withIsDisabled($map['isDisabled']);
}
if ($map['isMailingList'] !== null) {
$query->withIsMailingList($map['isMailingList']);
}
if ($map['isBot'] !== null) {
$query->withIsSystemAgent($map['isBot']);
}
if ($map['needsApproval'] !== null) {
$query->withIsApproved(!$map['needsApproval']);
}
if (idx($map, 'mfa') !== null) {
$viewer = $this->requireViewer();
if (!$viewer->getIsAdmin()) {
throw new PhabricatorSearchConstraintException(
pht(
'The "Has MFA" query constraint may only be used by '.
'administrators, to prevent attackers from using it to target '.
'weak accounts.'));
}
$query->withIsEnrolledInMultiFactor($map['mfa']);
}
if ($map['createdStart']) {
$query->withDateCreatedAfter($map['createdStart']);
}
if ($map['createdEnd']) {
$query->withDateCreatedBefore($map['createdEnd']);
}
return $query;
}
protected function getURI($path) {
return '/people/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'active' => pht('Active'),
'all' => pht('All'),
);
$viewer = $this->requireViewer();
if ($viewer->getIsAdmin()) {
$names['approval'] = pht('Approval Queue');
}
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'active':
return $query
->setParameter('isDisabled', false);
case 'approval':
return $query
->setParameter('needsApproval', true)
->setParameter('isDisabled', false);
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $users,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($users, 'PhabricatorUser');
$request = $this->getRequest();
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$is_approval = ($query->getQueryKey() == 'approval');
foreach ($users as $user) {
$primary_email = $user->loadPrimaryEmail();
if ($primary_email && $primary_email->getIsVerified()) {
$email = pht('Verified');
} else {
$email = pht('Unverified');
}
$item = new PHUIObjectItemView();
$item->setHeader($user->getFullName())
->setHref('/p/'.$user->getUsername().'/')
->addAttribute(phabricator_datetime($user->getDateCreated(), $viewer))
->addAttribute($email)
->setImageURI($user->getProfileImageURI());
if ($is_approval && $primary_email) {
$item->addAttribute($primary_email->getAddress());
}
if ($user->getIsDisabled()) {
$item->addIcon('fa-ban', pht('Disabled'));
$item->setDisabled(true);
}
if (!$is_approval) {
if (!$user->getIsApproved()) {
$item->addIcon('fa-clock-o', pht('Needs Approval'));
}
}
if ($user->getIsAdmin()) {
$item->addIcon('fa-star', pht('Admin'));
}
if ($user->getIsSystemAgent()) {
$item->addIcon('fa-desktop', pht('Bot'));
}
if ($user->getIsMailingList()) {
$item->addIcon('fa-envelope-o', pht('Mailing List'));
}
if ($viewer->getIsAdmin()) {
if ($user->getIsEnrolledInMultiFactor()) {
$item->addIcon('fa-lock', pht('Has MFA'));
}
}
if ($viewer->getIsAdmin()) {
$user_id = $user->getID();
if ($is_approval) {
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-ban')
->setName(pht('Disable'))
->setWorkflow(true)
->setHref($this->getApplicationURI('disapprove/'.$user_id.'/')));
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-thumbs-o-up')
->setName(pht('Approve'))
->setWorkflow(true)
->setHref($this->getApplicationURI('approve/'.$user_id.'/')));
}
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No accounts found.'));
return $result;
}
protected function newExportFields() {
return array(
id(new PhabricatorStringExportField())
->setKey('username')
->setLabel(pht('Username')),
id(new PhabricatorStringExportField())
->setKey('realName')
->setLabel(pht('Real Name')),
);
}
protected function newExportData(array $users) {
$viewer = $this->requireViewer();
$export = array();
foreach ($users as $user) {
$export[] = array(
'username' => $user->getUsername(),
'realName' => $user->getRealName(),
);
}
return $export;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/query/PhabricatorPeopleUserEmailQuery.php | src/applications/people/query/PhabricatorPeopleUserEmailQuery.php | <?php
final class PhabricatorPeopleUserEmailQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function newResultObject() {
return new PhabricatorUserEmail();
}
protected function getPrimaryTableAlias() {
return 'email';
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'email.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'email.phid IN (%Ls)',
$this->phids);
}
return $where;
}
protected function willLoadPage(array $page) {
$user_phids = mpull($page, 'getUserPHID');
$users = id(new PhabricatorPeopleQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withPHIDs($user_phids)
->execute();
$users = mpull($users, null, 'getPHID');
foreach ($page as $key => $address) {
$user = idx($users, $address->getUserPHID());
if (!$user) {
unset($page[$key]);
$this->didRejectResult($address);
continue;
}
$address->attachUser($user);
}
return $page;
}
public function getQueryApplicationClass() {
return 'PhabricatorPeopleApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/query/PhabricatorPeopleLogQuery.php | src/applications/people/query/PhabricatorPeopleLogQuery.php | <?php
final class PhabricatorPeopleLogQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $actorPHIDs;
private $userPHIDs;
private $relatedPHIDs;
private $sessionKeys;
private $actions;
private $remoteAddressPrefix;
private $dateCreatedMin;
private $dateCreatedMax;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withActorPHIDs(array $actor_phids) {
$this->actorPHIDs = $actor_phids;
return $this;
}
public function withUserPHIDs(array $user_phids) {
$this->userPHIDs = $user_phids;
return $this;
}
public function withRelatedPHIDs(array $related_phids) {
$this->relatedPHIDs = $related_phids;
return $this;
}
public function withSessionKeys(array $session_keys) {
$this->sessionKeys = $session_keys;
return $this;
}
public function withActions(array $actions) {
$this->actions = $actions;
return $this;
}
public function withRemoteAddressPrefix($remote_address_prefix) {
$this->remoteAddressPrefix = $remote_address_prefix;
return $this;
}
public function withDateCreatedBetween($min, $max) {
$this->dateCreatedMin = $min;
$this->dateCreatedMax = $max;
return $this;
}
public function newResultObject() {
return new PhabricatorUserLog();
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->actorPHIDs !== null) {
$where[] = qsprintf(
$conn,
'actorPHID IN (%Ls)',
$this->actorPHIDs);
}
if ($this->userPHIDs !== null) {
$where[] = qsprintf(
$conn,
'userPHID IN (%Ls)',
$this->userPHIDs);
}
if ($this->relatedPHIDs !== null) {
$where[] = qsprintf(
$conn,
'(actorPHID IN (%Ls) OR userPHID IN (%Ls))',
$this->relatedPHIDs,
$this->relatedPHIDs);
}
if ($this->sessionKeys !== null) {
$where[] = qsprintf(
$conn,
'session IN (%Ls)',
$this->sessionKeys);
}
if ($this->actions !== null) {
$where[] = qsprintf(
$conn,
'action IN (%Ls)',
$this->actions);
}
if ($this->remoteAddressPrefix !== null) {
$where[] = qsprintf(
$conn,
'remoteAddr LIKE %>',
$this->remoteAddressPrefix);
}
if ($this->dateCreatedMin !== null) {
$where[] = qsprintf(
$conn,
'dateCreated >= %d',
$this->dateCreatedMin);
}
if ($this->dateCreatedMax !== null) {
$where[] = qsprintf(
$conn,
'dateCreated <= %d',
$this->dateCreatedMax);
}
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorPeopleApplication';
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/query/PhabricatorPeopleTransactionQuery.php | src/applications/people/query/PhabricatorPeopleTransactionQuery.php | <?php
final class PhabricatorPeopleTransactionQuery
extends PhabricatorApplicationTransactionQuery {
public function getTemplateApplicationTransaction() {
return new PhabricatorUserTransaction();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/mail/PhabricatorPeopleMailEngineException.php | src/applications/people/mail/PhabricatorPeopleMailEngineException.php | <?php
final class PhabricatorPeopleMailEngineException
extends Exception {
private $title;
private $body;
public function __construct($title, $body) {
$this->title = $title;
$this->body = $body;
parent::__construct(pht('%s: %s', $title, $body));
}
public function getTitle() {
return $this->title;
}
public function getBody() {
return $this->body;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/mail/PhabricatorPeopleEmailLoginMailEngine.php | src/applications/people/mail/PhabricatorPeopleEmailLoginMailEngine.php | <?php
final class PhabricatorPeopleEmailLoginMailEngine
extends PhabricatorPeopleMailEngine {
public function validateMail() {
$recipient = $this->getRecipient();
if ($recipient->getIsDisabled()) {
$this->throwValidationException(
pht('User is Disabled'),
pht(
'You can not send an email login link to this email address '.
'because the associated user account is disabled.'));
}
if (!$recipient->canEstablishWebSessions()) {
$this->throwValidationException(
pht('Not a Normal User'),
pht(
'You can not send an email login link to this email address '.
'because the associated user account is not a normal user account '.
'and can not log in to the web interface.'));
}
}
protected function newMail() {
$is_set_password = $this->isSetPasswordWorkflow();
if ($is_set_password) {
$subject = pht(
'[%s] Account Password Link',
PlatformSymbols::getPlatformServerName());
} else {
$subject = pht(
'[%s] Account Login Link',
PlatformSymbols::getPlatformServerName());
}
$recipient = $this->getRecipient();
PhabricatorSystemActionEngine::willTakeAction(
array($recipient->getPHID()),
new PhabricatorAuthEmailLoginAction(),
1);
$engine = new PhabricatorAuthSessionEngine();
$login_uri = $engine->getOneTimeLoginURI(
$recipient,
null,
PhabricatorAuthSessionEngine::ONETIME_RESET);
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$have_passwords = $this->isPasswordAuthEnabled();
$body = array();
if ($is_set_password) {
$message_key = PhabricatorAuthEmailSetPasswordMessageType::MESSAGEKEY;
} else {
$message_key = PhabricatorAuthEmailLoginMessageType::MESSAGEKEY;
}
$message_body = PhabricatorAuthMessage::loadMessageText(
$recipient,
$message_key);
if ($message_body !== null && strlen($message_body)) {
$body[] = $this->newRemarkupText($message_body);
}
if ($have_passwords) {
if ($is_set_password) {
$body[] = pht(
'You can use this link to set a password on your account:'.
"\n\n %s\n",
$login_uri);
} else if ($is_serious) {
$body[] = pht(
"You can use this link to reset your password:".
"\n\n %s\n",
$login_uri);
} else {
$body[] = pht(
"Condolences on forgetting your password. You can use this ".
"link to reset it:\n\n".
" %s\n\n".
"After you set a new password, consider writing it down on a ".
"sticky note and attaching it to your monitor so you don't ".
"forget again! Choosing a very short, easy-to-remember password ".
"like \"cat\" or \"1234\" might also help.\n\n".
"Best Wishes,\nPhabricator\n",
$login_uri);
}
} else {
$body[] = pht(
"You can use this login link to regain access to your account:".
"\n\n".
" %s\n",
$login_uri);
}
$body = implode("\n\n", $body);
return id(new PhabricatorMetaMTAMail())
->setSubject($subject)
->setBody($body);
}
private function isPasswordAuthEnabled() {
return (bool)PhabricatorPasswordAuthProvider::getPasswordProvider();
}
private function isSetPasswordWorkflow() {
$sender = $this->getSender();
$recipient = $this->getRecipient();
// Users can hit the "login with an email link" workflow while trying to
// set a password on an account which does not yet have a password. We
// require they verify that they own the email address and send them
// through the email login flow. In this case, the messaging is slightly
// different.
if ($sender->getPHID()) {
if ($sender->getPHID() === $recipient->getPHID()) {
return true;
}
}
return false;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/mail/PhabricatorPeopleUsernameMailEngine.php | src/applications/people/mail/PhabricatorPeopleUsernameMailEngine.php | <?php
final class PhabricatorPeopleUsernameMailEngine
extends PhabricatorPeopleMailEngine {
private $oldUsername;
private $newUsername;
public function setNewUsername($new_username) {
$this->newUsername = $new_username;
return $this;
}
public function getNewUsername() {
return $this->newUsername;
}
public function setOldUsername($old_username) {
$this->oldUsername = $old_username;
return $this;
}
public function getOldUsername() {
return $this->oldUsername;
}
public function validateMail() {
return;
}
protected function newMail() {
$sender = $this->getSender();
$sender_username = $sender->getUsername();
$sender_realname = $sender->getRealName();
$old_username = $this->getOldUsername();
$new_username = $this->getNewUsername();
$body = sprintf(
"%s\n\n %s\n %s\n",
pht(
'%s (%s) has changed your %s username.',
$sender_username,
$sender_realname,
PlatformSymbols::getPlatformServerName()),
pht(
'Old Username: %s',
$old_username),
pht(
'New Username: %s',
$new_username));
return id(new PhabricatorMetaMTAMail())
->setSubject(
pht(
'[%s] Username Changed',
PlatformSymbols::getPlatformServerName()))
->setBody($body);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/mail/PhabricatorPeopleMailEngine.php | src/applications/people/mail/PhabricatorPeopleMailEngine.php | <?php
abstract class PhabricatorPeopleMailEngine
extends Phobject {
private $sender;
private $recipient;
private $recipientAddress;
private $activityLog;
final public function setSender(PhabricatorUser $sender) {
$this->sender = $sender;
return $this;
}
final public function getSender() {
if (!$this->sender) {
throw new PhutilInvalidStateException('setSender');
}
return $this->sender;
}
final public function setRecipient(PhabricatorUser $recipient) {
$this->recipient = $recipient;
return $this;
}
final public function getRecipient() {
if (!$this->recipient) {
throw new PhutilInvalidStateException('setRecipient');
}
return $this->recipient;
}
final public function setRecipientAddress(PhutilEmailAddress $address) {
$this->recipientAddress = $address;
return $this;
}
final public function getRecipientAddress() {
if (!$this->recipientAddress) {
throw new PhutilInvalidStateException('recipientAddress');
}
return $this->recipientAddress;
}
final public function hasRecipientAddress() {
return ($this->recipientAddress !== null);
}
final public function setActivityLog(PhabricatorUserLog $activity_log) {
$this->activityLog = $activity_log;
return $this;
}
final public function getActivityLog() {
return $this->activityLog;
}
final public function canSendMail() {
try {
$this->validateMail();
return true;
} catch (PhabricatorPeopleMailEngineException $ex) {
return false;
}
}
final public function sendMail() {
$this->validateMail();
$mail = $this->newMail();
if ($this->hasRecipientAddress()) {
$recipient_address = $this->getRecipientAddress();
$mail->addRawTos(array($recipient_address->getAddress()));
} else {
$recipient = $this->getRecipient();
$mail->addTos(array($recipient->getPHID()));
}
$activity_log = $this->getActivityLog();
if ($activity_log) {
$activity_log->save();
$body = array();
$body[] = rtrim($mail->getBody(), "\n");
$body[] = pht('Activity Log ID: #%d', $activity_log->getID());
$body = implode("\n\n", $body)."\n";
$mail->setBody($body);
}
$mail
->setForceDelivery(true)
->save();
return $mail;
}
abstract public function validateMail();
abstract protected function newMail();
final protected function throwValidationException($title, $body) {
throw new PhabricatorPeopleMailEngineException($title, $body);
}
final protected function newRemarkupText($text) {
$recipient = $this->getRecipient();
$engine = PhabricatorMarkupEngine::newMarkupEngine(array())
->setConfig('viewer', $recipient)
->setConfig('uri.base', PhabricatorEnv::getProductionURI('/'))
->setMode(PhutilRemarkupEngine::MODE_TEXT);
$rendered_text = $engine->markupText($text);
$rendered_text = rtrim($rendered_text, "\n");
return $rendered_text;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/mail/PhabricatorPeopleWelcomeMailEngine.php | src/applications/people/mail/PhabricatorPeopleWelcomeMailEngine.php | <?php
final class PhabricatorPeopleWelcomeMailEngine
extends PhabricatorPeopleMailEngine {
private $welcomeMessage;
public function setWelcomeMessage($welcome_message) {
$this->welcomeMessage = $welcome_message;
return $this;
}
public function getWelcomeMessage() {
return $this->welcomeMessage;
}
public function validateMail() {
$sender = $this->getSender();
$recipient = $this->getRecipient();
if (!$sender->getIsAdmin()) {
$this->throwValidationException(
pht('Not an Administrator'),
pht(
'You can not send welcome mail because you are not an '.
'administrator. Only administrators may send welcome mail.'));
}
if ($recipient->getIsDisabled()) {
$this->throwValidationException(
pht('User is Disabled'),
pht(
'You can not send welcome mail to this user because their account '.
'is disabled.'));
}
if (!$recipient->canEstablishWebSessions()) {
$this->throwValidationException(
pht('Not a Normal User'),
pht(
'You can not send this user welcome mail because they are not '.
'a normal user and can not log in to the web interface. Special '.
'users (like bots and mailing lists) are unable to establish '.
'web sessions.'));
}
}
protected function newMail() {
$sender = $this->getSender();
$recipient = $this->getRecipient();
$base_uri = PhabricatorEnv::getProductionURI('/');
$engine = new PhabricatorAuthSessionEngine();
$uri = $engine->getOneTimeLoginURI(
$recipient,
$recipient->loadPrimaryEmail(),
PhabricatorAuthSessionEngine::ONETIME_WELCOME);
$message = array();
$message[] = pht(
'Welcome to %s!',
PlatformSymbols::getPlatformServerName());
$message[] = pht(
'%s (%s) has created an account for you.',
$sender->getUsername(),
$sender->getRealName());
$message[] = pht(
' Username: %s',
$recipient->getUsername());
// If password auth is enabled, give the user specific instructions about
// how to add a credential to their account.
// If we aren't sure what they're supposed to be doing and passwords are
// not enabled, just give them generic instructions.
$use_passwords = PhabricatorPasswordAuthProvider::getPasswordProvider();
if ($use_passwords) {
$message[] = pht(
'To log in, follow this link and set a password:');
$message[] = pht(' %s', $uri);
$message[] = pht(
'After you have set a password, you can log in again in '.
'the future by going here:');
$message[] = pht(' %s', $base_uri);
} else {
$message[] = pht(
'To log in to your account for the first time, follow this link:');
$message[] = pht(' %s', $uri);
$message[] = pht(
'After you set up your account, you can log in again in '.
'the future by going here:');
$message[] = pht(' %s', $base_uri);
}
$message_body = $this->newBody();
if ($message_body !== null) {
$message[] = $message_body;
}
$message = implode("\n\n", $message);
return id(new PhabricatorMetaMTAMail())
->setSubject(
pht(
'[%s] Welcome to %s',
PlatformSymbols::getPlatformServerName(),
PlatformSymbols::getPlatformServerName()))
->setBody($message);
}
private function newBody() {
$recipient = $this->getRecipient();
$custom_body = $this->getWelcomeMessage();
if ($custom_body !== null && strlen($custom_body)) {
return $this->newRemarkupText($custom_body);
}
$default_body = PhabricatorAuthMessage::loadMessageText(
$recipient,
PhabricatorAuthWelcomeMailMessageType::MESSAGEKEY);
if ($default_body !== null && strlen($default_body)) {
return $this->newRemarkupText($default_body);
}
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
if (!$is_serious) {
return pht(
"Love,\n%s",
PlatformSymbols::getPlatformServerName());
}
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/cache/PhabricatorUserNotificationCountCacheType.php | src/applications/people/cache/PhabricatorUserNotificationCountCacheType.php | <?php
final class PhabricatorUserNotificationCountCacheType
extends PhabricatorUserCacheType {
const CACHETYPE = 'notification.count';
const KEY_COUNT = 'user.notification.count.v1';
public function getAutoloadKeys() {
return array(
self::KEY_COUNT,
);
}
public function canManageKey($key) {
return ($key === self::KEY_COUNT);
}
public function getValueFromStorage($value) {
return (int)$value;
}
public function newValueForUsers($key, array $users) {
if (!$users) {
return array();
}
$user_phids = mpull($users, 'getPHID');
$table = new PhabricatorFeedStoryNotification();
$conn_r = $table->establishConnection('r');
$rows = queryfx_all(
$conn_r,
'SELECT userPHID, COUNT(*) N FROM %T
WHERE userPHID IN (%Ls) AND hasViewed = 0
GROUP BY userPHID',
$table->getTableName(),
$user_phids);
$empty = array_fill_keys($user_phids, 0);
return ipull($rows, 'N', 'userPHID') + $empty;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/cache/PhabricatorUserCacheType.php | src/applications/people/cache/PhabricatorUserCacheType.php | <?php
abstract class PhabricatorUserCacheType extends Phobject {
final public function getViewer() {
return PhabricatorUser::getOmnipotentUser();
}
public function getAutoloadKeys() {
return array();
}
public function canManageKey($key) {
return false;
}
public function getDefaultValue() {
return array();
}
public function shouldValidateRawCacheData() {
return false;
}
public function isRawCacheDataValid(PhabricatorUser $user, $key, $data) {
throw new PhutilMethodNotImplementedException();
}
public function getValueFromStorage($value) {
return $value;
}
public function newValueForUsers($key, array $users) {
return array();
}
final public function getUserCacheType() {
return $this->getPhobjectClassConstant('CACHETYPE');
}
public static function getAllCacheTypes() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getUserCacheType')
->execute();
}
public static function getCacheTypeForKey($key) {
$all = self::getAllCacheTypes();
foreach ($all as $type) {
if ($type->canManageKey($key)) {
return $type;
}
}
return null;
}
public static function requireCacheTypeForKey($key) {
$type = self::getCacheTypeForKey($key);
if (!$type) {
throw new Exception(
pht(
'Failed to load UserCacheType to manage key "%s". This cache type '.
'is required.',
$key));
}
return $type;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/cache/PhabricatorUserMessageCountCacheType.php | src/applications/people/cache/PhabricatorUserMessageCountCacheType.php | <?php
final class PhabricatorUserMessageCountCacheType
extends PhabricatorUserCacheType {
const CACHETYPE = 'message.count';
const KEY_COUNT = 'user.message.count.v1';
public function getAutoloadKeys() {
return array(
self::KEY_COUNT,
);
}
public function canManageKey($key) {
return ($key === self::KEY_COUNT);
}
public function getValueFromStorage($value) {
return (int)$value;
}
public function newValueForUsers($key, array $users) {
if (!$users) {
return array();
}
$user_phids = mpull($users, 'getPHID');
$unread = id(new ConpherenceParticipantCountQuery())
->withParticipantPHIDs($user_phids)
->withUnread(true)
->execute();
$empty = array_fill_keys($user_phids, 0);
return $unread + $empty;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/cache/PhabricatorUserProfileImageCacheType.php | src/applications/people/cache/PhabricatorUserProfileImageCacheType.php | <?php
final class PhabricatorUserProfileImageCacheType
extends PhabricatorUserCacheType {
const CACHETYPE = 'user.profile';
const KEY_URI = 'user.profile.image.uri.v1';
public function getAutoloadKeys() {
return array(
self::KEY_URI,
);
}
public function canManageKey($key) {
return ($key === self::KEY_URI);
}
public function getDefaultValue() {
return PhabricatorUser::getDefaultProfileImageURI();
}
public function newValueForUsers($key, array $users) {
$viewer = $this->getViewer();
$file_phids = array();
$generate_users = array();
foreach ($users as $user) {
$user_phid = $user->getPHID();
$custom_phid = $user->getProfileImagePHID();
$default_phid = $user->getDefaultProfileImagePHID();
$version = $user->getDefaultProfileImageVersion();
if ($custom_phid) {
$file_phids[$user_phid] = $custom_phid;
continue;
}
if ($default_phid) {
if ($version == PhabricatorFilesComposeAvatarBuiltinFile::VERSION) {
$file_phids[$user_phid] = $default_phid;
continue;
}
}
$generate_users[] = $user;
}
$generator = new PhabricatorFilesComposeAvatarBuiltinFile();
foreach ($generate_users as $user) {
$file = $generator->updateUser($user);
$file_phids[$user->getPHID()] = $file->getPHID();
}
if ($file_phids) {
$files = id(new PhabricatorFileQuery())
->setViewer($viewer)
->withPHIDs($file_phids)
->execute();
$files = mpull($files, null, 'getPHID');
} else {
$files = array();
}
$results = array();
foreach ($users as $user) {
$image_phid = $user->getProfileImagePHID();
$default_phid = $user->getDefaultProfileImagePHID();
if (isset($files[$image_phid])) {
$image_uri = $files[$image_phid]->getBestURI();
} else if (isset($files[$default_phid])) {
$image_uri = $files[$default_phid]->getBestURI();
} else {
$image_uri = PhabricatorUser::getDefaultProfileImageURI();
}
$user_phid = $user->getPHID();
$version = $this->getCacheVersion($user);
$results[$user_phid] = "{$version},{$image_uri}";
}
return $results;
}
public function getValueFromStorage($value) {
$parts = explode(',', $value, 2);
return end($parts);
}
public function shouldValidateRawCacheData() {
return true;
}
public function isRawCacheDataValid(PhabricatorUser $user, $key, $data) {
if ($data === null) {
return false;
}
$parts = explode(',', $data, 2);
$version = reset($parts);
return ($version === $this->getCacheVersion($user));
}
private function getCacheVersion(PhabricatorUser $user) {
$parts = array(
PhabricatorEnv::getCDNURI('/'),
PhabricatorEnv::getEnvConfig('cluster.instance'),
$user->getProfileImagePHID(),
);
$parts = serialize($parts);
return PhabricatorHash::digestForIndex($parts);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/cache/PhabricatorUserPreferencesCacheType.php | src/applications/people/cache/PhabricatorUserPreferencesCacheType.php | <?php
final class PhabricatorUserPreferencesCacheType
extends PhabricatorUserCacheType {
const CACHETYPE = 'preferences';
const KEY_PREFERENCES = 'user.preferences.v2';
public function getAutoloadKeys() {
return array(
self::KEY_PREFERENCES,
);
}
public function canManageKey($key) {
return ($key === self::KEY_PREFERENCES);
}
public function getValueFromStorage($value) {
return phutil_json_decode($value);
}
public function newValueForUsers($key, array $users) {
$viewer = $this->getViewer();
$users = mpull($users, null, 'getPHID');
$user_phids = array_keys($users);
$preferences = id(new PhabricatorUserPreferencesQuery())
->setViewer($viewer)
->withUsers($users)
->needSyntheticPreferences(true)
->execute();
$preferences = mpull($preferences, null, 'getUserPHID');
$all_settings = PhabricatorSetting::getAllSettings();
$settings = array();
foreach ($users as $user_phid => $user) {
$preference = idx($preferences, $user_phid);
if (!$preference) {
continue;
}
foreach ($all_settings as $key => $setting) {
$value = $preference->getSettingValue($key);
try {
id(clone $setting)
->setViewer($viewer)
->assertValidValue($value);
} catch (Exception $ex) {
// If the saved value isn't valid, don't cache it: we'll use the
// default value instead.
continue;
}
// As an optimization, we omit the value from the cache if it is
// exactly the same as the hardcoded default.
$default_value = id(clone $setting)
->setViewer($user)
->getSettingDefaultValue();
if ($value === $default_value) {
continue;
}
$settings[$user_phid][$key] = $value;
}
}
$results = array();
foreach ($user_phids as $user_phid) {
$value = idx($settings, $user_phid, array());
$results[$user_phid] = phutil_json_encode($value);
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/cache/PhabricatorUserBadgesCacheType.php | src/applications/people/cache/PhabricatorUserBadgesCacheType.php | <?php
final class PhabricatorUserBadgesCacheType
extends PhabricatorUserCacheType {
const CACHETYPE = 'badges.award';
const KEY_BADGES = 'user.badge.award.v1';
const BADGE_COUNT = 2;
public function getAutoloadKeys() {
return array(
self::KEY_BADGES,
);
}
public function canManageKey($key) {
return ($key === self::KEY_BADGES);
}
public function getValueFromStorage($value) {
return phutil_json_decode($value);
}
public function newValueForUsers($key, array $users) {
if (!$users) {
return array();
}
$user_phids = mpull($users, 'getPHID');
$results = array();
foreach ($user_phids as $user_phid) {
$awards = id(new PhabricatorBadgesAwardQuery())
->setViewer($this->getViewer())
->withRecipientPHIDs(array($user_phid))
->withBadgeStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
->setLimit(self::BADGE_COUNT)
->execute();
$award_data = array();
if ($awards) {
foreach ($awards as $award) {
$badge = $award->getBadge();
$award_data[] = array(
'icon' => $badge->getIcon(),
'name' => $badge->getName(),
'quality' => $badge->getQuality(),
'id' => $badge->getID(),
);
}
}
$results[$user_phid] = phutil_json_encode($award_data);
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserConfiguredCustomField.php | src/applications/people/customfield/PhabricatorUserConfiguredCustomField.php | <?php
final class PhabricatorUserConfiguredCustomField
extends PhabricatorUserCustomField
implements PhabricatorStandardCustomFieldInterface {
public function getStandardCustomFieldNamespace() {
return 'user';
}
public function createFields($object) {
return PhabricatorStandardCustomField::buildStandardFields(
$this,
PhabricatorEnv::getEnvConfig('user.custom-field-definitions'));
}
public function newStorageObject() {
return new PhabricatorUserConfiguredCustomFieldStorage();
}
protected function newStringIndexStorage() {
return new PhabricatorUserCustomFieldStringIndex();
}
protected function newNumericIndexStorage() {
return new PhabricatorUserCustomFieldNumericIndex();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserBlurbField.php | src/applications/people/customfield/PhabricatorUserBlurbField.php | <?php
final class PhabricatorUserBlurbField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:blurb';
}
public function getModernFieldKey() {
return 'blurb';
}
public function getFieldKeyForConduit() {
return $this->getModernFieldKey();
}
public function getFieldName() {
return pht('Blurb');
}
public function getFieldDescription() {
return pht('Short blurb about the user.');
}
public function shouldAppearInApplicationTransactions() {
return true;
}
public function shouldAppearInEditView() {
return true;
}
public function shouldAppearInPropertyView() {
return true;
}
public function readValueFromObject(PhabricatorCustomFieldInterface $object) {
$this->value = $object->loadUserProfile()->getBlurb();
}
public function getOldValueForApplicationTransactions() {
return $this->getObject()->loadUserProfile()->getBlurb();
}
public function getNewValueForApplicationTransactions() {
return $this->value;
}
public function applyApplicationTransactionInternalEffects(
PhabricatorApplicationTransaction $xaction) {
$this->getObject()->loadUserProfile()->setBlurb($xaction->getNewValue());
}
public function readValueFromRequest(AphrontRequest $request) {
$this->value = $request->getStr($this->getFieldKey());
}
public function setValueFromStorage($value) {
$this->value = $value;
return $this;
}
public function renderEditControl(array $handles) {
return id(new PhabricatorRemarkupControl())
->setUser($this->getViewer())
->setName($this->getFieldKey())
->setValue($this->value)
->setLabel($this->getFieldName());
}
public function getApplicationTransactionRemarkupBlocks(
PhabricatorApplicationTransaction $xaction) {
return array(
$xaction->getNewValue(),
);
}
public function renderPropertyViewLabel() {
return null;
}
public function renderPropertyViewValue(array $handles) {
$blurb = $this->getObject()->loadUserProfile()->getBlurb();
if (!strlen($blurb)) {
return null;
}
$viewer = $this->getViewer();
$view = new PHUIRemarkupView($viewer, $blurb);
return $view;
}
public function getStyleForPropertyView() {
return 'block';
}
public function shouldAppearInConduitTransactions() {
return true;
}
protected function newConduitEditParameterType() {
return new ConduitStringParameterType();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserRealNameField.php | src/applications/people/customfield/PhabricatorUserRealNameField.php | <?php
final class PhabricatorUserRealNameField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:realname';
}
public function getModernFieldKey() {
return 'realName';
}
public function getFieldKeyForConduit() {
return $this->getModernFieldKey();
}
public function getFieldName() {
return pht('Real Name');
}
public function getFieldDescription() {
return pht('Stores the real name of the user, like "Abraham Lincoln".');
}
public function canDisableField() {
return false;
}
public function shouldAppearInApplicationTransactions() {
return true;
}
public function shouldAppearInEditView() {
return true;
}
public function readValueFromObject(PhabricatorCustomFieldInterface $object) {
$this->value = $object->getRealName();
}
public function getOldValueForApplicationTransactions() {
return $this->getObject()->getRealName();
}
public function getNewValueForApplicationTransactions() {
if (!$this->isEditable()) {
return $this->getObject()->getRealName();
}
return $this->value;
}
public function applyApplicationTransactionInternalEffects(
PhabricatorApplicationTransaction $xaction) {
$this->getObject()->setRealName($xaction->getNewValue());
}
public function readValueFromRequest(AphrontRequest $request) {
$this->value = $request->getStr($this->getFieldKey());
}
public function setValueFromStorage($value) {
$this->value = $value;
return $this;
}
public function renderEditControl(array $handles) {
return id(new AphrontFormTextControl())
->setName($this->getFieldKey())
->setValue($this->value)
->setLabel($this->getFieldName())
->setDisabled(!$this->isEditable());
}
private function isEditable() {
return PhabricatorEnv::getEnvConfig('account.editable');
}
public function shouldAppearInConduitTransactions() {
return true;
}
protected function newConduitEditParameterType() {
return new ConduitStringParameterType();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserStatusField.php | src/applications/people/customfield/PhabricatorUserStatusField.php | <?php
final class PhabricatorUserStatusField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:status';
}
public function getFieldName() {
return pht('Availability');
}
public function getFieldDescription() {
return pht('Shows when a user is away or busy.');
}
public function shouldAppearInPropertyView() {
return true;
}
public function isFieldEnabled() {
return PhabricatorApplication::isClassInstalled(
'PhabricatorCalendarApplication');
}
public function renderPropertyViewValue(array $handles) {
$user = $this->getObject();
$viewer = $this->requireViewer();
// Don't show availability for disabled users, since this is vaguely
// misleading to say "Availability: Available" and probably not useful.
if ($user->getIsDisabled()) {
return null;
}
return id(new PHUIUserAvailabilityView())
->setViewer($viewer)
->setAvailableUser($user);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserSinceField.php | src/applications/people/customfield/PhabricatorUserSinceField.php | <?php
final class PhabricatorUserSinceField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:since';
}
public function getFieldName() {
return pht('User Since');
}
public function getFieldDescription() {
return pht('Shows user join date.');
}
public function shouldAppearInPropertyView() {
return true;
}
public function renderPropertyViewValue(array $handles) {
$absolute = phabricator_datetime(
$this->getObject()->getDateCreated(),
$this->getViewer());
$relative = phutil_format_relative_time_detailed(
time() - $this->getObject()->getDateCreated(),
$levels = 2);
return hsprintf('%s (%s)', $absolute, $relative);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserTitleField.php | src/applications/people/customfield/PhabricatorUserTitleField.php | <?php
final class PhabricatorUserTitleField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:title';
}
public function getModernFieldKey() {
return 'title';
}
public function getFieldKeyForConduit() {
return $this->getModernFieldKey();
}
public function getFieldName() {
return pht('Title');
}
public function getFieldDescription() {
return pht('User title, like "CEO" or "Assistant to the Manager".');
}
public function canDisableField() {
return false;
}
public function shouldAppearInApplicationTransactions() {
return true;
}
public function shouldAppearInEditView() {
return true;
}
public function readValueFromObject(PhabricatorCustomFieldInterface $object) {
$this->value = $object->loadUserProfile()->getTitle();
}
public function getOldValueForApplicationTransactions() {
return $this->getObject()->loadUserProfile()->getTitle();
}
public function getNewValueForApplicationTransactions() {
return $this->value;
}
public function applyApplicationTransactionInternalEffects(
PhabricatorApplicationTransaction $xaction) {
$this->getObject()->loadUserProfile()->setTitle($xaction->getNewValue());
}
public function readValueFromRequest(AphrontRequest $request) {
$this->value = $request->getStr($this->getFieldKey());
}
public function setValueFromStorage($value) {
$this->value = $value;
return $this;
}
public function renderEditControl(array $handles) {
return id(new AphrontFormTextControl())
->setName($this->getFieldKey())
->setValue($this->value)
->setLabel($this->getFieldName());
}
public function shouldAppearInConduitTransactions() {
return true;
}
protected function newConduitEditParameterType() {
return new ConduitStringParameterType();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserCustomField.php | src/applications/people/customfield/PhabricatorUserCustomField.php | <?php
abstract class PhabricatorUserCustomField
extends PhabricatorCustomField {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserRolesField.php | src/applications/people/customfield/PhabricatorUserRolesField.php | <?php
final class PhabricatorUserRolesField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:roles';
}
public function getFieldName() {
return pht('Roles');
}
public function getFieldDescription() {
return pht('Shows roles like "Administrator" and "Disabled".');
}
public function shouldAppearInPropertyView() {
return true;
}
public function renderPropertyViewValue(array $handles) {
$user = $this->getObject();
$roles = array();
if ($user->getIsAdmin()) {
$roles[] = pht('Administrator');
}
if ($user->getIsDisabled()) {
$roles[] = pht('Disabled');
}
if (!$user->getIsApproved()) {
$roles[] = pht('Not Approved');
}
if ($user->getIsSystemAgent()) {
$roles[] = pht('Bot');
}
if ($user->getIsMailingList()) {
$roles[] = pht('Mailing List');
}
if ($roles) {
return implode(', ', $roles);
}
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/customfield/PhabricatorUserIconField.php | src/applications/people/customfield/PhabricatorUserIconField.php | <?php
final class PhabricatorUserIconField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:icon';
}
public function getModernFieldKey() {
return 'icon';
}
public function getFieldKeyForConduit() {
return $this->getModernFieldKey();
}
public function getFieldName() {
return pht('Icon');
}
public function getFieldDescription() {
return pht('User icon to accompany their title.');
}
public function canDisableField() {
return false;
}
public function shouldAppearInApplicationTransactions() {
return true;
}
public function shouldAppearInEditView() {
return true;
}
public function readValueFromObject(PhabricatorCustomFieldInterface $object) {
$this->value = $object->loadUserProfile()->getIcon();
}
public function getOldValueForApplicationTransactions() {
return $this->getObject()->loadUserProfile()->getIcon();
}
public function getNewValueForApplicationTransactions() {
return $this->value;
}
public function applyApplicationTransactionInternalEffects(
PhabricatorApplicationTransaction $xaction) {
$this->getObject()->loadUserProfile()->setIcon($xaction->getNewValue());
}
public function readValueFromRequest(AphrontRequest $request) {
$this->value = $request->getStr($this->getFieldKey());
}
public function setValueFromStorage($value) {
$this->value = $value;
return $this;
}
public function renderEditControl(array $handles) {
return id(new PHUIFormIconSetControl())
->setName($this->getFieldKey())
->setValue($this->value)
->setLabel($this->getFieldName())
->setIconSet(new PhabricatorPeopleIconSet());
}
public function shouldAppearInConduitTransactions() {
return true;
}
protected function newConduitEditParameterType() {
return new ConduitStringParameterType();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/editor/PhabricatorUserEditor.php | src/applications/people/editor/PhabricatorUserEditor.php | <?php
/**
* Editor class for creating and adjusting users. This class guarantees data
* integrity and writes logs when user information changes.
*
* @task config Configuration
* @task edit Creating and Editing Users
* @task role Editing Roles
* @task email Adding, Removing and Changing Email
* @task internal Internals
*/
final class PhabricatorUserEditor extends PhabricatorEditor {
private $logs = array();
/* -( Creating and Editing Users )----------------------------------------- */
/**
* @task edit
*/
public function createNewUser(
PhabricatorUser $user,
PhabricatorUserEmail $email,
$allow_reassign = false) {
if ($user->getID()) {
throw new Exception(pht('User has already been created!'));
}
$is_reassign = false;
if ($email->getID()) {
if ($allow_reassign) {
if ($email->getIsPrimary()) {
throw new Exception(
pht('Primary email addresses can not be reassigned.'));
}
$is_reassign = true;
} else {
throw new Exception(pht('Email has already been created!'));
}
}
if (!PhabricatorUser::validateUsername($user->getUsername())) {
$valid = PhabricatorUser::describeValidUsername();
throw new Exception(pht('Username is invalid! %s', $valid));
}
// Always set a new user's email address to primary.
$email->setIsPrimary(1);
// If the primary address is already verified, also set the verified flag
// on the user themselves.
if ($email->getIsVerified()) {
$user->setIsEmailVerified(1);
}
$this->willAddEmail($email);
$user->openTransaction();
try {
$user->save();
$email->setUserPHID($user->getPHID());
$email->save();
} catch (AphrontDuplicateKeyQueryException $ex) {
// We might have written the user but failed to write the email; if
// so, erase the IDs we attached.
$user->setID(null);
$user->setPHID(null);
$user->killTransaction();
throw $ex;
}
if ($is_reassign) {
$log = PhabricatorUserLog::initializeNewLog(
$this->requireActor(),
$user->getPHID(),
PhabricatorReassignEmailUserLogType::LOGTYPE);
$log->setNewValue($email->getAddress());
$log->save();
}
$user->saveTransaction();
if ($email->getIsVerified()) {
$this->didVerifyEmail($user, $email);
}
id(new DiffusionRepositoryIdentityEngine())
->didUpdateEmailAddress($email->getAddress());
return $this;
}
/* -( Editing Roles )------------------------------------------------------ */
/**
* @task role
*/
public function makeSystemAgentUser(PhabricatorUser $user, $system_agent) {
$actor = $this->requireActor();
if (!$user->getID()) {
throw new Exception(pht('User has not been created yet!'));
}
$user->openTransaction();
$user->beginWriteLocking();
$user->reload();
if ($user->getIsSystemAgent() == $system_agent) {
$user->endWriteLocking();
$user->killTransaction();
return $this;
}
$user->setIsSystemAgent((int)$system_agent);
$user->save();
$user->endWriteLocking();
$user->saveTransaction();
return $this;
}
/**
* @task role
*/
public function makeMailingListUser(PhabricatorUser $user, $mailing_list) {
$actor = $this->requireActor();
if (!$user->getID()) {
throw new Exception(pht('User has not been created yet!'));
}
$user->openTransaction();
$user->beginWriteLocking();
$user->reload();
if ($user->getIsMailingList() == $mailing_list) {
$user->endWriteLocking();
$user->killTransaction();
return $this;
}
$user->setIsMailingList((int)$mailing_list);
$user->save();
$user->endWriteLocking();
$user->saveTransaction();
return $this;
}
/* -( Adding, Removing and Changing Email )-------------------------------- */
/**
* @task email
*/
public function addEmail(
PhabricatorUser $user,
PhabricatorUserEmail $email) {
$actor = $this->requireActor();
if (!$user->getID()) {
throw new Exception(pht('User has not been created yet!'));
}
if ($email->getID()) {
throw new Exception(pht('Email has already been created!'));
}
// Use changePrimaryEmail() to change primary email.
$email->setIsPrimary(0);
$email->setUserPHID($user->getPHID());
$this->willAddEmail($email);
$user->openTransaction();
$user->beginWriteLocking();
$user->reload();
try {
$email->save();
} catch (AphrontDuplicateKeyQueryException $ex) {
$user->endWriteLocking();
$user->killTransaction();
throw $ex;
}
$log = PhabricatorUserLog::initializeNewLog(
$actor,
$user->getPHID(),
PhabricatorAddEmailUserLogType::LOGTYPE);
$log->setNewValue($email->getAddress());
$log->save();
$user->endWriteLocking();
$user->saveTransaction();
id(new DiffusionRepositoryIdentityEngine())
->didUpdateEmailAddress($email->getAddress());
return $this;
}
/**
* @task email
*/
public function removeEmail(
PhabricatorUser $user,
PhabricatorUserEmail $email) {
$actor = $this->requireActor();
if (!$user->getID()) {
throw new Exception(pht('User has not been created yet!'));
}
if (!$email->getID()) {
throw new Exception(pht('Email has not been created yet!'));
}
$user->openTransaction();
$user->beginWriteLocking();
$user->reload();
$email->reload();
if ($email->getIsPrimary()) {
throw new Exception(pht("Can't remove primary email!"));
}
if ($email->getUserPHID() != $user->getPHID()) {
throw new Exception(pht('Email not owned by user!'));
}
$destruction_engine = id(new PhabricatorDestructionEngine())
->setWaitToFinalizeDestruction(true)
->destroyObject($email);
$log = PhabricatorUserLog::initializeNewLog(
$actor,
$user->getPHID(),
PhabricatorRemoveEmailUserLogType::LOGTYPE);
$log->setOldValue($email->getAddress());
$log->save();
$user->endWriteLocking();
$user->saveTransaction();
$this->revokePasswordResetLinks($user);
$destruction_engine->finalizeDestruction();
return $this;
}
/**
* @task email
*/
public function changePrimaryEmail(
PhabricatorUser $user,
PhabricatorUserEmail $email) {
$actor = $this->requireActor();
if (!$user->getID()) {
throw new Exception(pht('User has not been created yet!'));
}
if (!$email->getID()) {
throw new Exception(pht('Email has not been created yet!'));
}
$user->openTransaction();
$user->beginWriteLocking();
$user->reload();
$email->reload();
if ($email->getUserPHID() != $user->getPHID()) {
throw new Exception(pht('User does not own email!'));
}
if ($email->getIsPrimary()) {
throw new Exception(pht('Email is already primary!'));
}
if (!$email->getIsVerified()) {
throw new Exception(pht('Email is not verified!'));
}
$old_primary = $user->loadPrimaryEmail();
if ($old_primary) {
$old_primary->setIsPrimary(0);
$old_primary->save();
}
$email->setIsPrimary(1);
$email->save();
// If the user doesn't have the verified flag set on their account
// yet, set it. We've made sure the email is verified above. See
// T12635 for discussion.
if (!$user->getIsEmailVerified()) {
$user->setIsEmailVerified(1);
$user->save();
}
$log = PhabricatorUserLog::initializeNewLog(
$actor,
$user->getPHID(),
PhabricatorPrimaryEmailUserLogType::LOGTYPE);
$log->setOldValue($old_primary ? $old_primary->getAddress() : null);
$log->setNewValue($email->getAddress());
$log->save();
$user->endWriteLocking();
$user->saveTransaction();
if ($old_primary) {
$old_primary->sendOldPrimaryEmail($user, $email);
}
$email->sendNewPrimaryEmail($user);
$this->revokePasswordResetLinks($user);
return $this;
}
/**
* Verify a user's email address.
*
* This verifies an individual email address. If the address is the user's
* primary address and their account was not previously verified, their
* account is marked as email verified.
*
* @task email
*/
public function verifyEmail(
PhabricatorUser $user,
PhabricatorUserEmail $email) {
$actor = $this->requireActor();
if (!$user->getID()) {
throw new Exception(pht('User has not been created yet!'));
}
if (!$email->getID()) {
throw new Exception(pht('Email has not been created yet!'));
}
$user->openTransaction();
$user->beginWriteLocking();
$user->reload();
$email->reload();
if ($email->getUserPHID() != $user->getPHID()) {
throw new Exception(pht('User does not own email!'));
}
if (!$email->getIsVerified()) {
$email->setIsVerified(1);
$email->save();
$log = PhabricatorUserLog::initializeNewLog(
$actor,
$user->getPHID(),
PhabricatorVerifyEmailUserLogType::LOGTYPE);
$log->setNewValue($email->getAddress());
$log->save();
}
if (!$user->getIsEmailVerified()) {
// If the user just verified their primary email address, mark their
// account as email verified.
$user_primary = $user->loadPrimaryEmail();
if ($user_primary->getID() == $email->getID()) {
$user->setIsEmailVerified(1);
$user->save();
}
}
$user->endWriteLocking();
$user->saveTransaction();
$this->didVerifyEmail($user, $email);
}
/**
* Reassign an unverified email address.
*/
public function reassignEmail(
PhabricatorUser $user,
PhabricatorUserEmail $email) {
$actor = $this->requireActor();
if (!$user->getID()) {
throw new Exception(pht('User has not been created yet!'));
}
if (!$email->getID()) {
throw new Exception(pht('Email has not been created yet!'));
}
$user->openTransaction();
$user->beginWriteLocking();
$user->reload();
$email->reload();
$old_user = $email->getUserPHID();
if ($old_user != $user->getPHID()) {
if ($email->getIsVerified()) {
throw new Exception(
pht('Verified email addresses can not be reassigned.'));
}
if ($email->getIsPrimary()) {
throw new Exception(
pht('Primary email addresses can not be reassigned.'));
}
$email->setUserPHID($user->getPHID());
$email->save();
$log = PhabricatorUserLog::initializeNewLog(
$actor,
$user->getPHID(),
PhabricatorReassignEmailUserLogType::LOGTYPE);
$log->setNewValue($email->getAddress());
$log->save();
}
$user->endWriteLocking();
$user->saveTransaction();
id(new DiffusionRepositoryIdentityEngine())
->didUpdateEmailAddress($email->getAddress());
}
/* -( Internals )---------------------------------------------------------- */
/**
* @task internal
*/
private function willAddEmail(PhabricatorUserEmail $email) {
// Hard check before write to prevent creation of disallowed email
// addresses. Normally, the application does checks and raises more
// user friendly errors for us, but we omit the courtesy checks on some
// pathways like administrative scripts for simplicity.
if (!PhabricatorUserEmail::isValidAddress($email->getAddress())) {
throw new Exception(PhabricatorUserEmail::describeValidAddresses());
}
if (!PhabricatorUserEmail::isAllowedAddress($email->getAddress())) {
throw new Exception(PhabricatorUserEmail::describeAllowedAddresses());
}
$application_email = id(new PhabricatorMetaMTAApplicationEmailQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withAddresses(array($email->getAddress()))
->executeOne();
if ($application_email) {
throw new Exception($application_email->getInUseMessage());
}
}
public function revokePasswordResetLinks(PhabricatorUser $user) {
// Revoke any outstanding password reset links. If an attacker compromises
// an account, changes the email address, and sends themselves a password
// reset link, it could otherwise remain live for a short period of time
// and allow them to compromise the account again later.
PhabricatorAuthTemporaryToken::revokeTokens(
$user,
array($user->getPHID()),
array(
PhabricatorAuthOneTimeLoginTemporaryTokenType::TOKENTYPE,
PhabricatorAuthPasswordResetTemporaryTokenType::TOKENTYPE,
));
}
private function didVerifyEmail(
PhabricatorUser $user,
PhabricatorUserEmail $email) {
$event_type = PhabricatorEventType::TYPE_AUTH_DIDVERIFYEMAIL;
$event_data = array(
'user' => $user,
'email' => $email,
);
$event = id(new PhabricatorEvent($event_type, $event_data))
->setUser($user);
PhutilEventEngine::dispatchEvent($event);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/editor/PhabricatorUserTransactionEditor.php | src/applications/people/editor/PhabricatorUserTransactionEditor.php | <?php
final class PhabricatorUserTransactionEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorPeopleApplication';
}
public function getEditorObjectsDescription() {
return pht('Users');
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
protected function getMailTo(PhabricatorLiskDAO $object) {
return array();
}
protected function getMailCC(PhabricatorLiskDAO $object) {
return array();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/editor/PhabricatorUserEditEngine.php | src/applications/people/editor/PhabricatorUserEditEngine.php | <?php
final class PhabricatorUserEditEngine
extends PhabricatorEditEngine {
const ENGINECONST = 'people.user';
public function isEngineConfigurable() {
return false;
}
public function getEngineName() {
return pht('Users');
}
public function getSummaryHeader() {
return pht('Configure User Forms');
}
public function getSummaryText() {
return pht('Configure creation and editing forms for users.');
}
public function getEngineApplicationClass() {
return 'PhabricatorPeopleApplication';
}
protected function newEditableObject() {
return new PhabricatorUser();
}
protected function newObjectQuery() {
return id(new PhabricatorPeopleQuery());
}
protected function getObjectCreateTitleText($object) {
return pht('Create New User');
}
protected function getObjectEditTitleText($object) {
return pht('Edit User: %s', $object->getUsername());
}
protected function getObjectEditShortText($object) {
return $object->getMonogram();
}
protected function getObjectCreateShortText() {
return pht('Create User');
}
protected function getObjectName() {
return pht('User');
}
protected function getObjectViewURI($object) {
return $object->getURI();
}
protected function getCreateNewObjectPolicy() {
// At least for now, forbid creating new users via EditEngine. This is
// primarily enforcing that "user.edit" can not create users via the API.
return PhabricatorPolicies::POLICY_NOONE;
}
protected function buildCustomEditFields($object) {
return array(
id(new PhabricatorBoolEditField())
->setKey('disabled')
->setOptions(pht('Active'), pht('Disabled'))
->setLabel(pht('Disabled'))
->setDescription(pht('Disable the user.'))
->setTransactionType(PhabricatorUserDisableTransaction::TRANSACTIONTYPE)
->setIsFormField(false)
->setConduitDescription(pht('Disable or enable the user.'))
->setConduitTypeDescription(pht('True to disable the user.'))
->setValue($object->getIsDisabled()),
id(new PhabricatorBoolEditField())
->setKey('approved')
->setOptions(pht('Approved'), pht('Unapproved'))
->setLabel(pht('Approved'))
->setDescription(pht('Approve the user.'))
->setTransactionType(PhabricatorUserApproveTransaction::TRANSACTIONTYPE)
->setIsFormField(false)
->setConduitDescription(pht('Approve or reject the user.'))
->setConduitTypeDescription(pht('True to approve the user.'))
->setValue($object->getIsApproved()),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php | src/applications/people/editor/__tests__/PhabricatorUserEditorTestCase.php | <?php
final class PhabricatorUserEditorTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testRegistrationEmailOK() {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('auth.email-domains', array('example.com'));
$this->registerUser(
'PhabricatorUserEditorTestCaseOK',
'PhabricatorUserEditorTest@example.com');
$this->assertTrue(true);
}
public function testRegistrationEmailInvalid() {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('auth.email-domains', array('example.com'));
$prefix = str_repeat('a', PhabricatorUserEmail::MAX_ADDRESS_LENGTH);
$email = $prefix.'@evil.com@example.com';
try {
$this->registerUser('PhabricatorUserEditorTestCaseInvalid', $email);
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertTrue($caught instanceof Exception);
}
public function testRegistrationEmailDomain() {
$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('auth.email-domains', array('example.com'));
$caught = null;
try {
$this->registerUser(
'PhabricatorUserEditorTestCaseDomain',
'PhabricatorUserEditorTest@whitehouse.gov');
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertTrue($caught instanceof Exception);
}
public function testRegistrationEmailApplicationEmailCollide() {
$app_email = 'bugs@whitehouse.gov';
$app_email_object =
PhabricatorMetaMTAApplicationEmail::initializeNewAppEmail(
$this->generateNewTestUser());
$app_email_object->setAddress($app_email);
$app_email_object->setApplicationPHID('test');
$app_email_object->save();
$caught = null;
try {
$this->registerUser(
'PhabricatorUserEditorTestCaseDomain',
$app_email);
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertTrue($caught instanceof Exception);
}
private function registerUser($username, $email) {
$user = id(new PhabricatorUser())
->setUsername($username)
->setRealname($username);
$email = id(new PhabricatorUserEmail())
->setAddress($email)
->setIsVerified(0);
id(new PhabricatorUserEditor())
->setActor($user)
->createNewUser($user, $email);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/xaction/PhabricatorUserApproveTransaction.php | src/applications/people/xaction/PhabricatorUserApproveTransaction.php | <?php
final class PhabricatorUserApproveTransaction
extends PhabricatorUserTransactionType {
const TRANSACTIONTYPE = 'user.approve';
public function generateOldValue($object) {
return (bool)$object->getIsApproved();
}
public function generateNewValue($object, $value) {
return (bool)$value;
}
public function applyInternalEffects($object, $value) {
$object->setIsApproved((int)$value);
}
public function applyExternalEffects($object, $value) {
$user = $object;
$actor = $this->getActor();
$title = pht(
'%s Account "%s" Approved',
PlatformSymbols::getPlatformServerName(),
$user->getUsername());
$body = sprintf(
"%s\n\n %s\n\n",
pht(
'Your %s account (%s) has been approved by %s. You can '.
'login here:',
PlatformSymbols::getPlatformServerName(),
$user->getUsername(),
$actor->getUsername()),
PhabricatorEnv::getProductionURI('/'));
$mail = id(new PhabricatorMetaMTAMail())
->addTos(array($user->getPHID()))
->addCCs(array($actor->getPHID()))
->setSubject(
pht(
'[%s] %s',
PlatformSymbols::getPlatformServerName(),
$title))
->setForceDelivery(true)
->setBody($body)
->saveAndSend();
}
public function getTitle() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s approved this user.',
$this->renderAuthor());
} else {
return pht(
'%s rejected this user.',
$this->renderAuthor());
}
}
public function shouldHideForFeed() {
return true;
}
public function validateTransactions($object, array $xactions) {
$actor = $this->getActor();
$errors = array();
foreach ($xactions as $xaction) {
$is_approved = (bool)$object->getIsApproved();
if ((bool)$xaction->getNewValue() === $is_approved) {
continue;
}
$is_admin = $actor->getIsAdmin();
$is_omnipotent = $actor->isOmnipotent();
if (!$is_admin && !$is_omnipotent) {
$errors[] = $this->newInvalidError(
pht('You must be an administrator to approve users.'));
}
}
return $errors;
}
public function getRequiredCapabilities(
$object,
PhabricatorApplicationTransaction $xaction) {
// Unlike normal user edits, approvals require admin permissions, which
// is enforced by validateTransactions().
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/xaction/PhabricatorUserNotifyTransaction.php | src/applications/people/xaction/PhabricatorUserNotifyTransaction.php | <?php
final class PhabricatorUserNotifyTransaction
extends PhabricatorUserTransactionType {
const TRANSACTIONTYPE = 'notify';
public function generateOldValue($object) {
return null;
}
public function generateNewValue($object, $value) {
return $value;
}
public function getTitle() {
return pht(
'%s sent this user a test notification.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return $this->getNewValue();
}
public function shouldHideForNotifications() {
return false;
}
public function shouldHideForFeed() {
return true;
}
public function shouldHideForMail() {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/xaction/PhabricatorUserDisableTransaction.php | src/applications/people/xaction/PhabricatorUserDisableTransaction.php | <?php
final class PhabricatorUserDisableTransaction
extends PhabricatorUserTransactionType {
const TRANSACTIONTYPE = 'user.disable';
public function generateOldValue($object) {
return (bool)$object->getIsDisabled();
}
public function generateNewValue($object, $value) {
return (bool)$value;
}
public function applyInternalEffects($object, $value) {
$object->setIsDisabled((int)$value);
}
public function getTitle() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s disabled this user.',
$this->renderAuthor());
} else {
return pht(
'%s enabled this user.',
$this->renderAuthor());
}
}
public function shouldHideForFeed() {
// Don't publish feed stories about disabling users, since this can be
// a sensitive action.
return true;
}
public function validateTransactions($object, array $xactions) {
$errors = array();
foreach ($xactions as $xaction) {
$is_disabled = (bool)$object->getIsDisabled();
if ((bool)$xaction->getNewValue() === $is_disabled) {
continue;
}
// You must have the "Can Disable Users" permission to disable a user.
$this->requireApplicationCapability(
PeopleDisableUsersCapability::CAPABILITY);
if ($this->getActingAsPHID() === $object->getPHID()) {
$errors[] = $this->newInvalidError(
pht('You can not enable or disable your own account.'));
}
}
return $errors;
}
public function getRequiredCapabilities(
$object,
PhabricatorApplicationTransaction $xaction) {
// You do not need to be able to edit users to disable them. Instead, this
// requirement is replaced with a requirement that you have the "Can
// Disable Users" permission.
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/xaction/PhabricatorUserEmpowerTransaction.php | src/applications/people/xaction/PhabricatorUserEmpowerTransaction.php | <?php
final class PhabricatorUserEmpowerTransaction
extends PhabricatorUserTransactionType {
const TRANSACTIONTYPE = 'user.admin';
public function generateOldValue($object) {
return (bool)$object->getIsAdmin();
}
public function generateNewValue($object, $value) {
return (bool)$value;
}
public function applyInternalEffects($object, $value) {
$object->setIsAdmin((int)$value);
}
public function validateTransactions($object, array $xactions) {
$user = $object;
$actor = $this->getActor();
$errors = array();
foreach ($xactions as $xaction) {
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
if ($old === $new) {
continue;
}
if ($user->getPHID() === $actor->getPHID()) {
$errors[] = $this->newInvalidError(
pht('After a time, your efforts fail. You can not adjust your own '.
'status as an administrator.'), $xaction);
}
$is_admin = $actor->getIsAdmin();
$is_omnipotent = $actor->isOmnipotent();
if (!$is_admin && !$is_omnipotent) {
$errors[] = $this->newInvalidError(
pht('You must be an administrator to create administrators.'),
$xaction);
}
}
return $errors;
}
public function getTitle() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s empowered this user as an administrator.',
$this->renderAuthor());
} else {
return pht(
'%s defrocked this user.',
$this->renderAuthor());
}
}
public function getTitleForFeed() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s empowered %s as an administrator.',
$this->renderAuthor(),
$this->renderObject());
} else {
return pht(
'%s defrocked %s.',
$this->renderAuthor(),
$this->renderObject());
}
}
public function getRequiredCapabilities(
$object,
PhabricatorApplicationTransaction $xaction) {
// Unlike normal user edits, admin promotions require admin
// permissions, which is enforced by validateTransactions().
return null;
}
public function shouldTryMFA(
$object,
PhabricatorApplicationTransaction $xaction) {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/xaction/PhabricatorUserTransactionType.php | src/applications/people/xaction/PhabricatorUserTransactionType.php | <?php
abstract class PhabricatorUserTransactionType
extends PhabricatorModularTransactionType {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/xaction/PhabricatorUserUsernameTransaction.php | src/applications/people/xaction/PhabricatorUserUsernameTransaction.php | <?php
final class PhabricatorUserUsernameTransaction
extends PhabricatorUserTransactionType {
const TRANSACTIONTYPE = 'user.rename';
public function generateOldValue($object) {
return $object->getUsername();
}
public function generateNewValue($object, $value) {
return $value;
}
public function applyInternalEffects($object, $value) {
$object->setUsername($value);
}
public function applyExternalEffects($object, $value) {
$actor = $this->getActor();
$user = $object;
$old_username = $this->getOldValue();
$new_username = $this->getNewValue();
// The SSH key cache currently includes usernames, so dirty it. See T12554
// for discussion.
PhabricatorAuthSSHKeyQuery::deleteSSHKeyCache();
id(new PhabricatorPeopleUsernameMailEngine())
->setSender($actor)
->setRecipient($object)
->setOldUsername($old_username)
->setNewUsername($new_username)
->sendMail();
}
public function getTitle() {
return pht(
'%s renamed this user from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function getTitleForFeed() {
return pht(
'%s renamed %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$actor = $this->getActor();
$errors = array();
foreach ($xactions as $xaction) {
$new = $xaction->getNewValue();
$old = $xaction->getOldValue();
if ($old === $new) {
continue;
}
if (!$actor->getIsAdmin()) {
$errors[] = $this->newInvalidError(
pht('You must be an administrator to rename users.'));
}
if (!strlen($new)) {
$errors[] = $this->newInvalidError(
pht('New username is required.'),
$xaction);
} else if (!PhabricatorUser::validateUsername($new)) {
$errors[] = $this->newInvalidError(
PhabricatorUser::describeValidUsername(),
$xaction);
}
$user = id(new PhabricatorPeopleQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withUsernames(array($new))
->executeOne();
if ($user) {
// See T13446. We may be changing the letter case of a username, which
// is a perfectly fine edit.
$is_self = ($user->getPHID() === $object->getPHID());
if (!$is_self) {
$errors[] = $this->newInvalidError(
pht(
'Another user already has the username "%s".',
$new),
$xaction);
}
}
}
return $errors;
}
public function getRequiredCapabilities(
$object,
PhabricatorApplicationTransaction $xaction) {
// Unlike normal user edits, renames require admin permissions, which
// is enforced by validateTransactions().
return null;
}
public function shouldTryMFA(
$object,
PhabricatorApplicationTransaction $xaction) {
return true;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php | src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php | <?php
final class PhabricatorPeopleRevisionsProfileMenuItem
extends PhabricatorProfileMenuItem {
const MENUITEMKEY = 'people.revisions';
public function getMenuItemTypeName() {
return pht('Revisions');
}
private function getDefaultName() {
return pht('Revisions');
}
public function getDisplayName(
PhabricatorProfileMenuItemConfiguration $config) {
$default = $this->getDefaultName();
return $this->getNameFromConfig($config, $default);
}
public function canHideMenuItem(
PhabricatorProfileMenuItemConfiguration $config) {
return true;
}
public function buildEditEngineFields(
PhabricatorProfileMenuItemConfiguration $config) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setPlaceholder($this->getDefaultName())
->setValue($config->getMenuItemProperty('name')),
);
}
protected function newMenuItemViewList(
PhabricatorProfileMenuItemConfiguration $config) {
$user = $config->getProfileObject();
$id = $user->getID();
$item = $this->newItemView()
->setURI("/people/revisions/{$id}/")
->setName($this->getDisplayName($config))
->setIcon('fa-gear');
return array(
$item,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/menuitem/PhabricatorPeopleDetailsProfileMenuItem.php | src/applications/people/menuitem/PhabricatorPeopleDetailsProfileMenuItem.php | <?php
final class PhabricatorPeopleDetailsProfileMenuItem
extends PhabricatorProfileMenuItem {
const MENUITEMKEY = 'people.details';
public function getMenuItemTypeName() {
return pht('User Details');
}
private function getDefaultName() {
return pht('User Details');
}
public function getDisplayName(
PhabricatorProfileMenuItemConfiguration $config) {
$default = $this->getDefaultName();
return $this->getNameFromConfig($config, $default);
}
public function buildEditEngineFields(
PhabricatorProfileMenuItemConfiguration $config) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setPlaceholder($this->getDefaultName())
->setValue($config->getMenuProperty('name')),
);
}
protected function newMenuItemViewList(
PhabricatorProfileMenuItemConfiguration $config) {
$user = $config->getProfileObject();
$uri = urisprintf(
'/p/%s/',
$user->getUsername());
$item = $this->newItemView()
->setURI($uri)
->setName(pht('Profile'))
->setIcon('fa-user');
return array(
$item,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php | src/applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php | <?php
final class PhabricatorPeopleManageProfileMenuItem
extends PhabricatorProfileMenuItem {
const MENUITEMKEY = 'people.manage';
public function getMenuItemTypeName() {
return pht('Manage User');
}
private function getDefaultName() {
return pht('Manage');
}
public function getDisplayName(
PhabricatorProfileMenuItemConfiguration $config) {
$default = $this->getDefaultName();
return $this->getNameFromConfig($config, $default);
}
public function canHideMenuItem(
PhabricatorProfileMenuItemConfiguration $config) {
return false;
}
public function buildEditEngineFields(
PhabricatorProfileMenuItemConfiguration $config) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setPlaceholder($this->getDefaultName())
->setValue($config->getMenuItemProperty('name')),
);
}
protected function newMenuItemViewList(
PhabricatorProfileMenuItemConfiguration $config) {
$user = $config->getProfileObject();
$id = $user->getID();
$item = $this->newItemView()
->setURI("/people/manage/{$id}/")
->setName($this->getDisplayName($config))
->setIcon('fa-gears');
return array(
$item,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/menuitem/PhabricatorPeoplePictureProfileMenuItem.php | src/applications/people/menuitem/PhabricatorPeoplePictureProfileMenuItem.php | <?php
final class PhabricatorPeoplePictureProfileMenuItem
extends PhabricatorProfileMenuItem {
const MENUITEMKEY = 'people.picture';
public function getMenuItemTypeName() {
return pht('User Picture');
}
private function getDefaultName() {
return pht('User Picture');
}
public function getDisplayName(
PhabricatorProfileMenuItemConfiguration $config) {
return $this->getDefaultName();
}
public function canHideMenuItem(
PhabricatorProfileMenuItemConfiguration $config) {
return false;
}
public function buildEditEngineFields(
PhabricatorProfileMenuItemConfiguration $config) {
return array();
}
protected function newMenuItemViewList(
PhabricatorProfileMenuItemConfiguration $config) {
$user = $config->getProfileObject();
$picture = $user->getProfileImageURI();
$name = $user->getUsername();
$item = $this->newItemView()
->setDisabled($user->getIsDisabled());
$item->newProfileImage($picture);
return array(
$item,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/menuitem/PhabricatorPeopleCommitsProfileMenuItem.php | src/applications/people/menuitem/PhabricatorPeopleCommitsProfileMenuItem.php | <?php
final class PhabricatorPeopleCommitsProfileMenuItem
extends PhabricatorProfileMenuItem {
const MENUITEMKEY = 'people.commits';
public function getMenuItemTypeName() {
return pht('Commits');
}
private function getDefaultName() {
return pht('Commits');
}
public function getDisplayName(
PhabricatorProfileMenuItemConfiguration $config) {
$default = $this->getDefaultName();
return $this->getNameFromConfig($config, $default);
}
public function canHideMenuItem(
PhabricatorProfileMenuItemConfiguration $config) {
return true;
}
public function buildEditEngineFields(
PhabricatorProfileMenuItemConfiguration $config) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setPlaceholder($this->getDefaultName())
->setValue($config->getMenuItemProperty('name')),
);
}
protected function newMenuItemViewList(
PhabricatorProfileMenuItemConfiguration $config) {
$user = $config->getProfileObject();
$id = $user->getID();
$item = $this->newItemView()
->setURI("/people/commits/{$id}/")
->setName($this->getDisplayName($config))
->setIcon('fa-code');
return array(
$item,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php | src/applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php | <?php
final class PhabricatorPeopleTasksProfileMenuItem
extends PhabricatorProfileMenuItem {
const MENUITEMKEY = 'people.tasks';
public function getMenuItemTypeName() {
return pht('Tasks');
}
private function getDefaultName() {
return pht('Tasks');
}
public function getDisplayName(
PhabricatorProfileMenuItemConfiguration $config) {
$default = $this->getDefaultName();
return $this->getNameFromConfig($config, $default);
}
public function canHideMenuItem(
PhabricatorProfileMenuItemConfiguration $config) {
return true;
}
public function buildEditEngineFields(
PhabricatorProfileMenuItemConfiguration $config) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setPlaceholder($this->getDefaultName())
->setValue($config->getMenuItemProperty('name')),
);
}
protected function newMenuItemViewList(
PhabricatorProfileMenuItemConfiguration $config) {
$user = $config->getProfileObject();
$id = $user->getID();
$item = $this->newItemView()
->setURI("/people/tasks/{$id}/")
->setName($this->getDisplayName($config))
->setIcon('fa-anchor');
return array(
$item,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/menuitem/PhabricatorPeopleBadgesProfileMenuItem.php | src/applications/people/menuitem/PhabricatorPeopleBadgesProfileMenuItem.php | <?php
final class PhabricatorPeopleBadgesProfileMenuItem
extends PhabricatorProfileMenuItem {
const MENUITEMKEY = 'people.badges';
public function getMenuItemTypeName() {
return pht('Badges');
}
private function getDefaultName() {
return pht('Badges');
}
public function getDisplayName(
PhabricatorProfileMenuItemConfiguration $config) {
$default = $this->getDefaultName();
return $this->getNameFromConfig($config, $default);
}
public function canHideMenuItem(
PhabricatorProfileMenuItemConfiguration $config) {
return true;
}
public function buildEditEngineFields(
PhabricatorProfileMenuItemConfiguration $config) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setPlaceholder($this->getDefaultName())
->setValue($config->getMenuItemProperty('name')),
);
}
protected function newMenuItemViewList(
PhabricatorProfileMenuItemConfiguration $config) {
$user = $config->getProfileObject();
$id = $user->getID();
$item = $this->newItemView()
->setURI("/people/badges/{$id}/")
->setName($this->getDisplayName($config))
->setIcon('fa-trophy');
return array(
$item,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/guidance/PhabricatorPeopleCreateGuidanceContext.php | src/applications/people/guidance/PhabricatorPeopleCreateGuidanceContext.php | <?php
final class PhabricatorPeopleCreateGuidanceContext
extends PhabricatorGuidanceContext {}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/searchfield/PhabricatorUsersSearchField.php | src/applications/people/searchfield/PhabricatorUsersSearchField.php | <?php
final class PhabricatorUsersSearchField
extends PhabricatorSearchTokenizerField {
protected function getDefaultValue() {
return array();
}
protected function getValueFromRequest(AphrontRequest $request, $key) {
return $this->getUsersFromRequest($request, $key);
}
protected function newDatasource() {
return new PhabricatorPeopleUserFunctionDatasource();
}
protected function newConduitParameterType() {
return new ConduitUserListParameterType();
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/application/PhabricatorPeopleApplication.php | src/applications/people/application/PhabricatorPeopleApplication.php | <?php
final class PhabricatorPeopleApplication extends PhabricatorApplication {
public function getName() {
return pht('People');
}
public function getShortDescription() {
return pht('User Accounts and Profiles');
}
public function getBaseURI() {
return '/people/';
}
public function getTitleGlyph() {
return "\xE2\x99\x9F";
}
public function getIcon() {
return 'fa-users';
}
public function isPinnedByDefault(PhabricatorUser $viewer) {
return $viewer->getIsAdmin();
}
public function getFlavorText() {
return pht('Sort of a social utility.');
}
public function getApplicationGroup() {
return self::GROUP_UTILITIES;
}
public function canUninstall() {
return false;
}
public function getRoutes() {
return array(
'/people/' => array(
$this->getQueryRoutePattern() => 'PhabricatorPeopleListController',
'logs/' => array(
$this->getQueryRoutePattern() => 'PhabricatorPeopleLogsController',
'(?P<id>\d+)/' => 'PhabricatorPeopleLogViewController',
),
'invite/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorPeopleInviteListController',
'send/'
=> 'PhabricatorPeopleInviteSendController',
),
'approve/(?P<id>[1-9]\d*)/(?:via/(?P<via>[^/]+)/)?'
=> 'PhabricatorPeopleApproveController',
'(?P<via>disapprove)/(?P<id>[1-9]\d*)/'
=> 'PhabricatorPeopleDisableController',
'(?P<via>disable)/(?P<id>[1-9]\d*)/'
=> 'PhabricatorPeopleDisableController',
'empower/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleEmpowerController',
'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleDeleteController',
'rename/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleRenameController',
'welcome/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleWelcomeController',
'create/' => 'PhabricatorPeopleCreateController',
'new/(?P<type>[^/]+)/' => 'PhabricatorPeopleNewController',
'editprofile/(?P<id>[1-9]\d*)/' =>
'PhabricatorPeopleProfileEditController',
'badges/(?P<id>[1-9]\d*)/' =>
'PhabricatorPeopleProfileBadgesController',
'tasks/(?P<id>[1-9]\d*)/' =>
'PhabricatorPeopleProfileTasksController',
'commits/(?P<id>[1-9]\d*)/' =>
'PhabricatorPeopleProfileCommitsController',
'revisions/(?P<id>[1-9]\d*)/' =>
'PhabricatorPeopleProfileRevisionsController',
'picture/(?P<id>[1-9]\d*)/' =>
'PhabricatorPeopleProfilePictureController',
'manage/(?P<id>[1-9]\d*)/' =>
'PhabricatorPeopleProfileManageController',
),
'/p/(?P<username>[\w._-]+)/' => array(
'' => 'PhabricatorPeopleProfileViewController',
),
);
}
public function getRemarkupRules() {
return array(
new PhabricatorMentionRemarkupRule(),
);
}
protected function getCustomCapabilities() {
return array(
PeopleCreateUsersCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_ADMIN,
),
PeopleDisableUsersCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_ADMIN,
),
PeopleBrowseUserDirectoryCapability::CAPABILITY => array(),
);
}
public function getApplicationSearchDocumentTypes() {
return array(
PhabricatorPeopleUserPHIDType::TYPECONST,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/policyrule/PhabricatorAdministratorsPolicyRule.php | src/applications/people/policyrule/PhabricatorAdministratorsPolicyRule.php | <?php
final class PhabricatorAdministratorsPolicyRule extends PhabricatorPolicyRule {
public function getRuleDescription() {
return pht('administrators');
}
public function applyRule(
PhabricatorUser $viewer,
$value,
PhabricatorPolicyInterface $object) {
return $viewer->getIsAdmin();
}
public function getValueControlType() {
return self::CONTROL_TYPE_NONE;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/policyrule/PhabricatorUsersPolicyRule.php | src/applications/people/policyrule/PhabricatorUsersPolicyRule.php | <?php
final class PhabricatorUsersPolicyRule extends PhabricatorPolicyRule {
public function getRuleDescription() {
return pht('users');
}
public function applyRule(
PhabricatorUser $viewer,
$value,
PhabricatorPolicyInterface $object) {
foreach ($value as $phid) {
if ($phid == $viewer->getPHID()) {
return true;
}
}
return false;
}
public function getValueControlType() {
return self::CONTROL_TYPE_TOKENIZER;
}
public function getValueControlTemplate() {
return $this->getDatasourceTemplate(new PhabricatorPeopleDatasource());
}
public function getRuleOrder() {
return 100;
}
public function getValueForStorage($value) {
PhutilTypeSpec::newFromString('list<string>')->check($value);
return array_values($value);
}
public function getValueForDisplay(PhabricatorUser $viewer, $value) {
if (!$value) {
return array();
}
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($value)
->execute();
return mpull($handles, 'getFullName', 'getPHID');
}
public function ruleHasEffect($value) {
return (bool)$value;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php | src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php | <?php
final class PhabricatorPeopleTestDataGenerator
extends PhabricatorTestDataGenerator {
const GENERATORKEY = 'users';
public function getGeneratorName() {
return pht('User Accounts');
}
public function generateObject() {
while (true) {
try {
$realname = $this->generateRealname();
$username = $this->generateUsername($realname);
$email = $this->generateEmail($username);
$admin = PhabricatorUser::getOmnipotentUser();
$user = new PhabricatorUser();
$user->setUsername($username);
$user->setRealname($realname);
$email_object = id(new PhabricatorUserEmail())
->setAddress($email)
->setIsVerified(1);
id(new PhabricatorUserEditor())
->setActor($admin)
->createNewUser($user, $email_object);
return $user;
} catch (AphrontDuplicateKeyQueryException $ex) {}
}
}
protected function generateRealname() {
$realname_generator = new PhutilRealNameContextFreeGrammar();
$random_real_name = $realname_generator->generate();
return $random_real_name;
}
protected function generateUsername($random_real_name) {
$name = strtolower($random_real_name);
$name = preg_replace('/[^a-z]/s' , ' ', $name);
$name = preg_replace('/\s+/', ' ', $name);
$words = explode(' ', $name);
$random = rand(0, 4);
$reduced = '';
if ($random == 0) {
foreach ($words as $w) {
if ($w == end($words)) {
$reduced .= $w;
} else {
$reduced .= $w[0];
}
}
} else if ($random == 1) {
foreach ($words as $w) {
if ($w == $words[0]) {
$reduced .= $w;
} else {
$reduced .= $w[0];
}
}
} else if ($random == 2) {
foreach ($words as $w) {
if ($w == $words[0] || $w == end($words)) {
$reduced .= $w;
} else {
$reduced .= $w[0];
}
}
} else if ($random == 3) {
foreach ($words as $w) {
if ($w == $words[0] || $w == end($words)) {
$reduced .= $w;
} else {
$reduced .= $w[0].'.';
}
}
} else if ($random == 4) {
foreach ($words as $w) {
if ($w == $words[0] || $w == end($words)) {
$reduced .= $w;
} else {
$reduced .= $w[0].'_';
}
}
}
$random1 = rand(0, 4);
if ($random1 >= 1) {
$reduced = ucfirst($reduced);
}
$username = $reduced;
return $username;
}
protected function generateEmail($username) {
$default_email_domain = 'example.com';
$email = $username.'@'.$default_email_domain;
return $email;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/garbagecollector/PeopleUserLogGarbageCollector.php | src/applications/people/garbagecollector/PeopleUserLogGarbageCollector.php | <?php
final class PeopleUserLogGarbageCollector
extends PhabricatorGarbageCollector {
const COLLECTORCONST = 'user.logs';
public function getCollectorName() {
return pht('User Activity Logs');
}
public function getDefaultRetentionPolicy() {
return phutil_units('180 days in seconds');
}
protected function collectGarbage() {
$table = new PhabricatorUserLog();
$conn_w = $table->establishConnection('w');
queryfx(
$conn_w,
'DELETE FROM %T WHERE dateCreated < %d LIMIT 100',
$table->getTableName(),
$this->getGarbageEpoch());
return ($conn_w->getAffectedRows() == 100);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/view/PhabricatorUserLogView.php | src/applications/people/view/PhabricatorUserLogView.php | <?php
final class PhabricatorUserLogView extends AphrontView {
private $logs;
private $searchBaseURI;
public function setSearchBaseURI($search_base_uri) {
$this->searchBaseURI = $search_base_uri;
return $this;
}
public function setLogs(array $logs) {
assert_instances_of($logs, 'PhabricatorUserLog');
$this->logs = $logs;
return $this;
}
public function render() {
$logs = $this->logs;
$viewer = $this->getUser();
$phids = array();
foreach ($logs as $log) {
$phids[] = $log->getActorPHID();
$phids[] = $log->getUserPHID();
}
$handles = $viewer->loadHandles($phids);
$types = PhabricatorUserLogType::getAllLogTypes();
$types = mpull($types, 'getLogTypeName', 'getLogTypeKey');
$base_uri = $this->searchBaseURI;
$viewer_phid = $viewer->getPHID();
$rows = array();
foreach ($logs as $log) {
// Events such as "Login Failure" will not have an associated session.
$session = $log->getSession();
if ($session === null) {
$session = '';
}
$session = substr($session, 0, 6);
$actor_phid = $log->getActorPHID();
$user_phid = $log->getUserPHID();
$remote_address = $log->getRemoteAddressForViewer($viewer);
if ($remote_address !== null) {
if ($base_uri) {
$remote_address = phutil_tag(
'a',
array(
'href' => $base_uri.'?ip='.$remote_address.'#R',
),
$remote_address);
}
}
$action = $log->getAction();
$action_name = idx($types, $action, $action);
if ($actor_phid) {
$actor_name = $handles[$actor_phid]->renderLink();
} else {
$actor_name = null;
}
if ($user_phid) {
$user_name = $handles[$user_phid]->renderLink();
} else {
$user_name = null;
}
$action_link = phutil_tag(
'a',
array(
'href' => $log->getURI(),
),
$action_name);
$rows[] = array(
$log->getID(),
$action_link,
$actor_name,
$user_name,
$remote_address,
$session,
phabricator_date($log->getDateCreated(), $viewer),
phabricator_time($log->getDateCreated(), $viewer),
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
pht('ID'),
pht('Action'),
pht('Actor'),
pht('User'),
pht('IP'),
pht('Session'),
pht('Date'),
pht('Time'),
));
$table->setColumnClasses(
array(
'',
'wide',
'',
'',
'',
'n',
'',
'right',
));
return $table;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/view/PhabricatorUserCardView.php | src/applications/people/view/PhabricatorUserCardView.php | <?php
final class PhabricatorUserCardView extends AphrontTagView {
private $profile;
private $viewer;
private $tag;
private $isExiled;
public function setProfile(PhabricatorUser $profile) {
$this->profile = $profile;
return $this;
}
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function setTag($tag) {
$this->tag = $tag;
return $this;
}
protected function getTagName() {
if ($this->tag) {
return $this->tag;
}
return 'div';
}
protected function getTagAttributes() {
$classes = array();
$classes[] = 'project-card-view';
$classes[] = 'people-card-view';
if ($this->profile->getIsDisabled()) {
$classes[] = 'project-card-disabled';
}
return array(
'class' => implode(' ', $classes),
);
}
public function setIsExiled($is_exiled) {
$this->isExiled = $is_exiled;
return $this;
}
public function getIsExiled() {
return $this->isExiled;
}
protected function getTagContent() {
$user = $this->profile;
$profile = $user->loadUserProfile();
$picture = $user->getProfileImageURI();
$viewer = $this->viewer;
require_celerity_resource('project-card-view-css');
// We don't have a ton of room on the hovercard, so we're trying to show
// the most important tag. Users can click through to the profile to get
// more details.
$classes = array();
if ($user->getIsDisabled()) {
$tag_icon = 'fa-ban';
$tag_title = pht('Disabled');
$tag_shade = PHUITagView::COLOR_RED;
$classes[] = 'phui-image-disabled';
} else if (!$user->getIsApproved()) {
$tag_icon = 'fa-ban';
$tag_title = pht('Unapproved Account');
$tag_shade = PHUITagView::COLOR_RED;
} else if (!$user->getIsEmailVerified()) {
$tag_icon = 'fa-envelope';
$tag_title = pht('Email Not Verified');
$tag_shade = PHUITagView::COLOR_VIOLET;
} else if ($user->getIsAdmin()) {
$tag_icon = 'fa-star';
$tag_title = pht('Administrator');
$tag_shade = PHUITagView::COLOR_INDIGO;
} else {
$tag_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon());
$tag_title = $profile->getDisplayTitle();
$tag_shade = null;
}
$tag = id(new PHUITagView())
->setIcon($tag_icon)
->setName($tag_title)
->setType(PHUITagView::TYPE_SHADE);
if ($tag_shade !== null) {
$tag->setColor($tag_shade);
}
$body = array();
/* TODO: Replace with Conpherence Availability if we ship it */
$body[] = $this->addItem(
'fa-user-plus',
phabricator_date($user->getDateCreated(), $viewer));
$has_calendar = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorCalendarApplication',
$viewer);
if ($has_calendar) {
if (!$user->getIsDisabled()) {
$body[] = $this->addItem(
'fa-calendar-o',
id(new PHUIUserAvailabilityView())
->setViewer($viewer)
->setAvailableUser($user));
}
}
if ($this->getIsExiled()) {
$body[] = $this->addItem(
'fa-eye-slash red',
pht('This user can not see this object.'),
array(
'project-card-item-exiled',
));
}
$classes[] = 'project-card-image';
$image = phutil_tag(
'img',
array(
'src' => $picture,
'class' => implode(' ', $classes),
));
$href = urisprintf(
'/p/%s/',
$user->getUsername());
$image = phutil_tag(
'a',
array(
'href' => $href,
'class' => 'project-card-image-href',
),
$image);
$name = phutil_tag_div('project-card-name',
$user->getRealname());
$username = phutil_tag_div('project-card-username',
'@'.$user->getUsername());
$tag = phutil_tag_div('phui-header-subheader',
$tag);
$header = phutil_tag(
'div',
array(
'class' => 'project-card-header',
),
array(
$name,
$username,
$tag,
$body,
));
$card = phutil_tag(
'div',
array(
'class' => 'project-card-inner',
),
array(
$header,
$image,
));
return $card;
}
private function addItem($icon, $value, $classes = array()) {
$classes[] = 'project-card-item';
$icon = id(new PHUIIconView())
->addClass('project-card-item-icon')
->setIcon($icon);
$text = phutil_tag(
'span',
array(
'class' => 'project-card-item-text',
),
$value);
return phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
),
array($icon, $text));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/phid/PhabricatorPeopleExternalPHIDType.php | src/applications/people/phid/PhabricatorPeopleExternalPHIDType.php | <?php
final class PhabricatorPeopleExternalPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'XUSR';
public function getTypeName() {
return pht('External Account');
}
public function newObject() {
return new PhabricatorExternalAccount();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorPeopleApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorExternalAccountQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$account = $objects[$phid];
$display_name = $account->getDisplayName();
$handle->setName($display_name);
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/phid/PhabricatorPeopleExternalIdentifierPHIDType.php | src/applications/people/phid/PhabricatorPeopleExternalIdentifierPHIDType.php | <?php
final class PhabricatorPeopleExternalIdentifierPHIDType
extends PhabricatorPHIDType {
const TYPECONST = 'XIDT';
public function getTypeName() {
return pht('External Account Identifier');
}
public function newObject() {
return new PhabricatorExternalAccountIdentifier();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorPeopleApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorExternalAccountIdentifierQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$identifier = $objects[$phid];
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php | src/applications/people/phid/PhabricatorPeopleUserEmailPHIDType.php | <?php
final class PhabricatorPeopleUserEmailPHIDType
extends PhabricatorPHIDType {
const TYPECONST = 'EADR';
public function getTypeName() {
return pht('User Email');
}
public function newObject() {
return new PhabricatorUserEmail();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorPeopleApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorPeopleUserEmailQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$email = $objects[$phid];
$handle->setName($email->getAddress());
}
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/phid/PhabricatorPeopleUserPHIDType.php | src/applications/people/phid/PhabricatorPeopleUserPHIDType.php | <?php
final class PhabricatorPeopleUserPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'USER';
public function getTypeName() {
return pht('User');
}
public function getTypeIcon() {
return 'fa-user bluegrey';
}
public function newObject() {
return new PhabricatorUser();
}
public function getPHIDTypeApplicationClass() {
return 'PhabricatorPeopleApplication';
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorPeopleQuery())
->withPHIDs($phids)
->needProfile(true)
->needProfileImage(true)
->needAvailability(true);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$user = $objects[$phid];
$realname = $user->getRealName();
$username = $user->getUsername();
$handle
->setName($username)
->setURI('/p/'.$username.'/')
->setFullName($user->getFullName())
->setImageURI($user->getProfileImageURI())
->setMailStampName('@'.$username);
if ($user->getIsMailingList()) {
$handle->setIcon('fa-envelope-o');
$handle->setSubtitle(pht('Mailing List'));
} else {
$profile = $user->getUserProfile();
$icon_key = $profile->getIcon();
$icon_icon = PhabricatorPeopleIconSet::getIconIcon($icon_key);
$subtitle = $profile->getDisplayTitle();
$handle
->setIcon($icon_icon)
->setSubtitle($subtitle)
->setTokenIcon('fa-user');
}
$availability = null;
if ($user->getIsDisabled()) {
$availability = PhabricatorObjectHandle::AVAILABILITY_DISABLED;
} else if (!$user->isResponsive()) {
$availability = PhabricatorObjectHandle::AVAILABILITY_NOEMAIL;
} else {
$until = $user->getAwayUntil();
if ($until) {
$away = PhabricatorCalendarEventInvitee::AVAILABILITY_AWAY;
if ($user->getDisplayAvailability() == $away) {
$availability = PhabricatorObjectHandle::AVAILABILITY_NONE;
} else {
$availability = PhabricatorObjectHandle::AVAILABILITY_PARTIAL;
}
}
}
if ($availability) {
$handle->setAvailability($availability);
}
}
}
public function canLoadNamedObject($name) {
return preg_match('/^@.+/', $name);
}
public function loadNamedObjects(
PhabricatorObjectQuery $query,
array $names) {
$id_map = array();
foreach ($names as $name) {
$id = substr($name, 1);
$id = phutil_utf8_strtolower($id);
$id_map[$id][] = $name;
}
$objects = id(new PhabricatorPeopleQuery())
->setViewer($query->getViewer())
->withUsernames(array_keys($id_map))
->execute();
$results = array();
foreach ($objects as $id => $object) {
$user_key = $object->getUsername();
$user_key = phutil_utf8_strtolower($user_key);
foreach (idx($id_map, $user_key, array()) as $name) {
$results[$name] = $object;
}
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/config/PhabricatorUserConfigOptions.php | src/applications/people/config/PhabricatorUserConfigOptions.php | <?php
final class PhabricatorUserConfigOptions
extends PhabricatorApplicationConfigOptions {
public function getName() {
return pht('User Profiles');
}
public function getDescription() {
return pht('User profiles configuration.');
}
public function getIcon() {
return 'fa-users';
}
public function getGroup() {
return 'apps';
}
public function getOptions() {
$default = array(
id(new PhabricatorUserRealNameField())->getFieldKey() => true,
id(new PhabricatorUserTitleField())->getFieldKey() => true,
id(new PhabricatorUserIconField())->getFieldKey() => true,
id(new PhabricatorUserSinceField())->getFieldKey() => true,
id(new PhabricatorUserRolesField())->getFieldKey() => true,
id(new PhabricatorUserStatusField())->getFieldKey() => true,
id(new PhabricatorUserBlurbField())->getFieldKey() => true,
);
foreach ($default as $key => $enabled) {
$default[$key] = array(
'disabled' => !$enabled,
);
}
$custom_field_type = 'custom:PhabricatorCustomFieldConfigOptionType';
return array(
$this->newOption('user.fields', $custom_field_type, $default)
->setCustomData(id(new PhabricatorUser())->getCustomFieldBaseClass())
->setDescription(pht('Select and reorder user profile fields.')),
$this->newOption('user.custom-field-definitions', 'wild', array())
->setDescription(pht('Add new simple fields to user profiles.')),
$this->newOption('user.require-real-name', 'bool', true)
->setDescription(pht('Always require real name for user profiles.'))
->setBoolOptions(
array(
pht('Make real names required'),
pht('Make real names optional'),
)),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/conduit/UserWhoAmIConduitAPIMethod.php | src/applications/people/conduit/UserWhoAmIConduitAPIMethod.php | <?php
final class UserWhoAmIConduitAPIMethod extends UserConduitAPIMethod {
public function getAPIMethodName() {
return 'user.whoami';
}
public function getMethodDescription() {
return pht('Retrieve information about the logged-in user.');
}
protected function defineParamTypes() {
return array();
}
protected function defineReturnType() {
return 'nonempty dict<string, wild>';
}
public function getRequiredScope() {
return self::SCOPE_ALWAYS;
}
protected function execute(ConduitAPIRequest $request) {
$person = id(new PhabricatorPeopleQuery())
->setViewer($request->getUser())
->needProfileImage(true)
->withPHIDs(array($request->getUser()->getPHID()))
->executeOne();
return $this->buildUserInformationDictionary(
$person,
$with_email = true,
$with_availability = false);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/conduit/UserEnableConduitAPIMethod.php | src/applications/people/conduit/UserEnableConduitAPIMethod.php | <?php
final class UserEnableConduitAPIMethod extends UserConduitAPIMethod {
public function getAPIMethodName() {
return 'user.enable';
}
public function getMethodDescription() {
return pht('Re-enable specified users (admin only).');
}
public function getMethodStatus() {
return self::METHOD_STATUS_DEPRECATED;
}
public function getMethodStatusDescription() {
return pht('Obsoleted by method "user.edit".');
}
protected function defineParamTypes() {
return array(
'phids' => 'required list<phid>',
);
}
protected function defineReturnType() {
return 'void';
}
protected function defineErrorTypes() {
return array(
'ERR-PERMISSIONS' => pht('Only admins can call this method.'),
'ERR-BAD-PHID' => pht('Non existent user PHID.'),
);
}
protected function execute(ConduitAPIRequest $request) {
$actor = $request->getUser();
if (!$actor->getIsAdmin()) {
throw new ConduitException('ERR-PERMISSIONS');
}
$phids = $request->getValue('phids');
$users = id(new PhabricatorUser())->loadAllWhere(
'phid IN (%Ls)',
$phids);
if (count($phids) != count($users)) {
throw new ConduitException('ERR-BAD-PHID');
}
foreach ($phids as $phid) {
$params = array(
'transactions' => array(
array(
'type' => 'disabled',
'value' => false,
),
),
'objectIdentifier' => $phid,
);
id(new ConduitCall('user.edit', $params))
->setUser($actor)
->execute();
}
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/conduit/UserSearchConduitAPIMethod.php | src/applications/people/conduit/UserSearchConduitAPIMethod.php | <?php
final class UserSearchConduitAPIMethod
extends PhabricatorSearchEngineAPIMethod {
public function getAPIMethodName() {
return 'user.search';
}
public function newSearchEngine() {
return new PhabricatorPeopleSearchEngine();
}
public function getMethodSummary() {
return pht('Read information about users.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/conduit/UserFindConduitAPIMethod.php | src/applications/people/conduit/UserFindConduitAPIMethod.php | <?php
final class UserFindConduitAPIMethod extends UserConduitAPIMethod {
public function getAPIMethodName() {
return 'user.find';
}
public function getMethodStatus() {
return self::METHOD_STATUS_DEPRECATED;
}
public function getMethodStatusDescription() {
return pht('Obsoleted by "%s".', 'user.query');
}
public function getMethodDescription() {
return pht('Lookup PHIDs by username. Obsoleted by "%s".', 'user.query');
}
protected function defineParamTypes() {
return array(
'aliases' => 'required list<string>',
);
}
protected function defineReturnType() {
return 'nonempty dict<string, phid>';
}
protected function execute(ConduitAPIRequest $request) {
$users = id(new PhabricatorPeopleQuery())
->setViewer($request->getUser())
->withUsernames($request->getValue('aliases', array()))
->execute();
return mpull($users, 'getPHID', 'getUsername');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/conduit/UserQueryConduitAPIMethod.php | src/applications/people/conduit/UserQueryConduitAPIMethod.php | <?php
final class UserQueryConduitAPIMethod extends UserConduitAPIMethod {
public function getAPIMethodName() {
return 'user.query';
}
public function getMethodDescription() {
return pht('Query users.');
}
public function getMethodStatus() {
return self::METHOD_STATUS_FROZEN;
}
public function getMethodStatusDescription() {
return pht(
'This method is frozen and will eventually be deprecated. New code '.
'should use "user.search" instead.');
}
protected function defineParamTypes() {
return array(
'usernames' => 'optional list<string>',
'emails' => 'optional list<string>',
'realnames' => 'optional list<string>',
'phids' => 'optional list<phid>',
'ids' => 'optional list<uint>',
'offset' => 'optional int',
'limit' => 'optional int (default = 100)',
);
}
protected function defineReturnType() {
return 'list<dict>';
}
protected function defineErrorTypes() {
return array(
'ERR-INVALID-PARAMETER' => pht('Missing or malformed parameter.'),
);
}
protected function execute(ConduitAPIRequest $request) {
$usernames = $request->getValue('usernames', array());
$emails = $request->getValue('emails', array());
$realnames = $request->getValue('realnames', array());
$phids = $request->getValue('phids', array());
$ids = $request->getValue('ids', array());
$offset = $request->getValue('offset', 0);
$limit = $request->getValue('limit', 100);
$query = id(new PhabricatorPeopleQuery())
->setViewer($request->getUser())
->needProfileImage(true)
->needAvailability(true);
if ($usernames) {
$query->withUsernames($usernames);
}
if ($emails) {
$query->withEmails($emails);
}
if ($realnames) {
$query->withRealnames($realnames);
}
if ($phids) {
$query->withPHIDs($phids);
}
if ($ids) {
$query->withIDs($ids);
}
if ($limit) {
$query->setLimit($limit);
}
if ($offset) {
$query->setOffset($offset);
}
$users = $query->execute();
$results = array();
foreach ($users as $user) {
$results[] = $this->buildUserInformationDictionary(
$user,
$with_email = false,
$with_availability = true);
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/conduit/UserConduitAPIMethod.php | src/applications/people/conduit/UserConduitAPIMethod.php | <?php
abstract class UserConduitAPIMethod extends ConduitAPIMethod {
final public function getApplication() {
return PhabricatorApplication::getByClass('PhabricatorPeopleApplication');
}
protected function buildUserInformationDictionary(
PhabricatorUser $user,
$with_email = false,
$with_availability = false) {
$roles = array();
if ($user->getIsDisabled()) {
$roles[] = 'disabled';
}
if ($user->getIsSystemAgent()) {
$roles[] = 'agent';
}
if ($user->getIsMailingList()) {
$roles[] = 'list';
}
if ($user->getIsAdmin()) {
$roles[] = 'admin';
}
$primary = $user->loadPrimaryEmail();
if ($primary && $primary->getIsVerified()) {
$email = $primary->getAddress();
$roles[] = 'verified';
} else {
$email = null;
$roles[] = 'unverified';
}
if ($user->getIsApproved()) {
$roles[] = 'approved';
}
if ($user->isUserActivated()) {
$roles[] = 'activated';
}
$return = array(
'phid' => $user->getPHID(),
'userName' => $user->getUserName(),
'realName' => $user->getRealName(),
'image' => $user->getProfileImageURI(),
'uri' => PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'),
'roles' => $roles,
);
if ($with_email) {
$return['primaryEmail'] = $email;
}
if ($with_availability) {
// TODO: Modernize this once we have a more long-term view of what the
// data looks like.
$until = $user->getAwayUntil();
if ($until) {
$return['currentStatus'] = 'away';
$return['currentStatusUntil'] = $until;
}
}
return $return;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/conduit/UserEditConduitAPIMethod.php | src/applications/people/conduit/UserEditConduitAPIMethod.php | <?php
final class UserEditConduitAPIMethod
extends PhabricatorEditEngineAPIMethod {
public function getAPIMethodName() {
return 'user.edit';
}
public function newEditEngine() {
return new PhabricatorUserEditEngine();
}
public function getMethodSummary() {
return pht(
'Apply transactions to edit a user. (Users can not be created via '.
'the API.)');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/conduit/UserDisableConduitAPIMethod.php | src/applications/people/conduit/UserDisableConduitAPIMethod.php | <?php
final class UserDisableConduitAPIMethod extends UserConduitAPIMethod {
public function getAPIMethodName() {
return 'user.disable';
}
public function getMethodDescription() {
return pht('Permanently disable specified users (admin only).');
}
public function getMethodStatus() {
return self::METHOD_STATUS_DEPRECATED;
}
public function getMethodStatusDescription() {
return pht('Obsoleted by method "user.edit".');
}
protected function defineParamTypes() {
return array(
'phids' => 'required list<phid>',
);
}
protected function defineReturnType() {
return 'void';
}
protected function defineErrorTypes() {
return array(
'ERR-PERMISSIONS' => pht('Only admins can call this method.'),
'ERR-BAD-PHID' => pht('Non existent user PHID.'),
);
}
protected function execute(ConduitAPIRequest $request) {
$actor = $request->getUser();
if (!$actor->getIsAdmin()) {
throw new ConduitException('ERR-PERMISSIONS');
}
$phids = $request->getValue('phids');
$users = id(new PhabricatorUser())->loadAllWhere(
'phid IN (%Ls)',
$phids);
if (count($phids) != count($users)) {
throw new ConduitException('ERR-BAD-PHID');
}
foreach ($phids as $phid) {
$params = array(
'transactions' => array(
array(
'type' => 'disabled',
'value' => true,
),
),
'objectIdentifier' => $phid,
);
id(new ConduitCall('user.edit', $params))
->setUser($actor)
->execute();
}
return null;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/search/PhabricatorUserFerretEngine.php | src/applications/people/search/PhabricatorUserFerretEngine.php | <?php
final class PhabricatorUserFerretEngine
extends PhabricatorFerretEngine {
public function getApplicationName() {
return 'user';
}
public function getScopeName() {
return 'user';
}
public function newSearchEngine() {
return new PhabricatorPeopleSearchEngine();
}
public function getObjectTypeRelevance() {
// Always sort users above other documents, regardless of relevance
// metrics. A user profile is very likely to be the best hit for a query
// which matches a user.
return 500;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/search/PhabricatorUserFulltextEngine.php | src/applications/people/search/PhabricatorUserFulltextEngine.php | <?php
final class PhabricatorUserFulltextEngine
extends PhabricatorFulltextEngine {
protected function buildAbstractDocument(
PhabricatorSearchAbstractDocument $document,
$object) {
$user = $object;
$document->setDocumentTitle($user->getFullName());
$document->addRelationship(
$user->isUserActivated()
? PhabricatorSearchRelationship::RELATIONSHIP_OPEN
: PhabricatorSearchRelationship::RELATIONSHIP_CLOSED,
$user->getPHID(),
PhabricatorPeopleUserPHIDType::TYPECONST,
PhabricatorTime::getNow());
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/engine/PhabricatorPeopleProfileMenuEngine.php | src/applications/people/engine/PhabricatorPeopleProfileMenuEngine.php | <?php
final class PhabricatorPeopleProfileMenuEngine
extends PhabricatorProfileMenuEngine {
const ITEM_PROFILE = 'people.profile';
const ITEM_MANAGE = 'people.manage';
const ITEM_PICTURE = 'people.picture';
const ITEM_BADGES = 'people.badges';
const ITEM_TASKS = 'people.tasks';
const ITEM_COMMITS = 'people.commits';
const ITEM_REVISIONS = 'people.revisions';
protected function isMenuEngineConfigurable() {
return false;
}
public function getItemURI($path) {
$user = $this->getProfileObject();
$username = $user->getUsername();
$username = phutil_escape_uri($username);
return "/p/{$username}/item/{$path}";
}
protected function getBuiltinProfileItems($object) {
$viewer = $this->getViewer();
$items = array();
$items[] = $this->newItem()
->setBuiltinKey(self::ITEM_PICTURE)
->setMenuItemKey(PhabricatorPeoplePictureProfileMenuItem::MENUITEMKEY);
$items[] = $this->newItem()
->setBuiltinKey(self::ITEM_PROFILE)
->setMenuItemKey(PhabricatorPeopleDetailsProfileMenuItem::MENUITEMKEY);
$have_badges = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorBadgesApplication',
$viewer);
if ($have_badges) {
$items[] = $this->newItem()
->setBuiltinKey(self::ITEM_BADGES)
->setMenuItemKey(PhabricatorPeopleBadgesProfileMenuItem::MENUITEMKEY);
}
$have_maniphest = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorManiphestApplication',
$viewer);
if ($have_maniphest) {
$items[] = $this->newItem()
->setBuiltinKey(self::ITEM_TASKS)
->setMenuItemKey(PhabricatorPeopleTasksProfileMenuItem::MENUITEMKEY);
}
$have_differential = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorDifferentialApplication',
$viewer);
if ($have_differential) {
$items[] = $this->newItem()
->setBuiltinKey(self::ITEM_REVISIONS)
->setMenuItemKey(
PhabricatorPeopleRevisionsProfileMenuItem::MENUITEMKEY);
}
$have_diffusion = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorDiffusionApplication',
$viewer);
if ($have_diffusion) {
$items[] = $this->newItem()
->setBuiltinKey(self::ITEM_COMMITS)
->setMenuItemKey(PhabricatorPeopleCommitsProfileMenuItem::MENUITEMKEY);
}
$items[] = $this->newItem()
->setBuiltinKey(self::ITEM_MANAGE)
->setMenuItemKey(PhabricatorPeopleManageProfileMenuItem::MENUITEMKEY);
return $items;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/typeahead/PhabricatorUserLogTypeDatasource.php | src/applications/people/typeahead/PhabricatorUserLogTypeDatasource.php | <?php
final class PhabricatorUserLogTypeDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Log Types');
}
public function getPlaceholderText() {
return pht('Type a log type name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorPeopleApplication';
}
public function loadResults() {
$results = $this->buildResults();
return $this->filterResultsAgainstTokens($results);
}
protected function renderSpecialTokens(array $values) {
return $this->renderTokensFromResults($this->buildResults(), $values);
}
private function buildResults() {
$results = array();
$type_map = PhabricatorUserLogType::getAllLogTypes();
foreach ($type_map as $type_key => $type) {
$result = id(new PhabricatorTypeaheadResult())
->setPHID($type_key)
->setName($type->getLogTypeName());
$results[$type_key] = $result;
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/typeahead/PhabricatorPeopleOwnerDatasource.php | src/applications/people/typeahead/PhabricatorPeopleOwnerDatasource.php | <?php
final class PhabricatorPeopleOwnerDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getBrowseTitle() {
return pht('Browse Owners');
}
public function getPlaceholderText() {
return pht('Type a username or function...');
}
public function getComponentDatasources() {
return array(
new PhabricatorViewerDatasource(),
new PhabricatorPeopleNoOwnerDatasource(),
new PhabricatorPeopleAnyOwnerDatasource(),
new PhabricatorPeopleDatasource(),
new PhabricatorProjectMembersDatasource(),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/typeahead/PhabricatorPeopleDatasource.php | src/applications/people/typeahead/PhabricatorPeopleDatasource.php | <?php
final class PhabricatorPeopleDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Users');
}
public function getPlaceholderText() {
return pht('Type a username...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorPeopleApplication';
}
public function loadResults() {
$viewer = $this->getViewer();
$query = id(new PhabricatorPeopleQuery())
->setOrderVector(array('username'))
->needAvailability(true);
if ($this->getPhase() == self::PHASE_PREFIX) {
$prefix = $this->getPrefixQuery();
$query->withNamePrefixes(array($prefix));
} else {
$tokens = $this->getTokens();
if ($tokens) {
$query->withNameTokens($tokens);
}
}
$users = $this->executeQuery($query);
$is_browse = $this->getIsBrowse();
if ($is_browse && $users) {
$phids = mpull($users, 'getPHID');
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($phids)
->execute();
}
$results = array();
foreach ($users as $user) {
$phid = $user->getPHID();
$closed = null;
if ($user->getIsDisabled()) {
$closed = pht('Disabled');
} else if ($user->getIsSystemAgent()) {
$closed = pht('Bot');
} else if ($user->getIsMailingList()) {
$closed = pht('Mailing List');
}
$username = $user->getUsername();
$result = id(new PhabricatorTypeaheadResult())
->setName($user->getFullName())
->setURI('/p/'.$username.'/')
->setPHID($phid)
->setPriorityString($username)
->setPriorityType('user')
->setAutocomplete('@'.$username)
->setClosed($closed);
if ($user->getIsMailingList()) {
$result->setIcon('fa-envelope-o');
}
if ($is_browse) {
$handle = $handles[$phid];
$result
->setIcon($handle->getIcon())
->setImageURI($handle->getImageURI())
->addAttribute($handle->getSubtitle());
if ($user->getIsAdmin()) {
$result->addAttribute(
array(
id(new PHUIIconView())->setIcon('fa-star'),
' ',
pht('Administrator'),
));
}
if ($user->getIsAdmin()) {
$display_type = pht('Administrator');
} else {
$display_type = pht('User');
}
$result->setDisplayType($display_type);
}
$until = $user->getAwayUntil();
if ($until) {
$availability = $user->getDisplayAvailability();
$color = PhabricatorCalendarEventInvitee::getAvailabilityColor(
$availability);
$result->setAvailabilityColor($color);
}
$results[] = $result;
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/typeahead/PhabricatorPeopleNoOwnerDatasource.php | src/applications/people/typeahead/PhabricatorPeopleNoOwnerDatasource.php | <?php
final class PhabricatorPeopleNoOwnerDatasource
extends PhabricatorTypeaheadDatasource {
const FUNCTION_TOKEN = 'none()';
public function getBrowseTitle() {
return pht('Browse No Owner');
}
public function getPlaceholderText() {
return pht('Type "none"...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorPeopleApplication';
}
public function getDatasourceFunctions() {
return array(
'none' => array(
'name' => pht('No Owner'),
'summary' => pht('Find results which are not assigned.'),
'description' => pht(
"This function includes results which have no owner. Use a query ".
"like this to find unassigned results:\n\n%s\n\n".
"If you combine this function with other functions, the query will ".
"return results which match the other selectors //or// have no ".
"owner. For example, this query will find results which are owned ".
"by `alincoln`, and will also find results which have no owner:".
"\n\n%s",
'> none()',
'> alincoln, none()'),
),
);
}
public function loadResults() {
$results = array(
$this->buildNoOwnerResult(),
);
return $this->filterResultsAgainstTokens($results);
}
protected function evaluateFunction($function, array $argv_list) {
$results = array();
foreach ($argv_list as $argv) {
$results[] = self::FUNCTION_TOKEN;
}
return $results;
}
public function renderFunctionTokens($function, array $argv_list) {
$results = array();
foreach ($argv_list as $argv) {
$results[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult(
$this->buildNoOwnerResult());
}
return $results;
}
private function buildNoOwnerResult() {
$name = pht('No Owner');
return $this->newFunctionResult()
->setName($name.' none')
->setDisplayName($name)
->setIcon('fa-ban')
->setPHID('none()')
->setUnique(true)
->addAttribute(pht('Select results with no owner.'));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/typeahead/PhabricatorPeopleAnyOwnerDatasource.php | src/applications/people/typeahead/PhabricatorPeopleAnyOwnerDatasource.php | <?php
final class PhabricatorPeopleAnyOwnerDatasource
extends PhabricatorTypeaheadDatasource {
const FUNCTION_TOKEN = 'anyone()';
public function getBrowseTitle() {
return pht('Browse Any Owner');
}
public function getPlaceholderText() {
return pht('Type "anyone()"...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorPeopleApplication';
}
public function getDatasourceFunctions() {
return array(
'anyone' => array(
'name' => pht('Anyone'),
'summary' => pht('Find results which are assigned to anyone.'),
'description' => pht(
'This function includes results which have any owner. It excludes '.
'unassigned or unowned results.'),
),
);
}
public function loadResults() {
$results = array(
$this->buildAnyoneResult(),
);
return $this->filterResultsAgainstTokens($results);
}
protected function evaluateFunction($function, array $argv_list) {
$results = array();
foreach ($argv_list as $argv) {
$results[] = self::FUNCTION_TOKEN;
}
return $results;
}
public function renderFunctionTokens($function, array $argv_list) {
$results = array();
foreach ($argv_list as $argv) {
$results[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult(
$this->buildAnyoneResult());
}
return $results;
}
private function buildAnyoneResult() {
$name = pht('Any Owner');
return $this->newFunctionResult()
->setName($name.' anyone')
->setDisplayName($name)
->setIcon('fa-certificate')
->setPHID(self::FUNCTION_TOKEN)
->setUnique(true)
->addAttribute(pht('Select results with any owner.'));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/typeahead/PhabricatorPeopleUserFunctionDatasource.php | src/applications/people/typeahead/PhabricatorPeopleUserFunctionDatasource.php | <?php
final class PhabricatorPeopleUserFunctionDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getBrowseTitle() {
return pht('Browse Users');
}
public function getPlaceholderText() {
return pht('Type a username or function...');
}
public function getComponentDatasources() {
$sources = array(
new PhabricatorViewerDatasource(),
new PhabricatorPeopleDatasource(),
new PhabricatorProjectMembersDatasource(),
);
return $sources;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/typeahead/PhabricatorViewerDatasource.php | src/applications/people/typeahead/PhabricatorViewerDatasource.php | <?php
final class PhabricatorViewerDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Viewer');
}
public function getPlaceholderText() {
return pht('Type viewer()...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorPeopleApplication';
}
public function getDatasourceFunctions() {
return array(
'viewer' => array(
'name' => pht('Current Viewer'),
'summary' => pht('Use the current viewing user.'),
'description' => pht(
"This function allows you to change the behavior of a query ".
"based on who is running it. When you use this function, you will ".
"be the current viewer, so it works like you typed your own ".
"username.\n\n".
"However, if you save a query using this function and send it ".
"to someone else, it will work like //their// username was the ".
"one that was typed. This can be useful for building dashboard ".
"panels that always show relevant information to the user who ".
"is looking at them."),
),
);
}
public function loadResults() {
if ($this->getViewer()->getPHID()) {
$results = array($this->renderViewerFunctionToken());
} else {
$results = array();
}
return $this->filterResultsAgainstTokens($results);
}
protected function canEvaluateFunction($function) {
if (!$this->getViewer()->getPHID()) {
return false;
}
return parent::canEvaluateFunction($function);
}
protected function evaluateFunction($function, array $argv_list) {
$results = array();
foreach ($argv_list as $argv) {
$results[] = $this->getViewer()->getPHID();
}
return $results;
}
public function renderFunctionTokens($function, array $argv_list) {
$tokens = array();
foreach ($argv_list as $argv) {
$tokens[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult(
$this->renderViewerFunctionToken());
}
return $tokens;
}
private function renderViewerFunctionToken() {
return $this->newFunctionResult()
->setName(pht('Current Viewer'))
->setPHID('viewer()')
->setIcon('fa-user')
->setUnique(true)
->addAttribute(pht('Select current viewer.'));
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/capability/PeopleDisableUsersCapability.php | src/applications/people/capability/PeopleDisableUsersCapability.php | <?php
final class PeopleDisableUsersCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'people.disable.users';
public function getCapabilityName() {
return pht('Can Disable Users');
}
public function describeCapabilityRejection() {
return pht('You do not have permission to disable or enable users.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/capability/PeopleBrowseUserDirectoryCapability.php | src/applications/people/capability/PeopleBrowseUserDirectoryCapability.php | <?php
final class PeopleBrowseUserDirectoryCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'people.browse';
public function getCapabilityName() {
return pht('Can Browse User Directory');
}
public function shouldAllowPublicPolicySetting() {
return true;
}
public function describeCapabilityRejection() {
return pht('You do not have permission to browse the user directory.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/capability/PeopleCreateUsersCapability.php | src/applications/people/capability/PeopleCreateUsersCapability.php | <?php
final class PeopleCreateUsersCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'people.create.users';
public function getCapabilityName() {
return pht('Can Create (non-bot) Users');
}
public function describeCapabilityRejection() {
return pht('You do not have permission to create users.');
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/people/markup/PhabricatorMentionRemarkupRule.php | src/applications/people/markup/PhabricatorMentionRemarkupRule.php | <?php
final class PhabricatorMentionRemarkupRule extends PhutilRemarkupRule {
const KEY_RULE_MENTION = 'rule.mention';
const KEY_RULE_MENTION_ORIGINAL = 'rule.mention.original';
const KEY_MENTIONED = 'phabricator.mentioned-user-phids';
// NOTE: The negative lookbehind prevents matches like "mail@lists", while
// allowing constructs like "@tomo/@mroch". Since we now allow periods in
// usernames, we can't reasonably distinguish that "@company.com" isn't a
// username, so we'll incorrectly pick it up, but there's little to be done
// about that. We forbid terminal periods so that we can correctly capture
// "@joe" instead of "@joe." in "Hey, @joe.".
//
// We disallow "@@joe" because it creates a false positive in the common
// construction "l@@k", made popular by eBay.
const REGEX = '/(?<!\w|@)@([a-zA-Z0-9._-]*[a-zA-Z0-9_-])/';
public function apply($text) {
return preg_replace_callback(
self::REGEX,
array($this, 'markupMention'),
$text);
}
protected function markupMention(array $matches) {
$engine = $this->getEngine();
if ($engine->isTextMode()) {
return $engine->storeText($matches[0]);
}
$token = $engine->storeText('');
// Store the original text exactly so we can preserve casing if it doesn't
// resolve into a username.
$original_key = self::KEY_RULE_MENTION_ORIGINAL;
$original = $engine->getTextMetadata($original_key, array());
$original[$token] = $matches[1];
$engine->setTextMetadata($original_key, $original);
$metadata_key = self::KEY_RULE_MENTION;
$metadata = $engine->getTextMetadata($metadata_key, array());
$username = strtolower($matches[1]);
if (empty($metadata[$username])) {
$metadata[$username] = array();
}
$metadata[$username][] = $token;
$engine->setTextMetadata($metadata_key, $metadata);
return $token;
}
public function didMarkupText() {
$engine = $this->getEngine();
$metadata_key = self::KEY_RULE_MENTION;
$metadata = $engine->getTextMetadata($metadata_key, array());
if (empty($metadata)) {
// No mentions, or we already processed them.
return;
}
$original_key = self::KEY_RULE_MENTION_ORIGINAL;
$original = $engine->getTextMetadata($original_key, array());
$usernames = array_keys($metadata);
$users = id(new PhabricatorPeopleQuery())
->setViewer($this->getEngine()->getConfig('viewer'))
->withUsernames($usernames)
->needAvailability(true)
->execute();
$actual_users = array();
$mentioned_key = self::KEY_MENTIONED;
$mentioned = $engine->getTextMetadata($mentioned_key, array());
foreach ($users as $row) {
$actual_users[strtolower($row->getUserName())] = $row;
$mentioned[$row->getPHID()] = $row->getPHID();
}
$engine->setTextMetadata($mentioned_key, $mentioned);
$context_object = $engine->getConfig('contextObject');
$policy_object = null;
if ($context_object) {
if ($context_object instanceof PhabricatorPolicyInterface) {
$policy_object = $context_object;
}
}
if ($policy_object) {
$policy_set = new PhabricatorPolicyFilterSet();
foreach ($actual_users as $user) {
$policy_set->addCapability(
$user,
$policy_object,
PhabricatorPolicyCapability::CAN_VIEW);
}
}
foreach ($metadata as $username => $tokens) {
$exists = isset($actual_users[$username]);
$user_can_not_view = false;
if ($exists) {
$user = $actual_users[$username];
// Check if the user has view access to the object she was mentioned in
if ($policy_object) {
$user_can_not_view = !$policy_set->hasCapability(
$user,
$policy_object,
PhabricatorPolicyCapability::CAN_VIEW);
}
$user_href = '/p/'.$user->getUserName().'/';
if ($engine->isHTMLMailMode()) {
$user_href = PhabricatorEnv::getProductionURI($user_href);
if ($user_can_not_view) {
$colors = '
border-color: #92969D;
color: #92969D;
background-color: #F7F7F7;';
} else {
$colors = '
border-color: #f1f7ff;
color: #19558d;
background-color: #f1f7ff;';
}
$tag = phutil_tag(
'a',
array(
'href' => $user_href,
'style' => $colors.'
border: 1px solid transparent;
border-radius: 3px;
font-weight: bold;
padding: 0 4px;',
),
'@'.$user->getUserName());
} else {
if ($engine->getConfig('uri.full')) {
$user_href = PhabricatorEnv::getURI($user_href);
}
$tag = id(new PHUITagView())
->setType(PHUITagView::TYPE_PERSON)
->setPHID($user->getPHID())
->setName('@'.$user->getUserName())
->setHref($user_href);
if ($context_object) {
$tag->setContextObject($context_object);
}
if ($user_can_not_view) {
$tag->setIcon('fa-eye-slash red');
$tag->setIsExiled(true);
}
if ($user->getIsDisabled()) {
$tag->setDotColor(PHUITagView::COLOR_GREY);
} else if (!$user->isResponsive()) {
$tag->setDotColor(PHUITagView::COLOR_VIOLET);
} else {
if ($user->getAwayUntil()) {
$away = PhabricatorCalendarEventInvitee::AVAILABILITY_AWAY;
if ($user->getDisplayAvailability() == $away) {
$tag->setDotColor(PHUITagView::COLOR_RED);
} else {
$tag->setDotColor(PHUITagView::COLOR_ORANGE);
}
}
}
}
foreach ($tokens as $token) {
$engine->overwriteStoredText($token, $tag);
}
} else {
// NOTE: The structure here is different from the 'exists' branch,
// because we want to preserve the original text capitalization and it
// may differ for each token.
foreach ($tokens as $token) {
$tag = phutil_tag(
'span',
array(
'class' => 'phabricator-remarkup-mention-unknown',
),
'@'.idx($original, $token, $username));
$engine->overwriteStoredText($token, $tag);
}
}
}
// Don't re-process these mentions.
$engine->setTextMetadata($metadata_key, array());
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/controller/PhabricatorSubscriptionsMuteController.php | src/applications/subscriptions/controller/PhabricatorSubscriptionsMuteController.php | <?php
final class PhabricatorSubscriptionsMuteController
extends PhabricatorController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$phid = $request->getURIData('phid');
$handle = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs(array($phid))
->executeOne();
$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($phid))
->executeOne();
if (!($object instanceof PhabricatorSubscribableInterface)) {
return new Aphront400Response();
}
$muted_type = PhabricatorMutedByEdgeType::EDGECONST;
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(array($object->getPHID()))
->withEdgeTypes(array($muted_type))
->withDestinationPHIDs(array($viewer->getPHID()));
$edge_query->execute();
$is_mute = !$edge_query->getDestinationPHIDs();
$object_uri = $handle->getURI();
if ($request->isFormPost()) {
if ($is_mute) {
$xaction_value = array(
'+' => array_fuse(array($viewer->getPHID())),
);
} else {
$xaction_value = array(
'-' => array_fuse(array($viewer->getPHID())),
);
}
$xaction = id($object->getApplicationTransactionTemplate())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', $muted_type)
->setNewValue($xaction_value);
$editor = id($object->getApplicationTransactionEditor())
->setActor($viewer)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->setContentSourceFromRequest($request);
$editor->applyTransactions($object, array($xaction));
return id(new AphrontReloadResponse())->setURI($object_uri);
}
$dialog = $this->newDialog()
->addCancelButton($object_uri);
if ($is_mute) {
$dialog
->setTitle(pht('Mute Notifications'))
->appendParagraph(
pht(
'Mute this object? You will no longer receive notifications or '.
'email about it.'))
->addSubmitButton(pht('Mute'));
} else {
$dialog
->setTitle(pht('Unmute Notifications'))
->appendParagraph(
pht(
'Unmute this object? You will receive notifications and email '.
'again.'))
->addSubmitButton(pht('Unmute'));
}
return $dialog;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php | src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php | <?php
final class PhabricatorSubscriptionsEditController
extends PhabricatorController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$phid = $request->getURIData('phid');
$action = $request->getURIData('action');
if (!$request->isFormOrHisecPost()) {
return new Aphront400Response();
}
switch ($action) {
case 'add':
$is_add = true;
break;
case 'delete':
$is_add = false;
break;
default:
return new Aphront400Response();
}
$handle = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs(array($phid))
->executeOne();
$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($phid))
->executeOne();
if (!($object instanceof PhabricatorSubscribableInterface)) {
return $this->buildErrorResponse(
pht('Bad Object'),
pht('This object is not subscribable.'),
$handle->getURI());
}
if ($object->isAutomaticallySubscribed($viewer->getPHID())) {
return $this->buildErrorResponse(
pht('Automatically Subscribed'),
pht('You are automatically subscribed to this object.'),
$handle->getURI());
}
if ($object instanceof PhabricatorApplicationTransactionInterface) {
if ($is_add) {
$xaction_value = array(
'+' => array($viewer->getPHID()),
);
} else {
$xaction_value = array(
'-' => array($viewer->getPHID()),
);
}
$xaction = id($object->getApplicationTransactionTemplate())
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
->setNewValue($xaction_value);
$editor = id($object->getApplicationTransactionEditor())
->setActor($viewer)
->setCancelURI($handle->getURI())
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->setContentSourceFromRequest($request);
$editor->applyTransactions($object, array($xaction));
} else {
// TODO: Eventually, get rid of this once everything implements
// PhabricatorApplicationTransactionInterface.
$editor = id(new PhabricatorSubscriptionsEditor())
->setActor($viewer)
->setObject($object);
if ($is_add) {
$editor->subscribeExplicit(array($viewer->getPHID()), $explicit = true);
} else {
$editor->unsubscribe(array($viewer->getPHID()));
}
$editor->save();
}
// TODO: We should just render the "Unsubscribe" action and swap it out
// in the document for Ajax requests.
return id(new AphrontReloadResponse())->setURI($handle->getURI());
}
private function buildErrorResponse($title, $message, $uri) {
$request = $this->getRequest();
$viewer = $request->getUser();
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle($title)
->appendChild($message)
->addCancelButton($uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/controller/PhabricatorSubscriptionsListController.php | src/applications/subscriptions/controller/PhabricatorSubscriptionsListController.php | <?php
final class PhabricatorSubscriptionsListController
extends PhabricatorController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$object = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($request->getURIData('phid')))
->executeOne();
if (!$object) {
return new Aphront404Response();
}
if (!($object instanceof PhabricatorSubscribableInterface)) {
return new Aphront404Response();
}
$phid = $object->getPHID();
$handle_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID($phid);
$handle_phids[] = $phid;
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($handle_phids)
->execute();
$object_handle = $handles[$phid];
$dialog = id(new SubscriptionListDialogBuilder())
->setViewer($viewer)
->setTitle(pht('Subscribers'))
->setObjectPHID($phid)
->setHandles($handles)
->buildDialog();
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php | src/applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php | <?php
final class PhabricatorSubscriptionsTransactionController
extends PhabricatorController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$phid = $request->getURIData('phid');
$type = $request->getURIData('type');
$xaction = id(new PhabricatorObjectQuery())
->withPHIDs(array($phid))
->setViewer($viewer)
->executeOne();
if (!$xaction) {
return new Aphront404Response();
}
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
switch ($type) {
case 'add':
$subscriber_phids = array_diff($new, $old);
break;
case 'rem':
$subscriber_phids = array_diff($old, $new);
break;
default:
return id(new Aphront404Response());
}
$object_phid = $xaction->getObjectPHID();
$author_phid = $xaction->getAuthorPHID();
$handle_phids = $subscriber_phids;
$handle_phids[] = $object_phid;
$handle_phids[] = $author_phid;
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($handle_phids)
->execute();
$author_handle = $handles[$author_phid];
if (!in_array($author_phid, $subscriber_phids)) {
unset($handles[$author_phid]);
}
switch ($type) {
case 'add':
$title = pht(
'All %d subscribers added by %s',
count($subscriber_phids),
$author_handle->renderLink());
break;
case 'rem':
$title = pht(
'All %d subscribers removed by %s',
count($subscriber_phids),
$author_handle->renderLink());
break;
}
$dialog = id(new SubscriptionListDialogBuilder())
->setViewer($viewer)
->setTitle($title)
->setObjectPHID($object_phid)
->setHandles($handles)
->buildDialog();
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsMailEngineExtension.php | src/applications/subscriptions/engineextension/PhabricatorSubscriptionsMailEngineExtension.php | <?php
final class PhabricatorSubscriptionsMailEngineExtension
extends PhabricatorMailEngineExtension {
const EXTENSIONKEY = 'subscriptions';
public function supportsObject($object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function newMailStampTemplates($object) {
return array(
id(new PhabricatorPHIDMailStamp())
->setKey('subscriber')
->setLabel(pht('Subscriber')),
);
}
public function newMailStamps($object, array $xactions) {
$editor = $this->getEditor();
$viewer = $this->getViewer();
$subscriber_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$object->getPHID(),
PhabricatorObjectHasSubscriberEdgeType::EDGECONST);
$this->getMailStamp('subscriber')
->setValue($subscriber_phids);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsEditEngineExtension.php | src/applications/subscriptions/engineextension/PhabricatorSubscriptionsEditEngineExtension.php | <?php
final class PhabricatorSubscriptionsEditEngineExtension
extends PhabricatorEditEngineExtension {
const EXTENSIONKEY = 'subscriptions.subscribers';
const FIELDKEY = 'subscriberPHIDs';
const EDITKEY_ADD = 'subscribers.add';
const EDITKEY_SET = 'subscribers.set';
const EDITKEY_REMOVE = 'subscribers.remove';
public function getExtensionPriority() {
return 750;
}
public function isExtensionEnabled() {
return true;
}
public function getExtensionName() {
return pht('Subscriptions');
}
public function supportsObject(
PhabricatorEditEngine $engine,
PhabricatorApplicationTransactionInterface $object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function buildCustomEditFields(
PhabricatorEditEngine $engine,
PhabricatorApplicationTransactionInterface $object) {
$subscribers_type = PhabricatorTransactions::TYPE_SUBSCRIBERS;
$object_phid = $object->getPHID();
if ($object_phid) {
$sub_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$object_phid);
} else {
$sub_phids = array();
}
$viewer = $engine->getViewer();
$subscribers_field = id(new PhabricatorSubscribersEditField())
->setKey(self::FIELDKEY)
->setLabel(pht('Subscribers'))
->setEditTypeKey('subscribers')
->setAliases(array('subscriber', 'subscribers'))
->setIsCopyable(true)
->setUseEdgeTransactions(true)
->setCommentActionLabel(pht('Change Subscribers'))
->setCommentActionOrder(9000)
->setDescription(pht('Choose subscribers.'))
->setTransactionType($subscribers_type)
->setValue($sub_phids)
->setViewer($viewer);
$subscriber_datasource = id(new PhabricatorMetaMTAMailableDatasource())
->setViewer($viewer);
$edit_add = $subscribers_field->getConduitEditType(self::EDITKEY_ADD)
->setConduitDescription(pht('Add subscribers.'));
$edit_set = $subscribers_field->getConduitEditType(self::EDITKEY_SET)
->setConduitDescription(
pht('Set subscribers, overwriting current value.'));
$edit_rem = $subscribers_field->getConduitEditType(self::EDITKEY_REMOVE)
->setConduitDescription(pht('Remove subscribers.'));
$subscribers_field->getBulkEditType(self::EDITKEY_ADD)
->setBulkEditLabel(pht('Add subscribers'))
->setDatasource($subscriber_datasource);
$subscribers_field->getBulkEditType(self::EDITKEY_SET)
->setBulkEditLabel(pht('Set subscribers to'))
->setDatasource($subscriber_datasource);
$subscribers_field->getBulkEditType(self::EDITKEY_REMOVE)
->setBulkEditLabel(pht('Remove subscribers'))
->setDatasource($subscriber_datasource);
return array(
$subscribers_field,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsFulltextEngineExtension.php | src/applications/subscriptions/engineextension/PhabricatorSubscriptionsFulltextEngineExtension.php | <?php
final class PhabricatorSubscriptionsFulltextEngineExtension
extends PhabricatorFulltextEngineExtension {
const EXTENSIONKEY = 'subscriptions';
public function getExtensionName() {
return pht('Subscribers');
}
public function shouldEnrichFulltextObject($object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function enrichFulltextObject(
$object,
PhabricatorSearchAbstractDocument $document) {
$subscriber_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$object->getPHID());
if (!$subscriber_phids) {
return;
}
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->getViewer())
->withPHIDs($subscriber_phids)
->execute();
foreach ($handles as $phid => $handle) {
$document->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_SUBSCRIBER,
$phid,
$handle->getType(),
$document->getDocumentModified()); // Bogus timestamp.
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsCurtainExtension.php | src/applications/subscriptions/engineextension/PhabricatorSubscriptionsCurtainExtension.php | <?php
final class PhabricatorSubscriptionsCurtainExtension
extends PHUICurtainExtension {
const EXTENSIONKEY = 'subscriptions.subscribers';
public function shouldEnableForObject($object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function getExtensionApplication() {
return new PhabricatorSubscriptionsApplication();
}
public function buildCurtainPanel($object) {
$viewer = $this->getViewer();
$viewer_phid = $viewer->getPHID();
$object_phid = $object->getPHID();
$max_handles = 100;
$max_visible = 8;
// TODO: We should limit the number of subscriber PHIDs we'll load, so
// we degrade gracefully when objects have thousands of subscribers.
$subscriber_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$object_phid);
$subscriber_count = count($subscriber_phids);
$subscriber_phids = $this->sortSubscriberPHIDs(
$subscriber_phids,
null);
// If we have fewer subscribers than the maximum number of handles we're
// willing to load, load all the handles and then sort the list based on
// complete handle data.
// If we have too many PHIDs, we'll skip this step and accept a less
// useful ordering.
$handles = null;
if ($subscriber_count <= $max_handles) {
$handles = $viewer->loadHandles($subscriber_phids);
$subscriber_phids = $this->sortSubscriberPHIDs(
$subscriber_phids,
$handles);
}
// If we have more PHIDs to show than visible slots, slice the list.
if ($subscriber_count > $max_visible) {
$visible_phids = array_slice($subscriber_phids, 0, $max_visible - 1);
$show_all = true;
} else {
$visible_phids = $subscriber_phids;
$show_all = false;
}
// If we didn't load handles earlier because we had too many PHIDs,
// load them now.
if ($handles === null) {
$handles = $viewer->loadHandles($visible_phids);
}
PhabricatorPolicyFilterSet::loadHandleViewCapabilities(
$viewer,
$handles,
array($object));
$ref_list = id(new PHUICurtainObjectRefListView())
->setViewer($viewer)
->setEmptyMessage(pht('None'));
foreach ($visible_phids as $phid) {
$handle = $handles[$phid];
$ref = $ref_list->newObjectRefView()
->setHandle($handle);
if ($phid === $viewer_phid) {
$ref->setHighlighted(true);
}
if ($handle->hasCapabilities()) {
if (!$handle->hasViewCapability($object)) {
$ref->setExiled(true);
}
}
}
if ($show_all) {
$view_all_uri = urisprintf(
'/subscriptions/list/%s/',
$object_phid);
$ref_list->newTailLink()
->setURI($view_all_uri)
->setText(pht('View All %d Subscriber(s)', $subscriber_count))
->setWorkflow(true);
}
return $this->newPanel()
->setHeaderText(pht('Subscribers'))
->setOrder(20000)
->appendChild($ref_list);
}
private function sortSubscriberPHIDs(array $subscriber_phids, $handles) {
// Sort subscriber PHIDs with or without handle data. If we have handles,
// we can sort results more comprehensively.
$viewer = $this->getViewer();
$user_type = PhabricatorPeopleUserPHIDType::TYPECONST;
$viewer_phid = $viewer->getPHID();
$type_order_map = array(
PhabricatorPeopleUserPHIDType::TYPECONST => 0,
PhabricatorProjectProjectPHIDType::TYPECONST => 1,
PhabricatorOwnersPackagePHIDType::TYPECONST => 2,
);
$default_type_order = count($type_order_map);
$subscriber_map = array();
foreach ($subscriber_phids as $subscriber_phid) {
$is_viewer = ($viewer_phid === $subscriber_phid);
$subscriber_type = phid_get_type($subscriber_phid);
$type_order = idx($type_order_map, $subscriber_type, $default_type_order);
$sort_name = '';
$is_complete = false;
if ($handles) {
if (isset($handles[$subscriber_phid])) {
$handle = $handles[$subscriber_phid];
if ($handle->isComplete()) {
$is_complete = true;
$sort_name = $handle->getLinkName();
$sort_name = phutil_utf8_strtolower($sort_name);
}
}
}
$subscriber_map[$subscriber_phid] = id(new PhutilSortVector())
->addInt($is_viewer ? 0 : 1)
->addInt($is_complete ? 0 : 1)
->addInt($type_order)
->addString($sort_name);
}
$subscriber_map = msortv($subscriber_map, 'getSelf');
return array_keys($subscriber_map);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsSearchEngineExtension.php | src/applications/subscriptions/engineextension/PhabricatorSubscriptionsSearchEngineExtension.php | <?php
final class PhabricatorSubscriptionsSearchEngineExtension
extends PhabricatorSearchEngineExtension {
const EXTENSIONKEY = 'subscriptions';
public function isExtensionEnabled() {
return PhabricatorApplication::isClassInstalled(
'PhabricatorSubscriptionsApplication');
}
public function getExtensionName() {
return pht('Support for Subscriptions');
}
public function getExtensionOrder() {
return 2000;
}
public function supportsObject($object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function applyConstraintsToQuery(
$object,
$query,
PhabricatorSavedQuery $saved,
array $map) {
if (!empty($map['subscriberPHIDs'])) {
$query->withEdgeLogicPHIDs(
PhabricatorObjectHasSubscriberEdgeType::EDGECONST,
PhabricatorQueryConstraint::OPERATOR_OR,
$map['subscriberPHIDs']);
}
}
public function getSearchFields($object) {
$fields = array();
$fields[] = id(new PhabricatorSearchSubscribersField())
->setLabel(pht('Subscribers'))
->setKey('subscriberPHIDs')
->setConduitKey('subscribers')
->setAliases(array('subscriber', 'subscribers'))
->setDescription(
pht('Search for objects with certain subscribers.'));
return $fields;
}
public function getSearchAttachments($object) {
return array(
id(new PhabricatorSubscriptionsSearchEngineAttachment())
->setAttachmentKey('subscribers'),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/engineextension/PhabricatorSubscriptionsSearchEngineAttachment.php | src/applications/subscriptions/engineextension/PhabricatorSubscriptionsSearchEngineAttachment.php | <?php
final class PhabricatorSubscriptionsSearchEngineAttachment
extends PhabricatorSearchEngineAttachment {
public function getAttachmentName() {
return pht('Subscribers');
}
public function getAttachmentDescription() {
return pht('Get information about subscribers.');
}
public function loadAttachmentData(array $objects, $spec) {
$object_phids = mpull($objects, 'getPHID');
$edge_type = PhabricatorObjectHasSubscriberEdgeType::EDGECONST;
$subscribers_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($object_phids)
->withEdgeTypes(array($edge_type));
$subscribers_query->execute();
$viewer = $this->getViewer();
$viewer_phid = $viewer->getPHID();
if ($viewer) {
$edges = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($object_phids)
->withEdgeTypes(array($edge_type))
->withDestinationPHIDs(array($viewer_phid))
->execute();
$viewer_map = array();
foreach ($edges as $object_phid => $types) {
if ($types[$edge_type]) {
$viewer_map[$object_phid] = true;
}
}
} else {
$viewer_map = array();
}
return array(
'subscribers.query' => $subscribers_query,
'viewer.map' => $viewer_map,
);
}
public function getAttachmentForObject($object, $data, $spec) {
$subscribers_query = idx($data, 'subscribers.query');
$viewer_map = idx($data, 'viewer.map');
$object_phid = $object->getPHID();
$subscribed_phids = $subscribers_query->getDestinationPHIDs(
array($object_phid),
array(PhabricatorObjectHasSubscriberEdgeType::EDGECONST));
$subscribed_count = count($subscribed_phids);
if ($subscribed_count > 10) {
$subscribed_phids = array_slice($subscribed_phids, 0, 10);
}
$subscribed_phids = array_values($subscribed_phids);
$viewer = $this->getViewer();
$viewer_phid = $viewer->getPHID();
if (!$viewer_phid) {
$self_subscribed = false;
} else if (isset($viewer_map[$object_phid])) {
$self_subscribed = true;
} else if ($object->isAutomaticallySubscribed($viewer_phid)) {
$self_subscribed = true;
} else {
$self_subscribed = false;
}
return array(
'subscriberPHIDs' => $subscribed_phids,
'subscriberCount' => $subscribed_count,
'viewerIsSubscribed' => $self_subscribed,
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/query/PhabricatorSubscribersQuery.php | src/applications/subscriptions/query/PhabricatorSubscribersQuery.php | <?php
final class PhabricatorSubscribersQuery extends PhabricatorQuery {
private $objectPHIDs;
private $subscriberPHIDs;
public static function loadSubscribersForPHID($phid) {
if (!$phid) {
return array();
}
$subscribers = id(new PhabricatorSubscribersQuery())
->withObjectPHIDs(array($phid))
->execute();
return $subscribers[$phid];
}
public function withObjectPHIDs(array $object_phids) {
$this->objectPHIDs = $object_phids;
return $this;
}
public function withSubscriberPHIDs(array $subscriber_phids) {
$this->subscriberPHIDs = $subscriber_phids;
return $this;
}
public function execute() {
$query = new PhabricatorEdgeQuery();
$edge_type = PhabricatorObjectHasSubscriberEdgeType::EDGECONST;
$query->withSourcePHIDs($this->objectPHIDs);
$query->withEdgeTypes(array($edge_type));
if ($this->subscriberPHIDs) {
$query->withDestinationPHIDs($this->subscriberPHIDs);
}
$edges = $query->execute();
$results = array_fill_keys($this->objectPHIDs, array());
foreach ($edges as $src => $edge_types) {
foreach ($edge_types[$edge_type] as $dst => $data) {
$results[$src][] = $dst;
}
}
return $results;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/command/PhabricatorSubscriptionsSubscribeEmailCommand.php | src/applications/subscriptions/command/PhabricatorSubscriptionsSubscribeEmailCommand.php | <?php
final class PhabricatorSubscriptionsSubscribeEmailCommand
extends MetaMTAEmailTransactionCommand {
public function getCommand() {
return 'subscribe';
}
public function getCommandSyntax() {
return '**!subscribe** //username #project ...//';
}
public function getCommandSummary() {
return pht('Add users or projects as subscribers.');
}
public function getCommandDescription() {
return pht(
'Add one or more subscribers to the object. You can add users by '.
'providing their usernames, or add projects by adding their hashtags. '.
'For example, use `%s` to add the user `alincoln` and the project with '.
'hashtag `#ios` as subscribers.'.
"\n\n".
'Subscribers which are invalid or unrecognized will be ignored. This '.
'command has no effect if you do not specify any subscribers.'.
"\n\n".
'Users who are CC\'d on the email itself are also automatically '.
'subscribed if their addresses are associated with a known account.',
'!subscribe alincoln #ios');
}
public function getCommandAliases() {
return array(
'cc',
);
}
public function isCommandSupportedForObject(
PhabricatorApplicationTransactionInterface $object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function buildTransactions(
PhabricatorUser $viewer,
PhabricatorApplicationTransactionInterface $object,
PhabricatorMetaMTAReceivedMail $mail,
$command,
array $argv) {
$subscriber_phids = id(new PhabricatorObjectListQuery())
->setViewer($viewer)
->setAllowedTypes(
array(
PhabricatorPeopleUserPHIDType::TYPECONST,
PhabricatorProjectProjectPHIDType::TYPECONST,
))
->setObjectList(implode(' ', $argv))
->setAllowPartialResults(true)
->execute();
$xactions = array();
$xactions[] = $object->getApplicationTransactionTemplate()
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
->setNewValue(
array(
'+' => array_fuse($subscriber_phids),
));
return $xactions;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/command/PhabricatorSubscriptionsUnsubscribeEmailCommand.php | src/applications/subscriptions/command/PhabricatorSubscriptionsUnsubscribeEmailCommand.php | <?php
final class PhabricatorSubscriptionsUnsubscribeEmailCommand
extends MetaMTAEmailTransactionCommand {
public function getCommand() {
return 'unsubscribe';
}
public function getCommandSummary() {
return pht('Remove yourself as a subscriber.');
}
public function isCommandSupportedForObject(
PhabricatorApplicationTransactionInterface $object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function buildTransactions(
PhabricatorUser $viewer,
PhabricatorApplicationTransactionInterface $object,
PhabricatorMetaMTAReceivedMail $mail,
$command,
array $argv) {
$xactions = array();
$xactions[] = $object->getApplicationTransactionTemplate()
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
->setNewValue(
array(
'-' => array($viewer->getPHID()),
));
return $xactions;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/interface/PhabricatorSubscribableInterface.php | src/applications/subscriptions/interface/PhabricatorSubscribableInterface.php | <?php
interface PhabricatorSubscribableInterface {
/**
* Return true to indicate that the given PHID is automatically subscribed
* to the object (for example, they are the author or in some other way
* irrevocably a subscriber). This will, e.g., cause the UI to render
* "Automatically Subscribed" instead of "Subscribe".
*
* @param PHID PHID (presumably a user) to test for automatic subscription.
* @return bool True if the object/user is automatically subscribed.
*/
public function isAutomaticallySubscribed($phid);
}
// TEMPLATE IMPLEMENTATION /////////////////////////////////////////////////////
/* -( PhabricatorSubscribableInterface )----------------------------------- */
/*
public function isAutomaticallySubscribed($phid) {
return false;
}
*/
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php | src/applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php | <?php
final class PhabricatorSubscriptionsEditor extends PhabricatorEditor {
private $object;
private $explicitSubscribePHIDs = array();
private $implicitSubscribePHIDs = array();
private $unsubscribePHIDs = array();
public function setObject(PhabricatorSubscribableInterface $object) {
$this->object = $object;
return $this;
}
/**
* Add explicit subscribers. These subscribers have explicitly subscribed
* (or been subscribed) to the object, and will be added even if they
* had previously unsubscribed.
*
* @param list<phid> List of PHIDs to explicitly subscribe.
* @return this
*/
public function subscribeExplicit(array $phids) {
$this->explicitSubscribePHIDs += array_fill_keys($phids, true);
return $this;
}
/**
* Add implicit subscribers. These subscribers have taken some action which
* implicitly subscribes them (e.g., adding a comment) but it will be
* suppressed if they've previously unsubscribed from the object.
*
* @param list<phid> List of PHIDs to implicitly subscribe.
* @return this
*/
public function subscribeImplicit(array $phids) {
$this->implicitSubscribePHIDs += array_fill_keys($phids, true);
return $this;
}
/**
* Unsubscribe PHIDs and mark them as unsubscribed, so implicit subscriptions
* will not resubscribe them.
*
* @param list<phid> List of PHIDs to unsubscribe.
* @return this
*/
public function unsubscribe(array $phids) {
$this->unsubscribePHIDs += array_fill_keys($phids, true);
return $this;
}
public function save() {
if (!$this->object) {
throw new PhutilInvalidStateException('setObject');
}
$actor = $this->requireActor();
$src = $this->object->getPHID();
if ($this->implicitSubscribePHIDs) {
$unsub = PhabricatorEdgeQuery::loadDestinationPHIDs(
$src,
PhabricatorObjectHasUnsubscriberEdgeType::EDGECONST);
$unsub = array_fill_keys($unsub, true);
$this->implicitSubscribePHIDs = array_diff_key(
$this->implicitSubscribePHIDs,
$unsub);
}
$add = $this->implicitSubscribePHIDs + $this->explicitSubscribePHIDs;
$del = $this->unsubscribePHIDs;
// If a PHID is marked for both subscription and unsubscription, treat
// unsubscription as the stronger action.
$add = array_diff_key($add, $del);
if ($add || $del) {
$u_type = PhabricatorObjectHasUnsubscriberEdgeType::EDGECONST;
$s_type = PhabricatorObjectHasSubscriberEdgeType::EDGECONST;
$editor = new PhabricatorEdgeEditor();
foreach ($add as $phid => $ignored) {
$editor->removeEdge($src, $u_type, $phid);
$editor->addEdge($src, $s_type, $phid);
}
foreach ($del as $phid => $ignored) {
$editor->removeEdge($src, $s_type, $phid);
$editor->addEdge($src, $u_type, $phid);
}
$editor->save();
}
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/application/PhabricatorSubscriptionsApplication.php | src/applications/subscriptions/application/PhabricatorSubscriptionsApplication.php | <?php
final class PhabricatorSubscriptionsApplication extends PhabricatorApplication {
public function getName() {
return pht('Subscriptions');
}
public function isLaunchable() {
return false;
}
public function canUninstall() {
return false;
}
public function getEventListeners() {
return array(
new PhabricatorSubscriptionsUIEventListener(),
);
}
public function getRoutes() {
return array(
'/subscriptions/' => array(
'(?P<action>add|delete)/'.
'(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsEditController',
'mute/' => array(
'(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsMuteController',
),
'list/(?P<phid>[^/]+)/' => 'PhabricatorSubscriptionsListController',
'transaction/(?P<type>add|rem)/(?<phid>[^/]+)/'
=> 'PhabricatorSubscriptionsTransactionController',
),
);
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
phacility/phabricator | https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/subscriptions/policyrule/PhabricatorSubscriptionsSubscribersPolicyRule.php | src/applications/subscriptions/policyrule/PhabricatorSubscriptionsSubscribersPolicyRule.php | <?php
final class PhabricatorSubscriptionsSubscribersPolicyRule
extends PhabricatorPolicyRule {
private $subscribed = array();
private $sourcePHIDs = array();
public function getObjectPolicyKey() {
return 'subscriptions.subscribers';
}
public function getObjectPolicyName() {
return pht('Subscribers');
}
public function getPolicyExplanation() {
return pht('Subscribers can take this action.');
}
public function getRuleDescription() {
return pht('subscribers');
}
public function canApplyToObject(PhabricatorPolicyInterface $object) {
return ($object instanceof PhabricatorSubscribableInterface);
}
public function willApplyRules(
PhabricatorUser $viewer,
array $values,
array $objects) {
// We want to let the user see the object if they're a subscriber or
// a member of any project which is a subscriber. Additionally, because
// subscriber state is complex, we need to read hints passed from
// the TransactionEditor to predict policy state after transactions apply.
$viewer_phid = $viewer->getPHID();
if (!$viewer_phid) {
return;
}
if (empty($this->subscribed[$viewer_phid])) {
$this->subscribed[$viewer_phid] = array();
}
// Load the project PHIDs the user is a member of. We use the omnipotent
// user here because projects may themselves have "Subscribers" visibility
// policies and we don't want to get stuck in an infinite stack of
// recursive policy checks. See T13106.
if (!isset($this->sourcePHIDs[$viewer_phid])) {
$projects = id(new PhabricatorProjectQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withMemberPHIDs(array($viewer_phid))
->execute();
$source_phids = mpull($projects, 'getPHID');
$source_phids[] = $viewer_phid;
$this->sourcePHIDs[$viewer_phid] = $source_phids;
}
// Look for transaction hints.
foreach ($objects as $key => $object) {
$cache = $this->getTransactionHint($object);
if ($cache === null) {
// We don't have a hint for this object, so we'll deal with it below.
continue;
}
// We have a hint, so use that as the source of truth.
unset($objects[$key]);
foreach ($this->sourcePHIDs[$viewer_phid] as $source_phid) {
if (isset($cache[$source_phid])) {
$this->subscribed[$viewer_phid][$object->getPHID()] = true;
break;
}
}
}
$phids = mpull($objects, 'getPHID');
if (!$phids) {
return;
}
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($this->sourcePHIDs[$viewer_phid])
->withEdgeTypes(
array(
PhabricatorSubscribedToObjectEdgeType::EDGECONST,
))
->withDestinationPHIDs($phids);
$edge_query->execute();
$subscribed = $edge_query->getDestinationPHIDs();
if (!$subscribed) {
return;
}
$this->subscribed[$viewer_phid] += array_fill_keys($subscribed, true);
}
public function applyRule(
PhabricatorUser $viewer,
$value,
PhabricatorPolicyInterface $object) {
$viewer_phid = $viewer->getPHID();
if (!$viewer_phid) {
return false;
}
if ($object->isAutomaticallySubscribed($viewer_phid)) {
return true;
}
$subscribed = idx($this->subscribed, $viewer_phid);
return isset($subscribed[$object->getPHID()]);
}
public function getValueControlType() {
return self::CONTROL_TYPE_NONE;
}
}
| php | Apache-2.0 | 5720a38cfe95b00ca4be5016dd0d2f3195f4fa04 | 2026-01-04T15:03:23.651835Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.