mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-01-20 02:59:58 +02:00
Merge pull request #131 from b4b4r07/feat/add-new-ep-ps
Add new endpoint for getting assigned permission scheme for the project
This commit is contained in:
commit
5cfdb85cc9
31
project.go
31
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
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ func TestProjectService_ListWithOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestProjectService_Get(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
@ -103,3 +102,57 @@ func TestProjectService_Get_NoProject(t *testing.T) {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectService_GetPermissionScheme_Failure(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)
|
||||
})
|
||||
|
||||
permissionScheme, resp, err := testClient.Project.GetPermissionScheme("99999999")
|
||||
if permissionScheme != nil {
|
||||
t.Errorf("Expected nil. Got %+v", permissionScheme)
|
||||
}
|
||||
|
||||
if resp.Status == "404" {
|
||||
t.Errorf("Expected status 404. Got %s", resp.Status)
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectService_GetPermissionScheme_Success(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, `{
|
||||
"expand": "permissions,user,group,projectRole,field,all",
|
||||
"id": 10201,
|
||||
"self": "https://www.example.com/rest/api/2/permissionscheme/10201",
|
||||
"name": "Project for specific-users",
|
||||
"description": "Projects that can only see for people belonging to specific-users group"
|
||||
}`)
|
||||
})
|
||||
|
||||
permissionScheme, resp, err := testClient.Project.GetPermissionScheme("99999999")
|
||||
if permissionScheme.ID != 10201 {
|
||||
t.Errorf("Expected Permission Scheme ID. Got %+v", permissionScheme)
|
||||
}
|
||||
|
||||
if resp.Status == "404" {
|
||||
t.Errorf("Expected status 404. Got %s", resp.Status)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user