2013-07-03 20:15:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class LegalpadDocument extends LegalpadDAO
|
|
|
|
implements
|
|
|
|
PhabricatorPolicyInterface,
|
|
|
|
PhabricatorSubscribableInterface,
|
2014-06-29 16:50:53 +02:00
|
|
|
PhabricatorApplicationTransactionInterface,
|
2014-07-21 15:59:22 +02:00
|
|
|
PhabricatorDestructibleInterface {
|
2013-07-03 20:15:45 +02:00
|
|
|
|
2013-07-09 02:06:49 +02:00
|
|
|
protected $title;
|
|
|
|
protected $contributorCount;
|
|
|
|
protected $recentContributorPHIDs = array();
|
2013-07-03 20:15:45 +02:00
|
|
|
protected $creatorPHID;
|
|
|
|
protected $versions;
|
|
|
|
protected $documentBodyPHID;
|
|
|
|
protected $viewPolicy;
|
|
|
|
protected $editPolicy;
|
2013-07-04 01:37:05 +02:00
|
|
|
protected $mailKey;
|
2014-07-04 17:04:28 +02:00
|
|
|
protected $signatureType;
|
2014-07-04 18:41:27 +02:00
|
|
|
protected $preamble;
|
2014-07-04 17:04:28 +02:00
|
|
|
|
|
|
|
const SIGNATURE_TYPE_INDIVIDUAL = 'user';
|
|
|
|
const SIGNATURE_TYPE_CORPORATION = 'corp';
|
2013-07-03 20:15:45 +02:00
|
|
|
|
2013-09-03 15:02:14 +02:00
|
|
|
private $documentBody = self::ATTACHABLE;
|
|
|
|
private $contributors = self::ATTACHABLE;
|
2014-06-29 01:37:04 +02:00
|
|
|
private $signatures = self::ATTACHABLE;
|
|
|
|
private $userSignatures = array();
|
2013-07-03 20:15:45 +02:00
|
|
|
|
2014-01-30 20:47:42 +01:00
|
|
|
public static function initializeNewDocument(PhabricatorUser $actor) {
|
|
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
|
|
->setViewer($actor)
|
2014-07-23 02:03:09 +02:00
|
|
|
->withClasses(array('PhabricatorLegalpadApplication'))
|
2014-01-30 20:47:42 +01:00
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
$view_policy = $app->getPolicy(LegalpadCapabilityDefaultView::CAPABILITY);
|
|
|
|
$edit_policy = $app->getPolicy(LegalpadCapabilityDefaultEdit::CAPABILITY);
|
|
|
|
|
|
|
|
return id(new LegalpadDocument())
|
|
|
|
->setVersions(0)
|
|
|
|
->setCreatorPHID($actor->getPHID())
|
|
|
|
->setContributorCount(0)
|
|
|
|
->setRecentContributorPHIDs(array())
|
|
|
|
->attachSignatures(array())
|
2014-07-04 17:04:28 +02:00
|
|
|
->setSignatureType(self::SIGNATURE_TYPE_INDIVIDUAL)
|
2014-07-04 18:41:27 +02:00
|
|
|
->setPreamble('')
|
2014-01-30 20:47:42 +01:00
|
|
|
->setViewPolicy($view_policy)
|
|
|
|
->setEditPolicy($edit_policy);
|
|
|
|
}
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2013-07-09 02:06:49 +02:00
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'recentContributorPHIDs' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
2013-07-03 20:15:45 +02:00
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(
|
2014-07-24 00:05:46 +02:00
|
|
|
PhabricatorLegalpadDocumentPHIDType::TYPECONST);
|
2013-07-03 20:15:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDocumentBody() {
|
2013-09-03 15:02:14 +02:00
|
|
|
return $this->assertAttached($this->documentBody);
|
2013-07-03 20:15:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachDocumentBody(LegalpadDocumentBody $body) {
|
|
|
|
$this->documentBody = $body;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getContributors() {
|
2013-09-03 15:02:14 +02:00
|
|
|
return $this->assertAttached($this->contributors);
|
2013-07-03 20:15:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachContributors(array $contributors) {
|
|
|
|
$this->contributors = $contributors;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-01-16 23:36:57 +01:00
|
|
|
public function getSignatures() {
|
|
|
|
return $this->assertAttached($this->signatures);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachSignatures(array $signatures) {
|
|
|
|
$this->signatures = $signatures;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-04 01:37:05 +02:00
|
|
|
public function save() {
|
|
|
|
if (!$this->getMailKey()) {
|
|
|
|
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
|
|
|
}
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
2014-01-15 02:17:18 +01:00
|
|
|
public function getMonogram() {
|
|
|
|
return 'L'.$this->getID();
|
|
|
|
}
|
|
|
|
|
2014-06-29 01:37:04 +02:00
|
|
|
public function getUserSignature($phid) {
|
|
|
|
return $this->assertAttachedKey($this->userSignatures, $phid);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachUserSignature(
|
|
|
|
$user_phid,
|
|
|
|
LegalpadDocumentSignature $signature = null) {
|
|
|
|
$this->userSignatures[$user_phid] = $signature;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-07-04 17:04:28 +02:00
|
|
|
public static function getSignatureTypeMap() {
|
|
|
|
return array(
|
|
|
|
self::SIGNATURE_TYPE_INDIVIDUAL => pht('Individuals'),
|
|
|
|
self::SIGNATURE_TYPE_CORPORATION => pht('Corporations'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSignatureTypeName() {
|
|
|
|
$type = $this->getSignatureType();
|
|
|
|
return idx(self::getSignatureTypeMap(), $type, $type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSignatureTypeIcon() {
|
|
|
|
$type = $this->getSignatureType();
|
|
|
|
$map = array(
|
|
|
|
self::SIGNATURE_TYPE_INDIVIDUAL => 'fa-user grey',
|
|
|
|
self::SIGNATURE_TYPE_CORPORATION => 'fa-building-o grey',
|
|
|
|
);
|
|
|
|
|
|
|
|
return idx($map, $type, 'fa-user grey');
|
|
|
|
}
|
|
|
|
|
Make Projects a PhabricatorSubscribableInterface, but with restricted defaults
Summary:
Ref T4379. I want project subscriptions to work like this (yell if this seems whacky, since it makes subscriptions mean somethign a little different for projects than they do for other objects):
- You can only subscribe to a project if you're a project member.
- When you're added as a member, you're added as a subscriber.
- When you're removed as a member, you're removed as a subscriber.
- While you're a member, you can optionally unsubscribe.
From a UI perspective:
- We don't show the subscriber list, since it's going to be some uninteresting subset of the member list.
- We don't show CC transactions in history, since they're an uninteresting near-approximation of the membership transactions.
- You only see the subscription controls if you're a member.
To do this, I've augmented `PhabricatorSubscribableInterface` with two new methods. It would be nice if we were on PHP 5.4+ and could just use traits for this, but we should get data about version usage before we think about this. For now, copy/paste the default implementations into every implementing class.
Then, I implemented the interface in `PhabricatorProject` but with alternate defaults.
Test Plan:
- Used the normal interaction on existing objects.
- This has no actual effect on projects, verified no subscription stuff mysteriously appeared.
- Hit the new error case by fiddling with the UI.
Reviewers: btrahan
Reviewed By: btrahan
CC: chad, aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8165
2014-02-10 23:29:17 +01:00
|
|
|
|
|
|
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
public function isAutomaticallySubscribed($phid) {
|
|
|
|
return ($this->creatorPHID == $phid);
|
|
|
|
}
|
|
|
|
|
Make Projects a PhabricatorSubscribableInterface, but with restricted defaults
Summary:
Ref T4379. I want project subscriptions to work like this (yell if this seems whacky, since it makes subscriptions mean somethign a little different for projects than they do for other objects):
- You can only subscribe to a project if you're a project member.
- When you're added as a member, you're added as a subscriber.
- When you're removed as a member, you're removed as a subscriber.
- While you're a member, you can optionally unsubscribe.
From a UI perspective:
- We don't show the subscriber list, since it's going to be some uninteresting subset of the member list.
- We don't show CC transactions in history, since they're an uninteresting near-approximation of the membership transactions.
- You only see the subscription controls if you're a member.
To do this, I've augmented `PhabricatorSubscribableInterface` with two new methods. It would be nice if we were on PHP 5.4+ and could just use traits for this, but we should get data about version usage before we think about this. For now, copy/paste the default implementations into every implementing class.
Then, I implemented the interface in `PhabricatorProject` but with alternate defaults.
Test Plan:
- Used the normal interaction on existing objects.
- This has no actual effect on projects, verified no subscription stuff mysteriously appeared.
- Hit the new error case by fiddling with the UI.
Reviewers: btrahan
Reviewed By: btrahan
CC: chad, aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8165
2014-02-10 23:29:17 +01:00
|
|
|
public function shouldShowSubscribersProperty() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAllowSubscription($phid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
$policy = $this->viewPolicy;
|
|
|
|
break;
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
$policy = $this->editPolicy;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$policy = PhabricatorPolicies::POLICY_NOONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $policy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $user) {
|
|
|
|
return ($user->getPHID() == $this->getCreatorPHID());
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return pht(
|
|
|
|
'The author of a document can always view and edit it.');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
|
|
|
|
2014-04-18 01:03:24 +02:00
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
public function getApplicationTransactionEditor() {
|
|
|
|
return new LegalpadDocumentEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionObject() {
|
2014-04-18 01:03:24 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionTemplate() {
|
2013-07-03 20:15:45 +02:00
|
|
|
return new LegalpadTransaction();
|
|
|
|
}
|
|
|
|
|
2014-06-29 16:50:53 +02:00
|
|
|
|
2014-07-21 15:59:22 +02:00
|
|
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
2014-06-29 16:50:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
public function destroyObjectPermanently(
|
|
|
|
PhabricatorDestructionEngine $engine) {
|
|
|
|
|
|
|
|
$this->openTransaction();
|
|
|
|
$this->delete();
|
|
|
|
|
|
|
|
$bodies = id(new LegalpadDocumentBody())->loadAllWhere(
|
|
|
|
'documentPHID = %s',
|
|
|
|
$this->getPHID());
|
|
|
|
foreach ($bodies as $body) {
|
|
|
|
$body->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
$signatures = id(new LegalpadDocumentSignature())->loadAllWhere(
|
|
|
|
'documentPHID = %s',
|
|
|
|
$this->getPHID());
|
|
|
|
foreach ($signatures as $signature) {
|
|
|
|
$signature->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->saveTransaction();
|
|
|
|
}
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
}
|