@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+187 -5
+9
src/__phutil_library_map__.php
··· 834 834 'MetaMTAConstants' => 'applications/metamta/constants/MetaMTAConstants.php', 835 835 'MetaMTANotificationType' => 'applications/metamta/constants/MetaMTANotificationType.php', 836 836 'MetaMTAReceivedMailStatus' => 'applications/metamta/constants/MetaMTAReceivedMailStatus.php', 837 + 'NuanceCapabilitySourceDefaultEdit' => 'applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php', 838 + 'NuanceCapabilitySourceDefaultView' => 'applications/nuance/capability/NuanceCapabilitySourceDefaultView.php', 839 + 'NuanceCapabilitySourceManage' => 'applications/nuance/capability/NuanceCapabilitySourceManage.php', 840 + 'NuanceConstants' => 'applications/nuance/constants/NuanceConstants.php', 837 841 'NuanceController' => 'applications/nuance/controller/NuanceController.php', 838 842 'NuanceDAO' => 'applications/nuance/storage/NuanceDAO.php', 839 843 'NuanceItem' => 'applications/nuance/storage/NuanceItem.php', ··· 874 878 'NuanceSourceTransaction' => 'applications/nuance/storage/NuanceSourceTransaction.php', 875 879 'NuanceSourceTransactionComment' => 'applications/nuance/storage/NuanceSourceTransactionComment.php', 876 880 'NuanceSourceTransactionQuery' => 'applications/nuance/query/NuanceSourceTransactionQuery.php', 881 + 'NuanceSourceType' => 'applications/nuance/constants/NuanceSourceType.php', 877 882 'NuanceSourceViewController' => 'applications/nuance/controller/NuanceSourceViewController.php', 878 883 'NuanceTransaction' => 'applications/nuance/storage/NuanceTransaction.php', 879 884 'OwnersPackageReplyHandler' => 'applications/owners/mail/OwnersPackageReplyHandler.php', ··· 3147 3152 'ManiphestView' => 'AphrontView', 3148 3153 'MetaMTANotificationType' => 'MetaMTAConstants', 3149 3154 'MetaMTAReceivedMailStatus' => 'MetaMTAConstants', 3155 + 'NuanceCapabilitySourceDefaultEdit' => 'PhabricatorPolicyCapability', 3156 + 'NuanceCapabilitySourceDefaultView' => 'PhabricatorPolicyCapability', 3157 + 'NuanceCapabilitySourceManage' => 'PhabricatorPolicyCapability', 3150 3158 'NuanceController' => 'PhabricatorController', 3151 3159 'NuanceDAO' => 'PhabricatorLiskDAO', 3152 3160 'NuanceItem' => ··· 3199 3207 'NuanceSourceTransaction' => 'NuanceTransaction', 3200 3208 'NuanceSourceTransactionComment' => 'PhabricatorApplicationTransactionComment', 3201 3209 'NuanceSourceTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 3210 + 'NuanceSourceType' => 'NuanceConstants', 3202 3211 'NuanceSourceViewController' => 'NuanceController', 3203 3212 'NuanceTransaction' => 'PhabricatorApplicationTransaction', 3204 3213 'OwnersPackageReplyHandler' => 'PhabricatorMailReplyHandler',
+15
src/applications/nuance/application/PhabricatorApplicationNuance.php
··· 50 50 ); 51 51 } 52 52 53 + protected function getCustomCapabilities() { 54 + return array( 55 + NuanceCapabilitySourceDefaultView::CAPABILITY => array( 56 + 'caption' => pht( 57 + 'Default view policy for newly created sources.'), 58 + ), 59 + NuanceCapabilitySourceDefaultEdit::CAPABILITY => array( 60 + 'caption' => pht( 61 + 'Default edit policy for newly created sources.'), 62 + ), 63 + NuanceCapabilitySourceManage::CAPABILITY => array( 64 + ), 65 + ); 66 + } 67 + 53 68 } 54 69
+16
src/applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php
··· 1 + <?php 2 + 3 + final class NuanceCapabilitySourceDefaultEdit 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'nuance.source.default.edit'; 7 + 8 + public function getCapabilityKey() { 9 + return self::CAPABILITY; 10 + } 11 + 12 + public function getCapabilityName() { 13 + return pht('Default Source Edit Policy'); 14 + } 15 + 16 + }
+20
src/applications/nuance/capability/NuanceCapabilitySourceDefaultView.php
··· 1 + <?php 2 + 3 + final class NuanceCapabilitySourceDefaultView 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'nuance.source.default.view'; 7 + 8 + public function getCapabilityKey() { 9 + return self::CAPABILITY; 10 + } 11 + 12 + public function getCapabilityName() { 13 + return pht('Default Source View Policy'); 14 + } 15 + 16 + public function shouldAllowPublicPolicySetting() { 17 + return true; 18 + } 19 + 20 + }
+20
src/applications/nuance/capability/NuanceCapabilitySourceManage.php
··· 1 + <?php 2 + 3 + final class NuanceCapabilitySourceManage 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'nuance.source.manage'; 7 + 8 + public function getCapabilityKey() { 9 + return self::CAPABILITY; 10 + } 11 + 12 + public function getCapabilityName() { 13 + return pht('Can Manage Sources'); 14 + } 15 + 16 + public function describeCapabilityRejection() { 17 + return pht('You do not have permission to manage sources.'); 18 + } 19 + 20 + }
+5
src/applications/nuance/constants/NuanceConstants.php
··· 1 + <?php 2 + 3 + abstract class NuanceConstants { 4 + 5 + }
+22
src/applications/nuance/constants/NuanceSourceType.php
··· 1 + <?php 2 + 3 + final class NuanceSourceType extends NuanceConstants { 4 + 5 + /* internal source types */ 6 + const PHABRICATOR_FORM = 1; 7 + 8 + /* social media source types */ 9 + const TWITTER = 101; 10 + 11 + /* engineering media source types */ 12 + const GITHUB = 201; 13 + 14 + 15 + public static function getSelectOptions() { 16 + 17 + return array( 18 + self::PHABRICATOR_FORM => pht('Phabricator Form'), 19 + ); 20 + } 21 + 22 + }
-1
src/applications/nuance/controller/NuanceItemEditController.php
··· 25 25 26 26 if ($is_new) { 27 27 $item = new NuanceItem(); 28 - 29 28 } else { 30 29 $item = id(new NuanceItemQuery()) 31 30 ->setViewer($user)
+64 -4
src/applications/nuance/controller/NuanceSourceEditController.php
··· 17 17 } 18 18 19 19 public function processRequest() { 20 + $can_edit = $this->requireApplicationCapability( 21 + NuanceCapabilitySourceManage::CAPABILITY); 22 + 20 23 $request = $this->getRequest(); 21 24 $user = $request->getUser(); 22 25 ··· 24 27 $is_new = !$source_id; 25 28 26 29 if ($is_new) { 27 - $source = new NuanceSource(); 28 - 30 + $source = NuanceSource::initializeNewSource($user); 31 + $title = pht('Create Source'); 29 32 } else { 30 33 $source = id(new NuanceSourceQuery()) 31 34 ->setViewer($user) 32 35 ->withIDs(array($source_id)) 36 + ->requireCapabilities( 37 + array( 38 + PhabricatorPolicyCapability::CAN_VIEW, 39 + PhabricatorPolicyCapability::CAN_EDIT, 40 + )) 33 41 ->executeOne(); 42 + $title = pht('Edit Source'); 34 43 } 35 44 36 45 if (!$source) { 37 46 return new Aphront404Response(); 38 47 } 39 48 49 + $error_view = null; 50 + $e_name = null; 51 + if ($request->isFormPost()) { 52 + $error_view = id(new AphrontErrorView()) 53 + ->setTitle(pht('This does not work at all yet.')); 54 + } 55 + 56 + $policies = id(new PhabricatorPolicyQuery()) 57 + ->setViewer($user) 58 + ->setObject($source) 59 + ->execute(); 60 + 40 61 $crumbs = $this->buildApplicationCrumbs(); 41 - $title = 'TODO'; 62 + 63 + $form = id(new AphrontFormView()) 64 + ->setUser($user) 65 + ->appendChild( 66 + id(new AphrontFormTextControl()) 67 + ->setLabel(pht('Name')) 68 + ->setName('name') 69 + ->setError($e_name) 70 + ->setValue($source->getName())) 71 + ->appendChild( 72 + id(new AphrontFormSelectControl()) 73 + ->setLabel(pht('Type')) 74 + ->setName('type') 75 + ->setOptions(NuanceSourceType::getSelectOptions()) 76 + ->setValue($source->getType())) 77 + ->appendChild( 78 + id(new AphrontFormPolicyControl()) 79 + ->setUser($user) 80 + ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) 81 + ->setPolicyObject($source) 82 + ->setPolicies($policies) 83 + ->setName('viewPolicy')) 84 + ->appendChild( 85 + id(new AphrontFormPolicyControl()) 86 + ->setUser($user) 87 + ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 88 + ->setPolicyObject($source) 89 + ->setPolicies($policies) 90 + ->setName('editPolicy')) 91 + ->appendChild( 92 + id(new AphrontFormSubmitControl()) 93 + ->setValue(pht('Save'))); 94 + 95 + $layout = id(new PHUIObjectBoxView()) 96 + ->setHeaderText($title) 97 + ->setFormError($error_view) 98 + ->setForm($form); 42 99 43 100 return $this->buildApplicationPage( 44 - $crumbs, 101 + array( 102 + $crumbs, 103 + $layout, 104 + ), 45 105 array( 46 106 'title' => $title, 47 107 'device' => true));
+16
src/applications/nuance/storage/NuanceSource.php
··· 36 36 return '/nuance/source/view/'.$this->getID().'/'; 37 37 } 38 38 39 + public static function initializeNewSource(PhabricatorUser $actor) { 40 + $app = id(new PhabricatorApplicationQuery()) 41 + ->setViewer($actor) 42 + ->withClasses(array('PhabricatorApplicationNuance')) 43 + ->executeOne(); 44 + 45 + $view_policy = $app->getPolicy( 46 + NuanceCapabilitySourceDefaultView::CAPABILITY); 47 + $edit_policy = $app->getPolicy( 48 + NuanceCapabilitySourceDefaultEdit::CAPABILITY); 49 + 50 + return id(new NuanceSource()) 51 + ->setViewPolicy($view_policy) 52 + ->setEditPolicy($edit_policy); 53 + } 54 + 39 55 public function getCapabilities() { 40 56 return array( 41 57 PhabricatorPolicyCapability::CAN_VIEW,