mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-13 10:22:42 +01:00
0a069cb55a
Summary: Unmuck almost all of the we-sort-of-have-viewers-some-of-the-time mess. There are a few notable cases here: - I used Omnipotent users when indexing objects for search. I think this is correct; we do policy filtering when showing results. - I cheated in a bad way in the Remarkup object rule, but fixing this requires fixing all the PhabricatorRemarkupEngine callsites (there are 85). I'll do that in the next diff. - I cheated in a few random places, like when sending mail about package edits. These aren't a big deal. Test Plan: - Grepped for all PhabricatorObjectHandleData references. - Gave them viewers. Reviewers: vrana Reviewed By: vrana CC: aran, edward Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D5151
159 lines
4.1 KiB
PHP
159 lines
4.1 KiB
PHP
<?php
|
|
|
|
final class PackageModifyMail extends PackageMail {
|
|
|
|
protected $addOwners;
|
|
protected $removeOwners;
|
|
protected $allOwners;
|
|
protected $touchedRepos;
|
|
protected $addPaths;
|
|
protected $removePaths;
|
|
|
|
public function __construct(
|
|
PhabricatorOwnersPackage $package,
|
|
$add_owners,
|
|
$remove_owners,
|
|
$all_owners,
|
|
$touched_repos,
|
|
$add_paths,
|
|
$remove_paths) {
|
|
|
|
$this->package = $package;
|
|
|
|
$this->addOwners = $add_owners;
|
|
$this->removeOwners = $remove_owners;
|
|
$this->allOwners = $all_owners;
|
|
$this->touchedRepos = $touched_repos;
|
|
$this->addPaths = $add_paths;
|
|
$this->removePaths = $remove_paths;
|
|
}
|
|
|
|
protected function getVerb() {
|
|
return 'Modified';
|
|
}
|
|
|
|
protected function isNewThread() {
|
|
return false;
|
|
}
|
|
|
|
protected function needSend() {
|
|
$package = $this->getPackage();
|
|
if ($package->getOldPrimaryOwnerPHID() !== $package->getPrimaryOwnerPHID()
|
|
|| $package->getOldAuditingEnabled() != $package->getAuditingEnabled()
|
|
|| $this->addOwners
|
|
|| $this->removeOwners
|
|
|| $this->addPaths
|
|
|| $this->removePaths) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
protected function loadData() {
|
|
$this->mailTo = $this->allOwners;
|
|
|
|
$phids = array_merge(
|
|
$this->allOwners,
|
|
$this->touchedRepos,
|
|
array(
|
|
$this->getPackage()->getActorPHID(),
|
|
));
|
|
$this->handles = id(new PhabricatorObjectHandleData($phids))
|
|
->setViewer($this->getActor())
|
|
->loadHandles();
|
|
}
|
|
|
|
protected function renderDescriptionSection() {
|
|
return null;
|
|
}
|
|
|
|
protected function renderPrimaryOwnerSection() {
|
|
$package = $this->getPackage();
|
|
$handles = $this->getHandles();
|
|
|
|
$old_primary_owner_phid = $package->getOldPrimaryOwnerPHID();
|
|
$primary_owner_phid = $package->getPrimaryOwnerPHID();
|
|
if ($old_primary_owner_phid == $primary_owner_phid) {
|
|
return null;
|
|
}
|
|
|
|
$section = array();
|
|
$section[] = 'PRIMARY OWNER CHANGE';
|
|
$section[] = ' Old owner: ' .
|
|
$handles[$old_primary_owner_phid]->getName();
|
|
$section[] = ' New owner: ' .
|
|
$handles[$primary_owner_phid]->getName();
|
|
|
|
return implode("\n", $section);
|
|
}
|
|
|
|
protected function renderOwnersSection() {
|
|
$section = array();
|
|
$add_owners = $this->addOwners;
|
|
$remove_owners = $this->removeOwners;
|
|
$handles = $this->getHandles();
|
|
|
|
if ($add_owners) {
|
|
$add_owners = array_select_keys($handles, $add_owners);
|
|
$add_owners = mpull($add_owners, 'getName');
|
|
$section[] = 'ADDED OWNERS';
|
|
$section[] = ' '.implode(', ', $add_owners);
|
|
}
|
|
|
|
if ($remove_owners) {
|
|
if ($add_owners) {
|
|
$section[] = '';
|
|
}
|
|
$remove_owners = array_select_keys($handles, $remove_owners);
|
|
$remove_owners = mpull($remove_owners, 'getName');
|
|
$section[] = 'REMOVED OWNERS';
|
|
$section[] = ' '.implode(', ', $remove_owners);
|
|
}
|
|
|
|
if ($section) {
|
|
return implode("\n", $section);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
protected function renderAuditingEnabledSection() {
|
|
$package = $this->getPackage();
|
|
$old_auditing_enabled = $package->getOldAuditingEnabled();
|
|
$auditing_enabled = $package->getAuditingEnabled();
|
|
if ($old_auditing_enabled == $auditing_enabled) {
|
|
return null;
|
|
}
|
|
|
|
$section = array();
|
|
$section[] = 'AUDITING ENABLED STATUS CHANGE';
|
|
$section[] = ' Old value: '.
|
|
($old_auditing_enabled ? 'Enabled' : 'Disabled');
|
|
$section[] = ' New value: '.
|
|
($auditing_enabled ? 'Enabled' : 'Disabled');
|
|
return implode("\n", $section);
|
|
}
|
|
|
|
protected function renderPathsSection() {
|
|
$section = array();
|
|
if ($this->addPaths) {
|
|
$section[] = 'ADDED PATHS';
|
|
foreach ($this->addPaths as $repository_phid => $paths) {
|
|
$section[] = $this->renderRepoSubSection($repository_phid, $paths);
|
|
}
|
|
}
|
|
|
|
if ($this->removePaths) {
|
|
if ($this->addPaths) {
|
|
$section[] = '';
|
|
}
|
|
$section[] = 'REMOVED PATHS';
|
|
foreach ($this->removePaths as $repository_phid => $paths) {
|
|
$section[] = $this->renderRepoSubSection($repository_phid, $paths);
|
|
}
|
|
}
|
|
return implode("\n", $section);
|
|
}
|
|
|
|
}
|