effective_cpd 1.2.2 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b7b747aec6776c9ea09dc1e36517084133694dca965f7d32ec8a20d66a9596d
4
- data.tar.gz: c21e47933d6026f612f79f0f63b52895d7319b2db744eb53b68e7881c280f497
3
+ metadata.gz: c0c18c1af80311c6e645ea9f7846924dd85a35e4ed11605f0791d1f9c7e73511
4
+ data.tar.gz: a216123cafd45efafcd9f85e53230799cb6a051006e7307dd7a629091cfa6082
5
5
  SHA512:
6
- metadata.gz: ec38bd12ba35145518b3285534b32e006a86fa6e29ed39da8fae6d6554ac554b0ffb676aaa32fc592920a3d4c2e8181c9138c9a5338edcfabd789d612af930be
7
- data.tar.gz: 6859e61d222b1fdcea05e91188f0b783de4ed76dd4f10dc8ce50dc0773ae4b4f5f39c90d2bb5ff188928bf2401ad7cd1e40b3ec4f1a2a2a7efd8e05063d0adb6
6
+ metadata.gz: 62f18ca3ad8b0b07cd5a60aa1435e047f6ec9c80d03f361c23024753202cecb1720cf773af88b1232732ea1f5b2c814554ce0104ff39a818746e7ff6399113f8
7
+ data.tar.gz: 2347e808fc551c592bd09c902d5e73bf4c2f1accb2c2ad66a0fc4f6b4cdec0671ef316931d0072259e9d7a584ae5a9e1b2302a73c13616569f5f7f48d71d19d1
data/README.md CHANGED
@@ -167,6 +167,14 @@ def cpd_statement_required_score(cpd_statement)
167
167
  end
168
168
  ```
169
169
 
170
+ ## Rake Tasks
171
+
172
+ You can use
173
+
174
+ `bundle exec rake effective_cpd:notify_auditees`
175
+
176
+ to send the cpd_audit_opened notification to all opened (but not yet started) auditees.
177
+
170
178
  ## Authorization
171
179
 
172
180
  All authorization checks are handled via the effective_resources gem found in the `config/initializers/effective_resources.rb` file.
@@ -36,6 +36,10 @@ module EffectiveCpdAudit
36
36
  [:opened, :started, :conflicted_resolved, :exemption_denied, :extension_granted, :extension_denied]
37
37
  end
38
38
 
39
+ def chat_permissions
40
+ ['Can send messages until closed', 'Always send messages', 'Never send messages']
41
+ end
42
+
39
43
  end
40
44
 
41
45
  included do
@@ -150,6 +154,9 @@ module EffectiveCpdAudit
150
154
  reviewed_at :datetime, permitted: false
151
155
  closed_at :datetime, permitted: false
152
156
 
157
+ # To control permission of sending messages
158
+ chat_permission :string, permitted: false
159
+
153
160
  # Acts as tokyyened
154
161
  token :string, permitted: false
155
162
 
@@ -181,6 +188,7 @@ module EffectiveCpdAudit
181
188
  before_validation(if: -> { new_record? }) do
182
189
  self.notification_date ||= Time.zone.now
183
190
  self.due_date ||= deadline_to_submit()
191
+ self.chat_permission ||= self.class.chat_permissions.first
184
192
  end
185
193
 
186
194
  with_options(if: -> { cpd_audit_level&.anonymous? }) do
@@ -222,13 +230,17 @@ module EffectiveCpdAudit
222
230
  end
223
231
  end
224
232
 
233
+ validate(if: -> { chat_permission.present? }) do
234
+ unless self.class.chat_permissions.include?(chat_permission)
235
+ self.errors.add(:chat_permission, 'is invalid')
236
+ end
237
+ end
238
+
225
239
  # If we're submitted. Check if we can go into reviewed?
226
240
  before_save(if: -> { submitted? }) { try_complete! }
227
241
  before_save(if: -> { completed? }) { try_review! }
228
242
 
229
- after_commit(on: :create) do
230
- send_email(:cpd_audit_opened)
231
- end
243
+ after_commit(on: :create) { notify! }
232
244
 
233
245
  def dynamic_wizard_steps
234
246
  cpd_audit_level.cpd_audit_level_sections.each_with_object({}) do |section, h|
@@ -289,6 +301,14 @@ module EffectiveCpdAudit
289
301
  chat
290
302
  end
291
303
 
304
+ def chat_url(chat:, user:, root_url:)
305
+ resource = if user.try(:cpd_audit_reviewer?)
306
+ cpd_audit_reviews.find { |review| review.user == user } || raise('expected to find existing reviewer')
307
+ end || self
308
+
309
+ [root_url.chomp('/'), resource.class.table_name, resource.to_param, 'chat'].join('/')
310
+ end
311
+
292
312
  end
293
313
 
294
314
  def to_s
@@ -323,6 +343,18 @@ module EffectiveCpdAudit
323
343
  was_completed?
324
344
  end
325
345
 
346
+ def chat_until_closed?
347
+ chat_permission == 'Can send messages until closed'
348
+ end
349
+
350
+ def chat_always?
351
+ chat_permission == 'Always send messages'
352
+ end
353
+
354
+ def chat_never?
355
+ chat_permission == 'Never send messages'
356
+ end
357
+
326
358
  def status_label
327
359
  (status_was || status).to_s.gsub('_', ' ')
328
360
  end
@@ -379,6 +411,11 @@ module EffectiveCpdAudit
379
411
  cpd_audit_response ||= cpd_audit_responses.build(cpd_audit: self, cpd_audit_level_question: cpd_audit_level_question)
380
412
  end
381
413
 
414
+ def notify!
415
+ send_email(:cpd_audit_opened)
416
+ true
417
+ end
418
+
382
419
  # Auditee wizard action
383
420
  def start!
384
421
  started!
@@ -1,3 +1,12 @@
1
+ = card('Chat Permission') do
2
+ = effective_form_with(model: [:admin, cpd_audit], engine: true) do |f|
3
+ %p By default, auditees and reviewers can send messages until the audit is closed.
4
+
5
+ .row
6
+ .col-sm-6
7
+ = f.select :chat_permission, cpd_audit.class.chat_permissions, label: false
8
+ = f.submit 'Save', center: true, border: false
9
+
1
10
  - if cpd_audit.chat.present?
2
11
  = render('effective/chats/chat', chat: cpd_audit.chat)
3
12
  - else
@@ -40,6 +40,10 @@
40
40
  %p You have completed these past statements:
41
41
  = render_datatable(completed, simple: true)
42
42
 
43
+ - unless current_user.try(:cpd_audit_reviewer?)
44
+ - if auditing.blank? && audited.blank? && available.blank? && completed.blank?
45
+ %p There are no activities available right now. When there are, we'll show them here.
46
+
43
47
  - if current_user.try(:cpd_audit_reviewer?)
44
48
  - # Auditor / Audit reviewer datatables (2)
45
49
  - reviewing = EffectiveCpdAvailableAuditReviewsDatatable.new(self)
@@ -2,7 +2,7 @@
2
2
  %table.table
3
3
  %tbody
4
4
  %tr
5
- %td{colspan: 2}
5
+ %td
6
6
  - if cpd_audit_review.feedback.present?
7
7
  = simple_format(cpd_audit_review.feedback)
8
8
  - else
@@ -75,4 +75,4 @@
75
75
  - if cpd_audit_review.comments.present?
76
76
  = simple_format(cpd_audit_review.comments)
77
77
  - else
78
- None
78
+ = '-'
@@ -227,6 +227,8 @@ class CreateEffectiveCpd < ActiveRecord::Migration[6.0]
227
227
 
228
228
  t.string :token
229
229
 
230
+ t.string :chat_permission
231
+
230
232
  t.datetime :updated_at
231
233
  t.datetime :created_at
232
234
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveCpd
2
- VERSION = '1.2.2'
2
+ VERSION = '1.2.4'
3
3
  end
@@ -1,6 +1,28 @@
1
- # bundle exec rake effective_cpd:seed
2
1
  namespace :effective_cpd do
2
+
3
+ # bundle exec rake effective_cpd:seed
3
4
  task seed: :environment do
4
5
  load "#{__dir__}/../../db/seeds.rb"
5
6
  end
7
+
8
+ # bundle exec rake effective_cpd:notify_auditees
9
+ desc 'Send cpd_audit_opened email notifications for effective cpd'
10
+ task notify_auditees: :environment do
11
+ audits = EffectiveCpd.CpdAudit.opened.sorted
12
+
13
+ audits.find_each do |audit|
14
+ begin
15
+ audit.notify!
16
+ puts "Sent #{audit} notification to #{audit.user.email}"
17
+ rescue => e
18
+ if defined?(ExceptionNotifier)
19
+ ExceptionNotifier.notify_exception(e, data: { audit_id: audit.id })
20
+ end
21
+
22
+ puts "Error with audit #{auditee.id}: #{e.errors.inspect}"
23
+ end
24
+ end
25
+
26
+ puts 'All done'
27
+ end
6
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_cpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-27 00:00:00.000000000 Z
11
+ date: 2023-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails