mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Add application and object level policy controls to Countdown
Summary: Ref T603. Give countdowns proper UI-level policy controls, and an application-level default policy. Put policy information in the header. Test Plan: - Adjusted default policy. - Created new countdowns. - Edited countdowns. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D7322
This commit is contained in:
parent
e381022bc7
commit
3410cbd53e
9 changed files with 77 additions and 25 deletions
5
resources/sql/patches/20131015.cpolicy.sql
Normal file
5
resources/sql/patches/20131015.cpolicy.sql
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_countdown.countdown
|
||||||
|
ADD viewPolicy VARCHAR(64) NOT NULL;
|
||||||
|
|
||||||
|
UPDATE {$NAMESPACE}_countdown.countdown
|
||||||
|
SET viewPolicy = 'users' WHERE viewPolicy = '';
|
|
@ -1068,6 +1068,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorController' => 'applications/base/controller/PhabricatorController.php',
|
'PhabricatorController' => 'applications/base/controller/PhabricatorController.php',
|
||||||
'PhabricatorCoreConfigOptions' => 'applications/config/option/PhabricatorCoreConfigOptions.php',
|
'PhabricatorCoreConfigOptions' => 'applications/config/option/PhabricatorCoreConfigOptions.php',
|
||||||
'PhabricatorCountdown' => 'applications/countdown/storage/PhabricatorCountdown.php',
|
'PhabricatorCountdown' => 'applications/countdown/storage/PhabricatorCountdown.php',
|
||||||
|
'PhabricatorCountdownCapabilityDefaultView' => 'applications/countdown/capability/PhabricatorCountdownCapabilityDefaultView.php',
|
||||||
'PhabricatorCountdownController' => 'applications/countdown/controller/PhabricatorCountdownController.php',
|
'PhabricatorCountdownController' => 'applications/countdown/controller/PhabricatorCountdownController.php',
|
||||||
'PhabricatorCountdownDAO' => 'applications/countdown/storage/PhabricatorCountdownDAO.php',
|
'PhabricatorCountdownDAO' => 'applications/countdown/storage/PhabricatorCountdownDAO.php',
|
||||||
'PhabricatorCountdownDeleteController' => 'applications/countdown/controller/PhabricatorCountdownDeleteController.php',
|
'PhabricatorCountdownDeleteController' => 'applications/countdown/controller/PhabricatorCountdownDeleteController.php',
|
||||||
|
@ -3244,6 +3245,7 @@ phutil_register_library_map(array(
|
||||||
0 => 'PhabricatorCountdownDAO',
|
0 => 'PhabricatorCountdownDAO',
|
||||||
1 => 'PhabricatorPolicyInterface',
|
1 => 'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
|
'PhabricatorCountdownCapabilityDefaultView' => 'PhabricatorPolicyCapability',
|
||||||
'PhabricatorCountdownController' => 'PhabricatorController',
|
'PhabricatorCountdownController' => 'PhabricatorController',
|
||||||
'PhabricatorCountdownDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorCountdownDAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorCountdownDeleteController' => 'PhabricatorCountdownController',
|
'PhabricatorCountdownDeleteController' => 'PhabricatorCountdownController',
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group countdown
|
|
||||||
*/
|
|
||||||
final class PhabricatorApplicationCountdown extends PhabricatorApplication {
|
final class PhabricatorApplicationCountdown extends PhabricatorApplication {
|
||||||
|
|
||||||
public function getBaseURI() {
|
public function getBaseURI() {
|
||||||
|
@ -50,4 +47,12 @@ final class PhabricatorApplicationCountdown extends PhabricatorApplication {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCustomCapabilities() {
|
||||||
|
return array(
|
||||||
|
PhabricatorCountdownCapabilityDefaultView::CAPABILITY => array(
|
||||||
|
'caption' => pht('Default view policy for new countdowns.'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -31,11 +31,6 @@ final class PhabricatorCountdownDeleteController
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($countdown->getAuthorPHID() !== $user->getPHID())
|
|
||||||
&& $user->getIsAdmin() === false) {
|
|
||||||
return new Aphront403Response();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$countdown->delete();
|
$countdown->delete();
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
|
|
|
@ -27,24 +27,23 @@ final class PhabricatorCountdownEditController
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
))
|
))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
// If no countdown is found
|
|
||||||
if (!$countdown) {
|
if (!$countdown) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$page_title = pht('Create Countdown');
|
$page_title = pht('Create Countdown');
|
||||||
$countdown = new PhabricatorCountdown();
|
$countdown = PhabricatorCountdown::initializeNewCountdown($user);
|
||||||
$countdown->setEpoch(time());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$error_view = null;
|
$error_view = null;
|
||||||
$e_text = null;
|
$e_text = true;
|
||||||
|
$e_epoch = null;
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$errors = array();
|
$errors = array();
|
||||||
$title = $request->getStr('title');
|
$title = $request->getStr('title');
|
||||||
$epoch = $request->getStr('epoch');
|
$epoch = $request->getStr('epoch');
|
||||||
|
$view_policy = $request->getStr('viewPolicy');
|
||||||
|
|
||||||
$e_text = null;
|
$e_text = null;
|
||||||
if (!strlen($title)) {
|
if (!strlen($title)) {
|
||||||
|
@ -68,7 +67,7 @@ final class PhabricatorCountdownEditController
|
||||||
if (!count($errors)) {
|
if (!count($errors)) {
|
||||||
$countdown->setTitle($title);
|
$countdown->setTitle($title);
|
||||||
$countdown->setEpoch($timestamp);
|
$countdown->setEpoch($timestamp);
|
||||||
$countdown->setAuthorPHID($user->getPHID());
|
$countdown->setViewPolicy($view_policy);
|
||||||
$countdown->save();
|
$countdown->save();
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/countdown/'.$countdown->getID().'/');
|
->setURI('/countdown/'.$countdown->getID().'/');
|
||||||
|
@ -106,6 +105,10 @@ final class PhabricatorCountdownEditController
|
||||||
$submit_label = pht('Create Countdown');
|
$submit_label = pht('Create Countdown');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$policies = id(new PhabricatorPolicyQuery())
|
||||||
|
->setViewer($user)
|
||||||
|
->setObject($countdown)
|
||||||
|
->execute();
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
|
@ -114,15 +117,24 @@ final class PhabricatorCountdownEditController
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setLabel(pht('Title'))
|
->setLabel(pht('Title'))
|
||||||
->setValue($countdown->getTitle())
|
->setValue($countdown->getTitle())
|
||||||
->setName('title'))
|
->setName('title')
|
||||||
|
->setError($e_text))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setLabel(pht('End Date'))
|
->setLabel(pht('End Date'))
|
||||||
->setValue($display_epoch)
|
->setValue($display_epoch)
|
||||||
->setName('epoch')
|
->setName('epoch')
|
||||||
|
->setError($e_epoch)
|
||||||
->setCaption(pht('Examples: '.
|
->setCaption(pht('Examples: '.
|
||||||
'2011-12-25 or 3 hours or '.
|
'2011-12-25 or 3 hours or '.
|
||||||
'June 8 2011, 5 PM.')))
|
'June 8 2011, 5 PM.')))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormPolicyControl())
|
||||||
|
->setUser($user)
|
||||||
|
->setName('viewPolicy')
|
||||||
|
->setPolicyObject($countdown)
|
||||||
|
->setPolicies($policies)
|
||||||
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->addCancelButton($cancel_uri)
|
->addCancelButton($cancel_uri)
|
||||||
|
|
|
@ -22,7 +22,6 @@ final class PhabricatorCountdownViewController
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withIDs(array($this->id))
|
->withIDs(array($this->id))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if (!$countdown) {
|
if (!$countdown) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
@ -42,7 +41,9 @@ final class PhabricatorCountdownViewController
|
||||||
->setName("C{$id}"));
|
->setName("C{$id}"));
|
||||||
|
|
||||||
$header = id(new PHUIHeaderView())
|
$header = id(new PHUIHeaderView())
|
||||||
->setHeader($title);
|
->setHeader($title)
|
||||||
|
->setUser($user)
|
||||||
|
->setPolicyObject($countdown);
|
||||||
|
|
||||||
$actions = $this->buildActionListView($countdown);
|
$actions = $this->buildActionListView($countdown);
|
||||||
$properties = $this->buildPropertyListView($countdown, $actions);
|
$properties = $this->buildPropertyListView($countdown, $actions);
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group countdown
|
|
||||||
*/
|
|
||||||
final class PhabricatorCountdown
|
final class PhabricatorCountdown
|
||||||
extends PhabricatorCountdownDAO
|
extends PhabricatorCountdownDAO
|
||||||
implements PhabricatorPolicyInterface {
|
implements PhabricatorPolicyInterface {
|
||||||
|
@ -10,7 +7,22 @@ final class PhabricatorCountdown
|
||||||
protected $title;
|
protected $title;
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
protected $epoch;
|
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() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
|
@ -23,10 +35,6 @@ final class PhabricatorCountdown
|
||||||
PhabricatorCountdownPHIDTypeCountdown::TYPECONST);
|
PhabricatorCountdownPHIDTypeCountdown::TYPECONST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getViewPolicy() {
|
|
||||||
return PhabricatorPolicies::POLICY_USER;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -1672,6 +1672,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'name' => $this->getPatchPath('20131010.pstorage.sql'),
|
'name' => $this->getPatchPath('20131010.pstorage.sql'),
|
||||||
),
|
),
|
||||||
|
'20131015.cpolicy.sql' => array(
|
||||||
|
'type' => 'sql',
|
||||||
|
'name' => $this->getPatchPath('20131015.cpolicy.sql'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue