From 9578e475babcf831c140692c46c900a8d7895b05 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 26 Sep 2024 20:43:20 +0200 Subject: [PATCH] Remove frontend elements controller This is a very old feature that very likely nobody uses. --- .../alchemy/elements_controller.rb | 29 ------------ app/views/alchemy/elements/show.html.erb | 1 - app/views/alchemy/elements/show.js.erb | 1 - config/routes.rb | 1 - .../alchemy/elements_controller_spec.rb | 45 ------------------- 5 files changed, 77 deletions(-) delete mode 100644 app/controllers/alchemy/elements_controller.rb delete mode 100644 app/views/alchemy/elements/show.html.erb delete mode 100644 app/views/alchemy/elements/show.js.erb delete mode 100644 spec/controllers/alchemy/elements_controller_spec.rb diff --git a/app/controllers/alchemy/elements_controller.rb b/app/controllers/alchemy/elements_controller.rb deleted file mode 100644 index 3ce41ac391..0000000000 --- a/app/controllers/alchemy/elements_controller.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Alchemy - class ElementsController < Alchemy::BaseController - load_and_authorize_resource - layout false - - rescue_from CanCan::AccessDenied do - raise ActiveRecord::RecordNotFound - end - - # == Renders the element view partial - # - # === Accepted Formats - # - # * html - # * js (Tries to replace a given +container_id+ with the elements view partial content via jQuery.) - # - def show - @page = @element.page - @options = params[:options] - - respond_to do |format| - format.html - format.js { @container_id = params[:container_id] } - end - end - end -end diff --git a/app/views/alchemy/elements/show.html.erb b/app/views/alchemy/elements/show.html.erb deleted file mode 100644 index c7cf253423..0000000000 --- a/app/views/alchemy/elements/show.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render @element, :element => @element %> diff --git a/app/views/alchemy/elements/show.js.erb b/app/views/alchemy/elements/show.js.erb deleted file mode 100644 index 09926c1384..0000000000 --- a/app/views/alchemy/elements/show.js.erb +++ /dev/null @@ -1 +0,0 @@ -$('#<%= @container_id %>').html('<%= j render(@element, element: @element, options: @options) %>'); diff --git a/config/routes.rb b/config/routes.rb index 80a8c096b9..95096ba9b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -114,7 +114,6 @@ as: :show_attachment resources :messages, only: [:index, :new, :create] - resources :elements, only: :show namespace :api, defaults: {format: "json"} do resources :attachments, only: [:index] diff --git a/spec/controllers/alchemy/elements_controller_spec.rb b/spec/controllers/alchemy/elements_controller_spec.rb deleted file mode 100644 index 18663bf0a9..0000000000 --- a/spec/controllers/alchemy/elements_controller_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -module Alchemy - describe ElementsController do - routes { Alchemy::Engine.routes } - - let(:public_page) { create(:alchemy_page, :public) } - let(:element) { create(:alchemy_element, page: public_page, name: "download") } - let(:restricted_page) { create(:alchemy_page, :public, restricted: true) } - let(:restricted_element) { create(:alchemy_element, page: restricted_page, name: "download") } - - describe "#show" do - it "should render available elements" do - get :show, params: {id: element.id} - expect(response.status).to eq(200) - end - - it "should raise ActiveRecord::RecordNotFound error for unpublished elements" do - element.update_columns(public: false) - expect { - get :show, params: {id: element.id} - }.to raise_error(ActiveRecord::RecordNotFound) - end - - context "for guest user" do - it "should raise ActiveRecord::RecordNotFound error for elements of restricted pages" do - expect { - get :show, params: {id: restricted_element.id} - }.to raise_error(ActiveRecord::RecordNotFound) - end - end - - context "for member user" do - before { authorize_user(build(:alchemy_dummy_user)) } - - it "should render elements of restricted pages" do - get :show, params: {id: restricted_element.id} - expect(response.status).to eq(200) - end - end - end - end -end