-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_borrower_forms_controller.rb
More file actions
75 lines (61 loc) · 2.43 KB
/
Copy pathproxy_borrower_forms_controller.rb
File metadata and controls
75 lines (61 loc) · 2.43 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'time'
# class ProxyBorrowerFormsController < ApplicationController
class ProxyBorrowerFormsController < AuthenticatedFormController
before_action :set_current_user, only: %i[dsp_form faculty_form process_dsp_request process_faculty_request]
# Simple page where you can select which form you wish to access
def index
# I think I want to get the users role now... if they're in the DB
# then I'll want to pass that info so they have the
# admin link...otherwise, NO admin link!
@user_is_admin = current_user.any_role?(Role.proxyborrow_admin, :framework_admin)
end
def dsp_form
# wisks us away to Disabled Student Program Form (views/proxy_borrower_forms/dsp_form)
@form = ProxyBorrowerRequests.new(student_name: @current_user.display_name)
end
def faculty_form
# wisks us away to Faculty Form
render :forbidden, status: :forbidden and return unless current_user.ucb_faculty?
@form = ProxyBorrowerRequests.new(faculty_name: @current_user.display_name,
department: @current_user.department_number)
end
# Processes a request from DSP form: (eventually dry this up)
def process_dsp_request
@form = ProxyBorrowerRequests.new form_params(:student_name, :dsp_rep)
@form.student_dsp = current_user.ucpath_id
@form.user_email = current_user.email
if @form.save
# Sends an email to the user with instructions:
@form.submit!
render 'result', status: :created
else
render 'dsp_form', status: :unprocessable_content
end
end
# Processes a request from faculty form:
def process_faculty_request
@form = ProxyBorrowerRequests.new form_params(:faculty_name, :department)
@form.faculty_id = current_user.ucpath_id
@form.user_email = current_user.email
if @form.save
# Sends an email to the user with instructions:
@form.submit!
render 'result', status: :created
else
# Failed to save - rerender the faculty form:
render 'faculty_form', status: :unprocessable_content
end
end
def result
# Hunkydory, we saved a request to the DB, let's let the user know!
end
private
def init_form!; end
def set_current_user
@current_user = current_user
end
def form_params(*extra)
params.require(:proxy_borrower_requests).permit(:research_last, :research_first, :research_middle,
:date_term, :renewal, *extra)
end
end