From 4ecfcbf5da2ae6b16791b90f1347f9fa75e2cf34 Mon Sep 17 00:00:00 2001 From: b4b4r07 Date: Sat, 12 May 2018 16:28:05 +0900 Subject: [PATCH] Add new endpoint for getting assigned permission scheme for the project --- project.go | 31 +++++++++++++++++++++++++++++++ project_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/project.go b/project.go index 37572dc9..b71b5bba 100644 --- a/project.go +++ b/project.go @@ -72,6 +72,15 @@ type ProjectComponent struct { ProjectID int `json:"projectId" structs:"projectId,omitempty"` } +// 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"` +} + // GetList gets all projects form JIRA // // JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects @@ -129,3 +138,25 @@ func (s *ProjectService) Get(projectID string) (*Project, *Response, error) { return project, resp, nil } + +// GetPermissionScheme returns a full representation of the permission scheme for the project +// JIRA will attempt to identify the project by the projectIdOrKey path parameter. +// This can be an project id, or an project key. +// +// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getProject +func (s *ProjectService) GetPermissionScheme(projectID string) (*PermissionScheme, *Response, error) { + apiEndpoint := fmt.Sprintf("/rest/api/2/project/%s/permissionscheme", projectID) + 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 +} diff --git a/project_test.go b/project_test.go index ebfb897d..c4b108d2 100644 --- a/project_test.go +++ b/project_test.go @@ -103,3 +103,27 @@ func TestProjectService_Get_NoProject(t *testing.T) { t.Errorf("Error given: %s", err) } } + +func TestProjectService_GetPermissionScheme(t *testing.T) { + setup() + defer teardown() + testAPIEdpoint := "/rest/api/2/project/99999999/permissionscheme" + + testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testRequestURL(t, r, testAPIEdpoint) + fmt.Fprint(w, nil) + }) + + projects, resp, err := testClient.Project.GetPermissionScheme("99999999") + if projects != nil { + t.Errorf("Expected nil. Got %+v", projects) + } + + if resp.Status == "404" { + t.Errorf("Expected status 404. Got %s", resp.Status) + } + if err == nil { + t.Errorf("Error given: %s", err) + } +}