docbrown/app/controllers/blocks_controller.rb
Edem Attikese 0ad8cd9eab Edem/improvements/pundit coverage (#498)
* added organization policy + spec

* user specs for is_org_admin?

* added authroize to organization controller

* admin policy + specs

* deleted enforce admin due to pundit policy redundancy

* applied admin policy to entire admin namespace

* refactoring analytics controller WIP - wanna test codeship

* Add protection against reactions to unpublished articles (#473)

* Add chat channel policy and spec (#474)

* Add comment policy and specs (#475)

* Fix edge case with apostrophes

* Add comment policy and specs

* Add login for deleting comment spec

* Change test to raise pundit error instead of 404

* Clean up comment destroy request specs

* Remove redundant raise

* Whitelist columns on to_json call (#477)

* Add pundit policy for several controllers (#476)

* Add pundit policy for several controllers

* Adjust video spec

* Fix tag request specs

* Add proper twilio tokens request specs

* Remove puts statements

* Add a couple basic request specs (#478)

* Add a few tests and fix user tag color bug (#482)

* Refactor handle_tag_index in stories_controller (#481)

* Modify valid_request_origin? (#483)

* Add misc specs and remove banned attribute from user model (#484)

*  Fix missing Cloudinary tags and misc specs (#486)

* removing current_user_is_admin? to use .is_admin? method

* added missing org policy routes

* Add comment for all public controllers

* Fix edge case for test

* Authorize mod controller and add specs

* Refactor methods via inheritance and use only super_admin role

* Create policy method for analytics via article_policy and refactor

* Capitalize all buttons in dashboard page

* Fix org tests and remove old admin test

* Use only happy path for analytics

* Fix tests to use Pundit error

* Update org_policy spec
2018-06-28 09:38:20 -04:00

84 lines
2 KiB
Ruby

class BlocksController < ApplicationController
before_action :set_block, only: [: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))
if permitted_attributes(@block)[:publish_now]
@block.publish!
end
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