forked from andygrunwald/go-jira
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpermissions.go
69 lines (59 loc) · 2.5 KB
/
permissions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package jira
import (
"context"
)
// PermissionsService handles projects for the Jira instance / API.
//
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-permissions/
type PermissionsService struct {
client *Client
}
type BulkProjectPermissions struct {
Permission string `json:"permission"`
ProjectIDs []int `json:"projects"`
IssueTypeIDs []int `json:"issues"`
}
type BulkPermissions struct {
ProjectPermissions []*BulkProjectPermissions `json:"projectPermissions"`
GlobalPermissions []string `json:"globalPermissions"`
}
type requestProjectPermission struct {
Permissions []string `json:"permissions"`
ProjectIDs []int `json:"projects"`
IssueTypeIDs []int `json:"issues"`
}
type requestBulkPermissions struct {
AccountID string `json:"accountId,omitempty"`
GlobalPermissions []string `json:"globalPermissions,omitempty"`
ProjectPermissions []requestProjectPermission `json:"projectPermissions,omitempty"`
}
// GetBulkPermissionsWithContext takes a list of projects with issue type IDs and
// returns permissions given user (or currently-authed user if that is not set)
// is granted on those projects and issue types. globalPermissions can also be
// passed, which will check non-project-specific permissions too.
//
// https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-permissions/#api-rest-api-2-permissions-check-post
func (s *PermissionsService) GetBulkPermissionsWithContext(ctx context.Context, accountID string, globalPermissions, permissions []string, projectIDs []int, issueTypeIDs []int) (*BulkPermissions, *Response, error) {
reqBody := requestBulkPermissions{
AccountID: accountID,
GlobalPermissions: globalPermissions,
ProjectPermissions: []requestProjectPermission{{
Permissions: permissions,
ProjectIDs: projectIDs,
IssueTypeIDs: issueTypeIDs,
}},
}
req, err := s.client.NewRequestWithContext(ctx, "POST", "/rest/api/2/permissions/check", reqBody)
if err != nil {
return nil, nil, err
}
bs := new(BulkPermissions)
resp, err := s.client.Do(req, bs)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
return bs, resp, nil
}
func (s *PermissionsService) GetBulkPermissions(accountID string, globalPermissions, permissions []string, projectIDs, issueTypeIDs []int) (*BulkPermissions, *Response, error) {
return s.GetBulkPermissionsWithContext(context.Background(), accountID, globalPermissions, permissions, projectIDs, issueTypeIDs)
}