1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2024-11-24 08:22:42 +02:00

Add PermissionSchemeService

Expand the PermissionScheme struct of ProjectService.

Add new PermissionSchemeService with functions Get and GetList.

Add corresponding mocks and tests.
This commit is contained in:
Matthias Weiss 2018-11-20 12:54:02 +01:00 committed by Wes McNamee
parent f4bc07d375
commit b2bcdc9f43
6 changed files with 2264 additions and 20 deletions

32
jira.go
View File

@ -27,21 +27,22 @@ type Client struct {
session *Session
// Services used for talking to different parts of the JIRA API.
Authentication *AuthenticationService
Issue *IssueService
Project *ProjectService
Board *BoardService
Sprint *SprintService
User *UserService
Group *GroupService
Version *VersionService
Priority *PriorityService
Field *FieldService
Component *ComponentService
Resolution *ResolutionService
StatusCategory *StatusCategoryService
Filter *FilterService
Role *RoleService
Authentication *AuthenticationService
Issue *IssueService
Project *ProjectService
Board *BoardService
Sprint *SprintService
User *UserService
Group *GroupService
Version *VersionService
Priority *PriorityService
Field *FieldService
Component *ComponentService
Resolution *ResolutionService
StatusCategory *StatusCategoryService
Filter *FilterService
Role *RoleService
PermissionScheme *PermissionSchemeService
}
// NewClient returns a new JIRA API client.
@ -85,6 +86,7 @@ func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
c.StatusCategory = &StatusCategoryService{client: c}
c.Filter = &FilterService{client: c}
c.Role = &RoleService{client: c}
c.PermissionScheme = &PermissionSchemeService{client: c}
return c, nil
}

File diff suppressed because it is too large Load Diff

659
mocks/permissionscheme.json Normal file
View File

@ -0,0 +1,659 @@
{
"expand": "permissions,user,group,projectRole,field,all",
"id": 10100,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100",
"name": "Default Permission Scheme",
"description": "This is the default Permission Scheme. Any new projects that are created will be assigned this scheme.",
"permissions": [
{
"id": 10520,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10520",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "MANAGE_WATCHERS"
},
{
"id": 10521,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10521",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "EDIT_ALL_COMMENTS"
},
{
"id": 10522,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10522",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "DELETE_ALL_COMMENTS"
},
{
"id": 10523,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10523",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "DELETE_ALL_ATTACHMENTS"
},
{
"id": 10524,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10524",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "ADMINISTER_PROJECTS"
},
{
"id": 10525,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10525",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "DELETE_ISSUES"
},
{
"id": 10526,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10526",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "MODIFY_REPORTER"
},
{
"id": 10527,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10527",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "DELETE_ALL_WORKLOGS"
},
{
"id": 10528,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10528",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "EDIT_ALL_WORKLOGS"
},
{
"id": 10529,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10529",
"holder": {
"type": "projectRole",
"parameter": "10002",
"expand": "projectRole"
},
"permission": "MANAGE_SPRINTS_PERMISSION"
},
{
"id": 10600,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10600",
"holder": {
"type": "projectRole",
"parameter": "10201",
"expand": "projectRole"
},
"permission": "TRANSITION_ISSUES"
},
{
"id": 12436,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12436",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "WORK_ON_ISSUES"
},
{
"id": 12435,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12435",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "VIEW_VOTERS_AND_WATCHERS"
},
{
"id": 12434,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12434",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "VIEW_READONLY_WORKFLOW"
},
{
"id": 12433,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12433",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "VIEW_DEV_TOOLS"
},
{
"id": 12432,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12432",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "TRANSITION_ISSUES"
},
{
"id": 12431,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12431",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "SET_ISSUE_SECURITY"
},
{
"id": 12430,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12430",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "SCHEDULE_ISSUES"
},
{
"id": 12429,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12429",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "RESOLVE_ISSUES"
},
{
"id": 12428,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12428",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "MOVE_ISSUES"
},
{
"id": 12427,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12427",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "MODIFY_REPORTER"
},
{
"id": 12426,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12426",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "MANAGE_WATCHERS"
},
{
"id": 12425,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12425",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "MANAGE_SPRINTS_PERMISSION"
},
{
"id": 12424,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12424",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "LINK_ISSUES"
},
{
"id": 12423,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12423",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "EDIT_OWN_WORKLOGS"
},
{
"id": 12422,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12422",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "EDIT_OWN_COMMENTS"
},
{
"id": 12421,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12421",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "EDIT_ISSUES"
},
{
"id": 12420,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12420",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "EDIT_ALL_WORKLOGS"
},
{
"id": 12419,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12419",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "EDIT_ALL_COMMENTS"
},
{
"id": 12418,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12418",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "DELETE_OWN_WORKLOGS"
},
{
"id": 12417,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12417",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "DELETE_OWN_COMMENTS"
},
{
"id": 12416,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12416",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "DELETE_OWN_ATTACHMENTS"
},
{
"id": 12415,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12415",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "DELETE_ISSUES"
},
{
"id": 12414,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12414",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "DELETE_ALL_WORKLOGS"
},
{
"id": 12413,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12413",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "DELETE_ALL_COMMENTS"
},
{
"id": 12412,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12412",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "DELETE_ALL_ATTACHMENTS"
},
{
"id": 12411,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12411",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "CREATE_ISSUES"
},
{
"id": 12410,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12410",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "CREATE_ATTACHMENTS"
},
{
"id": 12409,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12409",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "CLOSE_ISSUES"
},
{
"id": 12408,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12408",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "BROWSE_PROJECTS"
},
{
"id": 12407,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12407",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "ASSIGN_ISSUES"
},
{
"id": 12406,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12406",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "ASSIGNABLE_USER"
},
{
"id": 12405,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12405",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "ADMINISTER_PROJECTS"
},
{
"id": 12404,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/12404",
"holder": {
"type": "projectRole",
"parameter": "10302",
"expand": "projectRole"
},
"permission": "ADD_COMMENTS"
},
{
"id": 10552,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10552",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "ASSIGNABLE_USER"
},
{
"id": 10553,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10553",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "BROWSE_PROJECTS"
},
{
"id": 10554,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10554",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "CLOSE_ISSUES"
},
{
"id": 10555,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10555",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "CREATE_ISSUES"
},
{
"id": 10556,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10556",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "EDIT_ISSUES"
},
{
"id": 10557,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10557",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "LINK_ISSUES"
},
{
"id": 10558,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10558",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "MOVE_ISSUES"
},
{
"id": 10559,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10559",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "RESOLVE_ISSUES"
},
{
"id": 10560,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10560",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "VIEW_READONLY_WORKFLOW"
},
{
"id": 10561,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10561",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "VIEW_DEV_TOOLS"
},
{
"id": 10562,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10562",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "ASSIGN_ISSUES"
},
{
"id": 10563,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10563",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "SCHEDULE_ISSUES"
},
{
"id": 10564,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10564",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "TRANSITION_ISSUES"
},
{
"id": 10565,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10565",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "VIEW_VOTERS_AND_WATCHERS"
},
{
"id": 10566,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10566",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "ADD_COMMENTS"
},
{
"id": 10567,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10567",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "CREATE_ATTACHMENTS"
},
{
"id": 10568,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10568",
"holder": {
"type": "group",
"parameter": "FooBarGroup",
"expand": "group"
},
"permission": "WORK_ON_ISSUES"
},
{
"id": 10530,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10530",
"holder": {
"type": "applicationRole"
},
"permission": "EDIT_OWN_COMMENTS"
},
{
"id": 10531,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10531",
"holder": {
"type": "applicationRole"
},
"permission": "DELETE_OWN_COMMENTS"
},
{
"id": 10532,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10532",
"holder": {
"type": "applicationRole"
},
"permission": "DELETE_OWN_ATTACHMENTS"
},
{
"id": 10533,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10533",
"holder": {
"type": "applicationRole"
},
"permission": "DELETE_OWN_WORKLOGS"
},
{
"id": 10534,
"self": "https://sample.instance.org/rest/api/3/permissionscheme/10100/permission/10534",
"holder": {
"type": "applicationRole"
},
"permission": "EDIT_OWN_WORKLOGS"
}
]
}

62
permissionscheme.go Normal file
View File

@ -0,0 +1,62 @@
package jira
import "fmt"
// PermissionSchemeService handles permissionschemes for the JIRA instance / API.
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/3/permissionscheme
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"`
}
// GetList returns a list of all permission schemes
func (s *PermissionSchemeService) GetList() (*PermissionSchemes, *Response, error) {
apiEndpoint := "/rest/api/3/permissionscheme"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
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
}
// Get returns a full representation of the permission scheme for the schemeID
func (s *PermissionSchemeService) Get(schemeID int) (*PermissionScheme, *Response, error) {
apiEndpoint := fmt.Sprintf("/rest/api/3/permissionscheme/%d", schemeID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
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
}
return ps, resp, nil
}

56
permissionschemes_test.go Normal file
View File

@ -0,0 +1,56 @@
package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestPermissionSchemeService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/3/permissionscheme"
raw, err := ioutil.ReadFile("./mocks/all_permissionschemes.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprintf(w, string(raw))
})
permissionScheme, _, err := testClient.PermissionScheme.GetList()
if permissionScheme == nil {
t.Error("Expected role list. Role list is nil")
}
if err != nil {
t.Errorf("Error given: %v", err)
}
}
func TestPermissionSchemeService_Get(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/3/permissionscheme/10100"
raw, err := ioutil.ReadFile("./mocks/permissionscheme.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEdpoint)
fmt.Fprintf(writer, string(raw))
})
permissionScheme, _, err := testClient.PermissionScheme.Get(10100)
if permissionScheme == nil {
t.Errorf("Expected Role, got nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}

View File

@ -74,11 +74,12 @@ type ProjectComponent struct {
// PermissionScheme represents the permission scheme for the project
type PermissionScheme struct {
Expand string `json:"expand" structs:"expand,omitempty"`
Self string `json:"self" structs:"self,omitempty"`
ID int `json:"id" structs:"id,omitempty"`
Name string `json:"name" structs:"name,omitempty"`
Description string `json:"description" structs:"description,omitempty"`
Expand string `json:"expand" structs:"expand,omitempty"`
Self string `json:"self" structs:"self,omitempty"`
ID int `json:"id" structs:"id,omitempty"`
Name string `json:"name" structs:"name,omitempty"`
Description string `json:"description" structs:"description,omitempty"`
Permissions []Permission `json:"permissions" structs:"permissions,omitempty"`
}
// GetList gets all projects form JIRA