-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Add ProblemCheck for google (#167)
This commit brings error messages for Google Translate to the admin dashboard. And adds errors for missing Google API keys to the ProblemCheck ref: /t/136397 * update translation * small change about translation * Update app/services/problem_check/missing_translator_api_key.rb Co-authored-by: Ted Johansson <[email protected]>
- Loading branch information
Showing
8 changed files
with
124 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
class ProblemCheck::MissingTranslatorApiKey < ProblemCheck | ||
self.priority = "high" | ||
|
||
def call | ||
return no_problem unless SiteSetting.translator_enabled | ||
name = api_key_site_setting_name | ||
return no_problem if name.nil? | ||
return no_problem if SiteSetting.get(name).present? | ||
|
||
problem | ||
end | ||
|
||
private | ||
|
||
def translation_data | ||
{ | ||
provider: SiteSetting.translator, | ||
key: I18n.t("site_settings.#{api_key_site_setting_name}"), | ||
key_name: api_key_site_setting_name, | ||
} | ||
end | ||
|
||
def api_key_site_setting_name | ||
case SiteSetting.translator | ||
when "Google" | ||
"translator_google_api_key" | ||
when "Microsoft" | ||
"translator_azure_subscription_key" | ||
end | ||
end | ||
end |
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
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
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
spec/services/problem_check/missing_translator_api_key_spec.rb
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,48 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe ProblemCheck::MissingTranslatorApiKey do | ||
subject(:check) { described_class.new } | ||
|
||
describe ".call" do | ||
before { SiteSetting.stubs(translator_enabled: enabled) } | ||
|
||
shared_examples "missing key checker" do |provider, key| | ||
context "when translator is #{provider}" do | ||
before { SiteSetting.translator = provider } | ||
|
||
it "when #{provider} is not provided" do | ||
SiteSetting.set(key, "") | ||
|
||
expect(check).to have_a_problem.with_priority("high").with_message( | ||
I18n.t( | ||
"dashboard.problem.missing_translator_api_key", | ||
locale: "en", | ||
provider:, | ||
key: I18n.t("site_settings.#{key}"), | ||
key_name: key, | ||
), | ||
) | ||
end | ||
|
||
it "when #{provider} is provided" do | ||
SiteSetting.set(key, "foo") | ||
|
||
expect(check).to be_chill_about_it | ||
end | ||
end | ||
end | ||
|
||
context "when plugin is disabled" do | ||
let(:enabled) { false } | ||
|
||
it { expect(check).to be_chill_about_it } | ||
end | ||
|
||
context "when plugin is enabled" do | ||
let(:enabled) { true } | ||
|
||
include_examples "missing key checker", "Google", "translator_google_api_key" | ||
include_examples "missing key checker", "Microsoft", "translator_azure_subscription_key" | ||
end | ||
end | ||
end |