Skip to content

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

DEV: Drop `.dcstyle.json` theme import support (#38857)

David Taylor253a39dca420
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rb
index d8dfef37e70..66da2bf5062 100644
--- a/app/controllers/admin/themes_controller.rb
+++ b/app/controllers/admin/themes_controller.rb
@@ -50,45 +50,7 @@ class Admin::ThemesController < Admin::AdminController
def import
@theme = nil
- if params[:theme] && params[:theme].content_type == "application/json"
- ban_in_allowlist_mode!
-
- # .dcstyle.json import. Deprecated, but still available to allow conversion
- json = JSON.parse(params[:theme].read)
- theme = json["theme"]
-
- @theme = Theme.new(name: theme["name"], user_id: theme_user.id, auto_update: false)
- theme["theme_fields"]&.each do |field|
- if field["raw_upload"]
- begin
- tmp = Tempfile.new
- tmp.binmode
- file = Base64.decode64(field["raw_upload"])
- tmp.write(file)
- tmp.rewind
- upload = UploadCreator.new(tmp, field["filename"]).create_for(theme_user.id)
- field["upload_id"] = upload.id
- ensure
- tmp.unlink
- end
- end
-
- @theme.set_field(
- target: field["target"],
- name: field["name"],
- value: field["value"],
- type_id: field["type_id"],
- upload_id: field["upload_id"],
- )
- end
-
- if @theme.save
- log_theme_change(nil, @theme)
- render json: serialize_data(@theme, ThemeSerializer), status: :created
- else
- render json: @theme.errors, status: :unprocessable_entity
- end
- elsif remote = params[:remote]
+ if remote = params[:remote]
if remote.length > MAX_REMOTE_LENGTH
error =
I18n.t("themes.import_error.not_allowed_theme", { repo: remote[0..MAX_REMOTE_LENGTH] })
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 6af0f330a2d..0575fdb7b87 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -7552,7 +7552,7 @@ en:
import_web_tip: "Repository containing theme"
direct_install_tip: "Are you sure you want to install <strong>%{name}</strong> from the repository listed below?"
import_web_advanced: "Advanced…"
- import_file_tip: ".tar.gz, .zip, or .dcstyle.json file containing theme"
+ import_file_tip: ".tar.gz or .zip file containing theme"
is_private: "Theme is in a private git repository"
finish_install: "Finish Theme Installation"
last_attempt: "Installation process did not finish, last attempted:"
diff --git a/frontend/discourse/admin/components/modal/install-theme.gjs b/frontend/discourse/admin/components/modal/install-theme.gjs
index be24351d3e3..88925bf416e 100644
--- a/frontend/discourse/admin/components/modal/install-theme.gjs
+++ b/frontend/discourse/admin/components/modal/install-theme.gjs
@@ -376,7 +376,7 @@ export default class InstallThemeModal extends Component {
{{on "change" this.uploadLocaleFile}}
type="file"
id="file-input"
- accept=".dcstyle.json,application/json,.tar.gz,application/x-gzip,.zip,application/zip"
+ accept=".tar.gz,application/x-gzip,.zip,application/zip"
/>
<br />
<span class="description">
diff --git a/spec/fixtures/json/sam-s-simple-theme.dcstyle.json b/spec/fixtures/json/sam-s-simple-theme.dcstyle.json
deleted file mode 100644
index 103fae676f8..00000000000
--- a/spec/fixtures/json/sam-s-simple-theme.dcstyle.json
+++ /dev/null
@@ -1 +0,0 @@
-{"theme":{"id":2,"name":"Sam's Simple Theme","key":"6a390523-b662-4966-97d6-e731d292cd9d","created_at":"2017-05-08T06:17:14.510Z","updated_at":"2017-05-08T06:17:14.510Z","color_scheme":null,"color_scheme_id":null,"user_selectable":false,"remote_theme_id":1,"theme_fields":[{"name":"scss","target":"desktop","value":".topic-list \u003e tbody \u003e tr:nth-child(odd) {\n background-color: white;\n}\n\n\n.topic-list \u003e tbody tr:not(.last-visit):not(.topic-list-item-separator) td {\n border-bottom: 1px solid #eee;\n}\n\n.topic-list a.title:not(.badge-notification) {\n color: #3b5998;\n font-weight: normal;\n font-family: 'Helvetica Neue', Helvetica, Arial, Utkal, sans-serif;\n font-size: 18px;\n}\n\n.topic-list a.title:not(.badge-notification):hover {\n text-decoration: underline;\n}\n\n.topic-list .creator, .topic-list .editor {\n font-size: 13px;\n display: block;\n margin-top: 3px;\n}\n\n.topic-list .main-link {\n width: auto;\n}\n\n.topic-list {\n td, .creator a, .editor a {\n color: #888;\n }\n}\n\n.topic-list td {\n padding-bottom: 10px;\n}\n\n.topic-list th {\n color: black;\n background-color: #fafafa;\n}\n.topic-list {\n border-top: none;\n}\n\n.topic-list td:first-of-type {\n padding-bottom: 10px;\n padding-left: 10px;\n padding-top: 10px;\n}\n\n.topic-list tr.topic-list-item-separator td:first-of-type {\n padding: 0;\n}\n\n \n.topic-list {\n .fa-tag {\n opacity: 0.7;\n font-size: 10px;\n margin-right: -2px;\n }\n .num.posts-map {\n position: relative;\n font-size: 17px;\n a {\n color: #888 !important;\n font-weight: normal;\n }\n a.heatmap-high {\n color: #c66 !important; \n }\n width: 100px;\n }\n}\n\n.topic-list td.last-post, .topic-list th.activity {\n width: 160px;\n .relative-date {\n color: #666;\n }\n}\n\n.topic-list .creator .relative-date {\n margin-left: 8px;\n}\n\n.badge-category-bg {\n opacity: 0.8;\n}\n\n.topic-list .badge-wrapper.bar {\n .badge-category {\n color: #9a9a9a !important;\n font-weight: 600;\n font-size: 12px;\n padding: 2px 6px;\n }\n .badge-category-bg {\n top: -1px;\n }\n}\n\n.last-post {\n .poster-avatar {\n margin-right: 10px;\n }\n .poster-avatar, .poster-info {\n float: left;\n }\n}\n\n.topic-list .posts {\n width: auto;\n}\n\n/* topic page */\n#topic-progress {\n background-color: #f1f1f1;\n color: #666;\n font-weight: normal;\n .bg {\n background-color: #bee9e9;\n }\n}\n\nnav.post-controls button.has-like {\n color: #08c;\n}\n\n.title-wrapper .discourse-tag {\n border-radius: 5px !important;\n border: 0px solid #D0D0D0 !important;\n padding: 1px 6px !important;\n color: #1D1D1D !important;\n background-color: #F1F1F1 !important;\n}\n\n.badge-wrapper.bullet span.badge-category {\n color: #333 !important;\n}\n\n.creator .badge-wrapper.bullet span.badge-category {\n color: #888 !important;\n margin-top: -2px;\n}\n\nimg.avatar {\n border-radius: 3px;\n}\n\n#suggested-topics td.main-link {\n width: 500px;\n}\n\n.topic-list a.title.visited:not(.badge-notification) {\n color: #6644aa;\n}\n"},{"name":"header","target":"desktop","value":"\u003cscript type='text/x-handlebars' data-template-name='list/topic-list-item.raw'\u003e\n\n\u003ctd class='main-link clearfix'\u003e\n\n {{raw \"topic-status\" topic=topic}}\n {{topic-link topic}}\n {{#if controller.showTopicPostBadges}}\n {{raw \"topic-post-badges\" unreadPosts=topic.unread_posts unseen=topic.unseen url=topic.lastUnreadUrl}}\n {{/if}}\n\n\n {{raw \"list/topic-excerpt\" topic=model}}\n \u003cdiv class='creator'\u003e\n {{#if showCategory}}\n {{category-link topic.category}}\n {{/if}}\n {{~#if topic.creator ~}}\n \u003ca href=\"/users/{{topic.creator.username}}\" data-auto-route=\"true\" data-user-card=\"{{topic.creator.username}}\"\u003e{{topic.creator.username}}\u003c/a\u003e \u003ca href={{topic.url}}\u003e{{format-date topic.createdAt format=\"tiny\"}}\u003c/a\u003e\n {{~/if ~}}\n {{raw \"list/action-list\" topic=topic postNumbers=topic.liked_post_numbers className=\"likes\" icon=\"heart\"}}\n \u003c/div\u003e\n\u003c/td\u003e\n\n\n\n{{#if controller.showLikes}}\n\u003ctd class=\"num likes\"\u003e\n {{number topic.like_count}} \u003ci class='fa fa-heart'\u003e\u003c/i\u003e\n\u003c/td\u003e\n{{/if}}\n \n{{#if controller.showOpLikes}}\n\u003ctd class=\"num likes\"\u003e\n {{number topic.op_like_count}} \u003ci class='fa fa-heart'\u003e\u003c/i\u003e\n\u003c/td\u003e\n{{/if}}\n\n{{raw \"list/posts-count-column\" topic=topic}}\n\n\u003ctd class=\"last-post\"\u003e\n\u003cdiv class='poster-avatar'\u003e\n\u003ca href=\"{{topic.lastPostUr}}\" data-user-card=\"{{topic.last_poster_username}}\"\u003e{{avatar topic.lastPoster usernamePath=\"username\" imageSize=\"medium\"}}\u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv class='poster-info'\u003e\n\u003ca href=\"{{topic.lastPostUrl}}\"\u003e\n{{format-date topic.bumpedAt format=\"tiny\"}}\n\u003c/a\u003e\n\u003cspan class='editor'\u003e\u003ca href=\"/users/{{topic.last_poster_username}}\" data-auto-route=\"true\" data-user-card=\"{{topic.last_poster_username}}\"\u003e{{topic.last_poster_username}}\u003c/a\u003e\u003c/span\u003e\n\u003c/div\u003e\n\u003c/td\u003e\n\u003c/script\u003e\n\n\u003cscript type='text/x-handlebars' data-template-name='topic-list-header.raw'\u003e\n {{raw \"topic-list-header-column\" order='posts' name='topic.title'}}\n \n {{#if showLikes}}\n {{raw \"topic-list-header-column\" sortable='true' order='likes' number='true' forceName='Likes'}}\n {{/if}}\n {{#if showOpLikes}}\n {{raw \"topic-list-header-column\" sortable='true' order='op_likes' number='true' forceName='Likes'}}\n {{/if}}\n {{raw \"topic-list-header-column\" sortable='true' number='true' order='posts' forceName='Replies'}}\n {{raw \"topic-list-header-column\" sortable='true' order='activity' forceName='Last Post'}}\n\u003c/script\u003e\n\n\u003cscript\u003e\n\n(function(){\n\nvar TopicListItemView = require('discourse/components/topic-list-item').default;\n\n\nTopicListItemView.reopen({\n showCategory: function(){\n return !this.get('controller.hideCategory') \u0026\u0026\n this.get('topic.creator') \u0026\u0026\n this.get('topic.category.name') !== 'uncategorized';\n }.property()\n});\n \n})();\n \n\u003c/script\u003e\n"}],"child_themes":[],"remote_theme":{"id":1,"remote_url":"https://github.com/SamSaffron/discourse-simple-theme.git","remote_version":"49986016d76be1f526d5dc44704e6701021db900","local_version":"49986016d76be1f526d5dc44704e6701021db900","about_url":"https://meta.discourse.org/t/sams-personal-minimal-topic-list-design/23552","license_url":"https://github.com/SamSaffron/discourse-simple-theme/blob/master/LICENSE.txt","commits_behind":0,"remote_updated_at":"2017-05-08T06:17:14.487Z","updated_at":"2017-05-08T06:17:14.501Z"}}}
diff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rb
index 2e005dd0d91..efad8681d1b 100644
--- a/spec/requests/admin/themes_controller_spec.rb
+++ b/spec/requests/admin/themes_controller_spec.rb
@@ -166,13 +166,6 @@ RSpec.describe Admin::ThemesController do
end
describe "#import" do
- let(:theme_json_file) do
- Rack::Test::UploadedFile.new(
- file_from_fixtures("sam-s-simple-theme.dcstyle.json", "json"),
- "application/json",
- )
- end
-
let(:theme_archive) do
Rack::Test::UploadedFile.new(
file_from_fixtures("discourse-test-theme.zip", "themes"),
@@ -214,11 +207,6 @@ RSpec.describe Admin::ThemesController do
I18n.t("themes.import_error.not_allowed_theme", { repo: remote.strip }),
)
end
-
- it "bans json file import" do
- post "/admin/themes/import.json", params: { theme: theme_json_file }
- expect(response.status).to eq(403)
- end
end
it "can import a theme from Git" do
@@ -284,18 +272,6 @@ RSpec.describe Admin::ThemesController do
expect(response.status).to eq(201)
end
- it "imports a theme" do
- post "/admin/themes/import.json", params: { theme: theme_json_file }
- expect(response.status).to eq(201)
-
- json = response.parsed_body
-
- expect(json["theme"]["name"]).to eq("Sam's Simple Theme")
- expect(json["theme"]["theme_fields"].length).to eq(2)
- expect(json["theme"]["auto_update"]).to eq(false)
- expect(UserHistory.where(action: UserHistory.actions[:change_theme]).count).to eq(1)
- end
-
it "can fail if theme is not accessible" do
post "/admin/themes/import.json",
params: {
@@ -440,7 +416,7 @@ RSpec.describe Admin::ThemesController do
shared_examples "theme import not allowed" do
it "prevents theme import with a 404 response" do
- post "/admin/themes/import.json", params: { theme: theme_json_file }
+ post "/admin/themes/import.json", params: { theme: theme_archive }
expect(response.status).to eq(404)
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))