Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion cloud/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ func (s *UserService) GetCurrentUser(ctx context.Context) (*User, *Response, err
return &user, resp, nil
}

// GetAllUsers returns a list of all users, including active users, inactive users and previously deleted users that have an Atlassian account.
//
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-users/#api-rest-api-2-users-get
func (s *UserService) GetAllUsers(ctx context.Context) ([]User, *Response, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Jira docs, it looks like that this function can accept startAt and maxResults as input parameters. What do you think about adding this capability here as well?

Otherwise, adding those later would be a breaking change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const apiEndpoint = "rest/api/2/users"
req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil)
if err != nil {
return nil, nil, err
}

var users []User
resp, err := s.client.Do(req, &users)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}

return users, resp, nil
}

// WithMaxResults sets the max results to return
func WithMaxResults(maxResults int) UserSearchF {
return func(s UserSearch) UserSearch {
Expand Down Expand Up @@ -268,7 +287,7 @@ func WithProperty(property string) UserSearchF {
// Find searches for user info from Jira:
// It can find users by email or display name using the query parameter
//
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-user-search-get
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-user-search/#api-rest-api-2-user-search-get
//
// TODO Double check this method if this works as expected, is using the latest API and the response is complete
// This double check effort is done for v2 - Remove this two lines if this is completed.
Expand Down
23 changes: 23 additions & 0 deletions cloud/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,26 @@ func TestUserService_Find_SuccessParams(t *testing.T) {
t.Error("Expected user. User is nil")
}
}

func TestUserService_GetAllUsers_SuccessParams(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/users", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testRequestURL(t, r, "/rest/api/2/users")

fmt.Fprint(w, `[{"self":"http://www.example.com/jira/rest/api/2/users","key":"fred",
"name":"fred","emailAddress":"[email protected]","avatarUrls":{"48x48":"http://www.example.com/jira/secure/useravatar?size=large&ownerId=fred",
"24x24":"http://www.example.com/jira/secure/useravatar?size=small&ownerId=fred","16x16":"http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred",
"32x32":"http://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred"},"displayName":"Fred F. User","active":true,"timeZone":"Australia/Sydney","groups":{"size":3,"items":[
{"name":"jira-user","self":"http://www.example.com/jira/rest/api/2/group?groupname=jira-user"},{"name":"jira-admin",
"self":"http://www.example.com/jira/rest/api/2/group?groupname=jira-admin"},{"name":"important","self":"http://www.example.com/jira/rest/api/2/group?groupname=important"
}]},"applicationRoles":{"size":1,"items":[]},"expand":"groups,applicationRoles"}]`)
})

if user, _, err := testClient.User.GetAllUsers(context.Background()); err != nil {
t.Errorf("Error given: %s", err)
} else if user == nil {
t.Error("Expected user. User is nil")
}
}
Loading