2020-09-14 18:31:56 +00:00
|
|
|
package jira
|
|
|
|
|
2021-10-06 17:33:14 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
2020-09-14 18:31:56 +00:00
|
|
|
|
2021-10-06 17:33:14 +00:00
|
|
|
// PermissionSchemeService handles permissionschemes for the Jira instance / API.
|
2020-09-14 18:31:56 +00:00
|
|
|
//
|
2021-10-06 17:33:14 +00:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-group-Permissionscheme
|
2020-09-14 18:31:56 +00:00
|
|
|
type PermissionSchemeService struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
type PermissionSchemes struct {
|
|
|
|
PermissionSchemes []PermissionScheme `json:"permissionSchemes" structs:"permissionSchemes"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Permission struct {
|
|
|
|
ID int `json:"id" structs:"id"`
|
|
|
|
Self string `json:"expand" structs:"expand"`
|
|
|
|
Holder Holder `json:"holder" structs:"holder"`
|
|
|
|
Name string `json:"permission" structs:"permission"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Holder struct {
|
|
|
|
Type string `json:"type" structs:"type"`
|
|
|
|
Parameter string `json:"parameter" structs:"parameter"`
|
|
|
|
Expand string `json:"expand" structs:"expand"`
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:33:14 +00:00
|
|
|
// GetListWithContext returns a list of all permission schemes
|
2020-09-14 18:31:56 +00:00
|
|
|
//
|
2021-10-06 17:33:14 +00:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-permissionscheme-get
|
|
|
|
func (s *PermissionSchemeService) GetListWithContext(ctx context.Context) (*PermissionSchemes, *Response, error) {
|
2020-09-14 18:31:56 +00:00
|
|
|
apiEndpoint := "/rest/api/3/permissionscheme"
|
2021-10-06 17:33:14 +00:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
2020-09-14 18:31:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
pss := new(PermissionSchemes)
|
|
|
|
resp, err := s.client.Do(req, &pss)
|
|
|
|
if err != nil {
|
|
|
|
jerr := NewJiraError(resp, err)
|
|
|
|
return nil, resp, jerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return pss, resp, nil
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:33:14 +00:00
|
|
|
// GetList wraps GetListWithContext using the background context.
|
|
|
|
func (s *PermissionSchemeService) GetList() (*PermissionSchemes, *Response, error) {
|
|
|
|
return s.GetListWithContext(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWithContext returns a full representation of the permission scheme for the schemeID
|
2020-09-14 18:31:56 +00:00
|
|
|
//
|
2021-10-06 17:33:14 +00:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-permissionscheme-schemeId-get
|
|
|
|
func (s *PermissionSchemeService) GetWithContext(ctx context.Context, schemeID int) (*PermissionScheme, *Response, error) {
|
2020-09-14 18:31:56 +00:00
|
|
|
apiEndpoint := fmt.Sprintf("/rest/api/3/permissionscheme/%d", schemeID)
|
2021-10-06 17:33:14 +00:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
2020-09-14 18:31:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ps := new(PermissionScheme)
|
|
|
|
resp, err := s.client.Do(req, ps)
|
|
|
|
if err != nil {
|
|
|
|
jerr := NewJiraError(resp, err)
|
|
|
|
return nil, resp, jerr
|
|
|
|
}
|
|
|
|
if ps.Self == "" {
|
2021-10-06 17:33:14 +00:00
|
|
|
return nil, resp, fmt.Errorf("no permissionscheme with ID %d found", schemeID)
|
2020-09-14 18:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ps, resp, nil
|
|
|
|
}
|
2021-10-06 17:33:14 +00:00
|
|
|
|
|
|
|
// Get wraps GetWithContext using the background context.
|
|
|
|
func (s *PermissionSchemeService) Get(schemeID int) (*PermissionScheme, *Response, error) {
|
|
|
|
return s.GetWithContext(context.Background(), schemeID)
|
|
|
|
}
|