Page MenuHomePhabricator

D7535.diff

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
@@ -834,6 +834,10 @@
'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 @@
'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 @@
'ManiphestView' => 'AphrontView',
'MetaMTANotificationType' => 'MetaMTAConstants',
'MetaMTAReceivedMailStatus' => 'MetaMTAConstants',
+ 'NuanceCapabilitySourceDefaultEdit' => 'PhabricatorPolicyCapability',
+ 'NuanceCapabilitySourceDefaultView' => 'PhabricatorPolicyCapability',
+ 'NuanceCapabilitySourceManage' => 'PhabricatorPolicyCapability',
'NuanceController' => 'PhabricatorController',
'NuanceDAO' => 'PhabricatorLiskDAO',
'NuanceItem' =>
@@ -3199,6 +3207,7 @@
'NuanceSourceTransaction' => 'NuanceTransaction',
'NuanceSourceTransactionComment' => 'PhabricatorApplicationTransactionComment',
'NuanceSourceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+ 'NuanceSourceType' => 'NuanceConstants',
'NuanceSourceViewController' => 'NuanceController',
'NuanceTransaction' => 'PhabricatorApplicationTransaction',
'OwnersPackageReplyHandler' => 'PhabricatorMailReplyHandler',
diff --git a/src/applications/nuance/application/PhabricatorApplicationNuance.php b/src/applications/nuance/application/PhabricatorApplicationNuance.php
--- a/src/applications/nuance/application/PhabricatorApplicationNuance.php
+++ b/src/applications/nuance/application/PhabricatorApplicationNuance.php
@@ -50,5 +50,20 @@
);
}
+ 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(
+ ),
+ );
+ }
+
}
diff --git a/src/applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php b/src/applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php
new file mode 100644
--- /dev/null
+++ b/src/applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php
@@ -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');
+ }
+
+}
diff --git a/src/applications/nuance/capability/NuanceCapabilitySourceDefaultView.php b/src/applications/nuance/capability/NuanceCapabilitySourceDefaultView.php
new file mode 100644
--- /dev/null
+++ b/src/applications/nuance/capability/NuanceCapabilitySourceDefaultView.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/nuance/capability/NuanceCapabilitySourceManage.php b/src/applications/nuance/capability/NuanceCapabilitySourceManage.php
new file mode 100644
--- /dev/null
+++ b/src/applications/nuance/capability/NuanceCapabilitySourceManage.php
@@ -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.');
+ }
+
+}
diff --git a/src/applications/nuance/constants/NuanceConstants.php b/src/applications/nuance/constants/NuanceConstants.php
new file mode 100644
--- /dev/null
+++ b/src/applications/nuance/constants/NuanceConstants.php
@@ -0,0 +1,5 @@
+<?php
+
+abstract class NuanceConstants {
+
+}
diff --git a/src/applications/nuance/constants/NuanceSourceType.php b/src/applications/nuance/constants/NuanceSourceType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/nuance/constants/NuanceSourceType.php
@@ -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'),
+ );
+ }
+
+}
diff --git a/src/applications/nuance/controller/NuanceItemEditController.php b/src/applications/nuance/controller/NuanceItemEditController.php
--- a/src/applications/nuance/controller/NuanceItemEditController.php
+++ b/src/applications/nuance/controller/NuanceItemEditController.php
@@ -25,7 +25,6 @@
if ($is_new) {
$item = new NuanceItem();
-
} else {
$item = id(new NuanceItemQuery())
->setViewer($user)
diff --git a/src/applications/nuance/controller/NuanceSourceEditController.php b/src/applications/nuance/controller/NuanceSourceEditController.php
--- a/src/applications/nuance/controller/NuanceSourceEditController.php
+++ b/src/applications/nuance/controller/NuanceSourceEditController.php
@@ -17,31 +17,91 @@
}
public function processRequest() {
+ $can_edit = $this->requireApplicationCapability(
+ NuanceCapabilitySourceManage::CAPABILITY);
+
$request = $this->getRequest();
$user = $request->getUser();
$source_id = $this->getSourceID();
$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));
diff --git a/src/applications/nuance/storage/NuanceSource.php b/src/applications/nuance/storage/NuanceSource.php
--- a/src/applications/nuance/storage/NuanceSource.php
+++ b/src/applications/nuance/storage/NuanceSource.php
@@ -36,6 +36,22 @@
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,

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/vd/xs/3xxza333wqubgzb6
Default Alt Text
D7535.diff (10 KB)

Event Timeline