1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Make PhabricatorPolicyInterface require a getPHID() method

Summary:
Ref T603. This cleans up an existing callsite in the policy filter, and opens up some stuff in the future.

Some policy objects don't have real PHIDs:

  PhabricatorTokenGiven
  PhabricatorSavedQuery
  PhabricatorNamedQuery
  PhrequentUserTime
  PhabricatorFlag
  PhabricatorDaemonLog
  PhabricatorConduitMethodCallLog
  ConduitAPIMethod
  PhabricatorChatLogEvent
  PhabricatorChatLogChannel

Although it would be reasonable to add real PHIDs to some of these (like `ChatLogChannel`), it probably doesn't make much sense for others (`DaemonLog`, `MethodCallLog`). Just let them return `null`.

Also remove some duplicate `$id` and `$phid` properties. These are declared on `PhabricatorLiskDAO` and do not need to be redeclared.

Test Plan: Ran the `testEverythingImplemented` unit test, which verifies that all classes conform to the interface.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7306
This commit is contained in:
epriestley 2013-10-14 14:35:47 -07:00
parent 0ce4f6d176
commit 073cb0e78c
31 changed files with 24 additions and 46 deletions

View file

@ -25,7 +25,7 @@ abstract class ConduitAPIMethod
/**
* This is mostly for compatibility with
* @{class:AphrontCursorPagedPolicyAwareQuery}.
* @{class:PhabricatorCursorPagedPolicyAwareQuery}.
*/
public function getID() {
return $this->getAPIMethodName();
@ -166,6 +166,10 @@ abstract class ConduitAPIMethod
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getPHID() {
return null;
}
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,

View file

@ -3,8 +3,6 @@
final class PhabricatorConfigEntry extends PhabricatorConfigEntryDAO
implements PhabricatorPolicyInterface {
protected $id;
protected $phid;
protected $namespace;
protected $configKey;
protected $value;

View file

@ -6,8 +6,6 @@
final class ConpherenceThread extends ConpherenceDAO
implements PhabricatorPolicyInterface {
protected $id;
protected $phid;
protected $title;
protected $messageCount;
protected $recentParticipantPHIDs = array();

View file

@ -7,8 +7,6 @@ final class PhabricatorCountdown
extends PhabricatorCountdownDAO
implements PhabricatorPolicyInterface {
protected $id;
protected $phid;
protected $title;
protected $authorPHID;
protected $epoch;

View file

@ -26,6 +26,9 @@ final class PhabricatorDaemonLog extends PhabricatorDaemonDAO
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getPHID() {
return null;
}
public function getCapabilities() {
return array(

View file

@ -13,7 +13,6 @@ final class DifferentialRevision extends DifferentialDAO
protected $summary = '';
protected $testPlan = '';
protected $phid;
protected $authorPHID;
protected $lastReviewerPHID;

View file

@ -3,7 +3,6 @@
final class DivinerLiveBook extends DivinerDAO
implements PhabricatorPolicyInterface {
protected $phid;
protected $name;
protected $viewPolicy;
protected $configurationData = array();

View file

@ -3,7 +3,6 @@
final class DivinerLiveSymbol extends DivinerDAO
implements PhabricatorPolicyInterface, PhabricatorMarkupInterface {
protected $phid;
protected $bookPHID;
protected $context;
protected $type;

View file

@ -283,6 +283,9 @@ abstract class PhabricatorFeedStory implements PhabricatorPolicyInterface {
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */
public function getPHID() {
return null;
}
/**
* @task policy

View file

@ -14,7 +14,6 @@ final class PhabricatorFile extends PhabricatorFileDAO
const METADATA_IMAGE_WIDTH = 'width';
const METADATA_IMAGE_HEIGHT = 'height';
protected $phid;
protected $name;
protected $mimeType;
protected $byteSize;

View file

@ -3,9 +3,6 @@
final class HeraldTranscript extends HeraldDAO
implements PhabricatorPolicyInterface {
protected $id;
protected $phid;
protected $objectTranscript;
protected $ruleTranscripts = array();
protected $conditionTranscripts = array();

View file

@ -9,7 +9,6 @@ final class LegalpadDocument extends LegalpadDAO
PhabricatorSubscribableInterface,
PhabricatorApplicationTransactionInterface {
protected $phid;
protected $title;
protected $contributorCount;
protected $recentContributorPHIDs = array();

View file

@ -8,7 +8,6 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
protected $authorPHID;
protected $filePHID;
protected $phid;
protected $name;
protected $isDisabled = 0;
protected $audioPHID;

View file

@ -4,7 +4,6 @@ final class PhabricatorMetaMTAMailingList extends PhabricatorMetaMTADAO
implements PhabricatorPolicyInterface {
protected $name;
protected $phid;
protected $email;
protected $uri;

View file

@ -10,7 +10,6 @@ final class ManiphestTask extends ManiphestDAO
const MARKUP_FIELD_DESCRIPTION = 'markup:desc';
protected $phid;
protected $authorPHID;
protected $ownerPHID;
protected $ccPHIDs = array();

View file

@ -3,7 +3,6 @@
final class PhabricatorOwnersPackage extends PhabricatorOwnersDAO
implements PhabricatorPolicyInterface {
protected $phid;
protected $name;
protected $originalName;
protected $auditingEnabled;

View file

@ -9,7 +9,6 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
PhabricatorTokenReceiverInterface,
PhabricatorPolicyInterface {
protected $phid;
protected $title;
protected $authorPHID;
protected $filePHID;

View file

@ -11,7 +11,6 @@ final class PhabricatorUser
const NAMETOKEN_TABLE = 'user_nametoken';
const MAXIMUM_USERNAME_LENGTH = 64;
protected $phid;
protected $userName;
protected $realName;
protected $sex;

View file

@ -10,8 +10,6 @@ final class PhameBlog extends PhameDAO
const SKIN_DEFAULT = 'oblivious';
protected $id;
protected $phid;
protected $name;
protected $description;
protected $domain;

View file

@ -15,8 +15,6 @@ final class PhamePost extends PhameDAO
const VISIBILITY_DRAFT = 0;
const VISIBILITY_PUBLISHED = 1;
protected $id;
protected $phid;
protected $bloggerPHID;
protected $title;
protected $phameTitle;

View file

@ -9,8 +9,6 @@ final class PhrictionDocument extends PhrictionDAO
PhabricatorSubscribableInterface,
PhabricatorTokenReceiverInterface {
protected $id;
protected $phid;
protected $slug;
protected $depth;
protected $contentID;

View file

@ -10,6 +10,10 @@ final class PhabricatorPolicyTestObject
private $policies = array();
private $automaticCapabilities = array();
public function getPHID() {
return null;
}
public function getCapabilities() {
return $this->capabilities;
}

View file

@ -282,19 +282,9 @@ final class PhabricatorPolicyFilter {
$details = array_filter(array_merge(array($more), (array)$exceptions));
// NOTE: Not every policy object has a PHID, just pull an arbitrary
// "unknown object" handle if this fails. We're just using this to provide
// a better error message if we can.
$phid = '?';
if (($object instanceof PhabricatorLiskDAO) ||
(method_exists($object, 'getPHID'))) {
try {
$phid = $object->getPHID();
} catch (Exception $ignored) {
// Ignore.
}
}
// NOTE: Not every type of policy object has a real PHID; just load an
// empty handle if a real PHID isn't available.
$phid = nonempty($object->getPHID(), PhabricatorPHIDConstants::PHID_VOID);
$handle = id(new PhabricatorHandleQuery())
->setViewer($this->viewer)

View file

@ -2,6 +2,7 @@
interface PhabricatorPolicyInterface {
public function getPHID();
public function getCapabilities();
public function getPolicy($capability);
public function hasAutomaticCapability($capability, PhabricatorUser $viewer);

View file

@ -4,7 +4,6 @@ final class PhabricatorProject extends PhabricatorProjectDAO
implements PhabricatorPolicyInterface {
protected $name;
protected $phid;
protected $status = PhabricatorProjectStatus::STATUS_ACTIVE;
protected $authorPHID;
protected $subprojectPHIDs = array();

View file

@ -3,7 +3,6 @@
final class ReleephBranch extends ReleephDAO
implements PhabricatorPolicyInterface {
protected $phid;
protected $releephProjectID;
protected $isActive;
protected $createdByUserPHID;

View file

@ -10,7 +10,6 @@ final class ReleephProject extends ReleephDAO
const COMMIT_AUTHOR_FROM_DIFF = 'commit-author-is-from-diff';
const COMMIT_AUTHOR_REQUESTOR = 'commit-author-is-requestor';
protected $phid;
protected $name;
// Specifying the place to pick from is a requirement for svn, though not

View file

@ -5,7 +5,6 @@ final class ReleephRequest extends ReleephDAO
PhabricatorPolicyInterface,
PhabricatorCustomFieldInterface {
protected $phid;
protected $branchID;
protected $requestUserPHID;
protected $details = array();

View file

@ -25,7 +25,6 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
const TABLE_BADCOMMIT = 'repository_badcommit';
const TABLE_LINTMESSAGE = 'repository_lintmessage';
protected $phid;
protected $name;
protected $callsign;
protected $uuid;

View file

@ -8,7 +8,6 @@ final class PhabricatorRepositoryArcanistProject
implements PhabricatorPolicyInterface {
protected $name;
protected $phid;
protected $repositoryID;
protected $symbolIndexLanguages = array();

View file

@ -892,6 +892,11 @@ abstract class LiskDAO {
}
public function getPHID() {
return $this->phid;
}
/**
* Test if a property exists.
*