Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14012220
D7535.diff
No One
Temporary
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.diff
View Options
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ 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',
Index: src/applications/nuance/application/PhabricatorApplicationNuance.php
===================================================================
--- src/applications/nuance/application/PhabricatorApplicationNuance.php
+++ 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(
+ ),
+ );
+ }
+
}
Index: src/applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php
===================================================================
--- /dev/null
+++ 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');
+ }
+
+}
Index: src/applications/nuance/capability/NuanceCapabilitySourceDefaultView.php
===================================================================
--- /dev/null
+++ 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;
+ }
+
+}
Index: src/applications/nuance/capability/NuanceCapabilitySourceManage.php
===================================================================
--- /dev/null
+++ 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.');
+ }
+
+}
Index: src/applications/nuance/constants/NuanceConstants.php
===================================================================
--- /dev/null
+++ src/applications/nuance/constants/NuanceConstants.php
@@ -0,0 +1,5 @@
+<?php
+
+abstract class NuanceConstants {
+
+}
Index: src/applications/nuance/constants/NuanceSourceType.php
===================================================================
--- /dev/null
+++ 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'),
+ );
+ }
+
+}
Index: src/applications/nuance/controller/NuanceItemEditController.php
===================================================================
--- src/applications/nuance/controller/NuanceItemEditController.php
+++ src/applications/nuance/controller/NuanceItemEditController.php
@@ -25,7 +25,6 @@
if ($is_new) {
$item = new NuanceItem();
-
} else {
$item = id(new NuanceItemQuery())
->setViewer($user)
Index: src/applications/nuance/controller/NuanceSourceEditController.php
===================================================================
--- src/applications/nuance/controller/NuanceSourceEditController.php
+++ src/applications/nuance/controller/NuanceSourceEditController.php
@@ -17,6 +17,9 @@
}
public function processRequest() {
+ $can_edit = $this->requireApplicationCapability(
+ NuanceCapabilitySourceManage::CAPABILITY);
+
$request = $this->getRequest();
$user = $request->getUser();
@@ -24,24 +27,81 @@
$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));
Index: src/applications/nuance/storage/NuanceSource.php
===================================================================
--- src/applications/nuance/storage/NuanceSource.php
+++ 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/plain
Expires
Sat, Nov 2, 9:08 AM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6732784
Default Alt Text
D7535.diff (10 KB)
Attached To
Mode
D7535: Naunce - capalities for Source object
Attached
Detach File
Event Timeline
Log In to Comment