mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Naunce - capalities for Source object
Summary: another little piece here that basically just adds some permissions to source editing. serving it up before I do anything too complicated to make sure it seems kosher. in terms of what comes next this form needs to be dynamic based on source type so there'll be some fun there. That said, I plan to implement a more simple "phabricator form" only version to start here and flesh out a few other things like queues with that. Test Plan: set permission to no one for source edit and got a nice error page. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, epriestley, aran Differential Revision: https://secure.phabricator.com/D7535
This commit is contained in:
parent
d700e7f22d
commit
3de4e91dac
10 changed files with 187 additions and 5 deletions
|
@ -834,6 +834,10 @@ phutil_register_library_map(array(
|
|||
'MetaMTAConstants' => 'applications/metamta/constants/MetaMTAConstants.php',
|
||||
'MetaMTANotificationType' => 'applications/metamta/constants/MetaMTANotificationType.php',
|
||||
'MetaMTAReceivedMailStatus' => 'applications/metamta/constants/MetaMTAReceivedMailStatus.php',
|
||||
'NuanceCapabilitySourceDefaultEdit' => 'applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php',
|
||||
'NuanceCapabilitySourceDefaultView' => 'applications/nuance/capability/NuanceCapabilitySourceDefaultView.php',
|
||||
'NuanceCapabilitySourceManage' => 'applications/nuance/capability/NuanceCapabilitySourceManage.php',
|
||||
'NuanceConstants' => 'applications/nuance/constants/NuanceConstants.php',
|
||||
'NuanceController' => 'applications/nuance/controller/NuanceController.php',
|
||||
'NuanceDAO' => 'applications/nuance/storage/NuanceDAO.php',
|
||||
'NuanceItem' => 'applications/nuance/storage/NuanceItem.php',
|
||||
|
@ -874,6 +878,7 @@ phutil_register_library_map(array(
|
|||
'NuanceSourceTransaction' => 'applications/nuance/storage/NuanceSourceTransaction.php',
|
||||
'NuanceSourceTransactionComment' => 'applications/nuance/storage/NuanceSourceTransactionComment.php',
|
||||
'NuanceSourceTransactionQuery' => 'applications/nuance/query/NuanceSourceTransactionQuery.php',
|
||||
'NuanceSourceType' => 'applications/nuance/constants/NuanceSourceType.php',
|
||||
'NuanceSourceViewController' => 'applications/nuance/controller/NuanceSourceViewController.php',
|
||||
'NuanceTransaction' => 'applications/nuance/storage/NuanceTransaction.php',
|
||||
'OwnersPackageReplyHandler' => 'applications/owners/mail/OwnersPackageReplyHandler.php',
|
||||
|
@ -3147,6 +3152,9 @@ phutil_register_library_map(array(
|
|||
'ManiphestView' => 'AphrontView',
|
||||
'MetaMTANotificationType' => 'MetaMTAConstants',
|
||||
'MetaMTAReceivedMailStatus' => 'MetaMTAConstants',
|
||||
'NuanceCapabilitySourceDefaultEdit' => 'PhabricatorPolicyCapability',
|
||||
'NuanceCapabilitySourceDefaultView' => 'PhabricatorPolicyCapability',
|
||||
'NuanceCapabilitySourceManage' => 'PhabricatorPolicyCapability',
|
||||
'NuanceController' => 'PhabricatorController',
|
||||
'NuanceDAO' => 'PhabricatorLiskDAO',
|
||||
'NuanceItem' =>
|
||||
|
@ -3199,6 +3207,7 @@ phutil_register_library_map(array(
|
|||
'NuanceSourceTransaction' => 'NuanceTransaction',
|
||||
'NuanceSourceTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
'NuanceSourceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'NuanceSourceType' => 'NuanceConstants',
|
||||
'NuanceSourceViewController' => 'NuanceController',
|
||||
'NuanceTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'OwnersPackageReplyHandler' => 'PhabricatorMailReplyHandler',
|
||||
|
|
|
@ -50,5 +50,20 @@ final class PhabricatorApplicationNuance extends PhabricatorApplication {
|
|||
);
|
||||
}
|
||||
|
||||
protected function getCustomCapabilities() {
|
||||
return array(
|
||||
NuanceCapabilitySourceDefaultView::CAPABILITY => array(
|
||||
'caption' => pht(
|
||||
'Default view policy for newly created sources.'),
|
||||
),
|
||||
NuanceCapabilitySourceDefaultEdit::CAPABILITY => array(
|
||||
'caption' => pht(
|
||||
'Default edit policy for newly created sources.'),
|
||||
),
|
||||
NuanceCapabilitySourceManage::CAPABILITY => array(
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class NuanceCapabilitySourceDefaultEdit
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'nuance.source.default.edit';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Source Edit Policy');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
final class NuanceCapabilitySourceDefaultView
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'nuance.source.default.view';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Default Source View Policy');
|
||||
}
|
||||
|
||||
public function shouldAllowPublicPolicySetting() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
final class NuanceCapabilitySourceManage
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'nuance.source.manage';
|
||||
|
||||
public function getCapabilityKey() {
|
||||
return self::CAPABILITY;
|
||||
}
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Manage Sources');
|
||||
}
|
||||
|
||||
public function describeCapabilityRejection() {
|
||||
return pht('You do not have permission to manage sources.');
|
||||
}
|
||||
|
||||
}
|
5
src/applications/nuance/constants/NuanceConstants.php
Normal file
5
src/applications/nuance/constants/NuanceConstants.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
abstract class NuanceConstants {
|
||||
|
||||
}
|
22
src/applications/nuance/constants/NuanceSourceType.php
Normal file
22
src/applications/nuance/constants/NuanceSourceType.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
final class NuanceSourceType extends NuanceConstants {
|
||||
|
||||
/* internal source types */
|
||||
const PHABRICATOR_FORM = 1;
|
||||
|
||||
/* social media source types */
|
||||
const TWITTER = 101;
|
||||
|
||||
/* engineering media source types */
|
||||
const GITHUB = 201;
|
||||
|
||||
|
||||
public static function getSelectOptions() {
|
||||
|
||||
return array(
|
||||
self::PHABRICATOR_FORM => pht('Phabricator Form'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,6 @@ final class NuanceItemEditController extends NuanceController {
|
|||
|
||||
if ($is_new) {
|
||||
$item = new NuanceItem();
|
||||
|
||||
} else {
|
||||
$item = id(new NuanceItemQuery())
|
||||
->setViewer($user)
|
||||
|
|
|
@ -17,6 +17,9 @@ final class NuanceSourceEditController extends NuanceController {
|
|||
}
|
||||
|
||||
public function processRequest() {
|
||||
$can_edit = $this->requireApplicationCapability(
|
||||
NuanceCapabilitySourceManage::CAPABILITY);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
|
@ -24,24 +27,81 @@ final class NuanceSourceEditController extends NuanceController {
|
|||
$is_new = !$source_id;
|
||||
|
||||
if ($is_new) {
|
||||
$source = new NuanceSource();
|
||||
|
||||
$source = NuanceSource::initializeNewSource($user);
|
||||
$title = pht('Create Source');
|
||||
} else {
|
||||
$source = id(new NuanceSourceQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($source_id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
$title = pht('Edit Source');
|
||||
}
|
||||
|
||||
if (!$source) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$error_view = null;
|
||||
$e_name = null;
|
||||
if ($request->isFormPost()) {
|
||||
$error_view = id(new AphrontErrorView())
|
||||
->setTitle(pht('This does not work at all yet.'));
|
||||
}
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($user)
|
||||
->setObject($source)
|
||||
->execute();
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$title = 'TODO';
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Name'))
|
||||
->setName('name')
|
||||
->setError($e_name)
|
||||
->setValue($source->getName()))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Type'))
|
||||
->setName('type')
|
||||
->setOptions(NuanceSourceType::getSelectOptions())
|
||||
->setValue($source->getType()))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setUser($user)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||
->setPolicyObject($source)
|
||||
->setPolicies($policies)
|
||||
->setName('viewPolicy'))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setUser($user)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
||||
->setPolicyObject($source)
|
||||
->setPolicies($policies)
|
||||
->setName('editPolicy'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Save')));
|
||||
|
||||
$layout = id(new PHUIObjectBoxView())
|
||||
->setHeaderText($title)
|
||||
->setFormError($error_view)
|
||||
->setForm($form);
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
$crumbs,
|
||||
array(
|
||||
$crumbs,
|
||||
$layout,
|
||||
),
|
||||
array(
|
||||
'title' => $title,
|
||||
'device' => true));
|
||||
|
|
|
@ -36,6 +36,22 @@ final class NuanceSource
|
|||
return '/nuance/source/view/'.$this->getID().'/';
|
||||
}
|
||||
|
||||
public static function initializeNewSource(PhabricatorUser $actor) {
|
||||
$app = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($actor)
|
||||
->withClasses(array('PhabricatorApplicationNuance'))
|
||||
->executeOne();
|
||||
|
||||
$view_policy = $app->getPolicy(
|
||||
NuanceCapabilitySourceDefaultView::CAPABILITY);
|
||||
$edit_policy = $app->getPolicy(
|
||||
NuanceCapabilitySourceDefaultEdit::CAPABILITY);
|
||||
|
||||
return id(new NuanceSource())
|
||||
->setViewPolicy($view_policy)
|
||||
->setEditPolicy($edit_policy);
|
||||
}
|
||||
|
||||
public function getCapabilities() {
|
||||
return array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
|
|
Loading…
Reference in a new issue