Skip to content

Commit

Permalink
Feature/home 1780 permissions overhaul api (#479)
Browse files Browse the repository at this point in the history
* HOME-1780: basic new fields added and template model

* HOME-1780: added roles and tests
  • Loading branch information
VSevostianov authored Sep 30, 2024
1 parent 5e4421e commit b8e821e
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 8 deletions.
17 changes: 17 additions & 0 deletions src/collections/permission_templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {BaseCollection} from "./base_collection.js";
import {PermissionTemplate} from "../models/permission_template.js";
import type {TeamOnly} from "../types/index.js";
import type {PaginatedResult} from "../interfaces/index.js";


export class PermissionTemplates extends BaseCollection {
protected static prefixURI = "teams/{!:team_id}/roles";
protected static elementClass = PermissionTemplate;
protected static rootElementName = "roles"

list(
request_params: TeamOnly,
): Promise<PaginatedResult<PermissionTemplate>> {
return this.doList(request_params);
}
}
5 changes: 3 additions & 2 deletions src/interfaces/contributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ export interface Contributor {
fullname: string;
created_at: string;
created_at_timestamp: number;
is_admin: boolean;
is_reviewer: boolean;
is_admin: boolean; //deprecated
is_reviewer: boolean; //deprecated
languages: Array<{
lang_id: number;
lang_iso: string;
lang_name: string;
is_writable: boolean;
}>;
admin_rights: string[];
role_id: number;
}
9 changes: 9 additions & 0 deletions src/interfaces/permission_template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface PermissionTemplate {
id: number;
role: string;
permissions: string[];
description: string;
tag: string;
tagColor: string;
doesEnableAllReadOnlyLanguages: boolean;
}
5 changes: 3 additions & 2 deletions src/interfaces/user_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ export interface UserGroup {
group_id: number;
name: string;
permissions: {
is_admin: boolean;
is_reviewer: boolean;
is_admin: boolean; //deprecated
is_reviewer: boolean; //deprecated
admin_rights: string[];
languages: Array<{
lang_id: number;
lang_iso: string;
lang_name: string;
is_writable: boolean;
}>;
role_id: number;
};
created_at: string;
created_at_timestamp: number;
Expand Down
5 changes: 5 additions & 0 deletions src/lokalise/lokalise_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Translations } from "../collections/translations.js";
import { UserGroups } from "../collections/user_groups.js";
import { Webhooks } from "../collections/webhooks.js";
import { BaseClient, ClientParams } from "./base_client.js";
import {PermissionTemplates} from "../collections/permission_templates.js";

export { ClientParams };

Expand Down Expand Up @@ -119,6 +120,10 @@ export class LokaliseApi extends BaseClient {
return new UserGroups(this.clientData);
}

permissionTemplates(): PermissionTemplates {
return new PermissionTemplates(this.clientData);
}

webhooks(): Webhooks {
return new Webhooks(this.clientData);
}
Expand Down
5 changes: 3 additions & 2 deletions src/models/contributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ export class Contributor extends BaseModel implements ContributorInterface {
declare fullname: string;
declare created_at: string;
declare created_at_timestamp: number;
declare is_admin: boolean;
declare is_reviewer: boolean;
declare is_admin: boolean; //deprecated
declare is_reviewer: boolean; //deprecated
declare languages: Array<{
lang_id: number;
lang_iso: string;
lang_name: string;
is_writable: boolean;
}>;
declare admin_rights: string[];
declare role_id: number;
}
12 changes: 12 additions & 0 deletions src/models/permission_template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { PermissionTemplate as PermissionTemplateInterface } from "../interfaces/permission_template.js";
import { BaseModel } from "./base_model.js";

export class PermissionTemplate extends BaseModel implements PermissionTemplateInterface {
declare id: number;
declare role: string;
declare permissions: string[];
declare description: string;
declare tag: string;
declare tagColor: string;
declare doesEnableAllReadOnlyLanguages: boolean;
}
5 changes: 3 additions & 2 deletions src/models/user_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ export class UserGroup extends BaseModel implements UserGroupInterface {
declare group_id: number;
declare name: string;
declare permissions: {
is_admin: boolean;
is_reviewer: boolean;
is_admin: boolean;//deprecated
is_reviewer: boolean;//deprecated
admin_rights: string[];
languages: Array<{
lang_id: number;
lang_iso: string;
lang_name: string;
is_writable: boolean;
}>;
role_id: number;
};
declare created_at: string;
declare created_at_timestamp: number;
Expand Down
86 changes: 86 additions & 0 deletions test/fixtures/permission_templates/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"roles": [
{
"id": 1,
"role": "Localisation management",
"permissions": [
"activity",
"branches_main_modify",
"branches_create",
"branches_merge",
"statistics",
"tasks",
"contributors",
"settings",
"manage_languages",
"download",
"upload",
"glossary_delete",
"glossary_edit",
"manage_keys",
"screenshots",
"custom_status_modify"
],
"description": "Manage project settings, contributors and tasks",
"tag": "Full access",
"tagColor": "green",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 2,
"role": "Developer",
"permissions": [
"activity",
"branches_main_modify",
"branches_create",
"download",
"upload",
"manage_keys",
"screenshots"
],
"description": "Create keys, upload and download content",
"tag": "Advanced",
"tagColor": "cyan",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 3,
"role": "Content creator",
"permissions": [
"activity",
"manage_keys",
"manage_languages",
"screenshots",
"branches_main_modify"
],
"description": "Create, translate and edit keys, manage screenshots",
"tag": "Advanced",
"tagColor": "cyan",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 4,
"role": "Reviewer",
"permissions": [
"branches_main_modify",
"review",
"custom_status_modify"
],
"description": "Translate keys, control key statuses",
"tag": "Basic",
"tagColor": "grey",
"doesEnableAllReadOnlyLanguages": false
},
{
"id": 5,
"role": "Translator",
"permissions": [
"branches_main_modify"
],
"description": "Translate keys",
"tag": "Basic",
"tagColor": "grey",
"doesEnableAllReadOnlyLanguages": false
}
]
}

0 comments on commit b8e821e

Please sign in to comment.