diff --git a/docs/_data/api_items.yml b/docs/_data/api_items.yml index e3572c0..35a3e34 100644 --- a/docs/_data/api_items.yml +++ b/docs/_data/api_items.yml @@ -120,6 +120,11 @@ path: fetch-a-single-payment-card - title: Delete a payment card path: delete-a-payment-card +- title: Permission templates + path: permission-templates + sub_paths: + - title: Fetch permission templates + path: fetch-permission-templates - title: Projects path: projects sub_paths: diff --git a/docs/additional_info/changelog.md b/docs/additional_info/changelog.md index 35a1fa8..b29a5b7 100644 --- a/docs/additional_info/changelog.md +++ b/docs/additional_info/changelog.md @@ -1,5 +1,38 @@ # Changelog +## 9.2.0 (15-Oct-2024) + +* Added support for a new [`PermissionTemplates` endpoint](https://developers.lokalise.com/reference/list-all-permission-templates): + +```ruby +permission_templates = test_client.permission_templates team_id + +template = permission_templates[0] + +template.id # => 1 +template.role # => "Manager" +template.permissions # => ['branches_main_modify', ...] +template.description # => 'Manage project settings ...' +template.tag # => 'Full access' +template.tagColor # => 'green' +template.tagInfo # => '' +template.doesEnableAllReadOnlyLanguages # => true +``` + +* Added `role_id` attribute to the user group object. For example: + +```ruby +group = test_client.team_user_group team_id, group_id +group.role_id # => 5 +``` + +* Added `role_id` attribute to the contributor object. For example: + +```ruby +contributor = test_client.contributor project_id, user_id +contributor.role_id # => 5 +``` + ## 9.1.0 (15-May-2024) * Add support for [cursor pagination](https://lokalise.github.io/ruby-lokalise-api/api/getting-started#cursor-pagination) for List keys and List translation endpoints: diff --git a/docs/api/permission-templates.md b/docs/api/permission-templates.md new file mode 100644 index 0000000..7010093 --- /dev/null +++ b/docs/api/permission-templates.md @@ -0,0 +1,22 @@ +# Permission templates + +[Permission template attributes](https://developers.lokalise.com/reference/permission-template-object) + +## Fetch permission templates + +[API doc](https://developers.lokalise.com/reference/list-all-permission-templates) + +```ruby +permission_templates = test_client.permission_templates team_id + +template = permission_templates[0] + +template.id # => 1 +template.role # => "Manager" +template.permissions # => ['branches_main_modify', ...] +template.description # => 'Manage project settings ...' +template.tag # => 'Full access' +template.tagColor # => 'green' +template.tagInfo # => '' +template.doesEnableAllReadOnlyLanguages # => true +``` \ No newline at end of file diff --git a/lib/ruby_lokalise_api/collections/permission_templates.rb b/lib/ruby_lokalise_api/collections/permission_templates.rb new file mode 100644 index 0000000..65f7ccd --- /dev/null +++ b/lib/ruby_lokalise_api/collections/permission_templates.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module RubyLokaliseApi + module Collections + class PermissionTemplates < Base + ENDPOINT = RubyLokaliseApi::Endpoints::PermissionTemplatesEndpoint + RESOURCE = RubyLokaliseApi::Resources::PermissionTemplate + DATA_KEY = 'roles' + end + end +end diff --git a/lib/ruby_lokalise_api/data/resource_attributes.yml b/lib/ruby_lokalise_api/data/resource_attributes.yml index 1420f6e..6ef8100 100644 --- a/lib/ruby_lokalise_api/data/resource_attributes.yml +++ b/lib/ruby_lokalise_api/data/resource_attributes.yml @@ -28,6 +28,7 @@ contributor: - is_reviewer - languages - admin_rights + - role_id custom_translation_status: - project_id - branch @@ -142,6 +143,15 @@ queued_process: - created_at - created_at_timestamp - details +permission_template: + - id + - role + - permissions + - description + - tag + - tagColor + - tagInfo + - doesEnableAllReadOnlyLanguages screenshot: - project_id - branch @@ -256,6 +266,7 @@ team_user_group: - team_id - projects - members + - role_id translation: - project_id - branch diff --git a/lib/ruby_lokalise_api/endpoints/permission_templates_endpoint.rb b/lib/ruby_lokalise_api/endpoints/permission_templates_endpoint.rb new file mode 100644 index 0000000..50bfc7d --- /dev/null +++ b/lib/ruby_lokalise_api/endpoints/permission_templates_endpoint.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module RubyLokaliseApi + module Endpoints + class PermissionTemplatesEndpoint < MainEndpoint + private + + def base_query(team_id) + { + teams: [team_id, :roles] + } + end + end + end +end diff --git a/lib/ruby_lokalise_api/resources/permission_template.rb b/lib/ruby_lokalise_api/resources/permission_template.rb new file mode 100644 index 0000000..3ffd350 --- /dev/null +++ b/lib/ruby_lokalise_api/resources/permission_template.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module RubyLokaliseApi + module Resources + class PermissionTemplate < Base + MAIN_PARAMS = %i[nil].freeze + no_support_for %i[update destroy reload_data] + end + end +end diff --git a/lib/ruby_lokalise_api/rest.rb b/lib/ruby_lokalise_api/rest.rb index 4737a85..cc9d967 100644 --- a/lib/ruby_lokalise_api/rest.rb +++ b/lib/ruby_lokalise_api/rest.rb @@ -14,6 +14,7 @@ module Rest include Rest::Languages include Rest::Orders include Rest::PaymentCards + include Rest::PermissionTemplates include Rest::Projects include Rest::QueuedProcesses include Rest::Segments diff --git a/lib/ruby_lokalise_api/rest/permission_templates.rb b/lib/ruby_lokalise_api/rest/permission_templates.rb new file mode 100644 index 0000000..5f40788 --- /dev/null +++ b/lib/ruby_lokalise_api/rest/permission_templates.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module RubyLokaliseApi + module Rest + module PermissionTemplates + # Returns permission tempates for a team + # + # @see https://developers.lokalise.com/reference/list-all-permission-templates + # @return [RubyLokaliseApi::Collections::PermissionTemplates] + # @param team_id [Integer, String] + def permission_templates(team_id) + name = 'PermissionTemplates' + params = { query: team_id } + + data = endpoint(name: name, params: params).do_get + + collection name, data + end + end + end +end diff --git a/lib/ruby_lokalise_api/version.rb b/lib/ruby_lokalise_api/version.rb index eb0edf7..308b0e2 100644 --- a/lib/ruby_lokalise_api/version.rb +++ b/lib/ruby_lokalise_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RubyLokaliseApi - VERSION = '9.1.0' + VERSION = '9.2.0' end diff --git a/spec/fixtures/contributors/contributor.json b/spec/fixtures/contributors/contributor.json index 3056b2c..73f58a1 100644 --- a/spec/fixtures/contributors/contributor.json +++ b/spec/fixtures/contributors/contributor.json @@ -47,6 +47,7 @@ "create_branches", "activity", "statistics" - ] + ], + "role_id": 5 } } \ No newline at end of file diff --git a/spec/fixtures/permission_templates/list.json b/spec/fixtures/permission_templates/list.json new file mode 100644 index 0000000..213f6bc --- /dev/null +++ b/spec/fixtures/permission_templates/list.json @@ -0,0 +1,86 @@ +{ + "roles": [ + { + "id": 1, + "role": "Manager", + "permissions": [ + "activity", + "branches_main_modify", + "branches_create", + "branches_merge", + "statistics", + "tasks", + "contributors", + "settings", + "manage_languages", + "download", + "upload", + "glossary_delete", + "glossary_edit", + "manage_keys", + "screenshots", + "review", + "custom_status_modify" + ], + "description": "Manage project settings, contributors and tasks", + "tag": "Full access", + "tagColor": "green", + "tagInfo": null, + "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", + "tagInfo": null, + "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", + "tagInfo": null, + "doesEnableAllReadOnlyLanguages": true + }, + { + "id": 4, + "role": "Reviewer", + "permissions": ["branches_main_modify", "review", "custom_status_modify"], + "description": "Translate keys, control key statuses", + "tag": "Basic", + "tagColor": "grey", + "tagInfo": "All users, regardless of their assigned roles and permissions, are granted entry-level access, such as: View glossary, View source content, Collaborate via comments, Limited access to editor, Generate API tokens", + "doesEnableAllReadOnlyLanguages": false + }, + { + "id": 5, + "role": "Translator", + "permissions": ["branches_main_modify"], + "description": "Translate keys", + "tag": "Basic", + "tagColor": "grey", + "tagInfo": "All users, regardless of their assigned roles and permissions, are granted entry-level access, such as: View glossary, View source content, Collaborate via comments, Limited access to editor, Generate API tokens", + "doesEnableAllReadOnlyLanguages": false + } + ] +} diff --git a/spec/fixtures/team_user_groups/team_user_group.json b/spec/fixtures/team_user_groups/team_user_group.json index c0ee3f0..e83d835 100644 --- a/spec/fixtures/team_user_groups/team_user_group.json +++ b/spec/fixtures/team_user_groups/team_user_group.json @@ -39,5 +39,6 @@ "members": [ 49436, 72007 - ] + ], + "role_id": 5 } \ No newline at end of file diff --git a/spec/lib/ruby_lokalise_api/rest/contributors_spec.rb b/spec/lib/ruby_lokalise_api/rest/contributors_spec.rb index 2fe9f4f..c001452 100644 --- a/spec/lib/ruby_lokalise_api/rest/contributors_spec.rb +++ b/spec/lib/ruby_lokalise_api/rest/contributors_spec.rb @@ -27,6 +27,8 @@ 'is_writable' => true ) expect(contributor.admin_rights).to include('upload') + expect(contributor.user_id).to eq(user_id) + expect(contributor.role_id).to eq(5) end specify '#contributors' do diff --git a/spec/lib/ruby_lokalise_api/rest/permission_templates_spec.rb b/spec/lib/ruby_lokalise_api/rest/permission_templates_spec.rb new file mode 100644 index 0000000..dafdfc0 --- /dev/null +++ b/spec/lib/ruby_lokalise_api/rest/permission_templates_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +RSpec.describe RubyLokaliseApi::Rest::PermissionTemplates do + let(:team_id) { 176_692 } + + specify '#permission_templates' do + stub( + uri: "teams/#{team_id}/roles", + resp: { body: fixture('permission_templates/list') } + ) + + permission_templates = test_client.permission_templates team_id + + expect(permission_templates.collection.length).to eq(5) + expect(permission_templates).to be_an_instance_of(RubyLokaliseApi::Collections::PermissionTemplates) + + template = permission_templates[0] + + expect(template.id).to eq(1) + expect(template.role).to eq('Manager') + expect(template.permissions).to include('branches_main_modify') + expect(template.description).to include('Manage project settings') + expect(template.tag).to eq('Full access') + expect(template.tagColor).to eq('green') + expect(template.tagInfo).to be_nil + expect(template.doesEnableAllReadOnlyLanguages).to be true + end +end diff --git a/spec/lib/ruby_lokalise_api/rest/team_user_groups_spec.rb b/spec/lib/ruby_lokalise_api/rest/team_user_groups_spec.rb index 358209b..b25ff30 100644 --- a/spec/lib/ruby_lokalise_api/rest/team_user_groups_spec.rb +++ b/spec/lib/ruby_lokalise_api/rest/team_user_groups_spec.rb @@ -36,6 +36,7 @@ expect(group.created_at_timestamp).to eq(1_595_503_264) expect(group.projects).to eq([]) expect(group.members).to include(49_436) + expect(group.role_id).to eq(5) end specify '#create_team_user_group' do diff --git a/spec/support/expectations.rb b/spec/support/expectations.rb index 3d6b017..cd34476 100644 --- a/spec/support/expectations.rb +++ b/spec/support/expectations.rb @@ -34,7 +34,8 @@ def proper_collection(collection_obj, collection) def proper_endpoint(collection_obj) res, ep = first_collection_endpoint(collection_from(collection_obj)) - params = res.class.const_get(:MAIN_PARAMS).to_array.map do |p| + main_params = res.class.const_get(:MAIN_PARAMS).to_array + params = main_params.map do |p| res.send(p).to_s end