diff --git a/app/models/employee.rb b/app/models/employee.rb index b456aea..475ab19 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -147,6 +147,8 @@ def accepted_roles scope :qualifications, -> (qualification_id) { if qualification_id === "NONE" left_joins(:employee_qualifications).where(employee_qualifications: { id: nil }) + elsif qualification_id === "UNAPPROVED" + left_joins(:qualifications).where(qualifications: { approved: false }) else # get the highest qualification for each employee subquery = EmployeeQualification.select('employee_id, MAX(qualification_id) as max_qualification_id').group(:employee_id).to_sql @@ -206,8 +208,10 @@ def self.options_for_job_title def self.options_for_qualifications instance = new - qualifications = Qualification.all.map { |qualifications| [qualifications.name, qualifications.id] } - qualifications + [['No qualifications', 'NONE']] + qualifications = Qualification.all.approved(true).map { |qualifications| [qualifications.name, qualifications.id] } + qualifications += [['Unapproved qualifications', 'UNAPPROVED']] + qualifications += [['No saved qualifications', 'NONE']] + qualifications end diff --git a/app/models/qualification.rb b/app/models/qualification.rb index c8f6c58..5b683ce 100644 --- a/app/models/qualification.rb +++ b/app/models/qualification.rb @@ -9,16 +9,27 @@ class Qualification < ApplicationRecord # this is more for reference now that the content is in the table but its needed for seeding the database and rake tasks def accepted_qualifications [ - { name: "Level 7", order: 8 }, - { name: "QTS", order: 7 }, - { name: "EYC", order: 6 }, - { name: "EYPS", order: 5 }, - { name: "Level 6", order: 4 }, - { name: "Level 5", order: 3 }, - { name: "Level 4", order: 2 }, - { name: "Level 3", order: 1 }, - { name: "Level 2", order: 0 } + { name: "Unqualified", order: 0 }, + { name: "Level 2", order: 1 }, + { name: "Level 3", order: 2 }, + { name: "Level 4", order: 3 }, + { name: "Level 5", order: 4 }, + { name: "Level 6", order: 5 }, + { name: "Early Years Professional Status", order: 6 }, + { name: "Early Years Teacher Status", order: 7 }, + { name: "Qualified Teacher Status", order: 8 }, + { name: "Level 7", order: 9 } ] end + + + # add approved scope + scope :approved, -> (status = true) { + where(approved: status) + } + end + + + diff --git a/app/views/admin/employees/edit.html.erb b/app/views/admin/employees/edit.html.erb index e7131b3..e727940 100644 --- a/app/views/admin/employees/edit.html.erb +++ b/app/views/admin/employees/edit.html.erb @@ -67,6 +67,31 @@ <%= render "admin/shared/collapsible", name: "Qualifications", id: "employee-qualifications" do %> + + + <% if @employee.employee_qualifications.any? { |eq| !eq.qualification.approved } %> +
+

Some of this employee's previous qualifications are no longer approved

+

+ Some of this employees previous qualifications are no longer approved an admin will need to update them as unapproved qualifications do not show for users. +
+
+ The following are the unnapproved qualifications for this employee, please update them to approved options if they are still valid. +

+ +
+ <% end %> + + + + + <%= render "employees/editors/qualifications", f: f %> <% end %> diff --git a/app/views/admin/employees/show.html.erb b/app/views/admin/employees/show.html.erb index d099736..02ab559 100644 --- a/app/views/admin/employees/show.html.erb +++ b/app/views/admin/employees/show.html.erb @@ -174,6 +174,16 @@ <%= render "admin/shared/collapsible", name: "Qualifications", id: "employee-qualifications" do %> + + <% if @employee.employee_qualifications.any? { |eq| !eq.qualification.approved } %> +
+

Some of this employee's previous qualifications are no longer approved

+

+ Some of this employees previous qualifications are no longer approved an admin will need to update them as unapproved qualifications do not show for users. +

+
+ <% end %> + <% if @employee.employee_qualifications.present? %> @@ -182,7 +192,7 @@ <% @employee.employee_qualifications.each do |qualification| %> - + <% end %> diff --git a/app/views/employees/editors/_qualifications.html.erb b/app/views/employees/editors/_qualifications.html.erb index 6fd9c64..a41301f 100644 --- a/app/views/employees/editors/_qualifications.html.erb +++ b/app/views/employees/editors/_qualifications.html.erb @@ -1,10 +1,11 @@ +<% if Qualification.exists? %>

What qualifications does this person have?

Please only tick the highest full and relevant Early Years Qualification

- <% Qualification.all.each do |qualification| %> + <% Qualification.all.approved(true).each do |qualification| %> <% employee_qualification = @employee.employee_qualifications.find_or_initialize_by(qualification_id: qualification.id) %> <%= f.fields_for :employee_qualifications, employee_qualification do |eq| %> @@ -28,3 +29,4 @@ <% end %>
+<% end %> diff --git a/db/migrate/20240614204249_add_approved_col_to_qualifications.rb b/db/migrate/20240614204249_add_approved_col_to_qualifications.rb new file mode 100644 index 0000000..8347a1d --- /dev/null +++ b/db/migrate/20240614204249_add_approved_col_to_qualifications.rb @@ -0,0 +1,5 @@ +class AddApprovedColToQualifications < ActiveRecord::Migration[6.1] + def change + add_column :qualifications, :approved, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 6ad06f7..a3373a0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_06_14_193034) do +ActiveRecord::Schema.define(version: 2024_06_14_204249) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -73,6 +73,7 @@ t.integer "order" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.boolean "approved", default: false end create_table "services", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 9758cf6..ce7b6bb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -38,7 +38,7 @@ def employee_attributes surname: FFaker::Name.last_name, forenames: FFaker::Name.first_name, job_title: Employee.new.accepted_job_titles.sample, - qualifications: Qualification.all.sample(rand(0..Qualification.count)), + qualifications: Qualification.all.approved(true).sample(rand(0..Qualification.count)), roles: accepted_roles.sample(rand(1..accepted_roles.size)) , employed_from: FFaker::Time.date(year_latest: 18, year_range: 65 - 18), diff --git a/spec/controllers/employees_controller_spec.rb b/spec/controllers/employees_controller_spec.rb index 2b6c12e..3f887e6 100644 --- a/spec/controllers/employees_controller_spec.rb +++ b/spec/controllers/employees_controller_spec.rb @@ -93,7 +93,7 @@ surname: FFaker::Name.last_name, forenames: FFaker::Name.first_name, job_title: Employee.new.accepted_job_titles.sample, - qualifications: Qualification.all.sample, + qualifications: Qualification.all.approved(true).sample, roles: Employee.new.accepted_roles.sample, employed_from: FFaker::Time.date(year_latest: 18, year_range: 65 - 18), diff --git a/spec/features/managing_employees_spec.rb b/spec/features/managing_employees_spec.rb index 2648d6c..141486b 100644 --- a/spec/features/managing_employees_spec.rb +++ b/spec/features/managing_employees_spec.rb @@ -103,7 +103,7 @@ fill_in :employee_safeguarding_achieved_on, with: safeguarding_achieved_on check :employee_has_designated_safeguarding_lead fill_in :employee_designated_safeguarding_lead_achieved_on, with: designated_safeguarding_lead_achieved_on - Qualification.all.each do |qualification| + Qualification.all.approved(true).each do |qualification| check(qualification.name) end click_button 'Continue' @@ -135,7 +135,7 @@ expect(page).to have_checked_field(:employee_has_safeguarding) expect(page).to have_field(:employee_designated_safeguarding_lead_achieved_on, with: designated_safeguarding_lead_achieved_on) expect(page).to have_checked_field(:employee_has_designated_safeguarding_lead) - Qualification.all.each do |qualification| + Qualification.all.approved(true).each do |qualification| expect(page).to have_checked_field(qualification.name) end end diff --git a/spec/models/employee_spec.rb b/spec/models/employee_spec.rb index c3ccce5..fd5e232 100644 --- a/spec/models/employee_spec.rb +++ b/spec/models/employee_spec.rb @@ -124,19 +124,23 @@ end end + describe '.options_for_qualifications' do it 'returns an array of options for qualifications' do expect(Employee.options_for_qualifications).to match_array([ - include('Level 2', a_kind_of(Integer)), - include('Level 3', a_kind_of(Integer)), - include('Level 4', a_kind_of(Integer)), - include('Level 5', a_kind_of(Integer)), - include('Level 6', a_kind_of(Integer)), - include('EYPS', a_kind_of(Integer)), - include('QTS', a_kind_of(Integer)), - include('EYC', a_kind_of(Integer)), - ['No qualifications', 'NONE'] + # include('Unqualified', a_kind_of(Integer)), + # include('Level 2', a_kind_of(Integer)), + # include('Level 3', a_kind_of(Integer)), + # include('Level 4', a_kind_of(Integer)), + # include('Level 5', a_kind_of(Integer)), + # include('Level 6', a_kind_of(Integer)), + # include('Early Years Professional Status', a_kind_of(Integer)), + # include('Early Years Teacher Status', a_kind_of(Integer)), + # include('Qualified Teacher Status', a_kind_of(Integer)), + # include('Level 7', a_kind_of(Integer)), + ['Unapproved qualifications', 'UNAPPROVED'], + ['No saved qualifications', 'NONE'] ]) end end -end +end \ No newline at end of file
<%= qualification.qualification.name %><%= qualification.qualification.name %> <%= "(unapproved)" if !qualification.qualification.approved %> <%= qualification.achieved_on.strftime("%d/%m/%Y") if qualification.achieved_on %>