Skip to content

Commit

Permalink
Merge pull request #13634 from opf/code-maintenance/49936-raise-missi…
Browse files Browse the repository at this point in the history
…ng-translation-errors-on-test-runs

Add in all currently-missing translations
  • Loading branch information
oliverguenther committed Sep 6, 2023
2 parents 2ba12ca + 7441331 commit fe88bf0
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 38 deletions.
26 changes: 18 additions & 8 deletions app/helpers/no_results_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
Expand Down Expand Up @@ -36,26 +38,34 @@ module NoResultsHelper
# - 'action_url' The url for the link in the content.
# - 'display_action' Whether or not the link should be displayed.
# - 'custom_title' custom text for the title.
# - 'custom_action_text' custom text for the title.
# - 'custom_action_text' custom text for the action.
#
# Calling this on its on without any arguments creates the box in its simplest
# form with only the title. Providing an action_url and display_action: true
# Displays the box with the title and link to the passed in url.
# The title and action_text are found using the locales key lookup unless
# The title_text and action_text are found using the locales key lookup unless
# custom_title and custom_action_text are provided.
#
# In the case of action_text, lookup is also only performed if display_action
# is true, in order not to perform unnecessary lookups when action_text
# shouldn't even be considered.
def no_results_box(action_url: nil,
display_action: false,
custom_title: nil,
custom_action_text: nil)

title = custom_title || t('.no_results_title_text', cascade: true)
action_text = custom_action_text || t('.no_results_content_text')
title_text = custom_title || t('.no_results_title_text', cascade: true) || ''
action_text = if display_action
custom_action_text || t('.no_results_content_text')
else
''
end
action_url = action_url || ''

render partial: '/common/no_results',
locals: {
title_text: title,
action_text: display_action ? action_text : '',
action_url: action_url || ''
title_text:,
action_text:,
action_url:
}
end
end
2 changes: 1 addition & 1 deletion app/views/oauth/applications/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ See COPYRIGHT and LICENSE files for more details.
</p>

<div class="form--field -visible-overflow">
<label class="form--label"> <%= t('doorkeeper.application.client_credentials_user_id') %>
<label class="form--label"> <%= t('activerecord.attributes.doorkeeper/application.client_credentials_user_id') %>
</label>
<div class="form--field-container">
<div class="form--text-field-container -middle">
Expand Down
2 changes: 1 addition & 1 deletion app/views/user_mailer/wiki_page_added.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>

<p>
<%=raw t(:mail_body_wiki_content_added,
<%=raw t(:mail_body_wiki_page_added,
id: link_to(@wiki_page.title, project_wiki_url(@wiki_page.project, @wiki_page)),
author: @wiki_page.author) %><br />
<em><%= @wiki_page.journals.last.notes %></em>
Expand Down
2 changes: 1 addition & 1 deletion app/views/user_mailer/wiki_page_updated.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>

<p>
<%=raw t(:mail_body_wiki_content_updated,
<%=raw t(:mail_body_wiki_page_updated,
id: link_to(@wiki_page.title, project_wiki_url(@wiki_page.project, @wiki_page)),
author: @wiki_page.journals.last.user) %><br />
<em><%= @wiki_page.journals.last.notes %></em>
Expand Down
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
config.assets.debug = false

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.i18n.raise_on_missing_translations = true

config.cache_store = :file_store, Rails.root.join("tmp", "cache", "paralleltests#{ENV.fetch('TEST_ENV_NUMBER', nil)}")

Expand Down
8 changes: 6 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ en:
tls_certificate_string: "LDAP server SSL certificate"
changeset:
repository: "Repository"
color:
hexcode: "Hex code"
comment:
commented: "Commented" # an object that this comment belongs to
custom_action:
Expand Down Expand Up @@ -2282,8 +2284,8 @@ en:
mail_body_register_ending: "Stay connected! Kind regards,"
mail_body_reminder: "%{count} work package(s) that are assigned to you are due in the next %{days} days:"
mail_body_group_reminder: "%{count} work package(s) that are assigned to group \"%{group}\" are due in the next %{days} days:"
mail_body_wiki_content_added: "The '%{id}' wiki page has been added by %{author}."
mail_body_wiki_content_updated: "The '%{id}' wiki page has been updated by %{author}."
mail_body_wiki_page_added: "The '%{id}' wiki page has been added by %{author}."
mail_body_wiki_page_updated: "The '%{id}' wiki page has been updated by %{author}."
mail_subject_account_activation_request: "%{value} account activation request"
mail_subject_backup_ready: "Your backup is ready"
mail_subject_backup_token_reset: "Backup token reset"
Expand Down Expand Up @@ -2475,6 +2477,7 @@ en:
permission_log_time: "Log time for other users"
permission_manage_forums: "Manage forums"
permission_manage_categories: "Manage work package categories"
permission_manage_dashboards: "Manage dashboards"
permission_manage_work_package_relations: "Manage work package relations"
permission_manage_members: "Manage members"
permission_manage_news: "Manage news"
Expand All @@ -2494,6 +2497,7 @@ en:
permission_manage_types: "Select types"
permission_view_changesets: "View repository revisions in OpenProject"
permission_view_commit_author_statistics: "View commit author statistics"
permission_view_dashboards: "View dashboards"
permission_view_work_package_watchers: "View watchers list"
permission_view_work_packages: "View work packages"
permission_view_messages: "View messages"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
<% html_title t(:label_administration), t("project_module_storages"), t(@storage.name) %>
<% html_title t(:label_administration), t("project_module_storages"), @storage.name %>
<%
breadcrumb_paths(
Expand Down
2 changes: 2 additions & 0 deletions modules/storages/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ en:
edit_automatically_managed_project_folders: "Edit automatically managed project folders"
replace_openproject_oauth: "Replace OpenProject OAuth"
replace_provider_type_oauth: "Replace %{provider_type} OAuth"
save: "Save"
save_and_continue_setup: "Save and continue setup"
save_and_complete_setup: "Save and complete setup"
select_folder: "Select folder"
Expand Down Expand Up @@ -146,6 +147,7 @@ en:
label_provider_type: "Provider type"
label_project_folder: "Project folder"
label_new_storage: "New storage"
label_edit_storage: "Edit storage"
label_existing_manual_folder: "Existing folder with manually managed permissions"
label_no_specific_folder: "No specific folder"
label_automatic_folder: "New folder with automatically managed permissions"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% html_title(t(:label_my_account), t('two_factor_authentication.devices.confirm')) -%>
<% html_title(t(:label_my_account), t('two_factor_authentication.devices.confirm_device')) -%>
<% breadcrumb_paths link_to(t('two_factor_authentication.label_two_factor_authentication'), index_path),
t('two_factor_authentication.devices.confirm') -%>
t('two_factor_authentication.devices.confirm_device') -%>
<%= styled_form_tag(confirm_path, method: :post, id: 'login-form', class: 'form -bordered', autocomplete: "off") do %>
<h2><%= title %></h2>
Expand Down
32 changes: 19 additions & 13 deletions spec/features/global_roles/global_role_assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#++

require 'spec_helper'
require_relative './mock_global_permissions'
require_relative 'mock_global_permissions'

RSpec.describe 'Global role: Global role assignment',
js: true,
Expand All @@ -37,9 +37,8 @@
end

describe 'Going to the global role assignment page' do
before do
mock_global_permissions [['global1', { project_module: :global }], ['global2', { project_module: :global }]]
end
include_context 'with mocked global permissions',
[['global1', { project_module: :global }], ['global2', { project_module: :global }]]

let!(:global_role1) { create(:global_role, name: 'global_role1', permissions: %i[global1]) }
let!(:global_role2) { create(:global_role, name: 'global_role2', permissions: %i[global2]) }
Expand Down Expand Up @@ -67,36 +66,43 @@
expect(page).to have_text 'global_role2'
end

# And I select the available global role "global_role"
# And I select the available global role "global_role2"
check 'global_role2'
# And I press "Add"
click_on 'Add'

# And I should not see "global_role" within "#available_principal_roles"
# And I should see "There is currently nothing to display"
wait_for_network_idle

# And I should see "global_role1" within "#table_principal_roles"
# Then I should see "global_role2" within "#table_principal_roles"
page.within('#table_principal_roles') do
expect(page).to have_text 'global_role1'
expect(page).to have_text 'global_role2'
end

# Then I should see "global_role" within "#table_principal_roles"
# And I should not see "global_role1" within "#available_principal_roles"
# And I should not see "global_role2" within "#available_principal_roles"
page.within('#available_principal_roles') do
expect(page).not_to have_text 'global_role1'
expect(page).not_to have_text 'global_role2'
end

# And I delete the assigned role "global_role"
# And I delete the assigned role "global_role1"
page.within("#assigned_global_role_#{global_role1.id}") do
page.find('.buttons a.icon-delete').click
end

# Then I should see "global_role" within "#table_principal_roles"
wait_for_network_idle

# Then I should see "global_role1" within "#available_principal_roles"
# And I should not see "global_role2" within "#available_principal_roles"
page.within('#available_principal_roles') do
expect(page).not_to have_text 'global_role2'
expect(page).to have_text 'global_role1'
expect(page).not_to have_text 'global_role2'
end
# And I should not see "global_role" within "#available_principal_roles"
# And I should see "There is currently nothing to display"

# And I should not see "global_role1" within "#table_principal_roles"
# And I should see "global_role1" within "#table_principal_roles"
page.within('#table_principal_roles') do
expect(page).not_to have_text 'global_role1'
expect(page).to have_text 'global_role2'
Expand Down
7 changes: 4 additions & 3 deletions spec/features/global_roles/global_role_crud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
#++

require 'spec_helper'
require_relative './mock_global_permissions'
require_relative 'mock_global_permissions'

RSpec.describe 'Global role: Global role CRUD',
js: true,
with_cuprite: true do
# Scenario: Global Role creation
# Given there is the global permission "glob_test" of the module "global_group"
include_context 'with mocked global permissions', [['glob_test', { project_module: 'global_group' }]]

before do
mock_global_permissions [['glob_test', { project_module: 'global_group' }]]
login_as current_user
end

Expand All @@ -53,7 +54,7 @@
# And I should see "Global group"
expect(page).to have_text 'GLOBAL GROUP'
# And I should see "Glob test"
expect(page).to have_text 'Permission Glob Test'
expect(page).to have_text 'Glob test'
# And I should not see "Issues can be assigned to this role"
expect(page).not_to have_text 'Issues can be assigned to this role'
# When I fill in "Name" with "Manager"
Expand Down
58 changes: 58 additions & 0 deletions spec/features/global_roles/mock_global_permissions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# frozen_string_literal: true

# Allows mocking a specific global permission
# that's not registered in an initializer by providing
# a name and a set of options.
# It also takes care of mocking a translation for each provided
# permission only if it wasn't already an existing key, preventing
# a mock of an already present translation.
RSpec.shared_context 'with mocked global permissions' do |permissions|
before do
mock_global_permissions(permissions)
end

around do |example|
permission_translation_mocker = PermissionTranslationMocker.new(permissions)

permission_translation_mocker.register

example.run
ensure
permission_translation_mocker.unregister
end
end

def mock_global_permissions(permissions)
mapped = permissions.map do |name, options|
mock_permissions(name, options.merge(global: true))
Expand Down Expand Up @@ -28,3 +52,37 @@ def mock_permissions(name, options = {})
**options
)
end

class PermissionTranslationMocker
def initialize(permissions)
@permissions = permissions
end

def register
@permissions.each do |name, _options|
unless translation_already_registered?(name)
I18n.backend.store_translations(:en, "permission_#{name}": name.humanize)
end
end
end

def unregister
@permissions.each do |name, _options|
unless translation_already_registered?(name)
I18n.backend.store_translations(:en, "permission_#{name}": name.humanize)
end
end
end

private

def translation_already_registered?(name)
translation_registry[name]
end

def translation_registry
@translation_registry ||= @permissions.to_h do |name, _options|
[name, I18n.exists?("permissions_#{name}")]
end
end
end
10 changes: 5 additions & 5 deletions spec/features/global_roles/no_module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#++

require 'spec_helper'
require_relative './mock_global_permissions'
require_relative 'mock_global_permissions'

RSpec.describe 'Global role: No module',
js: true,
Expand All @@ -36,15 +36,15 @@
let(:project) { create(:project) }
let!(:role) { create(:role) }

# Scenario:
# Given there is the global permission "glob_test" of the module "global"
include_context 'with mocked global permissions', [['global_perm1', { project_module: :global }]]

before do
login_as admin
end

it 'Global Rights Modules do not exist as Project -> Settings -> Modules' do
# Scenario:
# Given there is the global permission "glob_test" of the module "global"
mock_global_permissions [['global_perm1', { project_module: :global }]]

# And there is 1 project with the following:
# | name | test |
# | identifier | test |
Expand Down

0 comments on commit fe88bf0

Please sign in to comment.