effective_cpd 1.5.1 → 1.6.1

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: '007309633bd01dfa4ad2731f7c36f6d576c471c6de1f8ec21f355da5615a2b0d'
4
- data.tar.gz: f1a0b42227c58dea846ad8e288bccec8472ce05a747b790ef4a6b83ee8ab0539
3
+ metadata.gz: 89acef6977a76e2072c93505be5f2e140df846d7a4c811cf9c6ae6f71b8f7cf5
4
+ data.tar.gz: a3bd58305e0e7ae3667ce9039944dbeba4f4c7a4f4299e48caaf723debc97db3
5
5
  SHA512:
6
- metadata.gz: 99d7615012e34a640bd5e3009559a431638880894f819910cbc3d6df770316c6e4329bebb2dfdd28cf44d7c39abf2f63f1682205232f5a8bea5f43c9e7b25c73
7
- data.tar.gz: 99e4617ac625fa40c15e60cbe535824be383edf62306ebd3337b01204c5a03d9f3b89c7c441045848f932fcdb1c21c564aa349c3334eddb2c2eee9c73a54631e
6
+ metadata.gz: da56f6fa2fe0699f60f071abf0b694621398efaa71979d8d9efdc07974010497d95d20529222609446b0a79f02aebd0527af3b321706a787471e439f98c06693
7
+ data.tar.gz: 297d83fdad2dbf217a16148fd624ce0411db56a937555ec1afb4efa043aeccdcfbb88f0acb713c8f8b46bf98698d21a358d6a9525d4d1c50f88dc5a95ba50c79
@@ -26,8 +26,8 @@ class EffectiveCpdAvailableCyclesDatatable < Effective::Datatable
26
26
 
27
27
  collection do
28
28
  raise('expected a current_user') unless current_user.present?
29
+
29
30
  completed = EffectiveCpd.CpdStatement.completed.where(user: current_user)
30
31
  Effective::CpdCycle.available.where.not(id: completed.select('cpd_cycle_id as id'))
31
32
  end
32
-
33
33
  end
@@ -3,7 +3,6 @@
3
3
  # EffectiveCpdAudit
4
4
  #
5
5
  # Mark your owner model with effective_cpd_audit to get all the includes
6
-
7
6
  module EffectiveCpdAudit
8
7
  extend ActiveSupport::Concern
9
8
 
@@ -39,7 +38,6 @@ module EffectiveCpdAudit
39
38
  def chat_permissions
40
39
  ['Can send messages until closed', 'Always send messages', 'Never send messages']
41
40
  end
42
-
43
41
  end
44
42
 
45
43
  included do
@@ -65,15 +65,15 @@ module EffectiveCpdBulkAudit
65
65
  validates :audit_reviewers_count, numericality: { greater_than: 0 }
66
66
 
67
67
  validate(if: -> { cpd_user_scope.present? }) do
68
- self.errors.add(:cpd_user_class_name, "expecting an effective_cpd_user") unless cpd_user_scope.respond_to?(:effective_cpd_user?)
68
+ errors.add(:cpd_user_class_name, 'expecting an effective_cpd_user') unless cpd_user_scope.respond_to?(:effective_cpd_user?)
69
69
  end
70
70
 
71
71
  validate(if: -> { audits.present? && auditees_count.present? }) do
72
- self.errors.add(:audits, "can't be more than the number of auditees #{auditees_count}") if audits > auditees_count
72
+ errors.add(:audits, "can't be more than the number of auditees #{auditees_count}") if audits > auditees_count
73
73
  end
74
74
 
75
75
  validate(if: -> { audit_reviewers_per_audit.present? && audit_reviewers_count.present? }) do
76
- self.errors.add(:audit_reviewers_per_audit, "can't be more than the number of audit reviewers #{audit_reviewers_count}") if audit_reviewers_per_audit > audit_reviewers_count
76
+ errors.add(:audit_reviewers_per_audit, "can't be more than the number of audit reviewers #{audit_reviewers_count}") if audit_reviewers_per_audit > audit_reviewers_count
77
77
  end
78
78
 
79
79
  after_commit(on: :create) { create_bulk_audit_job! }
@@ -154,5 +154,4 @@ module EffectiveCpdBulkAudit
154
154
 
155
155
  @reviewers[@reviewers_index]
156
156
  end
157
-
158
157
  end
@@ -3,7 +3,6 @@
3
3
  # EffectiveCpdStatement
4
4
  #
5
5
  # Mark your owner model with effective_cpd_statement to get all the includes
6
-
7
6
  module EffectiveCpdStatement
8
7
  extend ActiveSupport::Concern
9
8
 
@@ -14,7 +13,9 @@ module EffectiveCpdStatement
14
13
  end
15
14
 
16
15
  module ClassMethods
17
- def effective_cpd_statement?; true; end
16
+ def effective_cpd_statement?
17
+ true
18
+ end
18
19
  end
19
20
 
20
21
  included do
@@ -81,8 +82,8 @@ module EffectiveCpdStatement
81
82
  end
82
83
 
83
84
  validate(if: -> { completed? && target_score_required_to_submit? }) do
84
- min = target_score() || 0.0
85
- self.errors.add(:score, "must be #{min} or greater to submit a statement") if score < min
85
+ min = target_score || 0.0
86
+ errors.add(:score, "must be #{min} or greater to submit a statement") if score < min
86
87
  end
87
88
 
88
89
  with_options(if: -> { current_step == :agreements }) do
@@ -93,6 +94,8 @@ module EffectiveCpdStatement
93
94
  with_options(if: -> { current_step == :submit}) do
94
95
  validates :confirm_readonly, acceptance: true
95
96
  end
97
+
98
+ validates :cpd_cycle_id, uniqueness: { scope: [:user_type, :user_id] }, if: -> { new_record? && cpd_cycle && user }
96
99
  end
97
100
 
98
101
  def to_s
@@ -148,5 +151,4 @@ module EffectiveCpdStatement
148
151
  cpd_statement_activities.each { |activity| scores[activity.cpd_category_id] += activity.score.to_d }
149
152
  end
150
153
  end
151
-
152
154
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+ # rubocop:disable all
3
+
1
4
  module Effective
2
5
  class CpdScorer
3
6
  include EffectiveResourcesHelper
@@ -9,9 +12,9 @@ module Effective
9
12
 
10
13
  if from.present?
11
14
  raise('expected from to be a CpdStatement') unless from.class.respond_to?(:effective_cpd_statement?)
15
+
12
16
  @statements = @statements.where('cpd_cycle_id >= ?', from.cpd_cycle_id)
13
17
  end
14
-
15
18
  end
16
19
 
17
20
  def score!
@@ -156,7 +159,11 @@ module Effective
156
159
 
157
160
  def save_carry_forward_activity(existing, statement)
158
161
  activity = statement.cpd_statement_activities.find { |a| a.original == (existing.original || existing) }
159
- activity ||= statement.cpd_statement_activities.build()
162
+
163
+ return if activity.blank? && statement.completed?
164
+ return if activity.blank? && !statement.cpd_cycle.available?
165
+
166
+ activity ||= statement.cpd_statement_activities.build
160
167
 
161
168
  activity.assign_attributes(
162
169
  cpd_category: existing.cpd_category,
@@ -57,8 +57,8 @@ module Effective
57
57
  end
58
58
 
59
59
  validate(if: -> { new_record? && cpd_statement.present? }, unless: -> { importing }) do
60
- self.errors.add(:base, "statement has already been completed") if cpd_statement.completed?
61
- self.errors.add(:base, "cycle is unavailable") unless cpd_statement.cpd_cycle.available?
60
+ errors.add(:base, 'statement has already been completed') if cpd_statement.completed?
61
+ errors.add(:base, 'cycle is unavailable') unless cpd_statement.cpd_cycle.available?
62
62
  end
63
63
 
64
64
  def to_s
@@ -85,6 +85,5 @@ module Effective
85
85
  def to_debug
86
86
  "id=#{id}, score=#{score}, carry_foward=#{carry_forward}, carry_from_last=#{carry_over}, original=#{original&.id}"
87
87
  end
88
-
89
88
  end
90
89
  end
data/config/routes.rb CHANGED
@@ -38,7 +38,7 @@ EffectiveCpd::Engine.routes.draw do
38
38
  resources :cpd_special_rules, except: [:show]
39
39
  resources :cpd_targets, except: [:show]
40
40
 
41
- resources :cpd_statements, only: [:index, :show] do
41
+ resources :cpd_statements, only: [:index, :show, :destroy] do
42
42
  post :unsubmit, on: :member
43
43
  end
44
44
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveCpd
2
- VERSION = '1.5.1'
2
+ VERSION = '1.6.1'
3
3
  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.5.1
4
+ version: 1.6.1
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-03-31 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails