-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalma_item_set_controller.rb
More file actions
46 lines (34 loc) · 1.17 KB
/
alma_item_set_controller.rb
File metadata and controls
46 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'date'
class AlmaItemSetController < ApplicationController
VALID_ENVS = %w[production sandbox].freeze
# TODO: - Need to make sure only certain staff access this page
before_action :authorize!
def index
# Lookup of all sets for drop-boxes:
@production_sets = Alma::ItemSet.fetch_set_array 'production'
@sandbox_sets = Alma::ItemSet.fetch_set_array 'sandbox'
end
# rubocop:disable Metrics/AbcSize
def update
env = params[:alma_env]
return head(:bad_request) unless env.in? VALID_ENVS
alma_set_id = params[:"alma_set_id_#{env}"]
num = params[:note_num]
note = new_note(params[:note_value], params[:initials])
Alma::ItemSet.prepend_note_to_set(env, alma_set_id, note, num, current_user.email)
respond_to do |format|
format.js { render json: current_user.email }
end
end
# rubocop:enable Metrics/AbcSize
private
def authorize!
return if Rails.env.development?
authenticate!
# raise Error::ForbiddenError unless current_user.framework_admin
raise Error::ForbiddenError unless current_user.alma_admin
end
def new_note(text, initials)
"#{Time.zone.today} - #{text} - #{initials}"
end
end