effective_cpd 1.4.3 → 1.4.5

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: c9bf9fab63804fd9df4169549c0c278ca470da4b7b702b8203bbabd9cae1a687
4
- data.tar.gz: 32976d633df1ad0832af4bd563c2b9082733e0faca24a43102c4c1f6782d793a
3
+ metadata.gz: ea1c3574d959eac96d4ea26c8c0c4a25560c81d08bc5e54a85c238adb51f70f0
4
+ data.tar.gz: af871c4f6ec38aa0e1c1090c1877e857f65db572b087e422ecd2029a338fc0f2
5
5
  SHA512:
6
- metadata.gz: 0ba9c124af907479bf330535e963aa65b3926430b308c00842cdb4f1346297cf096a15b03a1227b6c53e60a4267a20596e4fe616c0e768d421cfd5a7e4cd5b8a
7
- data.tar.gz: 6b6f0b3c1090e94b6e361bcfe2a0e99649ca2dc1a7ae3be0f3974479ce06f2f587e314fb39ebdde1e973688624340e3cbb6cb4871c0c46fd34925dc846a6385f
6
+ metadata.gz: 405c0b8e3c5f5b21ac04f97bf8db864ed7a8a1994b25027aa41d535e1f7ce84585e38ec7d1fd1eeb77d58d51e080f96ee62aa57e0cca472c055978a3dc936992
7
+ data.tar.gz: 113e27bb06f1cc3a0ae4c664e0af1255de13f52e55a176912d25b064931ba7c6f41f0636c8ff5cdcdaab2eee27e15f260b611a2b1960708e0ad021035da63dc6
@@ -14,7 +14,7 @@ class EffectiveCpdAvailableCyclesDatatable < Effective::Datatable
14
14
  end
15
15
 
16
16
  actions_col(actions: []) do |cpd_cycle|
17
- statement = cpd_cycle.cpd_statements.where(user: current_user).first
17
+ statement = current_user.cpd_statement(cpd_cycle: cpd_cycle)
18
18
 
19
19
  if statement.blank?
20
20
  dropdown_link_to('Start', effective_cpd.cpd_cycle_cpd_statement_build_path(cpd_cycle, :new, :start))
@@ -256,12 +256,11 @@ module EffectiveCpdAudit
256
256
  def required_steps
257
257
  steps = [:start, :information, :instructions, :demographics]
258
258
 
259
- steps << :conflict if cpd_audit_level.conflict_of_interest?
260
-
261
- steps << :exemption if cpd_audit_level.can_request_exemption?
259
+ steps << :conflict if cpd_audit_level.conflict_of_interest? && !was_submitted?
260
+ steps << :exemption if cpd_audit_level.can_request_exemption? && !was_submitted?
262
261
 
263
262
  unless exemption_requested?
264
- steps << :extension if cpd_audit_level.can_request_extension?
263
+ steps << :extension if cpd_audit_level.can_request_extension? && !was_submitted?
265
264
  end
266
265
 
267
266
  if exemption_requested? || extension_requested?
@@ -26,7 +26,7 @@ module EffectiveCpdUser
26
26
 
27
27
  # Effective scoped
28
28
  has_many :cpd_targets, -> { order(:cpd_cycle_id) }, inverse_of: :user, class_name: 'Effective::CpdTarget', dependent: :delete_all
29
- accepts_nested_attributes_for :cpd_targets
29
+ accepts_nested_attributes_for :cpd_targets, reject_if: proc { |atts| atts['score'].blank? && atts['required_to_submit'].blank? }
30
30
 
31
31
  # These two should not be sorted
32
32
  scope :cpd_audit_auditees, -> { without_role(:cpd_audit_reviewer).without_role(:admin) }
@@ -43,11 +43,17 @@ module EffectiveCpdUser
43
43
  }
44
44
  end
45
45
 
46
+ # Requires for this user
46
47
  def cpd_target_score(cpd_cycle:)
47
48
  target = cpd_target(cpd_cycle: cpd_cycle)
48
49
  return target.score if target&.score.present?
49
50
 
50
- # Otherwise calculate default by membership category
51
+ default_cpd_target_score(cpd_cycle: cpd_cycle)
52
+ end
53
+
54
+ # Required for this user category without the targets
55
+ # Otherwise calculate default by membership category
56
+ def default_cpd_target_score(cpd_cycle:)
51
57
  if self.class.try(:effective_memberships_user?)
52
58
  category = membership_categories_on(cpd_cycle.start_at)&.first if cpd_cycle.start_at.present?
53
59
  category ||= membership_categories_on(cpd_cycle.end_at)&.first if cpd_cycle.end_at.present?
@@ -73,19 +79,20 @@ module EffectiveCpdUser
73
79
  end
74
80
 
75
81
  def cpd_statement(cpd_cycle:)
76
- raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cycle?)
82
+ raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?)
77
83
  cpd_statements.find { |cpd_statement| cpd_statement.cpd_cycle_id == cpd_cycle.id }
78
84
  end
79
85
 
80
86
  # Find or build
81
87
  def build_cpd_statement(cpd_cycle:)
82
- raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cycle?)
88
+ raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?)
83
89
  cpd_statement(cpd_cycle: cpd_cycle) || cpd_statements.build(cpd_cycle: cpd_cycle)
84
90
  end
85
91
 
92
+ # Dont use IDs here
86
93
  def cpd_target(cpd_cycle:)
87
94
  raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?)
88
- cpd_targets.find { |cpd_target| cpd_target.cpd_cycle_id == cpd_cycle.id }
95
+ cpd_targets.find { |cpd_target| cpd_target.cpd_cycle == cpd_cycle }
89
96
  end
90
97
 
91
98
  # Find or build
@@ -20,8 +20,10 @@ module Effective
20
20
  scope :deep, -> { includes(:user, :cpd_cycle) }
21
21
  scope :sorted, -> { order(:cpd_cycle_id) }
22
22
 
23
- validates :score, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
24
- validates :score, presence: true, if: -> { required_to_submit? }
23
+ validates :score, numericality: { greater_than_or_equal_to: 0 }
24
+ validates :required_to_submit, inclusion: { in: [true, false], message: "can't be blank" }
25
+
26
+ validates :cpd_cycle_id, uniqueness: { scope: [:user_id, :user_type], message: 'target already exists' }
25
27
 
26
28
  def to_s
27
29
  score&.to_s || model_name.human
@@ -18,17 +18,17 @@
18
18
  - collection = Effective::CpdTarget::REQUIRED_TO_SUBMIT
19
19
  - cpd_cycle = ctf.object.cpd_cycle
20
20
  - target = f.object.cpd_target_score(cpd_cycle: cpd_cycle)
21
+ - target_placeholder = f.object.default_cpd_target_score(cpd_cycle: cpd_cycle)
21
22
  - required_to_submit = f.object.cpd_target_score_required_to_submit?(cpd_cycle: cpd_cycle)
22
23
  - required_to_submit_placeholder = collection.find { |label, value| value == required_to_submit }.first
23
24
 
24
25
  %tr
25
26
  %td= link_to(cpd_cycle, effective_cpd.edit_admin_cpd_cycle_path(cpd_cycle), target: '_blank')
26
-
27
27
  %td
28
28
  .row
29
29
  .col
30
- = ctf.number_field :score, label: false, required: false, placeholder: target.to_s
30
+ = ctf.number_field :score, label: false, required: false, placeholder: target_placeholder.to_s
31
31
  .col
32
- = ctf.select :required_to_submit, Effective::CpdTarget::REQUIRED_TO_SUBMIT, label: false, placeholder: required_to_submit_placeholder.to_s
32
+ = ctf.select :required_to_submit, Effective::CpdTarget::REQUIRED_TO_SUBMIT, label: false, required: false, placeholder: required_to_submit_placeholder.to_s
33
33
 
34
34
  = f.save "Save #{cpd_targets_label}", 'data-confirm': "Really Save #{cpd_targets_label} for #{user}?"
@@ -1,3 +1,3 @@
1
1
  module EffectiveCpd
2
- VERSION = '1.4.3'
2
+ VERSION = '1.4.5'
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.4.3
4
+ version: 1.4.5
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-10 00:00:00.000000000 Z
11
+ date: 2023-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails