@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.

Allow applications to test if a user could edit a certain field by clicking "Edit Thing"

Summary: See D15432. There, we can use this test to check if the user //could// reassign the task by using "Edit Form" or the stacked actions, so any dedicated "claim" element is consistent with the other permissions.

Test Plan:
- Added a `var_dump($can_reassign)` after the call.
- Saw `true`.
- Edited the edit form, locked and disabled "Assigned To".
- Saw `false`.

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D15433

+69 -9
+14 -8
src/applications/maniphest/controller/ManiphestTaskDetailController.php
··· 26 26 ->setViewer($viewer) 27 27 ->readFieldsFromStorage($task); 28 28 29 + $edit_engine = id(new ManiphestEditEngine()) 30 + ->setViewer($viewer) 31 + ->setTargetObject($task); 32 + 29 33 $e_commit = ManiphestTaskHasCommitEdgeType::EDGECONST; 30 34 $e_dep_on = ManiphestTaskDependsOnTaskEdgeType::EDGECONST; 31 35 $e_dep_by = ManiphestTaskDependedOnByTaskEdgeType::EDGECONST; ··· 73 77 $header = $this->buildHeaderView($task); 74 78 $details = $this->buildPropertyView($task, $field_list, $edges, $handles); 75 79 $description = $this->buildDescriptionView($task, $engine); 76 - $curtain = $this->buildCurtain($task); 80 + $curtain = $this->buildCurtain($task, $edit_engine); 77 81 78 82 $title = pht('%s %s', $monogram, $task->getTitle()); 79 83 80 - $comment_view = id(new ManiphestEditEngine()) 81 - ->setViewer($viewer) 84 + $comment_view = $edit_engine 82 85 ->buildEditEngineCommentView($task); 83 86 84 87 $timeline->setQuoteRef($monogram); ··· 146 149 } 147 150 148 151 149 - private function buildCurtain(ManiphestTask $task) { 152 + private function buildCurtain( 153 + ManiphestTask $task, 154 + PhabricatorEditEngine $edit_engine) { 150 155 $viewer = $this->getViewer(); 151 156 152 157 $id = $task->getID(); ··· 176 181 ->setDisabled(!$can_edit) 177 182 ->setWorkflow(true)); 178 183 179 - $edit_config = id(new ManiphestEditEngine()) 180 - ->setViewer($viewer) 181 - ->loadDefaultEditConfiguration(); 184 + $edit_config = $edit_engine->loadDefaultEditConfiguration(); 185 + $can_create = (bool)$edit_config; 186 + 187 + $can_reassign = $edit_engine->hasEditAccessToTransaction( 188 + ManiphestTransaction::TYPE_OWNER); 182 189 183 - $can_create = (bool)$edit_config; 184 190 if ($can_create) { 185 191 $form_key = $edit_config->getIdentifier(); 186 192 $edit_uri = id(new PhutilURI("/task/edit/form/{$form_key}/"))
+55 -1
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 821 821 } 822 822 823 823 private function buildCrumbs($object, $final = false) { 824 - $controller = $this->getcontroller(); 824 + $controller = $this->getController(); 825 825 826 826 $crumbs = $controller->buildApplicationCrumbsForEditEngine(); 827 827 if ($this->getIsCreate()) { ··· 1178 1178 1179 1179 return $actions; 1180 1180 } 1181 + 1182 + 1183 + /** 1184 + * Test if the viewer could apply a certain type of change by using the 1185 + * normal "Edit" form. 1186 + * 1187 + * This method returns `true` if the user has access to an edit form and 1188 + * that edit form has a field which applied the specified transaction type, 1189 + * and that field is visible and editable for the user. 1190 + * 1191 + * For example, you can use it to test if a user is able to reassign tasks 1192 + * or not, prior to rendering dedicated UI for task reassingment. 1193 + * 1194 + * Note that this method does NOT test if the user can actually edit the 1195 + * current object, just if they have access to the related field. 1196 + * 1197 + * @param const Transaction type to test for. 1198 + * @return bool True if the user could "Edit" to apply the transaction type. 1199 + */ 1200 + final public function hasEditAccessToTransaction($xaction_type) { 1201 + $viewer = $this->getViewer(); 1202 + 1203 + $config = $this->loadDefaultEditConfiguration(); 1204 + if (!$config) { 1205 + return false; 1206 + } 1207 + 1208 + $object = $this->getTargetObject(); 1209 + if (!$object) { 1210 + $object = $this->newEditableObject(); 1211 + } 1212 + 1213 + $fields = $this->buildEditFields($object); 1214 + 1215 + $field = null; 1216 + foreach ($fields as $form_field) { 1217 + $field_xaction_type = $form_field->getTransactionType(); 1218 + if ($field_xaction_type === $xaction_type) { 1219 + $field = $form_field; 1220 + break; 1221 + } 1222 + } 1223 + 1224 + if (!$field) { 1225 + return false; 1226 + } 1227 + 1228 + if (!$field->shouldReadValueFromSubmit()) { 1229 + return false; 1230 + } 1231 + 1232 + return true; 1233 + } 1234 + 1181 1235 1182 1236 final public function addActionToCrumbs(PHUICrumbsView $crumbs) { 1183 1237 $viewer = $this->getViewer();