Skip to content

A platform for community discussion. Free, open, simple.

FIX: Keep the type chosen when creating a theme placeholder

Régis Hanol0ae967f2d257
diff --git a/app/assets/stylesheets/admin/customize-install-theme.scss b/app/assets/stylesheets/admin/customize-install-theme.scss
index 469528db997..bff57e62f5a 100644
--- a/app/assets/stylesheets/admin/customize-install-theme.scss
+++ b/app/assets/stylesheets/admin/customize-install-theme.scss
@@ -89,6 +89,15 @@
}
}
+.install-theme-content__placeholder-type {
+ margin-top: 1em;
+}
+
+.install-theme-content__placeholder-type-tip {
+ margin-top: 0.25em;
+ color: var(--primary-medium);
+}
+
.popular-theme-items {
min-height: 60vh;
overflow: auto;
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rb
index ed69c4a24f5..dc1b8cc60da 100644
--- a/app/controllers/admin/themes_controller.rb
+++ b/app/controllers/admin/themes_controller.rb
@@ -426,6 +426,7 @@ class Admin::ThemesController < Admin::AdminController
Theme.create!(
user_id: theme_user&.id || -1,
name: remote.gsub(/\.git\z/, "").split("/").last,
+ component: params[:component].to_s == "true",
remote_theme: remote_theme,
)
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 1f6de1621d5..7d6cc4347f4 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -9225,6 +9225,7 @@ en:
duplicate_remote_theme: "The theme component “%{name}” is already installed, are you sure you want to install another copy?"
force_install: "The theme cannot be installed because the Git repository is inaccessible. Are you sure you want to continue installing it?"
create_placeholder: "Create placeholder"
+ placeholder_type_tip: "Once the installation is finished, the type from the repository's about.json is used."
about_theme: "About"
license: "License"
version: "Version:"
diff --git a/frontend/discourse/admin/components/modal/install-theme.gjs b/frontend/discourse/admin/components/modal/install-theme.gjs
index d4f57beccd3..8e07ddd1055 100644
--- a/frontend/discourse/admin/components/modal/install-theme.gjs
+++ b/frontend/discourse/admin/components/modal/install-theme.gjs
@@ -29,6 +29,16 @@ const CREATE_TYPES = [
{ name: i18n("admin.customize.theme.component"), value: COMPONENTS },
];
+const TypeSelect = <template>
+ <div class="label">{{i18n "admin.customize.theme.create_type"}}</div>
+ <ComboBox
+ @content={{CREATE_TYPES}}
+ @onChange={{@onChange}}
+ @value={{@value}}
+ @valueProperty="value"
+ />
+</template>;
+
export default class InstallThemeModal extends Component {
@service store;
@@ -240,6 +250,7 @@ export default class InstallThemeModal extends Component {
remote: this.uploadUrl,
branch: this.branch,
public_key: this.publicKey,
+ component: this.component,
};
if (placeholder) {
@@ -488,6 +499,15 @@ export default class InstallThemeModal extends Component {
<DCopyButton @selector="textarea.public-key-value" />
</div>
</div>
+ <div class="install-theme-content__placeholder-type">
+ <TypeSelect
+ @onChange={{this.updateSelectedType}}
+ @value={{this.selectedType}}
+ />
+ <div class="install-theme-content__placeholder-type-tip">
+ {{i18n "admin.customize.theme.placeholder_type_tip"}}
+ </div>
+ </div>
{{/if}}
</div>
{{/if}}
@@ -503,14 +523,9 @@ export default class InstallThemeModal extends Component {
value={{this.name}}
{{on "input" (withEventValue (fn (mut this.name)))}}
/>
- <div class="label">{{i18n
- "admin.customize.theme.create_type"
- }}</div>
- <ComboBox
- @content={{CREATE_TYPES}}
+ <TypeSelect
@onChange={{this.updateSelectedType}}
@value={{this.selectedType}}
- @valueProperty="value"
/>
</div>
{{/if}}
diff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rb
index f30d2389cc8..2e817f0cd96 100644
--- a/spec/requests/admin/themes_controller_spec.rb
+++ b/spec/requests/admin/themes_controller_spec.rb
@@ -317,6 +317,33 @@ RSpec.describe Admin::ThemesController do
)
end
+ it "creates a private component placeholder" do
+ Discourse.redis.setex("ssh_key_public_key", 1.hour, "private_key")
+
+ post "/admin/themes/import.json",
+ params: {
+ remote: "[email protected]:discourse/private-component.git",
+ public_key: "public_key",
+ placeholder: true,
+ component: true,
+ }
+
+ expect(response.status).to eq(201)
+ expect(Theme.last.component).to eq(true)
+ end
+
+ it "can force install a component" do
+ post "/admin/themes/import.json",
+ params: {
+ remote: "[email protected]:discourse/discourse-inexistent-component.git",
+ force: true,
+ component: true,
+ }
+
+ expect(response.status).to eq(201)
+ expect(Theme.last.component).to eq(true)
+ end
+
it "rolls back the remote theme when placeholder creation fails" do
Discourse.redis.setex("ssh_key_public_key", 1.hour, "private_key")
Theme.stubs(:create!).raises(ActiveRecord::RecordInvalid.new(Theme.new))
diff --git a/spec/system/page_objects/modals/install_theme.rb b/spec/system/page_objects/modals/install_theme.rb
index 6e407572b0d..cf0cf945db1 100644
--- a/spec/system/page_objects/modals/install_theme.rb
+++ b/spec/system/page_objects/modals/install_theme.rb
@@ -33,6 +33,13 @@ module PageObjects
self
end
+ def select_placeholder_type(type)
+ PageObjects::Components::SelectKit.new(
+ "#{MODAL_CLASS} .install-theme-content__placeholder-type .select-kit",
+ ).select_row_by_value(type)
+ self
+ end
+
def stage_private_theme
within(MODAL_CLASS) { find(".create-placeholder").click }
end
diff --git a/spec/system/stage_private_theme_spec.rb b/spec/system/stage_private_theme_spec.rb
index 88ac1513102..2fcb6cf6d22 100644
--- a/spec/system/stage_private_theme_spec.rb
+++ b/spec/system/stage_private_theme_spec.rb
@@ -4,6 +4,7 @@ RSpec.describe "Stage a private theme" do
fab!(:admin)
let(:themes_page) { PageObjects::Pages::AdminCustomizeThemesConfigArea.new }
+ let(:components_page) { PageObjects::Pages::AdminCustomizeComponentsConfigArea.new }
let(:theme_page) { PageObjects::Pages::AdminCustomizeThemes.new }
let(:dialog) { PageObjects::Components::Dialog.new }
let(:repository_url) { "[email protected]:discourse/private-theme.git" }
@@ -20,10 +21,33 @@ RSpec.describe "Stage a private theme" do
install_modal.stage_private_theme
expect(install_modal).to be_closed
- expect(themes_page).to have_theme_named("private-theme")
+ expect(theme_page).to have_incomplete_installation
+ expect(theme_page).to have_back_button_to_themes_page
+ end
+
+ it "lets an admin stage a private component before repository access is granted" do
+ components_page.visit
+ install_modal = components_page.click_install_button
+ install_modal.choose_remote_repository("[email protected]:discourse/private-component.git")
+
+ expect(install_modal).to have_private_theme_actions_enabled
+
+ install_modal.stage_private_theme
- themes_page.click_edit_by_name("private-theme")
+ expect(install_modal).to be_closed
expect(theme_page).to have_incomplete_installation
+ expect(theme_page).to have_back_button_to_components_page
+ end
+
+ it "lets an admin choose the type of the placeholder" do
+ themes_page.visit
+ install_modal = themes_page.click_install_button
+ install_modal.choose_remote_repository("[email protected]:discourse/private-component.git")
+ install_modal.select_placeholder_type("components")
+ install_modal.stage_private_theme
+
+ expect(install_modal).to be_closed
+ expect(theme_page).to have_back_button_to_components_page
end
it "keeps installation unavailable when deploy key generation fails" do