1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 04:50:55 +01: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 * This is mostly for compatibility with
* @{class:AphrontCursorPagedPolicyAwareQuery}. * @{class:PhabricatorCursorPagedPolicyAwareQuery}.
*/ */
public function getID() { public function getID() {
return $this->getAPIMethodName(); return $this->getAPIMethodName();
@ -166,6 +166,10 @@ abstract class ConduitAPIMethod
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getPHID() {
return null;
}
public function getCapabilities() { public function getCapabilities() {
return array( return array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,7 +3,6 @@
final class ReleephBranch extends ReleephDAO final class ReleephBranch extends ReleephDAO
implements PhabricatorPolicyInterface { implements PhabricatorPolicyInterface {
protected $phid;
protected $releephProjectID; protected $releephProjectID;
protected $isActive; protected $isActive;
protected $createdByUserPHID; 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_FROM_DIFF = 'commit-author-is-from-diff';
const COMMIT_AUTHOR_REQUESTOR = 'commit-author-is-requestor'; const COMMIT_AUTHOR_REQUESTOR = 'commit-author-is-requestor';
protected $phid;
protected $name; protected $name;
// Specifying the place to pick from is a requirement for svn, though not // 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, PhabricatorPolicyInterface,
PhabricatorCustomFieldInterface { PhabricatorCustomFieldInterface {
protected $phid;
protected $branchID; protected $branchID;
protected $requestUserPHID; protected $requestUserPHID;
protected $details = array(); protected $details = array();

View file

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

View file

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

View file

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