3
3
class Sessions ::EditController < ApplicationController
4
4
before_action :set_session
5
5
6
- def edit_programmes
6
+ before_action :authorize_session_edit ,
7
+ except : %i[
8
+ update_programmes
9
+ update_send_consent_requests_at
10
+ update_send_invitations_at
11
+ update_weeks_before_consent_reminders
12
+ update_register_attendance
13
+ update_delegation
14
+ ]
15
+ before_action :authorize_session_update ,
16
+ only : %i[
17
+ update_programmes
18
+ update_send_consent_requests_at
19
+ update_send_invitations_at
20
+ update_weeks_before_consent_reminders
21
+ update_register_attendance
22
+ update_delegation
23
+ ]
24
+
25
+ def show
26
+ end
27
+
28
+ def programmes
7
29
@form =
8
30
SessionProgrammesForm . new (
9
31
session : @session ,
10
32
programme_ids : @session . programme_ids
11
33
)
12
-
13
- render :programmes
14
34
end
15
35
16
36
def update_programmes
17
37
@form = SessionProgrammesForm . new ( session : @session , **programmes_params )
18
38
19
39
if @form . save
20
- redirect_to edit_session_path ( @session )
40
+ redirect_to session_edit_path ( @session )
21
41
else
22
42
render :programmes , status : :unprocessable_content
23
43
end
24
44
end
25
45
26
- def edit_send_consent_requests_at
27
- render :send_consent_requests_at
46
+ def send_consent_requests_at
28
47
end
29
48
30
49
def update_send_consent_requests_at
@@ -35,12 +54,11 @@ def update_send_consent_requests_at
35
54
elsif !@session . update ( send_consent_requests_at_params )
36
55
render :send_consent_requests_at , status : :unprocessable_content
37
56
else
38
- redirect_to edit_session_path ( @session )
57
+ redirect_to session_edit_path ( @session )
39
58
end
40
59
end
41
60
42
- def edit_send_invitations_at
43
- render :send_invitations_at
61
+ def send_invitations_at
44
62
end
45
63
46
64
def update_send_invitations_at
@@ -51,26 +69,55 @@ def update_send_invitations_at
51
69
elsif !@session . update ( send_invitations_at_params )
52
70
render :send_invitations_at , status : :unprocessable_content
53
71
else
54
- redirect_to edit_session_path ( @session )
72
+ redirect_to session_edit_path ( @session )
55
73
end
56
74
end
57
75
58
- def edit_weeks_before_consent_reminders
59
- render :weeks_before_consent_reminders
76
+ def weeks_before_consent_reminders
60
77
end
61
78
62
79
def update_weeks_before_consent_reminders
63
80
if @session . update ( weeks_before_consent_reminders_params )
64
- redirect_to edit_session_path ( @session )
81
+ redirect_to session_edit_path ( @session )
65
82
else
66
83
render :weeks_before_consent_reminders , status : :unprocessable_content
67
84
end
68
85
end
69
86
87
+ def register_attendance
88
+ end
89
+
90
+ def update_register_attendance
91
+ if @session . update ( register_attendance_params )
92
+ redirect_to session_edit_path ( @session )
93
+ else
94
+ render :register_attendance , status : :unprocessable_content
95
+ end
96
+ end
97
+
98
+ def delegation
99
+ end
100
+
101
+ def update_delegation
102
+ if @session . update ( delegation_params )
103
+ redirect_to session_edit_path ( @session )
104
+ else
105
+ render :delegation , status : :unprocessable_content
106
+ end
107
+ end
108
+
70
109
private
71
110
72
111
def set_session
73
- @session = policy_scope ( Session ) . find_by! ( slug : params [ :slug ] )
112
+ @session = policy_scope ( Session ) . find_by! ( slug : params [ :session_slug ] )
113
+ end
114
+
115
+ def authorize_session_edit
116
+ authorize @session , :edit?
117
+ end
118
+
119
+ def authorize_session_update
120
+ authorize @session , :update?
74
121
end
75
122
76
123
def programmes_params
@@ -106,4 +153,12 @@ def send_invitations_at_params
106
153
def weeks_before_consent_reminders_params
107
154
params . expect ( session : :weeks_before_consent_reminders )
108
155
end
156
+
157
+ def register_attendance_params
158
+ params . expect ( session : :requires_registration )
159
+ end
160
+
161
+ def delegation_params
162
+ params . expect ( session : %i[ psd_enabled national_protocol_enabled ] )
163
+ end
109
164
end
0 commit comments