Skip to content

Commit af86b39

Browse files
committed
find users, find assignable users
1 parent 59543b4 commit af86b39

File tree

3 files changed

+155
-4
lines changed

3 files changed

+155
-4
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ $iss = new IssueService(new ArrayConfiguration(
122122

123123
### User
124124
- [Get User Info](#get-user-info)
125+
- [Find Users](#find-users)
126+
- [Find Assignable Users](#find-assignable-users)
125127

126128
### Group
127129
- [Create Group](#create-group)
@@ -932,6 +934,66 @@ try {
932934

933935
```
934936

937+
#### Find Users
938+
939+
Returns a list of users that match the search string and/or property.
940+
941+
```php
942+
<?php
943+
require 'vendor/autoload.php';
944+
945+
use JiraRestApi\JiraException;
946+
use JiraRestApi\User\UserService;
947+
948+
try {
949+
$us = new UserService();
950+
951+
$paramArray = [
952+
'username' => '.', // get all users.
953+
'startAt' => 0,
954+
'maxResults' => 1000,
955+
'includeInactive' => true,
956+
//'property' => '*',
957+
];
958+
959+
// get the user info.
960+
$users = $us->findUsers($paramArray);
961+
} catch (JiraException $e) {
962+
print("Error Occured! " . $e->getMessage());
963+
}
964+
965+
```
966+
967+
#### Find Assignable Users
968+
969+
Returns a list of users that match the search string.
970+
971+
```php
972+
<?php
973+
require 'vendor/autoload.php';
974+
975+
use JiraRestApi\JiraException;
976+
use JiraRestApi\User\UserService;
977+
978+
try {
979+
$us = new UserService();
980+
981+
$paramArray = [
982+
//'username' => null,
983+
'project' => 'TEST',
984+
//'issueKey' => 'TEST-1',
985+
'startAt' => 0,
986+
'maxResults' => 50, //max 1000
987+
//'actionDescriptorId' => 1,
988+
];
989+
990+
$users = $us->findAssignableUsers($paramArray);
991+
} catch (JiraException $e) {
992+
print("Error Occured! " . $e->getMessage());
993+
}
994+
995+
```
996+
935997
#### Create Group
936998

937999
Create new group.

src/User/UserService.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class UserService extends \JiraRestApi\JiraClient
2121
*/
2222
public function get($paramArray)
2323
{
24-
$queryParam = '?'.http_build_query($paramArray);
24+
$queryParam = '?' . http_build_query($paramArray);
2525

2626
$ret = $this->exec($this->uri.$queryParam, null);
2727

@@ -32,11 +32,49 @@ public function get($paramArray)
3232
);
3333
}
3434

35-
public function search($paramArray)
35+
/**
36+
* Returns a list of users that match the search string and/or property.
37+
*
38+
* @param $paramArray
39+
* @return array
40+
* @throws \JiraRestApi\JiraException
41+
* @throws \JsonMapper_Exception
42+
*/
43+
public function findUsers($paramArray)
44+
{
45+
$queryParam = '?' . http_build_query($paramArray);
46+
47+
$ret = $this->exec($this->uri . '/search' . $queryParam, null);
48+
49+
$this->log->addInfo("Result=\n".$ret);
50+
51+
$userData = json_decode($ret);
52+
$users = [];
53+
54+
foreach($userData as $user) {
55+
$users[] = $this->json_mapper->map(
56+
$user, new User()
57+
);
58+
}
59+
return $users;
60+
}
61+
62+
/**
63+
* Returns a list of users that match the search string.
64+
* Please note that this resource should be called with an issue key when a list of assignable users is retrieved for editing.
65+
*
66+
* @param $paramArray
67+
* @return array
68+
* @throws \JiraRestApi\JiraException
69+
* @throws \JsonMapper_Exception
70+
*
71+
* @see https://docs.atlassian.com/jira/REST/cloud/#api/2/user-findAssignableUsers
72+
*/
73+
public function findAssignableUsers($paramArray)
3674
{
37-
$queryParam = '?'.http_build_query($paramArray);
75+
$queryParam = '?' . http_build_query($paramArray);
3876

39-
$ret = $this->exec($this->uri.'/search'.$queryParam, null);
77+
$ret = $this->exec($this->uri . '/assignable/search' . $queryParam, null);
4078

4179
$this->log->addInfo("Result=\n".$ret);
4280

@@ -48,6 +86,7 @@ public function search($paramArray)
4886
$user, new User()
4987
);
5088
}
89+
5190
return $users;
5291
}
5392
}

tests/UserTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,54 @@ public function testAddUser()
2828
$this->markTestSkipped('not yet implemented');
2929
}
3030

31+
/**
32+
* @depends testGetUser
33+
*/
34+
public function testSearch()
35+
{
36+
try {
37+
$us = new UserService();
38+
39+
$paramArray = [
40+
'username' => '.', // . means all users
41+
'startAt' => 0,
42+
'maxResults' => 1000,
43+
'includeInactive' => true,
44+
//'property' => '*',
45+
];
46+
47+
// get the user info.
48+
$users = $us->findUsers($paramArray);
49+
50+
Dumper::dump($users);
51+
} catch (JiraException $e) {
52+
$this->assertTrue(false, 'testGetUser Failed : '.$e->getMessage());
53+
}
54+
}
55+
56+
/**
57+
* @depends testSearch
58+
*/
59+
public function testSearchAssignable()
60+
{
61+
try {
62+
$us = new UserService();
63+
64+
$paramArray = [
65+
//'username' => null,
66+
'project' => 'TEST',
67+
//'issueKey' => 'TEST-1',
68+
'startAt' => 0,
69+
'maxResults' => 1000,
70+
//'actionDescriptorId' => 1,
71+
];
72+
73+
// get the user info.
74+
$users = $us->findAssignableUsers($paramArray);
75+
76+
Dumper::dump($users);
77+
} catch (JiraException $e) {
78+
$this->assertTrue(false, 'testSearchAssignable Failed : '.$e->getMessage());
79+
}
80+
}
3181
}

0 commit comments

Comments
 (0)