mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 02:02:41 +01:00
4b9765b896
Summary: Ref T2628. Implements PhabricatorProjectInterface (D9340) in Paste. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2628 Differential Revision: https://secure.phabricator.com/D9341
135 lines
3.2 KiB
PHP
135 lines
3.2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorPaste extends PhabricatorPasteDAO
|
|
implements
|
|
PhabricatorSubscribableInterface,
|
|
PhabricatorTokenReceiverInterface,
|
|
PhabricatorFlaggableInterface,
|
|
PhabricatorPolicyInterface,
|
|
PhabricatorProjectInterface {
|
|
|
|
protected $title;
|
|
protected $authorPHID;
|
|
protected $filePHID;
|
|
protected $language;
|
|
protected $parentPHID;
|
|
protected $viewPolicy;
|
|
protected $mailKey;
|
|
|
|
private $content = self::ATTACHABLE;
|
|
private $rawContent = self::ATTACHABLE;
|
|
|
|
public static function initializeNewPaste(PhabricatorUser $actor) {
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
->setViewer($actor)
|
|
->withClasses(array('PhabricatorApplicationPaste'))
|
|
->executeOne();
|
|
|
|
$view_policy = $app->getPolicy(PasteCapabilityDefaultView::CAPABILITY);
|
|
|
|
return id(new PhabricatorPaste())
|
|
->setTitle('')
|
|
->setAuthorPHID($actor->getPHID())
|
|
->setViewPolicy($view_policy);
|
|
}
|
|
|
|
public function getURI() {
|
|
return '/P'.$this->getID();
|
|
}
|
|
|
|
public function getConfiguration() {
|
|
return array(
|
|
self::CONFIG_AUX_PHID => true,
|
|
) + parent::getConfiguration();
|
|
}
|
|
|
|
public function generatePHID() {
|
|
return PhabricatorPHID::generateNewPHID(
|
|
PhabricatorPastePHIDTypePaste::TYPECONST);
|
|
}
|
|
|
|
public function save() {
|
|
if (!$this->getMailKey()) {
|
|
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
|
}
|
|
return parent::save();
|
|
}
|
|
|
|
public function getFullName() {
|
|
$title = $this->getTitle();
|
|
if (!$title) {
|
|
$title = pht('(An Untitled Masterwork)');
|
|
}
|
|
return 'P'.$this->getID().' '.$title;
|
|
}
|
|
|
|
public function getContent() {
|
|
return $this->assertAttached($this->content);
|
|
}
|
|
|
|
public function attachContent($content) {
|
|
$this->content = $content;
|
|
return $this;
|
|
}
|
|
|
|
public function getRawContent() {
|
|
return $this->assertAttached($this->rawContent);
|
|
}
|
|
|
|
public function attachRawContent($raw_content) {
|
|
$this->rawContent = $raw_content;
|
|
return $this;
|
|
}
|
|
|
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
|
|
|
|
|
public function isAutomaticallySubscribed($phid) {
|
|
return ($this->authorPHID == $phid);
|
|
}
|
|
|
|
public function shouldShowSubscribersProperty() {
|
|
return true;
|
|
}
|
|
|
|
public function shouldAllowSubscription($phid) {
|
|
return true;
|
|
}
|
|
|
|
|
|
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
|
|
|
|
public function getUsersToNotifyOfTokenGiven() {
|
|
return array(
|
|
$this->getAuthorPHID(),
|
|
);
|
|
}
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
public function getCapabilities() {
|
|
return array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
);
|
|
}
|
|
|
|
public function getPolicy($capability) {
|
|
if ($capability == PhabricatorPolicyCapability::CAN_VIEW) {
|
|
return $this->viewPolicy;
|
|
}
|
|
return PhabricatorPolicies::POLICY_NOONE;
|
|
}
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $user) {
|
|
return ($user->getPHID() == $this->getAuthorPHID());
|
|
}
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
return pht('The author of a paste can always view and edit it.');
|
|
}
|
|
|
|
|
|
}
|