|
7 | 7 | use JiraCloud\Issue\Reporter; |
8 | 8 | use JiraCloud\Issue\Version; |
9 | 9 | use JiraCloud\JiraException; |
| 10 | +use JiraCloud\Role\Role; |
10 | 11 |
|
11 | 12 | class ProjectService extends \JiraCloud\JiraClient |
12 | 13 | { |
@@ -392,4 +393,61 @@ public function archiveProject($projectIdOrKey) |
392 | 393 |
|
393 | 394 | return $ret; |
394 | 395 | } |
| 396 | + |
| 397 | + /** |
| 398 | + * @param $projectIdOrKey |
| 399 | + * |
| 400 | + * @throws JiraException |
| 401 | + * |
| 402 | + * @return array<string, string> |
| 403 | + * |
| 404 | + * STATUS 401 Returned if the user is not logged in. |
| 405 | + * STATUS 404 - Returned if the project does not exist. |
| 406 | + */ |
| 407 | + public function getProjectRoles($projectIdOrKey) |
| 408 | + { |
| 409 | + $response = $this->exec($this->uri.'/'.$projectIdOrKey.'/role'); |
| 410 | + |
| 411 | + $this->log->info('getProjectRoles Result='.$response); |
| 412 | + |
| 413 | + return (array) json_decode($response); |
| 414 | + } |
| 415 | + |
| 416 | + /** |
| 417 | + * @param $projectIdOrKey |
| 418 | + * @param $roleId |
| 419 | + * |
| 420 | + * @throws JiraException |
| 421 | + * |
| 422 | + * @return Role |
| 423 | + * |
| 424 | + * STATUS 401 Returned if the user is not logged in. |
| 425 | + * STATUS 404 - Returned if the project does not exist. |
| 426 | + */ |
| 427 | + public function getProjectRole($projectIdOrKey, $roleId, $excludeInactiveUsers = false) |
| 428 | + { |
| 429 | + $response = $this->exec($this->uri.'/'.$projectIdOrKey.'/role/'.$roleId.'?excludeInactiveUsers='.$excludeInactiveUsers); |
| 430 | + |
| 431 | + $this->log->info('getProjectRole Result='.$response); |
| 432 | + |
| 433 | + $reporters = array_map( |
| 434 | + function ($elem) { |
| 435 | + $reporter = $this->json_mapper->map($elem, new Reporter()); |
| 436 | + $reporter->accountId = $elem->actorUser->accountId; |
| 437 | + |
| 438 | + return $reporter; |
| 439 | + }, |
| 440 | + array_filter(json_decode($response)->actors, function ($elem) { |
| 441 | + return $elem->type === 'atlassian-user-role-actor'; |
| 442 | + }), |
| 443 | + ); |
| 444 | + |
| 445 | + $role = $this->json_mapper->map( |
| 446 | + json_decode($response), |
| 447 | + new Role() |
| 448 | + ); |
| 449 | + $role->actors = $reporters; |
| 450 | + |
| 451 | + return $role; |
| 452 | + } |
395 | 453 | } |
0 commit comments