Skip to content

Commit

Permalink
Merge pull request #131 from b4b4r07/feat/add-new-ep-ps
Browse files Browse the repository at this point in the history
Add new endpoint for getting assigned permission scheme for the project
  • Loading branch information
rbriski authored May 14, 2018
2 parents 3225585 + 3ca90a4 commit 5cfdb85
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
31 changes: 31 additions & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 changes: 54 additions & 1 deletion project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func TestProjectService_ListWithOptions(t *testing.T) {
}
}


func TestProjectService_Get(t *testing.T) {
setup()
defer teardown()
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 5cfdb85

Please sign in to comment.