Add authorization to CodeHarborLink controller

(leoselig/codeocean#2)
This commit is contained in:
leo.selig
2016-02-04 11:34:54 +01:00
parent ca9a9c7e85
commit e534a8cb2d
3 changed files with 26 additions and 25 deletions

View File

@ -1,70 +1,62 @@
class CodeHarborLinksController < ApplicationController class CodeHarborLinksController < ApplicationController
include CommonBehavior
before_action :set_code_harbor_link, only: [:show, :edit, :update, :destroy] before_action :set_code_harbor_link, only: [:show, :edit, :update, :destroy]
def authorize!
authorize(@code_harbor_link || @code_harbor_links)
end
private :authorize!
# GET /code_harbor_links # GET /code_harbor_links
# GET /code_harbor_links.json # GET /code_harbor_links.json
def index def index
@code_harbor_links = CodeHarborLink.all @code_harbor_links = CodeHarborLink.all
authorize!
end end
# GET /code_harbor_links/1 # GET /code_harbor_links/1
# GET /code_harbor_links/1.json # GET /code_harbor_links/1.json
def show def show
authorize!
end end
# GET /code_harbor_links/new # GET /code_harbor_links/new
def new def new
@code_harbor_link = CodeHarborLink.new @code_harbor_link = CodeHarborLink.new
authorize!
end end
# GET /code_harbor_links/1/edit # GET /code_harbor_links/1/edit
def edit def edit
authorize!
end end
# POST /code_harbor_links # POST /code_harbor_links
# POST /code_harbor_links.json # POST /code_harbor_links.json
def create def create
@code_harbor_link = CodeHarborLink.new(code_harbor_link_params) @code_harbor_link = CodeHarborLink.new(code_harbor_link_params)
authorize!
respond_to do |format| create_and_respond(object: @code_harbor_link)
if @code_harbor_link.save
format.html { redirect_to @code_harbor_link, notice: 'Code harbor link was successfully created.' }
format.json { render :show, status: :created, location: @code_harbor_link }
else
format.html { render :new }
format.json { render json: @code_harbor_link.errors, status: :unprocessable_entity }
end
end
end end
# PATCH/PUT /code_harbor_links/1 # PATCH/PUT /code_harbor_links/1
# PATCH/PUT /code_harbor_links/1.json # PATCH/PUT /code_harbor_links/1.json
def update def update
respond_to do |format| update_and_respond(object: @code_harbor_link, params: code_harbor_link_params)
if @code_harbor_link.update(code_harbor_link_params) authorize!
format.html { redirect_to @code_harbor_link, notice: 'Code harbor link was successfully updated.' }
format.json { render :show, status: :ok, location: @code_harbor_link }
else
format.html { render :edit }
format.json { render json: @code_harbor_link.errors, status: :unprocessable_entity }
end
end
end end
# DELETE /code_harbor_links/1 # DELETE /code_harbor_links/1
# DELETE /code_harbor_links/1.json # DELETE /code_harbor_links/1.json
def destroy def destroy
@code_harbor_link.destroy destroy_and_respond(object: @code_harbor_link)
respond_to do |format|
format.html { redirect_to code_harbor_links_url, notice: 'Code harbor link was successfully destroyed.' }
format.json { head :no_content }
end
end end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_code_harbor_link def set_code_harbor_link
@code_harbor_link = CodeHarborLink.find(params[:id]) @code_harbor_link = CodeHarborLink.find(params[:id])
authorize!
end end
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.

View File

@ -0,0 +1,3 @@
class CodeHarborLinkPolicy < AdminOnlyPolicy
end

View File

@ -11,11 +11,17 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150922125415) do ActiveRecord::Schema.define(version: 20160204094409) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
create_table "code_harbor_links", force: true do |t|
t.string "oauth2token"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "comments", force: true do |t| create_table "comments", force: true do |t|
t.integer "user_id" t.integer "user_id"
t.integer "file_id" t.integer "file_id"