2011-07-08 11:13:11 -07:00
|
|
|
<?php
|
|
|
|
|
2013-07-13 10:41:30 -07:00
|
|
|
final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO
|
2013-07-15 05:21:36 -07:00
|
|
|
implements
|
|
|
|
PhabricatorPolicyInterface,
|
2013-07-15 06:19:50 -07:00
|
|
|
PhabricatorSubscribableInterface,
|
2013-10-25 12:52:00 -07:00
|
|
|
PhabricatorFlaggableInterface,
|
2014-06-24 10:13:18 -07:00
|
|
|
PhabricatorTokenReceiverInterface,
|
|
|
|
PhabricatorProjectInterface {
|
2011-07-08 11:13:11 -07:00
|
|
|
|
|
|
|
const RESPONSES_VISIBLE = 0;
|
|
|
|
const RESPONSES_VOTERS = 1;
|
|
|
|
const RESPONSES_OWNER = 2;
|
|
|
|
|
|
|
|
const METHOD_PLURALITY = 0;
|
|
|
|
const METHOD_APPROVAL = 1;
|
|
|
|
|
|
|
|
protected $question;
|
2013-07-14 16:02:04 -07:00
|
|
|
protected $description;
|
2011-07-08 11:13:11 -07:00
|
|
|
protected $authorPHID;
|
|
|
|
protected $responseVisibility;
|
|
|
|
protected $shuffle;
|
|
|
|
protected $method;
|
2013-07-14 16:02:04 -07:00
|
|
|
protected $viewPolicy;
|
2014-04-24 12:00:31 -07:00
|
|
|
protected $isClosed = 0;
|
2011-07-08 11:13:11 -07:00
|
|
|
|
2013-09-03 06:02:14 -07:00
|
|
|
private $options = self::ATTACHABLE;
|
|
|
|
private $choices = self::ATTACHABLE;
|
|
|
|
private $viewerChoices = self::ATTACHABLE;
|
2013-07-15 06:09:37 -07:00
|
|
|
|
2013-10-16 10:36:00 -07:00
|
|
|
public static function initializeNewPoll(PhabricatorUser $actor) {
|
|
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
|
|
->setViewer($actor)
|
|
|
|
->withClasses(array('PhabricatorApplicationSlowvote'))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
$view_policy = $app->getPolicy(
|
|
|
|
PhabricatorSlowvoteCapabilityDefaultView::CAPABILITY);
|
|
|
|
|
|
|
|
return id(new PhabricatorSlowvotePoll())
|
|
|
|
->setAuthorPHID($actor->getPHID())
|
|
|
|
->setViewPolicy($view_policy);
|
|
|
|
}
|
|
|
|
|
2011-07-08 11:13:11 -07:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(
|
2013-07-21 06:34:21 -07:00
|
|
|
PhabricatorSlowvotePHIDTypePoll::TYPECONST);
|
2011-07-08 11:13:11 -07:00
|
|
|
}
|
|
|
|
|
2013-07-15 06:09:37 -07:00
|
|
|
public function getOptions() {
|
2013-09-03 06:02:14 -07:00
|
|
|
return $this->assertAttached($this->options);
|
2013-07-15 06:09:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachOptions(array $options) {
|
|
|
|
assert_instances_of($options, 'PhabricatorSlowvoteOption');
|
|
|
|
$this->options = $options;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getChoices() {
|
2013-09-03 06:02:14 -07:00
|
|
|
return $this->assertAttached($this->choices);
|
2013-07-15 06:09:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachChoices(array $choices) {
|
|
|
|
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
|
|
|
|
$this->choices = $choices;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViewerChoices(PhabricatorUser $viewer) {
|
2013-09-03 06:02:14 -07:00
|
|
|
return $this->assertAttachedKey($this->viewerChoices, $viewer->getPHID());
|
2013-07-15 06:09:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachViewerChoices(PhabricatorUser $viewer, array $choices) {
|
2013-09-03 06:02:14 -07:00
|
|
|
if ($this->viewerChoices === self::ATTACHABLE) {
|
|
|
|
$this->viewerChoices = array();
|
|
|
|
}
|
2013-07-15 13:18:50 -07:00
|
|
|
assert_instances_of($choices, 'PhabricatorSlowvoteChoice');
|
2013-07-15 06:09:37 -07:00
|
|
|
$this->viewerChoices[$viewer->getPHID()] = $choices;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-13 10:41:30 -07:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
2013-07-14 16:02:04 -07:00
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return $this->viewPolicy;
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return PhabricatorPolicies::POLICY_NOONE;
|
|
|
|
}
|
2013-07-13 10:41:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return ($viewer->getPHID() == $this->getAuthorPHID());
|
|
|
|
}
|
|
|
|
|
2013-09-27 08:43:41 -07:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return pht(
|
|
|
|
'The author of a poll can always view and edit it.');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-15 05:21:36 -07:00
|
|
|
|
|
|
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function isAutomaticallySubscribed($phid) {
|
|
|
|
return ($phid == $this->getAuthorPHID());
|
|
|
|
}
|
|
|
|
|
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 14:29:17 -08:00
|
|
|
public function shouldShowSubscribersProperty() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAllowSubscription($phid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-15 05:21:36 -07:00
|
|
|
|
2013-07-15 06:19:50 -07:00
|
|
|
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getUsersToNotifyOfTokenGiven() {
|
|
|
|
return array($this->getAuthorPHID());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-08 11:13:11 -07:00
|
|
|
}
|