-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/home 1781 new permission related api (#54)
* HOME-1781: added new permission related API calls * HOME-1781: extracted templates separately, added tests * HOME-1781: fixed test
- Loading branch information
1 parent
17997bb
commit 0298d0f
Showing
5 changed files
with
238 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,101 @@ func TestContributorService_Create(t *testing.T) { | |
} | ||
} | ||
|
||
func TestContributorService_CreateWithRoleId(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc( | ||
fmt.Sprintf("/projects/%s/contributors", testProjectID), | ||
func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
testMethod(t, r, "POST") | ||
testHeader(t, r, apiTokenHeader, testApiToken) | ||
data := `{ | ||
"contributors": [ | ||
{ | ||
"email": "[email protected]", | ||
"fullname": "Mr. Translator", | ||
"is_admin": false, | ||
"is_reviewer": true, | ||
"languages": [ | ||
{ | ||
"lang_iso": "en", | ||
"is_writable": false | ||
} | ||
], | ||
"role_id": 2 | ||
} | ||
] | ||
}` | ||
|
||
req := new(bytes.Buffer) | ||
_ = json.Compact(req, []byte(data)) | ||
|
||
testBody(t, r, req.String()) | ||
|
||
_, _ = fmt.Fprint(w, `{ | ||
"project_id": "`+testProjectID+`", | ||
"contributors": [{ | ||
"user_id": 421, | ||
"email": "[email protected]", | ||
"fullname": "Mr. Translator", | ||
"is_admin": false, | ||
"is_reviewer": true, | ||
"languages": [ | ||
{ | ||
"lang_iso": "en", | ||
"is_writable": false | ||
} | ||
], | ||
"role_id": 2 | ||
}] | ||
}`) | ||
}) | ||
|
||
r, err := client.Contributors().Create(testProjectID, []NewContributor{ | ||
{ | ||
Email: "[email protected]", | ||
Fullname: "Mr. Translator", | ||
Permission: Permission{ | ||
IsAdmin: false, | ||
IsReviewer: true, | ||
Languages: []Language{{ | ||
LangISO: "en", | ||
IsWritable: false, | ||
}}, | ||
AdminRights: nil, | ||
RoleId: 2, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
t.Errorf("Contributors.Create returned error: %v", err) | ||
} | ||
|
||
want := []Contributor{ | ||
{ | ||
WithUserID: WithUserID{UserID: 421}, | ||
Email: "[email protected]", | ||
Fullname: "Mr. Translator", | ||
Permission: Permission{ | ||
IsAdmin: false, | ||
IsReviewer: true, | ||
Languages: []Language{{ | ||
LangISO: "en", | ||
IsWritable: false, | ||
}}, | ||
AdminRights: nil, | ||
RoleId: 2, | ||
}, | ||
}, | ||
} | ||
|
||
if !reflect.DeepEqual(r.Contributors, want) { | ||
t.Errorf("Contributors.Create returned %+v, want %+v", r.Contributors, want) | ||
} | ||
} | ||
|
||
func TestContributorService_Delete(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package lokalise | ||
|
||
import "fmt" | ||
|
||
const ( | ||
pathTemplates = "teams/%d/roles" | ||
) | ||
|
||
// The PermissionTemplate service | ||
type PermissionTemplateService struct { | ||
BaseService | ||
} | ||
|
||
type PermissionTemplate struct { | ||
ID int `json:"id"` | ||
Role string `json:"role"` | ||
Permissions []string `json:"permissions"` | ||
Description string `json:"description"` | ||
Tag string `json:"tag"` | ||
TagColor string `json:"tagColor"` | ||
TagInfo string `json:"tagInfo"` | ||
DoesEnableAllReadOnlyLanguages bool `json:"doesEnableAllReadOnlyLanguages"` | ||
} | ||
|
||
type PermissionRoleResponse struct { | ||
Roles []PermissionTemplate `json:"roles"` | ||
} | ||
|
||
// List all possible permission roles | ||
func (c *PermissionTemplateService) ListPermissionRoles(teamID int64) (r PermissionRoleResponse, err error) { | ||
resp, err := c.getWithOptions(c.Ctx(), pathPermissionRoles(teamID), &r, c.PageOpts()) | ||
|
||
if err != nil { | ||
return r, err | ||
} | ||
return r, apiError(resp) | ||
} | ||
|
||
func pathPermissionRoles(teamID int64) string { | ||
return fmt.Sprintf(pathTemplates, teamID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package lokalise | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestTeamPermissionTemplates_List(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc( | ||
"/teams/1/roles", | ||
func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
testMethod(t, r, "GET") | ||
testHeader(t, r, apiTokenHeader, testApiToken) | ||
|
||
_, _ = fmt.Fprint(w, `{ | ||
"roles": [ | ||
{ | ||
"id": 1, | ||
"role": "Localisation management", | ||
"permissions": [ | ||
"activity", | ||
"branches_main_modify" | ||
], | ||
"description": "Manage project settings, contributors and tasks", | ||
"tag": "Full access", | ||
"tagColor": "green", | ||
"doesEnableAllReadOnlyLanguages": true | ||
}, | ||
{ | ||
"id": 2, | ||
"role": "Developer", | ||
"permissions": [ | ||
"download", | ||
"upload" | ||
], | ||
"description": "Create keys, upload and download content", | ||
"tag": "Advanced", | ||
"tagColor": "cyan", | ||
"doesEnableAllReadOnlyLanguages": true | ||
} | ||
] | ||
}`) | ||
}) | ||
|
||
r, err := client.PermissionTemplates().ListPermissionRoles(1) | ||
if err != nil { | ||
t.Errorf("Teams.List returned error: %v", err) | ||
} | ||
|
||
want := PermissionRoleResponse{ | ||
Roles: []PermissionTemplate{ | ||
{ | ||
ID: 1, | ||
Role: "Localisation management", | ||
Permissions: []string{ | ||
"activity", | ||
"branches_main_modify", | ||
}, | ||
Description: "Manage project settings, contributors and tasks", | ||
Tag: "Full access", | ||
TagColor: "green", | ||
DoesEnableAllReadOnlyLanguages: true, | ||
}, | ||
{ | ||
ID: 2, | ||
Role: "Developer", | ||
Permissions: []string{ | ||
"download", | ||
"upload", | ||
}, | ||
Description: "Create keys, upload and download content", | ||
Tag: "Advanced", | ||
TagColor: "cyan", | ||
DoesEnableAllReadOnlyLanguages: true, | ||
}, | ||
}, | ||
} | ||
|
||
if !reflect.DeepEqual(r, want) { | ||
t.Errorf("Team.PermissionRoles.List returned %+v, want %+v", r, want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters