Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F85261
D7535.id16996.diff
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D7535.id16996.diff
View Options
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
@@ -833,6 +833,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',
+ 'NuanceCapabilitySourceEdit' => 'applications/nuance/capability/NuanceCapabilitySourceEdit.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',
@@ -873,6 +877,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',
@@ -3145,6 +3150,9 @@
'ManiphestView' => 'AphrontView',
'MetaMTANotificationType' => 'MetaMTAConstants',
'MetaMTAReceivedMailStatus' => 'MetaMTAConstants',
+ 'NuanceCapabilitySourceDefaultEdit' => 'PhabricatorPolicyCapability',
+ 'NuanceCapabilitySourceDefaultView' => 'PhabricatorPolicyCapability',
+ 'NuanceCapabilitySourceEdit' => 'PhabricatorPolicyCapability',
'NuanceController' => 'PhabricatorController',
'NuanceDAO' => 'PhabricatorLiskDAO',
'NuanceItem' =>
@@ -3197,6 +3205,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.'),
+ ),
+ NuanceCapabilitySourceEdit::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/NuanceCapabilitySourceEdit.php b/src/applications/nuance/capability/NuanceCapabilitySourceEdit.php
new file mode 100644
--- /dev/null
+++ b/src/applications/nuance/capability/NuanceCapabilitySourceEdit.php
@@ -0,0 +1,20 @@
+<?php
+
+final class NuanceCapabilitySourceEdit
+ extends PhabricatorPolicyCapability {
+
+ const CAPABILITY = 'nuance.source.edit';
+
+ public function getCapabilityKey() {
+ return self::CAPABILITY;
+ }
+
+ public function getCapabilityName() {
+ return pht('Can Edit Sources');
+ }
+
+ public function describeCapabilityRejection() {
+ return pht('You do not have permission to edit 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 = 0;
+
+ /* social media source types */
+ const TWITTER = 100;
+
+ /* engineering media source types */
+ const GITHUB = 200;
+
+
+ public static function getSelectOptions() {
+
+ return array(
+ self::PHABRICATOR_FORM => '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,87 @@
}
public function processRequest() {
+ $can_edit = $this->requireApplicationCapability(
+ NuanceCapabilitySourceEdit::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')));
return $this->buildApplicationPage(
- $crumbs,
+ array(
+ $crumbs,
+ $error_view,
+ $form
+ ),
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
Details
Attached
Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/xt/ou/jsq5ylxtdmow6rhk
Default Alt Text
D7535.id16996.diff (10 KB)
Attached To
Mode
D7535: Naunce - capalities for Source object
Attached
Detach File
Event Timeline
Log In to Comment