bible270 1.16.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +60 -32
- data/README.md +129 -58
- data/Rakefile +3 -2
- data/app/controllers/bible270/admin_controller.rb +152 -33
- data/app/controllers/bible270/admin_roles_controller.rb +50 -0
- data/app/controllers/bible270/admin_scripture_frames_controller.rb +89 -0
- data/app/controllers/bible270/application_controller.rb +18 -2
- data/app/controllers/bible270/checkoffs_controller.rb +38 -9
- data/app/controllers/bible270/readers_controller.rb +1 -1
- data/app/controllers/bible270/scripture_frames_controller.rb +16 -0
- data/app/helpers/bible270/plan_helper.rb +4 -4
- data/app/mailers/bible270/notice_mailer.rb +2 -2
- data/app/models/bible270/checkoff.rb +69 -3
- data/app/models/bible270/participation.rb +71 -0
- data/app/models/bible270/plan_run.rb +121 -0
- data/app/models/bible270/reader.rb +142 -24
- data/app/models/bible270/scripture_frame.rb +48 -0
- data/app/models/bible270/setting.rb +13 -4
- data/app/views/bible270/admin/_reader_list.html.erb +55 -0
- data/app/views/bible270/admin/_scripture_frames.html.erb +34 -0
- data/app/views/bible270/admin/_scripture_text.html.erb +11 -0
- data/app/views/bible270/admin/index.html.erb +64 -49
- data/app/views/bible270/admin/show.html.erb +117 -54
- data/app/views/bible270/admin_scripture_frames/_form.html.erb +72 -0
- data/app/views/bible270/admin_scripture_frames/edit.html.erb +4 -0
- data/app/views/bible270/admin_scripture_frames/new.html.erb +4 -0
- data/app/views/bible270/days/_day_progress.html.erb +2 -2
- data/app/views/bible270/days/_reading.html.erb +5 -4
- data/app/views/bible270/profiles/edit.html.erb +14 -12
- data/app/views/bible270/readers/show.html.erb +1 -1
- data/app/views/bible270/shared/_admin_confirmations.html.erb +16 -0
- data/app/views/bible270/shared/_admin_reader_list_ui.html.erb +49 -0
- data/app/views/bible270/shared/_day_completion.html.erb +13 -0
- data/app/views/bible270/shared/_day_completion_ui.html.erb +152 -0
- data/app/views/bible270/shared/_day_index.html.erb +2 -1
- data/app/views/bible270/shared/_header.html.erb +12 -4
- data/app/views/bible270/shared/_interaction_ui.html.erb +2 -62
- data/app/views/bible270/shared/_scripture_frame.html.erb +14 -0
- data/app/views/bible270/shared/_scripture_frame_ui.html.erb +247 -0
- data/app/views/bible270/shared/_scripture_library_ui.html.erb +34 -0
- data/app/views/bible270/shared/_styles.html.erb +141 -10
- data/app/views/layouts/bible270/application.html.erb +8 -0
- data/config/routes.rb +9 -2
- data/config/scripture_frames.yml +134 -0
- data/db/migrate/20260101000024_create_bible270_plan_runs.rb +60 -0
- data/db/migrate/20260101000025_add_admin_to_bible270_readers.rb +7 -0
- data/db/migrate/20260101000026_add_revert_to_bible270_plan_runs.rb +8 -0
- data/db/migrate/20260101000027_create_bible270_scripture_frames.rb +16 -0
- data/lib/bible270/configuration.rb +17 -4
- data/lib/bible270/migration_reconciler.rb +91 -8
- data/lib/bible270/reader_consistency.rb +8 -4
- data/lib/bible270/reader_progress_report.rb +2 -1
- data/lib/bible270/scripture_frames.rb +226 -0
- data/lib/bible270/version.rb +1 -1
- data/lib/bible270.rb +1 -0
- data/lib/generators/bible270/install/templates/bible270.rb.tt +8 -1
- metadata +26 -1
|
@@ -4,9 +4,8 @@ module Bible270
|
|
|
4
4
|
# Small administrative panel: remove readers, adjust their completions, and
|
|
5
5
|
# move them to a given day of the plan.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
# so its existence isn't advertised.
|
|
7
|
+
# Configured site-admins and UI-appointed admins share panel access.
|
|
8
|
+
# Unauthorized requests 404 so its existence is not advertised.
|
|
10
9
|
class AdminController < ApplicationController
|
|
11
10
|
LAST_BROADCAST_AT = 'last_broadcast_at'
|
|
12
11
|
LAST_BROADCAST_SUBJECT = 'last_broadcast_subject'
|
|
@@ -25,26 +24,82 @@ module Bible270
|
|
|
25
24
|
before_action :require_admin_view!, except: %i[index update_view]
|
|
26
25
|
before_action :load_reader,
|
|
27
26
|
only: %i[show destroy update_start update_profile update_theme update_notifications update_completion_animation
|
|
28
|
-
remove_avatar complete_through toggle_day]
|
|
27
|
+
remove_avatar complete_through toggle_day update_participation]
|
|
28
|
+
before_action :require_active_reader!, only: %i[update_start complete_through toggle_day]
|
|
29
|
+
rescue_from Participation::ArchivedProgress, with: :archived_progress
|
|
30
|
+
rescue_from PlanRun::StaleRun, with: :stale_run
|
|
29
31
|
before_action :load_comment, only: %i[hide_comment unhide_comment destroy_comment]
|
|
30
32
|
|
|
31
33
|
# ---- enrolment --------------------------------------------------------
|
|
32
34
|
|
|
33
35
|
def update_enrollment
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
run = PlanRun.current
|
|
37
|
+
run.with_lock do
|
|
38
|
+
raise PlanRun::StaleRun unless run.current?
|
|
39
|
+
|
|
40
|
+
case params[:state]
|
|
41
|
+
when 'closed'
|
|
42
|
+
Setting.close_enrollment!
|
|
43
|
+
redirect_to admin_path, notice: 'Closed to new readers. Existing readers can still sign in.'
|
|
44
|
+
when 'open'
|
|
45
|
+
Setting.open_enrollment!
|
|
46
|
+
redirect_to admin_path, notice: 'Open to new readers.'
|
|
47
|
+
else
|
|
48
|
+
redirect_to admin_path, alert: 'Choose whether enrollment is open or closed. Nothing was changed.'
|
|
49
|
+
end
|
|
43
50
|
end
|
|
44
51
|
end
|
|
45
52
|
|
|
53
|
+
def restart
|
|
54
|
+
unless params[:confirm_restart] == '1'
|
|
55
|
+
return redirect_to admin_path, alert: 'Confirm starting a new run: admins start fresh and other readers become alumni. Nothing was changed.'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
PlanRun.restart!(start_date: params[:start_date], expected_run_id: params[:expected_run_id])
|
|
59
|
+
redirect_to admin_path,
|
|
60
|
+
notice: 'Started a new run and opened enrollment. Admins and Site-admins are active with zero progress and no personal start date; other readers are alumni. Past progress, reflections and admin roles are preserved.'
|
|
61
|
+
rescue PlanRun::InvalidStartDate
|
|
62
|
+
redirect_to admin_path, alert: 'Choose a valid start date. Nothing was changed.'
|
|
63
|
+
rescue PlanRun::StaleRun
|
|
64
|
+
redirect_to admin_path, alert: 'The current run changed. Reload this page before starting a new run. Nothing was changed.'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def revert
|
|
68
|
+
unless params[:confirm_revert] == '1'
|
|
69
|
+
return redirect_to admin_path, alert: 'Confirm that you want to restore the previous run. Nothing was changed.'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
PlanRun.revert!(expected_run_id: params[:expected_run_id])
|
|
73
|
+
redirect_to admin_path,
|
|
74
|
+
notice: 'Previous run restored with saved reader statuses, calendars and enrollment settings for everyone, including admins. Both runs’ progress, reflections and roles are preserved.'
|
|
75
|
+
rescue PlanRun::CannotRevert
|
|
76
|
+
redirect_to admin_path, alert: 'There is no saved restart to revert. Nothing was changed.'
|
|
77
|
+
rescue PlanRun::StaleRun
|
|
78
|
+
redirect_to admin_path, alert: 'The current run changed. Reload this page before reverting. Nothing was changed.'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def update_participation
|
|
82
|
+
unless %w[active alumni].include?(params[:status])
|
|
83
|
+
return redirect_to participation_return_path, alert: 'Choose Active or Alumni. Nothing was changed.'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
run = PlanRun.current
|
|
87
|
+
run.with_lock do
|
|
88
|
+
unless run.current? && run.id.to_s == params[:expected_run_id].to_s
|
|
89
|
+
raise PlanRun::StaleRun
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
@reader.reload
|
|
93
|
+
params[:status] == 'active' ? @reader.activate! : @reader.archive!
|
|
94
|
+
end
|
|
95
|
+
notice = params[:status] == 'active' ? 'Reader is active in the current run.' : 'Reader marked as alumni. Progress and history are preserved.'
|
|
96
|
+
redirect_to participation_return_path, notice: notice
|
|
97
|
+
rescue PlanRun::StaleRun
|
|
98
|
+
redirect_to participation_return_path, alert: 'The current run changed. Reload this page before changing membership. Nothing was changed.'
|
|
99
|
+
end
|
|
100
|
+
|
|
46
101
|
def update_run_start
|
|
47
|
-
if Setting.set_run_start_date!(params[:start_date])
|
|
102
|
+
if with_current_run { Setting.set_run_start_date!(params[:start_date]) }
|
|
48
103
|
date = Setting.run_start_date
|
|
49
104
|
redirect_to admin_path, notice: "Current run start date changed to #{date.strftime('%B %-d, %Y')}."
|
|
50
105
|
else
|
|
@@ -53,8 +108,10 @@ module Bible270
|
|
|
53
108
|
end
|
|
54
109
|
|
|
55
110
|
def reset_run_start
|
|
56
|
-
|
|
57
|
-
|
|
111
|
+
date = with_current_run do
|
|
112
|
+
Setting.clear_run_start_date!
|
|
113
|
+
Setting.run_start_date
|
|
114
|
+
end
|
|
58
115
|
notice = if date
|
|
59
116
|
"Current run now uses the configured start date, #{date.strftime('%B %-d, %Y')}."
|
|
60
117
|
else
|
|
@@ -80,12 +137,16 @@ module Bible270
|
|
|
80
137
|
def index
|
|
81
138
|
return render :reader_view if b270_reader_view?
|
|
82
139
|
|
|
140
|
+
@active_readers_session_key = session[:b270_active_readers_session_key] ||= SecureRandom.hex(16)
|
|
83
141
|
@enrollment_closed = Setting.enrollment_closed?
|
|
84
142
|
@enrollment_closed_at = Setting.enrollment_closed_at
|
|
85
143
|
@days_completed = Reader.completed_days_by_id
|
|
86
144
|
@reader_sort_options = READER_SORT_OPTIONS
|
|
87
145
|
@reader_sort = READER_SORT_OPTIONS.key?(params[:sort]) ? params[:sort] : 'first_name'
|
|
88
|
-
|
|
146
|
+
@current_run = PlanRun.current
|
|
147
|
+
|
|
148
|
+
@alumni_count = Reader.alumni.count
|
|
149
|
+
readers = Reader.active.with_avatar.load
|
|
89
150
|
@recent_reader_activities = Checkoff.recent_activity_by_reader(readers.map(&:id))
|
|
90
151
|
@reader_report = ReaderProgressReport.new(
|
|
91
152
|
readers: readers,
|
|
@@ -94,6 +155,16 @@ module Bible270
|
|
|
94
155
|
sort: @reader_sort
|
|
95
156
|
)
|
|
96
157
|
@readers = @reader_report.sorted_readers
|
|
158
|
+
@alumni = Reader.alumni.with_avatar.to_a
|
|
159
|
+
@alumni_activities = {}
|
|
160
|
+
if @alumni.any?
|
|
161
|
+
@alumni_activities = Checkoff.recent_activity_by_reader(@alumni.map(&:id))
|
|
162
|
+
@alumni_report = ReaderProgressReport.new(
|
|
163
|
+
readers: @alumni, completed_days: @days_completed,
|
|
164
|
+
recent_activities: @alumni_activities, sort: @reader_sort
|
|
165
|
+
)
|
|
166
|
+
@alumni = @alumni_report.sorted_readers
|
|
167
|
+
end
|
|
97
168
|
@run_start_date = Setting.run_start_date
|
|
98
169
|
@configured_start_date = Bible270.config.start_date
|
|
99
170
|
@run_start_date_overridden = Setting.run_start_date_overridden?
|
|
@@ -106,12 +177,23 @@ module Bible270
|
|
|
106
177
|
end
|
|
107
178
|
reachable_readers = @readers.select { |reader| reader.email.present? }
|
|
108
179
|
@reachable = reachable_readers.size
|
|
109
|
-
@reachable_admins =
|
|
180
|
+
@reachable_admins = broadcast_recipients('admins').count
|
|
110
181
|
@last_broadcast_at = parsed_time(Setting.read(LAST_BROADCAST_AT))
|
|
111
182
|
@last_broadcast_subject = Setting.read(LAST_BROADCAST_SUBJECT)
|
|
183
|
+
@scripture_frame_defaults = ScriptureFrames.defaults
|
|
184
|
+
@scripture_frame_default_settings_available = ScriptureFrames.default_settings_available?
|
|
185
|
+
@disabled_default_scripture_frame_ids = ScriptureFrames.disabled_default_ids
|
|
186
|
+
@scripture_frame_storage = ScriptureFrames.custom_available?
|
|
187
|
+
@custom_scripture_frames = @scripture_frame_storage ? ScriptureFrames.in_biblical_order(ScriptureFrame.order(:id).to_a) : []
|
|
112
188
|
end
|
|
113
189
|
|
|
114
190
|
def show
|
|
191
|
+
@current_run = PlanRun.current
|
|
192
|
+
@past_participations = @reader.participations.where(active: false).includes(:plan_run).order(plan_run_id: :desc).load
|
|
193
|
+
@history_completed_days = Hash.new(0)
|
|
194
|
+
Checkoff.where(participation_id: @past_participations.map(&:id)).group(:participation_id, :day).count.each do |(participation_id, day), count|
|
|
195
|
+
@history_completed_days[participation_id] += 1 if count >= Plan.total_parts(day)
|
|
196
|
+
end
|
|
115
197
|
@comment_notifications_available = comment_notifications_available_for?(@reader)
|
|
116
198
|
@completion_dove_preference_available = completion_dove_available_for(@reader)
|
|
117
199
|
@days_completed = @reader.days_completed
|
|
@@ -149,8 +231,23 @@ module Bible270
|
|
|
149
231
|
|
|
150
232
|
def destroy
|
|
151
233
|
name = @reader.display_name
|
|
152
|
-
|
|
153
|
-
|
|
234
|
+
denial = nil
|
|
235
|
+
# Role changes use the same row lock, so deletion cannot authorize against
|
|
236
|
+
# a stale role while a site-admin promotes this reader.
|
|
237
|
+
@reader.with_lock do
|
|
238
|
+
if Bible270.config.site_admin?(@reader)
|
|
239
|
+
denial = 'Configured site-admins cannot be removed here. Their privileges are controlled by configuration.'
|
|
240
|
+
elsif Bible270.config.admin?(@reader) && !b270_site_admin?
|
|
241
|
+
denial = 'Only a site-admin may remove an admin.'
|
|
242
|
+
else
|
|
243
|
+
@reader.destroy!
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
if denial
|
|
247
|
+
redirect_to admin_reader_path(@reader), alert: denial
|
|
248
|
+
else
|
|
249
|
+
redirect_to admin_path, notice: "Removed #{name} and all their check-offs and reflections."
|
|
250
|
+
end
|
|
154
251
|
end
|
|
155
252
|
|
|
156
253
|
# Put the reader on a given day as of today, or set an explicit start date.
|
|
@@ -350,7 +447,7 @@ module Bible270
|
|
|
350
447
|
|
|
351
448
|
def broadcast_recipients(audience)
|
|
352
449
|
recipients = Reader.where.not(email: [nil, '']).order(:id)
|
|
353
|
-
return recipients if audience == 'everyone'
|
|
450
|
+
return recipients.active if audience == 'everyone'
|
|
354
451
|
|
|
355
452
|
admin_ids = recipients.select { |reader| Bible270.config.admin?(reader) }.map(&:id)
|
|
356
453
|
recipients.where(id: admin_ids)
|
|
@@ -373,6 +470,40 @@ module Bible270
|
|
|
373
470
|
|
|
374
471
|
private
|
|
375
472
|
|
|
473
|
+
def participation_return_path
|
|
474
|
+
return admin_reader_path(@reader) unless params[:return_to] == 'admin'
|
|
475
|
+
|
|
476
|
+
sort = READER_SORT_OPTIONS.key?(params[:sort]) ? params[:sort] : 'first_name'
|
|
477
|
+
admin_path(sort: sort)
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
def require_active_reader!
|
|
481
|
+
return archived_progress if @reader.alumni?
|
|
482
|
+
|
|
483
|
+
return unless params.key?(:participation_id) && params[:participation_id].to_s != @reader.participation.id.to_s
|
|
484
|
+
|
|
485
|
+
stale_run
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
def with_current_run
|
|
489
|
+
run = PlanRun.current
|
|
490
|
+
run.with_lock do
|
|
491
|
+
unless run.current? && (!params.key?(:expected_run_id) || params[:expected_run_id].to_s == run.id.to_s)
|
|
492
|
+
raise PlanRun::StaleRun
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
yield
|
|
496
|
+
end
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
def stale_run
|
|
500
|
+
redirect_to admin_path, alert: 'The current run changed. Reload this page before making changes. Nothing was changed.'
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
def archived_progress
|
|
504
|
+
redirect_to admin_reader_path(@reader), alert: 'Alumni progress is read-only. Reactivate this reader in the current run before changing progress.'
|
|
505
|
+
end
|
|
506
|
+
|
|
376
507
|
def render_theme_error(message)
|
|
377
508
|
respond_to do |format|
|
|
378
509
|
format.json { render json: { error: message }, status: :unprocessable_entity }
|
|
@@ -393,18 +524,6 @@ module Bible270
|
|
|
393
524
|
available
|
|
394
525
|
end
|
|
395
526
|
|
|
396
|
-
def require_admin!
|
|
397
|
-
return if b270_admin?
|
|
398
|
-
|
|
399
|
-
raise ActionController::RoutingError, 'Not Found'
|
|
400
|
-
end
|
|
401
|
-
|
|
402
|
-
def require_admin_view!
|
|
403
|
-
return if b270_admin_view?
|
|
404
|
-
|
|
405
|
-
raise ActionController::RoutingError, 'Not Found'
|
|
406
|
-
end
|
|
407
|
-
|
|
408
527
|
def load_comment
|
|
409
528
|
@comment = Comment.find_by(id: params[:id])
|
|
410
529
|
return if @comment
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bible270
|
|
4
|
+
class AdminRolesController < ApplicationController
|
|
5
|
+
before_action :require_site_admin!
|
|
6
|
+
|
|
7
|
+
protect_from_forgery with: :exception
|
|
8
|
+
self.forgery_protection_origin_check = true
|
|
9
|
+
rescue_from ActionController::InvalidAuthenticityToken, with: :hide_role_endpoint
|
|
10
|
+
|
|
11
|
+
def update
|
|
12
|
+
target = Reader.find(params[:id])
|
|
13
|
+
|
|
14
|
+
if Bible270.config.site_admin?(target)
|
|
15
|
+
redirect_to admin_reader_path(target),
|
|
16
|
+
status: :see_other, alert: 'Site-admin roles are controlled by configuration. Nothing was changed.'
|
|
17
|
+
elsif !%w[admin reader].include?(params[:role])
|
|
18
|
+
redirect_to admin_reader_path(target),
|
|
19
|
+
status: :see_other, alert: 'Choose admin or reader. Nothing was changed.'
|
|
20
|
+
elsif !target.has_attribute?(:admin)
|
|
21
|
+
redirect_to admin_reader_path(target),
|
|
22
|
+
status: :see_other, alert: 'Admin roles are unavailable until database migrations are run. Nothing was changed.'
|
|
23
|
+
else
|
|
24
|
+
target.with_lock do
|
|
25
|
+
target.admin = params[:role] == 'admin'
|
|
26
|
+
target.save!
|
|
27
|
+
end
|
|
28
|
+
redirect_to admin_reader_path(target),
|
|
29
|
+
status: :see_other, notice: target.admin? ? 'Admin access granted.' : 'Admin access removed.'
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def require_site_admin!
|
|
36
|
+
return if b270_site_admin? && b270_admin_view?
|
|
37
|
+
|
|
38
|
+
hide_role_endpoint
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Role changes must not use the ordinary stale-page recovery redirect.
|
|
42
|
+
def handle_unverified_request
|
|
43
|
+
hide_role_endpoint
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def hide_role_endpoint
|
|
47
|
+
raise ActionController::RoutingError, 'Not Found'
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bible270
|
|
4
|
+
class AdminScriptureFramesController < ApplicationController
|
|
5
|
+
before_action :require_admin!
|
|
6
|
+
before_action :require_admin_view!
|
|
7
|
+
before_action :set_reader_sort
|
|
8
|
+
before_action :require_storage!, except: %i[index update_default]
|
|
9
|
+
before_action :load_scripture_frame, only: %i[edit update destroy]
|
|
10
|
+
|
|
11
|
+
helper_method :scripture_frames_return_path
|
|
12
|
+
|
|
13
|
+
def index
|
|
14
|
+
redirect_to scripture_frames_return_path, status: :see_other
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update_default
|
|
18
|
+
frame = ScriptureFrames.defaults.find { |entry| entry.id == params[:id] }
|
|
19
|
+
raise ActiveRecord::RecordNotFound unless frame
|
|
20
|
+
|
|
21
|
+
unless %w[0 1].include?(params[:enabled])
|
|
22
|
+
return redirect_to scripture_frames_return_path, status: :see_other, alert: 'Choose Enable or Disable. Nothing was changed.'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
enabled = params[:enabled] == '1'
|
|
26
|
+
ScriptureFrames.set_default_enabled!(frame.id, enabled: enabled)
|
|
27
|
+
redirect_to scripture_frames_return_path, status: :see_other, notice: "Default Scripture text #{enabled ? 'enabled' : 'disabled'}."
|
|
28
|
+
rescue ArgumentError => e
|
|
29
|
+
redirect_to scripture_frames_return_path, status: :see_other, alert: e.message
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def new
|
|
33
|
+
@scripture_frame = ScriptureFrame.new(translation: 'NASB95', enabled: true)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def create
|
|
37
|
+
@scripture_frame = ScriptureFrame.new(scripture_frame_params)
|
|
38
|
+
if @scripture_frame.save
|
|
39
|
+
redirect_to scripture_frames_return_path, status: :see_other, notice: 'Scripture frame added.'
|
|
40
|
+
else
|
|
41
|
+
render :new, status: :unprocessable_entity
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def edit; end
|
|
46
|
+
|
|
47
|
+
def update
|
|
48
|
+
@scripture_frame.assign_attributes(scripture_frame_params)
|
|
49
|
+
if @scripture_frame.save
|
|
50
|
+
redirect_to scripture_frames_return_path, status: :see_other, notice: 'Scripture frame saved.'
|
|
51
|
+
else
|
|
52
|
+
render :edit, status: :unprocessable_entity
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def destroy
|
|
57
|
+
@scripture_frame.destroy!
|
|
58
|
+
redirect_to scripture_frames_return_path, status: :see_other, notice: 'Scripture frame deleted.'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def set_reader_sort
|
|
64
|
+
@reader_sort = AdminController::READER_SORT_OPTIONS.key?(params[:sort]) ? params[:sort] : 'first_name'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def scripture_frames_return_path
|
|
68
|
+
admin_path(sort: @reader_sort, anchor: 'b270-scripture-frames')
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def require_storage!
|
|
72
|
+
return if ScriptureFrames.custom_available?
|
|
73
|
+
|
|
74
|
+
redirect_to scripture_frames_return_path,
|
|
75
|
+
status: :see_other, alert: 'Custom scripture frames are unavailable until database migrations are run. Nothing was changed.'
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def load_scripture_frame
|
|
79
|
+
# Bundled IDs are not database IDs; reject them before Active Record can coerce them.
|
|
80
|
+
raise ActiveRecord::RecordNotFound unless params[:id].to_s.match?(%r{\A[1-9]\d*\z})
|
|
81
|
+
|
|
82
|
+
@scripture_frame = ScriptureFrame.find(params[:id])
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def scripture_frame_params
|
|
86
|
+
params.require(:scripture_frame).permit(:reference, :text, :translation, :enabled)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -29,7 +29,7 @@ module Bible270
|
|
|
29
29
|
rescue_from ActionController::InvalidAuthenticityToken, with: :recover_from_stale_page
|
|
30
30
|
|
|
31
31
|
helper_method :current_reader, :signed_in?, :b270_config, :enrollment_closed?,
|
|
32
|
-
:b270_admin?, :b270_reader_view?, :b270_admin_view?
|
|
32
|
+
:b270_admin?, :b270_site_admin?, :b270_reader_view?, :b270_admin_view?
|
|
33
33
|
|
|
34
34
|
private
|
|
35
35
|
|
|
@@ -105,7 +105,11 @@ module Bible270
|
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
def b270_admin?
|
|
108
|
-
Bible270.config.
|
|
108
|
+
Bible270.config.admin?(current_reader)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def b270_site_admin?
|
|
112
|
+
Bible270.config.site_admin?(current_reader)
|
|
109
113
|
end
|
|
110
114
|
|
|
111
115
|
def b270_reader_view?
|
|
@@ -117,6 +121,18 @@ module Bible270
|
|
|
117
121
|
b270_admin? && !b270_reader_view?
|
|
118
122
|
end
|
|
119
123
|
|
|
124
|
+
def require_admin!
|
|
125
|
+
return if b270_admin?
|
|
126
|
+
|
|
127
|
+
raise ActionController::RoutingError, 'Not Found'
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def require_admin_view!
|
|
131
|
+
return if b270_admin_view?
|
|
132
|
+
|
|
133
|
+
raise ActionController::RoutingError, 'Not Found'
|
|
134
|
+
end
|
|
135
|
+
|
|
120
136
|
# A suspended mobile tab can outlive its Rails session cookie. The page still
|
|
121
137
|
# contains the old session's CSRF token, so Rails would normally raise before
|
|
122
138
|
# current_reader could restore the session from the remember cookie. Redirect
|
|
@@ -4,6 +4,7 @@ module Bible270
|
|
|
4
4
|
class CheckoffsController < ApplicationController
|
|
5
5
|
def toggle
|
|
6
6
|
return unless require_reader!
|
|
7
|
+
return archived_progress if current_reader.alumni?
|
|
7
8
|
|
|
8
9
|
@day = params[:day].to_i
|
|
9
10
|
@track = params[:track].to_s
|
|
@@ -18,14 +19,7 @@ module Bible270
|
|
|
18
19
|
requested_state = params[:checked] if params.key?(:checked)
|
|
19
20
|
head :bad_request and return if params.key?(:checked) && !%w[0 1].include?(requested_state)
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
# submitted concurrently cannot both announce the same day completion.
|
|
23
|
-
marked_read = nil
|
|
24
|
-
current_reader.with_lock do
|
|
25
|
-
marked_read, @completion_event_id = apply_checkoff(requested_state)
|
|
26
|
-
@reader = current_reader.reload.reload_progress
|
|
27
|
-
@day_just_completed = marked_read && @completion_event_id && @reader.day_complete?(@day)
|
|
28
|
-
end
|
|
22
|
+
marked_read = persist_checkoff(requested_state)
|
|
29
23
|
@reader_tracks = @reader.read_tracks_for(@day)
|
|
30
24
|
@readings = Plan.readings_for(@day)
|
|
31
25
|
|
|
@@ -45,10 +39,45 @@ module Bible270
|
|
|
45
39
|
end
|
|
46
40
|
end
|
|
47
41
|
end
|
|
42
|
+
rescue Participation::ArchivedProgress
|
|
43
|
+
archived_progress
|
|
44
|
+
rescue PlanRun::StaleRun
|
|
45
|
+
respond_to do |format|
|
|
46
|
+
format.turbo_stream { head :conflict }
|
|
47
|
+
format.html { redirect_to day_path(@day), alert: 'Your plan run changed. Reload the page before updating progress.' }
|
|
48
|
+
end
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
private
|
|
51
52
|
|
|
53
|
+
def archived_progress
|
|
54
|
+
respond_to do |format|
|
|
55
|
+
format.turbo_stream { head :forbidden }
|
|
56
|
+
format.html { redirect_to root_path, alert: 'Alumni progress is read-only. An admin can add you to the current run.' }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def persist_checkoff(requested_state)
|
|
61
|
+
marked_read = nil
|
|
62
|
+
membership = current_reader.participation
|
|
63
|
+
# Serialize completion events and match restart's run-then-reader lock order.
|
|
64
|
+
membership.plan_run.with_lock do
|
|
65
|
+
current_reader.with_lock do
|
|
66
|
+
current_reader.reload_progress
|
|
67
|
+
unless current_reader.participation.id == membership.id &&
|
|
68
|
+
(!params.key?(:participation_id) || params[:participation_id].to_s == membership.id.to_s)
|
|
69
|
+
raise PlanRun::StaleRun
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
current_reader.ensure_progress_writable!
|
|
73
|
+
marked_read, @completion_event_id = apply_checkoff(requested_state)
|
|
74
|
+
@reader = current_reader.reload.reload_progress
|
|
75
|
+
@day_just_completed = marked_read && @completion_event_id && @reader.day_complete?(@day)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
marked_read
|
|
79
|
+
end
|
|
80
|
+
|
|
52
81
|
def apply_checkoff(requested_state)
|
|
53
82
|
existing = find_checkoff
|
|
54
83
|
if requested_state == '1'
|
|
@@ -65,7 +94,7 @@ module Bible270
|
|
|
65
94
|
|
|
66
95
|
def find_checkoff
|
|
67
96
|
Checkoff.uncached do
|
|
68
|
-
|
|
97
|
+
current_reader.checkoffs.find_by(day: @day, track: @track, part: @part)
|
|
69
98
|
end
|
|
70
99
|
end
|
|
71
100
|
|
|
@@ -5,7 +5,7 @@ module Bible270
|
|
|
5
5
|
def index
|
|
6
6
|
# Community is a directory of fellow readers, not a leaderboard. Keep the
|
|
7
7
|
# order predictable without implying that progress determines standing.
|
|
8
|
-
@readers = Reader.with_avatar.to_a.sort_by(&:sort_name)
|
|
8
|
+
@readers = Reader.active.with_avatar.to_a.sort_by(&:sort_name)
|
|
9
9
|
@today_day = current_reader&.today_day
|
|
10
10
|
@show_admin_progress = b270_admin_view?
|
|
11
11
|
return unless signed_in?
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bible270
|
|
4
|
+
class ScriptureFramesController < ApplicationController
|
|
5
|
+
def show
|
|
6
|
+
response.set_header('Cache-Control', 'no-store')
|
|
7
|
+
return head :not_acceptable unless request.format.json?
|
|
8
|
+
|
|
9
|
+
exclude = params[:exclude] if params[:exclude].is_a?(String)
|
|
10
|
+
frame = ScriptureFrames.random(exclude: exclude)
|
|
11
|
+
return head :no_content unless frame
|
|
12
|
+
|
|
13
|
+
render json: frame.to_h
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -225,16 +225,16 @@ module Bible270
|
|
|
225
225
|
#
|
|
226
226
|
# The title attribute carries the readings for pointer users; aria-label also
|
|
227
227
|
# includes date, progress, today, and reflection state for assistive technology.
|
|
228
|
-
def b270_day_cell(day, reader: nil, today: nil)
|
|
228
|
+
def b270_day_cell(day, reader: nil, today: nil, start_date: reader&.effective_start_date)
|
|
229
229
|
link_to day, day_path(day),
|
|
230
230
|
class: b270_day_cell_classes(day, reader: reader, today: today),
|
|
231
231
|
title: b270_day_readings(day),
|
|
232
|
-
aria: { label: b270_day_cell_label(day, reader: reader, today: today) }
|
|
232
|
+
aria: { label: b270_day_cell_label(day, reader: reader, today: today, start_date: start_date) }
|
|
233
233
|
end
|
|
234
234
|
|
|
235
|
-
def b270_day_cell_label(day, reader: nil, today: nil)
|
|
235
|
+
def b270_day_cell_label(day, reader: nil, today: nil, start_date: reader&.effective_start_date)
|
|
236
236
|
parts = ["Day #{day}"]
|
|
237
|
-
parts <<
|
|
237
|
+
parts << Plan.date_for(day, start_date).strftime('%A, %B %-d, %Y') if start_date
|
|
238
238
|
if reader
|
|
239
239
|
status = { complete: 'complete', partial: 'partially read', none: 'not read' }.fetch(reader.day_status(day))
|
|
240
240
|
parts << status
|
|
@@ -12,7 +12,7 @@ module Bible270
|
|
|
12
12
|
return message.perform_deliveries = false if @reader.nil? || addresses.empty?
|
|
13
13
|
|
|
14
14
|
@app_name = Bible270.config.app_name
|
|
15
|
-
@total = Reader.count
|
|
15
|
+
@total = Reader.active.count
|
|
16
16
|
@admin_url = admin_url_for(@reader)
|
|
17
17
|
|
|
18
18
|
mail to: addresses, subject: "#{@app_name}: #{@reader.display_name} has joined"
|
|
@@ -54,7 +54,7 @@ module Bible270
|
|
|
54
54
|
def daily_reminder(reader_id:, day:, on: Bible270.today)
|
|
55
55
|
@reader = Reader.find_by(id: reader_id)
|
|
56
56
|
return message.perform_deliveries = false unless Bible270.config.daily_reminders?
|
|
57
|
-
return message.perform_deliveries = false if @reader.nil? || !@reader.daily_reminders? || @reader.email.blank?
|
|
57
|
+
return message.perform_deliveries = false if @reader.nil? || @reader.alumni? || !@reader.daily_reminders? || @reader.email.blank?
|
|
58
58
|
|
|
59
59
|
@day = day.to_i
|
|
60
60
|
@on = Plan.to_date(on)
|