diff --git a/app/controllers/blocks_controller.rb b/app/controllers/blocks_controller.rb deleted file mode 100644 index 7fafce011..000000000 --- a/app/controllers/blocks_controller.rb +++ /dev/null @@ -1,80 +0,0 @@ -class BlocksController < ApplicationController - before_action :set_block, only: %i[show edit update destroy] - - after_action :verify_authorized - - # GET /blocks - # GET /blocks.json - def index - authorize Block - @blocks = Block.order("index_position ASC") - end - - # GET /blocks/1 - # GET /blocks/1.json - def show - authorize @block - end - - # GET /blocks/new - def new - authorize Block - @block = Block.new - end - - # GET /blocks/1/edit - def edit - authorize @block - end - - # POST /blocks - # POST /blocks.json - def create - authorize Block - @block = Block.new(permitted_attributes(Block)) - @block.user_id = current_user.id - respond_to do |format| - if @block.save - format.html { redirect_to @block, notice: "Block was successfully created." } - format.json { render :show, status: :created, location: @block } - else - format.html { render :new } - format.json { render json: @block.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /blocks/1 - # PATCH/PUT /blocks/1.json - def update - authorize @block - respond_to do |format| - if @block.update(permitted_attributes(@block)) - @block.publish! if permitted_attributes(@block)[:publish_now] - format.html { redirect_to @block, notice: "Block was successfully updated." } - format.json { render :show, status: :ok, location: @block } - else - format.html { render :edit } - format.json { render json: @block.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /blocks/1 - # DELETE /blocks/1.json - def destroy - authorize @block - @block.destroy - respond_to do |format| - format.html { redirect_to blocks_url, notice: "Block was successfully destroyed." } - format.json { head :no_content } - end - end - - private - - # Use callbacks to share common setup or constraints between actions. - def set_block - @block = Block.find(params[:id]) - end -end diff --git a/app/models/block.rb b/app/models/block.rb deleted file mode 100644 index a0b005cfc..000000000 --- a/app/models/block.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Block < ApplicationRecord - attr_accessor :publish_now - - belongs_to :user - - validate :permissions - - before_save :process_html - before_save :process_javascript - before_save :process_css - - def publish! - self.published_html = processed_html - self.published_javascript = processed_javascript - self.published_css = processed_css - self.featured = true - save - end - - private - - def process_html - self.processed_html = input_html - end - - def process_javascript - self.processed_javascript = input_javascript - end - - def process_css - scoped_scss = ".block-wrapper-#{id} { #{input_css}}" - se = Sass::Engine.new(scoped_scss, syntax: :scss) - self.processed_css = se.render - end - - def permissions - return if user&.has_role?(:super_admin) - - errors.add(:commentable_id, "is not valid.") - end -end diff --git a/app/policies/block_policy.rb b/app/policies/block_policy.rb deleted file mode 100644 index d54196d5b..000000000 --- a/app/policies/block_policy.rb +++ /dev/null @@ -1,33 +0,0 @@ -class BlockPolicy < ApplicationPolicy - def index? - user_admin? - end - - def show? - user_admin? - end - - def new? - user_admin? - end - - def edit? - user_admin? - end - - def create? - user_admin? - end - - def update? - user_admin? - end - - def destroy? - user_admin? - end - - def permitted_attributes - %i[input_html input_css input_javascript featured index_position publish_now] - end -end diff --git a/app/views/blocks/_actions.html.erb b/app/views/blocks/_actions.html.erb deleted file mode 100644 index 6d22442d2..000000000 --- a/app/views/blocks/_actions.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -
- Featured: <%= block.featured %> | Position: <%= block.index_position %> - <% if block.processed_html != block.published_html || block.processed_css != block.published_css %> - <%= form_for(block) do |f| %> - <%= f.hidden_field :publish_now %>
- - <% end %> - <% end %> -
diff --git a/app/views/blocks/_form.html.erb b/app/views/blocks/_form.html.erb deleted file mode 100644 index 89eefe201..000000000 --- a/app/views/blocks/_form.html.erb +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - -
- <%= form_for(@block) do |f| %> - <% if @block.errors.any? %> -
-

<%= pluralize(@block.errors.count, "error") %> prohibited this block from being saved:

- - -
- <% end %> - - <%= f.label :input_css %>
- <%= f.text_area :input_css %>
- <%= f.label :input_javascript %>
- <%= f.text_area :input_javascript %>
- <%= f.label :input_html %>
- <%= f.text_area :input_html %>
- <%= f.label :featured %>
- <%= f.check_box :featured %>
- <%= f.label :index_position %>
- <%= f.text_field :index_position %>
-
- <%= f.submit %> -
- <% end %> -
diff --git a/app/views/blocks/edit.html.erb b/app/views/blocks/edit.html.erb deleted file mode 100644 index 16d31e3e3..000000000 --- a/app/views/blocks/edit.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -



-<%= render "form" %> diff --git a/app/views/blocks/index.html.erb b/app/views/blocks/index.html.erb deleted file mode 100644 index c7e838375..000000000 --- a/app/views/blocks/index.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
- -
- <% @blocks.each_with_index do |block, i| %> - <%= render "articles/block", block: block, show_published: false, i: i %> -
- <%= render "blocks/actions", block: block %> - <%= link_to "Edit", edit_block_path(block), style: "color:white;display:block;font-size:35px;background:rgb(0, 93, 190);padding:10px 0px;" %> -
- <% end %> -
-
- -<%= link_to "New Block", new_block_path %> diff --git a/app/views/blocks/index.json.jbuilder b/app/views/blocks/index.json.jbuilder deleted file mode 100644 index c1994acfd..000000000 --- a/app/views/blocks/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@blocks) do |block| - json.extract! block, :id - json.url block_url(block, format: :json) -end diff --git a/app/views/blocks/new.html.erb b/app/views/blocks/new.html.erb deleted file mode 100644 index 32787ed47..000000000 --- a/app/views/blocks/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New Block

- -<%= render "form" %> - -<%= link_to "Back", blocks_path %> diff --git a/app/views/blocks/show.html.erb b/app/views/blocks/show.html.erb deleted file mode 100644 index 8dc19ab42..000000000 --- a/app/views/blocks/show.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -
-
- <%= render "articles/block", block: @block, show_published: false, i: 0 %> -
- <%= render "blocks/actions", block: @block %> - <%= link_to "Edit", edit_block_path(@block), style: "color:white;display:block;font-size:35px;background:rgb(0, 93, 190);padding:10px 0px;" %> -
-

Go to Index

-
-
diff --git a/app/views/blocks/show.json.jbuilder b/app/views/blocks/show.json.jbuilder deleted file mode 100644 index abbd21591..000000000 --- a/app/views/blocks/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @block, :id, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index eb0b1c4a9..09534c6a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -203,7 +203,6 @@ Rails.application.routes.draw do end end resources :image_uploads, only: [:create] - resources :blocks resources :notifications, only: [:index] resources :tags, only: [:index] do collection do diff --git a/spec/models/block_spec.rb b/spec/models/block_spec.rb deleted file mode 100644 index 999b5a760..000000000 --- a/spec/models/block_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "rails_helper" - -RSpec.describe Block, type: :model do - let_it_be(:user) { create(:user) } - let_it_be(:block) { described_class.new(user: user, input_html: "hello") } - - it "creates processed_html after published!" do - user.add_role(:super_admin) - block.publish! - expect(block.processed_html).to eq("hello") - end - - it "is not valid without user" do - expect(described_class.new(user: nil)).not_to be_valid - end - - it "is not valid with non-admin user" do - expect(block).not_to be_valid - end -end diff --git a/spec/policies/block_policy_spec.rb b/spec/policies/block_policy_spec.rb deleted file mode 100644 index 3723efdf0..000000000 --- a/spec/policies/block_policy_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "rails_helper" - -RSpec.describe BlockPolicy, type: :policy do - subject { described_class.new(user, block) } - - let(:block) { build_stubbed(:block) } - - let(:valid_attributes) do - %i[input_html input_css input_javascript featured index_position publish_now] - end - - context "when not signed in" do - let(:user) { nil } - - it { within_block_is_expected.to raise_error(Pundit::NotAuthorizedError) } - end - - context "when signed in as a regular user" do - let(:user) { build_stubbed(:user) } - - it { is_expected.to forbid_actions(%i[index show new edit create update destroy]) } - end - - context "when user is signed in as a super admin" do - let(:user) { build(:user, :super_admin) } - - it { is_expected.to permit_actions(%i[index show new edit create update destroy]) } - it { is_expected.to permit_mass_assignment_of(valid_attributes) } - end -end diff --git a/spec/requests/blocks_spec.rb b/spec/requests/blocks_spec.rb deleted file mode 100644 index 109f05b8e..000000000 --- a/spec/requests/blocks_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require "rails_helper" - -RSpec.describe "Blocks", type: :request do - let(:user) { create(:user, :super_admin) } - - before { sign_in user } - - describe "GET blocks index" do - it "renders proper blocks index" do - create(:block, user_id: user.id, input_css: ".blue { color: blue;}") - get "/blocks" - expect(response.body).to include("color: blue") - end - end - - describe "POST blocks" do - it "creates block from input data" do - post "/blocks", params: { - block: { - input_css: ".blue { color: blue;}", - input_html: "yo", - input_javascript: "alert('hey')" - } - } - expect(Block.all.size).to eq(1) - end - end - - describe "PUT blocks" do - it "updates block from input data" do - block = create(:block, user_id: user.id, input_css: ".blue { color: blue;}") - put "/blocks/#{block.id}", params: { - block: { input_css: ".blue { color: red;}", - input_html: "yo", - input_javascript: "alert('hey')" } - } - expect(Block.last.processed_css).to include("color: red") - end - end - - describe "DELETE blocks" do - it "updates block from input data" do - block = create(:block, user_id: user.id, input_css: ".blue { color: blue;}") - delete "/blocks/#{block.id}" - expect(Block.all.size).to eq(0) - end - end -end