manages permissions for debate editing

This commit is contained in:
Juanjo Bazán
2015-07-19 14:47:14 +02:00
parent df1a800d94
commit 2a63d1f953
3 changed files with 40 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
class DebatesController < ApplicationController
before_action :set_debate, only: [:show, :edit, :update]
before_action :authenticate_user!, only: [:new, :create]
before_action :authenticate_user!, except: [:show, :index]
before_action :validate_ownership, only: [:edit, :update]
def index
if params[:tag]
@debates = Debate.tagged_with(params[:tag])
@@ -42,4 +43,8 @@ class DebatesController < ApplicationController
params.require(:debate).permit(:title, :description, :tag_list, :terms_of_service)
end
def validate_ownership
raise ActiveRecord::RecordNotFound unless @debate.editable_by?(current_user)
end
end