Skip to content

Commit

Permalink
the mods#approve and mods#hide actions now use the mod builder so pro…
Browse files Browse the repository at this point in the history
…per callbacks can be triggered
  • Loading branch information
matortheeternal committed Nov 29, 2016
1 parent bf5019a commit fd89131
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions mod-picker/app/controllers/mods_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def update

# POST /mods/1/hide
def hide
authorize! :hide, @mod
@mod.hidden = params[:hidden]
if @mod.save
authorize! :hide, @mod, :message => "You are not allowed to hide/unhide this mod."
builder = ModBuilder.new(current_user, hide_params)
if builder.update
render json: {status: :ok}
else
render json: @mod.errors, status: :unprocessable_entity
Expand All @@ -106,9 +106,9 @@ def hide

# POST /mods/1/approve
def approve
authorize! :approve, @mod
@mod.approved = params[:approved]
if @mod.save
authorize! :approve, @mod, :message => "You are not allowed to approve/unapprove this mod."
builder = ModBuilder.new(current_user, approve_params)
if builder.update
render json: {status: :ok}
else
render json: @mod.errors, status: :unprocessable_entity
Expand Down Expand Up @@ -358,6 +358,20 @@ def sorting_params
params.fetch(:sort, {}).permit(:column, :direction)
end

def approve_params
{
id: params[:id],
approved: params[:approved]
}
end

def hide_params
{
id: params[:id],
hidden: params[:hidden]
}
end

# Params we allow filtering on
def filtering_params
# construct valid filters array
Expand Down

0 comments on commit fd89131

Please sign in to comment.