docbrown/app/controllers/reading_list_items_controller.rb
Sun-Li Beatteay 5bebf628df Update ReadingListItemsController#update to return NotAuthorized (#5658)
* change ReadingListItemsController#update to return NotAuthorized if user_id does not match

* fix spec description

Co-authored-by: rhymes <rhymesete@gmail.com>
2020-01-23 13:22:48 -05:00

33 lines
803 B
Ruby

class ReadingListItemsController < ApplicationController
def index
@reading_list_items_index = true
set_view
generate_algolia_search_key
end
def update
@reaction = Reaction.find(params[:id])
not_authorized if @reaction.user_id != session_current_user_id
@reaction.status = params[:current_status] == "archived" ? "valid" : "archived"
@reaction.save
head :ok
end
private
def generate_algolia_search_key
params = { filters: "viewable_by:#{session_current_user_id}" }
@secured_algolia_key = Algolia.generate_secured_api_key(
ApplicationConfig["ALGOLIASEARCH_SEARCH_ONLY_KEY"], params
)
end
def set_view
@view = if params[:view] == "archive"
"archived"
else
"valid"
end
end
end