Page MenuHomePhabricator

D7322.diff

diff --git a/resources/sql/patches/20131015.cpolicy.sql b/resources/sql/patches/20131015.cpolicy.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/patches/20131015.cpolicy.sql
@@ -0,0 +1,5 @@
+ALTER TABLE {$NAMESPACE}_countdown.countdown
+ ADD viewPolicy VARCHAR(64) NOT NULL;
+
+UPDATE {$NAMESPACE}_countdown.countdown
+ SET viewPolicy = 'users' WHERE viewPolicy = '';
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1068,6 +1068,7 @@
'PhabricatorController' => 'applications/base/controller/PhabricatorController.php',
'PhabricatorCoreConfigOptions' => 'applications/config/option/PhabricatorCoreConfigOptions.php',
'PhabricatorCountdown' => 'applications/countdown/storage/PhabricatorCountdown.php',
+ 'PhabricatorCountdownCapabilityDefaultView' => 'applications/countdown/capability/PhabricatorCountdownCapabilityDefaultView.php',
'PhabricatorCountdownController' => 'applications/countdown/controller/PhabricatorCountdownController.php',
'PhabricatorCountdownDAO' => 'applications/countdown/storage/PhabricatorCountdownDAO.php',
'PhabricatorCountdownDeleteController' => 'applications/countdown/controller/PhabricatorCountdownDeleteController.php',
@@ -3244,6 +3245,7 @@
0 => 'PhabricatorCountdownDAO',
1 => 'PhabricatorPolicyInterface',
),
+ 'PhabricatorCountdownCapabilityDefaultView' => 'PhabricatorPolicyCapability',
'PhabricatorCountdownController' => 'PhabricatorController',
'PhabricatorCountdownDAO' => 'PhabricatorLiskDAO',
'PhabricatorCountdownDeleteController' => 'PhabricatorCountdownController',
diff --git a/src/applications/countdown/application/PhabricatorApplicationCountdown.php b/src/applications/countdown/application/PhabricatorApplicationCountdown.php
--- a/src/applications/countdown/application/PhabricatorApplicationCountdown.php
+++ b/src/applications/countdown/application/PhabricatorApplicationCountdown.php
@@ -1,8 +1,5 @@
<?php
-/**
- * @group countdown
- */
final class PhabricatorApplicationCountdown extends PhabricatorApplication {
public function getBaseURI() {
@@ -50,4 +47,12 @@
);
}
+ public function getCustomCapabilities() {
+ return array(
+ PhabricatorCountdownCapabilityDefaultView::CAPABILITY => array(
+ 'caption' => pht('Default view policy for new countdowns.'),
+ ),
+ );
+ }
+
}
diff --git a/src/applications/countdown/capability/PhabricatorCountdownCapabilityDefaultView.php b/src/applications/countdown/capability/PhabricatorCountdownCapabilityDefaultView.php
new file mode 100644
--- /dev/null
+++ b/src/applications/countdown/capability/PhabricatorCountdownCapabilityDefaultView.php
@@ -0,0 +1,20 @@
+<?php
+
+final class PhabricatorCountdownCapabilityDefaultView
+ extends PhabricatorPolicyCapability {
+
+ const CAPABILITY = 'countdown.default.view';
+
+ public function getCapabilityKey() {
+ return self::CAPABILITY;
+ }
+
+ public function getCapabilityName() {
+ return pht('Default View Policy');
+ }
+
+ public function shouldAllowPublicPolicySetting() {
+ return true;
+ }
+
+}
diff --git a/src/applications/countdown/controller/PhabricatorCountdownDeleteController.php b/src/applications/countdown/controller/PhabricatorCountdownDeleteController.php
--- a/src/applications/countdown/controller/PhabricatorCountdownDeleteController.php
+++ b/src/applications/countdown/controller/PhabricatorCountdownDeleteController.php
@@ -31,11 +31,6 @@
return new Aphront404Response();
}
- if (($countdown->getAuthorPHID() !== $user->getPHID())
- && $user->getIsAdmin() === false) {
- return new Aphront403Response();
- }
-
if ($request->isFormPost()) {
$countdown->delete();
return id(new AphrontRedirectResponse())
diff --git a/src/applications/countdown/controller/PhabricatorCountdownEditController.php b/src/applications/countdown/controller/PhabricatorCountdownEditController.php
--- a/src/applications/countdown/controller/PhabricatorCountdownEditController.php
+++ b/src/applications/countdown/controller/PhabricatorCountdownEditController.php
@@ -27,24 +27,23 @@
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
-
- // If no countdown is found
if (!$countdown) {
return new Aphront404Response();
}
} else {
$page_title = pht('Create Countdown');
- $countdown = new PhabricatorCountdown();
- $countdown->setEpoch(time());
+ $countdown = PhabricatorCountdown::initializeNewCountdown($user);
}
$error_view = null;
- $e_text = null;
+ $e_text = true;
+ $e_epoch = null;
if ($request->isFormPost()) {
$errors = array();
$title = $request->getStr('title');
$epoch = $request->getStr('epoch');
+ $view_policy = $request->getStr('viewPolicy');
$e_text = null;
if (!strlen($title)) {
@@ -68,7 +67,7 @@
if (!count($errors)) {
$countdown->setTitle($title);
$countdown->setEpoch($timestamp);
- $countdown->setAuthorPHID($user->getPHID());
+ $countdown->setViewPolicy($view_policy);
$countdown->save();
return id(new AphrontRedirectResponse())
->setURI('/countdown/'.$countdown->getID().'/');
@@ -106,24 +105,37 @@
$submit_label = pht('Create Countdown');
}
+ $policies = id(new PhabricatorPolicyQuery())
+ ->setViewer($user)
+ ->setObject($countdown)
+ ->execute();
$form = id(new AphrontFormView())
->setUser($user)
->setAction($request->getRequestURI()->getPath())
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Title'))
->setValue($countdown->getTitle())
- ->setName('title'))
+ ->setName('title')
+ ->setError($e_text))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('End Date'))
->setValue($display_epoch)
->setName('epoch')
+ ->setError($e_epoch)
->setCaption(pht('Examples: '.
'2011-12-25 or 3 hours or '.
'June 8 2011, 5 PM.')))
->appendChild(
+ id(new AphrontFormPolicyControl())
+ ->setUser($user)
+ ->setName('viewPolicy')
+ ->setPolicyObject($countdown)
+ ->setPolicies($policies)
+ ->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
+ ->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($cancel_uri)
->setValue($submit_label));
diff --git a/src/applications/countdown/controller/PhabricatorCountdownViewController.php b/src/applications/countdown/controller/PhabricatorCountdownViewController.php
--- a/src/applications/countdown/controller/PhabricatorCountdownViewController.php
+++ b/src/applications/countdown/controller/PhabricatorCountdownViewController.php
@@ -22,7 +22,6 @@
->setViewer($user)
->withIDs(array($this->id))
->executeOne();
-
if (!$countdown) {
return new Aphront404Response();
}
@@ -42,7 +41,9 @@
->setName("C{$id}"));
$header = id(new PHUIHeaderView())
- ->setHeader($title);
+ ->setHeader($title)
+ ->setUser($user)
+ ->setPolicyObject($countdown);
$actions = $this->buildActionListView($countdown);
$properties = $this->buildPropertyListView($countdown, $actions);
diff --git a/src/applications/countdown/storage/PhabricatorCountdown.php b/src/applications/countdown/storage/PhabricatorCountdown.php
--- a/src/applications/countdown/storage/PhabricatorCountdown.php
+++ b/src/applications/countdown/storage/PhabricatorCountdown.php
@@ -1,16 +1,28 @@
<?php
-/**
- * @group countdown
- */
final class PhabricatorCountdown
extends PhabricatorCountdownDAO
implements PhabricatorPolicyInterface {
protected $title;
protected $authorPHID;
protected $epoch;
- // protected $viewPolicy; //commented out till we have it on countdown table
+ protected $viewPolicy;
+
+ public static function initializeNewCountdown(PhabricatorUser $actor) {
+ $app = id(new PhabricatorApplicationQuery())
+ ->setViewer($actor)
+ ->withClasses(array('PhabricatorApplicationCountdown'))
+ ->executeOne();
+
+ $view_policy = $app->getPolicy(
+ PhabricatorCountdownCapabilityDefaultView::CAPABILITY);
+
+ return id(new PhabricatorCountdown())
+ ->setAuthorPHID($actor->getPHID())
+ ->setViewPolicy($view_policy)
+ ->setEpoch(PhabricatorTime::getNow());
+ }
public function getConfiguration() {
return array(
@@ -23,10 +35,6 @@
PhabricatorCountdownPHIDTypeCountdown::TYPECONST);
}
- public function getViewPolicy() {
- return PhabricatorPolicies::POLICY_USER;
- }
-
/* -( PhabricatorPolicyInterface )----------------------------------------- */
diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
--- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
+++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
@@ -1672,6 +1672,10 @@
'type' => 'sql',
'name' => $this->getPatchPath('20131010.pstorage.sql'),
),
+ '20131015.cpolicy.sql' => array(
+ 'type' => 'sql',
+ 'name' => $this->getPatchPath('20131015.cpolicy.sql'),
+ ),
);
}
}

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/um/wb/fuuidhe6tkeabguc
Default Alt Text
D7322.diff (9 KB)

Event Timeline