Skip to content

Commit 58a1181

Browse files
authored
Merge pull request #589 from andygrunwald/pr-414
Cloud/Group: Update Add/Remove and replace username parameter with accountId
2 parents 6cf5212 + 5891423 commit 58a1181

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ client, err := jira.NewClient("https://...", tp.Client())
398398
* Cloud/Authentication: Removes `CookieAuthTransport` and `AuthenticationService`, because this type of auth is not supported by the Jira cloud offering
399399
* Cloud/Component: The type `CreateComponentOptions` was renamed to `ComponentCreateOptions`
400400
* Cloud/User: Renamed `User.GetSelf` to `User.GetCurrentUser`
401+
* Cloud/Group: Renamed `Group.Add` to `Group.AddUserByGroupName`
402+
* Cloud/Group: Renamed `Group.Remove` to `Group.RemoveUserByGroupName`
401403

402404
### Features
403405

cloud/group.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ type groupMembersResult struct {
2323

2424
// Group represents a Jira group
2525
type Group struct {
26-
ID string `json:"id"`
27-
Title string `json:"title"`
28-
Type string `json:"type"`
29-
Properties groupProperties `json:"properties"`
30-
AdditionalProperties bool `json:"additionalProperties"`
26+
Name string `json:"name,omitempty" structs:"name,omitempty"`
27+
Self string `json:"self,omitempty" structs:"self,omitempty"`
28+
Users GroupMembers `json:"users,omitempty" structs:"users,omitempty"`
29+
Expand string `json:"expand,omitempty" structs:"expand,omitempty"`
3130
}
3231

33-
type groupProperties struct {
34-
Name groupPropertiesName `json:"name"`
35-
}
36-
37-
type groupPropertiesName struct {
38-
Type string `json:"type"`
32+
// GroupMembers represent members in a Jira group
33+
type GroupMembers struct {
34+
Size int `json:"size,omitempty" structs:"size,omitempty"`
35+
Items []GroupMember `json:"items,omitempty" structs:"items,omitempty"`
36+
MaxResults int `json:"max-results,omitempty" structs:"max-results.omitempty"`
37+
StartIndex int `json:"start-index,omitempty" structs:"start-index,omitempty"`
38+
EndIndex int `json:"end-index,omitempty" structs:"end-index,omitempty"`
3939
}
4040

4141
// GroupMember reflects a single member of a group
@@ -95,18 +95,18 @@ func (s *GroupService) Get(ctx context.Context, name string, options *GroupSearc
9595
return group.Members, resp, nil
9696
}
9797

98-
// Add adds user to group
98+
// Add adds a user to a group.
9999
//
100-
// Jira API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-addUserToGroup
100+
// The account ID of the user, which uniquely identifies the user across all Atlassian products.
101+
// For example, 5b10ac8d82e05b22cc7d4ef5.
101102
//
102-
// TODO Double check this method if this works as expected, is using the latest API and the response is complete
103-
// This double check effort is done for v2 - Remove this two lines if this is completed.
104-
func (s *GroupService) Add(ctx context.Context, groupname string, username string) (*Group, *Response, error) {
105-
apiEndpoint := fmt.Sprintf("/rest/api/2/group/user?groupname=%s", groupname)
103+
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-user-post
104+
func (s *GroupService) AddUserByGroupName(ctx context.Context, groupName string, accountID string) (*Group, *Response, error) {
105+
apiEndpoint := fmt.Sprintf("/rest/api/3/group/user?groupname=%s", groupName)
106106
var user struct {
107-
Name string `json:"name"`
107+
AccountID string `json:"accountId"`
108108
}
109-
user.Name = username
109+
user.AccountID = accountID
110110
req, err := s.client.NewRequest(ctx, http.MethodPost, apiEndpoint, &user)
111111
if err != nil {
112112
return nil, nil, err
@@ -122,15 +122,15 @@ func (s *GroupService) Add(ctx context.Context, groupname string, username strin
122122
return responseGroup, resp, nil
123123
}
124124

125-
// Remove removes user from group
125+
// Remove removes a user from a group.
126126
//
127-
// Jira API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-removeUserFromGroup
128-
// Caller must close resp.Body
127+
// The account ID of the user, which uniquely identifies the user across all Atlassian products.
128+
// For example, 5b10ac8d82e05b22cc7d4ef5.
129129
//
130-
// TODO Double check this method if this works as expected, is using the latest API and the response is complete
131-
// This double check effort is done for v2 - Remove this two lines if this is completed.
132-
func (s *GroupService) Remove(ctx context.Context, groupname string, username string) (*Response, error) {
133-
apiEndpoint := fmt.Sprintf("/rest/api/2/group/user?groupname=%s&username=%s", groupname, username)
130+
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-user-delete
131+
// Caller must close resp.Body
132+
func (s *GroupService) RemoveUserByGroupName(ctx context.Context, groupName string, accountID string) (*Response, error) {
133+
apiEndpoint := fmt.Sprintf("/rest/api/3/group/user?groupname=%s&accountId=%s", groupName, accountID)
134134
req, err := s.client.NewRequest(ctx, http.MethodDelete, apiEndpoint, nil)
135135
if err != nil {
136136
return nil, err

cloud/group_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ func TestGroupService_GetPage(t *testing.T) {
6565
func TestGroupService_Add(t *testing.T) {
6666
setup()
6767
defer teardown()
68-
testMux.HandleFunc("/rest/api/2/group/user", func(w http.ResponseWriter, r *http.Request) {
68+
testMux.HandleFunc("/rest/api/3/group/user", func(w http.ResponseWriter, r *http.Request) {
6969
testMethod(t, r, http.MethodPost)
70-
testRequestURL(t, r, "/rest/api/2/group/user?groupname=default")
70+
testRequestURL(t, r, "/rest/api/3/group/user?groupname=default")
7171

7272
w.WriteHeader(http.StatusCreated)
7373
fmt.Fprint(w, `{"name":"default","self":"http://www.example.com/jira/rest/api/2/group?groupname=default","users":{"size":1,"items":[],"max-results":50,"start-index":0,"end-index":0},"expand":"users"}`)
7474
})
7575

76-
if group, _, err := testClient.Group.Add(context.Background(), "default", "theodore"); err != nil {
76+
if group, _, err := testClient.Group.AddUserByGroupName(context.Background(), "default", "5b10ac8d82e05b22cc7d4ef5"); err != nil {
7777
t.Errorf("Error given: %s", err)
7878
} else if group == nil {
7979
t.Error("Expected group. Group is nil")
@@ -83,15 +83,15 @@ func TestGroupService_Add(t *testing.T) {
8383
func TestGroupService_Remove(t *testing.T) {
8484
setup()
8585
defer teardown()
86-
testMux.HandleFunc("/rest/api/2/group/user", func(w http.ResponseWriter, r *http.Request) {
86+
testMux.HandleFunc("/rest/api/3/group/user", func(w http.ResponseWriter, r *http.Request) {
8787
testMethod(t, r, http.MethodDelete)
88-
testRequestURL(t, r, "/rest/api/2/group/user?groupname=default")
88+
testRequestURL(t, r, "/rest/api/3/group/user?groupname=default")
8989

9090
w.WriteHeader(http.StatusOK)
9191
fmt.Fprint(w, `{"name":"default","self":"http://www.example.com/jira/rest/api/2/group?groupname=default","users":{"size":1,"items":[],"max-results":50,"start-index":0,"end-index":0},"expand":"users"}`)
9292
})
9393

94-
if _, err := testClient.Group.Remove(context.Background(), "default", "theodore"); err != nil {
94+
if _, err := testClient.Group.RemoveUserByGroupName(context.Background(), "default", "5b10ac8d82e05b22cc7d4ef5"); err != nil {
9595
t.Errorf("Error given: %s", err)
9696
}
9797
}

0 commit comments

Comments
 (0)