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

Improve the flag.* Conduit methods

Summary:
- Put the code to generate informational dicts about flags into the
base class.
- Update flag.delete to accept an object PHID in order to delete the
flag on that object, since currently the model is that each object
may have at most one flag, and each flag has exactly one object,
although the former is not enforced.
- Add flag.edit, which creates or updates a flag, optionally with the
given color and note.

Test Plan:
Spend endless hours repeatedly running arc call-conduit and
arc flag.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

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

+245 -58
+4
src/__phutil_library_map__.php
··· 146 146 'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/ConduitAPI_file_upload_Method.php', 147 147 'ConduitAPI_flag_Method' => 'applications/conduit/method/flag/ConduitAPI_flag_Method.php', 148 148 'ConduitAPI_flag_delete_Method' => 'applications/conduit/method/flag/ConduitAPI_flag_delete_Method.php', 149 + 'ConduitAPI_flag_edit_Method' => 'applications/conduit/method/flag/ConduitAPI_flag_edit_Method.php', 149 150 'ConduitAPI_flag_query_Method' => 'applications/conduit/method/flag/ConduitAPI_flag_query_Method.php', 150 151 'ConduitAPI_macro_Method' => 'applications/conduit/method/macro/ConduitAPI_macro_Method.php', 151 152 'ConduitAPI_macro_query_Method' => 'applications/conduit/method/macro/ConduitAPI_macro_query_Method.php', ··· 163 164 'ConduitAPI_path_getowners_Method' => 'applications/conduit/method/path/ConduitAPI_path_getowners_Method.php', 164 165 'ConduitAPI_phid_Method' => 'applications/conduit/method/phid/ConduitAPI_phid_Method.php', 165 166 'ConduitAPI_phid_info_Method' => 'applications/conduit/method/phid/ConduitAPI_phid_info_Method.php', 167 + 'ConduitAPI_phid_lookup_Method' => 'applications/conduit/method/phid/ConduitAPI_phid_lookup_Method.php', 166 168 'ConduitAPI_phid_query_Method' => 'applications/conduit/method/phid/ConduitAPI_phid_query_Method.php', 167 169 'ConduitAPI_phriction_Method' => 'applications/conduit/method/phriction/ConduitAPI_phriction_Method.php', 168 170 'ConduitAPI_phriction_edit_Method' => 'applications/conduit/method/phriction/ConduitAPI_phriction_edit_Method.php', ··· 1274 1276 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', 1275 1277 'ConduitAPI_flag_Method' => 'ConduitAPIMethod', 1276 1278 'ConduitAPI_flag_delete_Method' => 'ConduitAPI_flag_Method', 1279 + 'ConduitAPI_flag_edit_Method' => 'ConduitAPI_flag_Method', 1277 1280 'ConduitAPI_flag_query_Method' => 'ConduitAPI_flag_Method', 1278 1281 'ConduitAPI_macro_Method' => 'ConduitAPIMethod', 1279 1282 'ConduitAPI_macro_query_Method' => 'ConduitAPI_macro_Method', ··· 1291 1294 'ConduitAPI_path_getowners_Method' => 'ConduitAPIMethod', 1292 1295 'ConduitAPI_phid_Method' => 'ConduitAPIMethod', 1293 1296 'ConduitAPI_phid_info_Method' => 'ConduitAPI_phid_Method', 1297 + 'ConduitAPI_phid_lookup_Method' => 'ConduitAPI_phid_Method', 1294 1298 'ConduitAPI_phid_query_Method' => 'ConduitAPI_phid_Method', 1295 1299 'ConduitAPI_phriction_Method' => 'ConduitAPIMethod', 1296 1300 'ConduitAPI_phriction_edit_Method' => 'ConduitAPI_phriction_Method',
+28
src/applications/conduit/method/flag/ConduitAPI_flag_Method.php
··· 21 21 */ 22 22 abstract class ConduitAPI_flag_Method extends ConduitAPIMethod { 23 23 24 + protected function attachHandleToFlag($flag) { 25 + $flag->attachHandle( 26 + PhabricatorObjectHandleData::loadOneHandle($flag->getObjectPHID()) 27 + ); 28 + } 29 + 30 + protected function buildFlagInfoDictionary($flag) { 31 + $color = $flag->getColor(); 32 + $uri = PhabricatorEnv::getProductionURI($flag->getHandle()->getURI()); 33 + 34 + return array( 35 + 'id' => $flag->getID(), 36 + 'ownerPHID' => $flag->getOwnerPHID(), 37 + 'type' => $flag->getType(), 38 + 'objectPHID' => $flag->getObjectPHID(), 39 + 'reasonPHID' => $flag->getReasonPHID(), 40 + 'color' => $color, 41 + 'colorName' => PhabricatorFlagColor::getColorName($color), 42 + 'note' => $flag->getNote(), 43 + 'handle' => array( 44 + 'uri' => $uri, 45 + 'name' => $flag->getHandle()->getName(), 46 + 'fullname' => $flag->getHandle()->getFullName(), 47 + ), 48 + 'dateCreated' => $flag->getDateCreated(), 49 + 'dateModified' => $flag->getDateModified(), 50 + ); 51 + } 24 52 25 53 }
+26 -9
src/applications/conduit/method/flag/ConduitAPI_flag_delete_Method.php
··· 27 27 28 28 public function defineParamTypes() { 29 29 return array( 30 - 'id' => 'required id', 30 + 'id' => 'optional id', 31 + 'objectPHID' => 'optional phid', 31 32 ); 32 33 } 33 34 34 35 public function defineReturnType() { 35 - return 'void'; 36 + return 'dict | null'; 36 37 } 37 38 38 39 public function defineErrorTypes() { 39 40 return array( 40 41 'ERR_NOT_FOUND' => 'Bad flag ID.', 41 42 'ERR_WRONG_USER' => 'You are not the creator of this flag.', 43 + 'ERR_NEED_PARAM' => 'Must pass an id or an objectPHID.', 42 44 ); 43 45 } 44 46 45 47 protected function execute(ConduitAPIRequest $request) { 46 48 $id = $request->getValue('id'); 47 - $flag = id(new PhabricatorFlag())->load($id); 48 - if (!$flag) { 49 - throw new ConduitException('ERR_NOT_FOUND'); 50 - } 51 - if ($flag->getOwnerPHID() != $request->getUser()->getPHID()) { 52 - throw new ConduitException('ERR_WRONG_USER'); 49 + $object = $request->getValue('objectPHID'); 50 + if ($id) { 51 + $flag = id(new PhabricatorFlag())->load($id); 52 + if (!$flag) { 53 + throw new ConduitException('ERR_NOT_FOUND'); 54 + } 55 + if ($flag->getOwnerPHID() != $request->getUser()->getPHID()) { 56 + throw new ConduitException('ERR_WRONG_USER'); 57 + } 58 + } elseif ($object) { 59 + $flag = id(new PhabricatorFlag())->loadOneWhere( 60 + 'objectPHID = %s AND ownerPHID = %s', 61 + $object, 62 + $request->getUser()->getPHID()); 63 + if (!$flag) { 64 + return null; 65 + } 66 + } else { 67 + throw new ConduitException('ERR_NEED_PARAM'); 53 68 } 69 + $this->attachHandleToFlag($flag); 70 + $ret = $this->buildFlagInfoDictionary($flag); 54 71 $flag->delete(); 55 - return; 72 + return $ret; 56 73 } 57 74 58 75 }
+80
src/applications/conduit/method/flag/ConduitAPI_flag_edit_Method.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + /** 20 + * @group conduit 21 + */ 22 + final class ConduitAPI_flag_edit_Method extends ConduitAPI_flag_Method { 23 + 24 + public function getMethodDescription() { 25 + return "Create or modify a flag."; 26 + } 27 + 28 + public function defineParamTypes() { 29 + return array( 30 + 'objectPHID' => 'required phid', 31 + 'color' => 'optional int', 32 + 'note' => 'optional string', 33 + ); 34 + } 35 + 36 + public function defineReturnType() { 37 + return 'dict'; 38 + } 39 + 40 + public function defineErrorTypes() { 41 + return array( 42 + ); 43 + } 44 + 45 + protected function execute(ConduitAPIRequest $request) { 46 + $user = $request->getUser()->getPHID(); 47 + $phid = $request->getValue('objectPHID'); 48 + $new = false; 49 + 50 + $flag = id(new PhabricatorFlag())->loadOneWhere( 51 + 'objectPHID = %s AND ownerPHID = %s', 52 + $phid, 53 + $user); 54 + if ($flag) { 55 + $params = $request->getAllParameters(); 56 + if (isset($params['color'])) { 57 + $flag->setColor($params['color']); 58 + } 59 + if (isset($params['note'])) { 60 + $flag->setNote($params['note']); 61 + } 62 + } else { 63 + $default_color = PhabricatorFlagColor::COLOR_BLUE; 64 + $flag = id(new PhabricatorFlag()) 65 + ->setOwnerPHID($user) 66 + ->setType(phid_get_type($phid)) 67 + ->setObjectPHID($phid) 68 + ->setReasonPHID($user) 69 + ->setColor($request->getValue('color', $default_color)) 70 + ->setNote($request->getValue('note', '')); 71 + $new = true; 72 + } 73 + $this->attachHandleToFlag($flag); 74 + $flag->save(); 75 + $ret = $this->buildFlagInfoDictionary($flag); 76 + $ret['new'] = $new; 77 + return $ret; 78 + } 79 + 80 + }
+1 -19
src/applications/conduit/method/flag/ConduitAPI_flag_query_Method.php
··· 73 73 74 74 $results = array(); 75 75 foreach ($flags as $flag) { 76 - $color = $flag->getColor(); 77 - $uri = PhabricatorEnv::getProductionURI($flag->getHandle()->getURI()); 78 - 79 - $results[] = array( 80 - 'id' => $flag->getID(), 81 - 'ownerPHID' => $flag->getOwnerPHID(), 82 - 'type' => $flag->getType(), 83 - 'objectPHID' => $flag->getObjectPHID(), 84 - 'reasonPHID' => $flag->getReasonPHID(), 85 - 'color' => $color, 86 - 'colorName' => PhabricatorFlagColor::getColorName($color), 87 - 'note' => $flag->getNote(), 88 - 'handle' => array( 89 - 'uri' => $uri, 90 - 'name' => $flag->getHandle()->getName(), 91 - ), 92 - 'dateCreated' => $flag->getDateCreated(), 93 - 'dateModified' => $flag->getDateModified(), 94 - ); 76 + $results[] = $this->buildFlagInfoDictionary($flag); 95 77 } 96 78 97 79 return $results;
+66
src/applications/conduit/method/phid/ConduitAPI_phid_lookup_Method.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + /** 20 + * @group conduit 21 + */ 22 + final class ConduitAPI_phid_lookup_Method 23 + extends ConduitAPI_phid_Method { 24 + 25 + public function getMethodDescription() { 26 + return "Look up objects by name."; 27 + } 28 + 29 + public function defineParamTypes() { 30 + return array( 31 + 'names' => 'required list<string>', 32 + ); 33 + } 34 + 35 + public function defineReturnType() { 36 + return 'nonempty dict<string, wild>'; 37 + } 38 + 39 + public function defineErrorTypes() { 40 + return array(); 41 + } 42 + 43 + protected function execute(ConduitAPIRequest $request) { 44 + $names = $request->getValue('names'); 45 + $phids = array(); 46 + foreach ($names as $name) { 47 + $phid = PhabricatorPHID::fromObjectName($name); 48 + if ($phid) { 49 + $phids[$name] = $phid; 50 + } 51 + } 52 + 53 + $handles = id(new PhabricatorObjectHandleData($phids)) 54 + ->loadHandles(); 55 + $result = array(); 56 + foreach ($phids as $name => $phid) { 57 + if (isset($handles[$phid]) && $handles[$phid]->isComplete()) { 58 + $result[$name] = $this->buildHandleInformationDictionary( 59 + $handles[$phid]); 60 + } 61 + } 62 + 63 + return $result; 64 + } 65 + 66 + }
+38
src/applications/phid/storage/PhabricatorPHID.php
··· 32 32 return 'PHID-'.$type.'-'.$uniq; 33 33 } 34 34 35 + public static function fromObjectName($name) { 36 + $object = null; 37 + $match = null; 38 + if (preg_match('/^PHID-[A-Z]+-.{20}$/', $name)) { 39 + // It's already a PHID! Yay. 40 + return $name; 41 + } 42 + if (preg_match('/^r([A-Z]+)(\S*)$/', $name, $match)) { 43 + $repository = id(new PhabricatorRepository()) 44 + ->loadOneWhere('callsign = %s', $match[1]); 45 + if ($match[2] == '') { 46 + $object = $repository; 47 + } else if ($repository) { 48 + $object = id(new PhabricatorRepositoryCommit())->loadOneWhere( 49 + 'repositoryID = %d AND commitIdentifier = %s', 50 + $repository->getID(), 51 + $match[2]); 52 + if (!$object) { 53 + try { 54 + $object = id(new PhabricatorRepositoryCommit())->loadOneWhere( 55 + 'repositoryID = %d AND commitIdentifier LIKE %>', 56 + $repository->getID(), 57 + $match[2]); 58 + } catch (AphrontQueryCountException $ex) { 59 + // Ambiguous, no jump. 60 + } 61 + } 62 + } 63 + } else if (preg_match('/^d(\d+)$/i', $name, $match)) { 64 + $object = id(new DifferentialRevision())->load($match[1]); 65 + } else if (preg_match('/^t(\d+)$/i', $name, $match)) { 66 + $object = id(new ManiphestTask())->load($match[1]); 67 + } 68 + if ($object) { 69 + return $object->getPHID(); 70 + } 71 + return null; 72 + } 35 73 }
+2 -30
src/applications/search/controller/PhabricatorSearchController.php
··· 222 222 $results = $pager->sliceResults($results); 223 223 224 224 if (!$request->getInt('page')) { 225 - $jump = null; 226 - $query_str = $query->getQuery(); 227 - $match = null; 228 - if (preg_match('/^r([A-Z]+)(\S*)$/', $query_str, $match)) { 229 - $repository = id(new PhabricatorRepository()) 230 - ->loadOneWhere('callsign = %s', $match[1]); 231 - if ($match[2] == '') { 232 - $jump = $repository; 233 - } else if ($repository) { 234 - $jump = id(new PhabricatorRepositoryCommit())->loadOneWhere( 235 - 'repositoryID = %d AND commitIdentifier = %s', 236 - $repository->getID(), 237 - $match[2]); 238 - if (!$jump) { 239 - try { 240 - $jump = id(new PhabricatorRepositoryCommit())->loadOneWhere( 241 - 'repositoryID = %d AND commitIdentifier LIKE %>', 242 - $repository->getID(), 243 - $match[2]); 244 - } catch (AphrontQueryCountException $ex) { 245 - // Ambiguous, no jump. 246 - } 247 - } 248 - } 249 - } else if (preg_match('/^d(\d+)$/i', $query_str, $match)) { 250 - $jump = id(new DifferentialRevision())->load($match[1]); 251 - } else if (preg_match('/^t(\d+)$/i', $query_str, $match)) { 252 - $jump = id(new ManiphestTask())->load($match[1]); 253 - } 225 + $jump = PhabricatorPHID::fromObjectName($query->getQuery()); 254 226 if ($jump) { 255 - array_unshift($results, $jump->getPHID()); 227 + array_unshift($results, $jump); 256 228 } 257 229 } 258 230