From 13be059d506d172ebe57dc8200b62b91d703a7ff Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Fri, 24 May 2024 11:25:54 -0300 Subject: [PATCH 01/32] ISSUE#448 - Add the relation n-m with institution and professor through the table affiliation --- app/models/affiliation.rb | 9 +++++++++ app/models/institution.rb | 4 +++- app/models/professor.rb | 3 ++- config/application.rb | 2 ++ .../20240524135850_create_affiliation.rb | 19 +++++++++++++++++++ db/schema.rb | 16 +++++++++++++--- spec/factories/factory_affiliation.rb | 10 ++++++++++ spec/models/affiliation_spec.rb | 9 +++++++++ spec/models/institution_spec.rb | 3 ++- spec/models/professor_spec.rb | 6 +++--- 10 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 app/models/affiliation.rb create mode 100644 db/migrate/20240524135850_create_affiliation.rb create mode 100644 spec/factories/factory_affiliation.rb create mode 100644 spec/models/affiliation_spec.rb diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb new file mode 100644 index 00000000..4155cae5 --- /dev/null +++ b/app/models/affiliation.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Affiliation < ApplicationRecord + has_paper_trail + + belongs_to :institution + belongs_to :professor + +end diff --git a/app/models/institution.rb b/app/models/institution.rb index e3bdc403..c8459c02 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -8,7 +8,9 @@ class Institution < ApplicationRecord has_paper_trail has_many :majors, dependent: :restrict_with_exception - has_many :professors, dependent: :restrict_with_exception + has_many :affiliations, dependent: :restrict_with_exception + has_many :professors, through: :affiliations + validates :name, presence: true, uniqueness: true diff --git a/app/models/professor.rb b/app/models/professor.rb index de52ea61..a12a8ab4 100644 --- a/app/models/professor.rb +++ b/app/models/professor.rb @@ -18,9 +18,10 @@ class Professor < ApplicationRecord dependent: :restrict_with_exception has_many :thesis_defense_committee_enrollments, source: :enrollment, through: :thesis_defense_committee_participations + has_many :affiliations, dependent: :restrict_with_exception + has_many :institutions, through: :affiliations belongs_to :city, optional: true - belongs_to :institution, optional: true belongs_to :academic_title_country, optional: true, class_name: "Country", diff --git a/config/application.rb b/config/application.rb index 38ce92cc..37750697 100644 --- a/config/application.rb +++ b/config/application.rb @@ -35,9 +35,11 @@ class Application < Rails::Application # config.autoload_paths += %W(#{config.root}/extras) config.autoload_paths << "#{config.root}/lib" + # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time] # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer diff --git a/db/migrate/20240524135850_create_affiliation.rb b/db/migrate/20240524135850_create_affiliation.rb new file mode 100644 index 00000000..00fa027e --- /dev/null +++ b/db/migrate/20240524135850_create_affiliation.rb @@ -0,0 +1,19 @@ +class CreateAffiliation < ActiveRecord::Migration[7.0] + def up + create_table :affiliations do |t| + t.belongs_to :professor, index: true + t.belongs_to :institution, index: true + t.boolean :active + t.datetime :start_date + t.datetime :end_date + + t.timestamps + end + remove_column :professors, :institution_id + end + def down + drop_table :affiliations + add_column :professors, :institution_id, :integer + add_index :professors, :institution_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 5fc78926..c8da40e3 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[7.0].define(version: 2024_01_18_203814) do +ActiveRecord::Schema[7.0].define(version: 2024_05_24_135850) do create_table "accomplishments", force: :cascade do |t| t.integer "enrollment_id" t.integer "phase_id" @@ -256,6 +256,18 @@ t.index ["professor_id"], name: "index_advisements_on_professor_id" end + create_table "affiliations", force: :cascade do |t| + t.integer "professor_id" + t.integer "institution_id" + t.boolean "active" + t.datetime "start_date" + t.datetime "end_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["institution_id"], name: "index_affiliations_on_institution_id" + t.index ["professor_id"], name: "index_affiliations_on_professor_id" + end + create_table "allocations", force: :cascade do |t| t.string "day", limit: 255 t.string "room", limit: 255 @@ -701,7 +713,6 @@ t.string "siape", limit: 255 t.string "enrollment_number", limit: 255 t.string "identity_issuing_place", limit: 255 - t.integer "institution_id" t.string "email", limit: 255 t.date "academic_title_date" t.integer "academic_title_country_id" @@ -715,7 +726,6 @@ t.index ["city_id"], name: "index_professors_on_city_id" t.index ["cpf"], name: "index_professors_on_cpf" t.index ["email"], name: "index_professors_on_email" - t.index ["institution_id"], name: "index_professors_on_institution_id" t.index ["user_id"], name: "index_professors_on_user_id" end diff --git a/spec/factories/factory_affiliation.rb b/spec/factories/factory_affiliation.rb new file mode 100644 index 00000000..1425f5b6 --- /dev/null +++ b/spec/factories/factory_affiliation.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :affiliation do + institution + professor + start_date { Time.now } + end_date { Time.now } + end +end diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb new file mode 100644 index 00000000..7ee5164d --- /dev/null +++ b/spec/models/affiliation_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Affiliation, type: :model do + it { should be_able_to_be_destroyed } + it { should belong_to(:institution) } + it { should belong_to(:professor) } +end diff --git a/spec/models/institution_spec.rb b/spec/models/institution_spec.rb index 1c2b82ce..a4dadad2 100644 --- a/spec/models/institution_spec.rb +++ b/spec/models/institution_spec.rb @@ -8,7 +8,8 @@ RSpec.describe Institution, type: :model do it { should be_able_to_be_destroyed } it { should have_many(:majors).dependent(:restrict_with_exception) } - it { should have_many(:professors).dependent(:restrict_with_exception) } + it { should have_many(:affiliations).dependent(:restrict_with_exception) } + it { should have_many(:professors).through(:affiliations) } let(:institution) { Institution.new(name: "instituicao") } subject { institution } diff --git a/spec/models/professor_spec.rb b/spec/models/professor_spec.rb index 44caffb3..2d77bf1a 100644 --- a/spec/models/professor_spec.rb +++ b/spec/models/professor_spec.rb @@ -16,7 +16,8 @@ it { should have_many(:course_classes).dependent(:restrict_with_exception) } it { should have_many(:thesis_defense_committee_participations).dependent(:restrict_with_exception) } it { should have_many(:thesis_defense_committee_enrollments).source(:enrollment).through(:thesis_defense_committee_participations) } - + it { should have_many(:affiliations).dependent(:restrict_with_exception) } + it { should have_many(:institutions).through(:affiliations) } before(:all) do @professor_role = FactoryBot.create :role_professor @destroy_later = [] @@ -35,13 +36,12 @@ name: "professor", email: "professor@ic.uff.br", enrollment_number: "P1", - ) + ) end subject { professor } describe "Validations" do it { should be_valid } it { should belong_to(:city).required(false) } - it { should belong_to(:institution).required(false) } it { should belong_to(:academic_title_country).required(false) } it { should belong_to(:academic_title_institution).required(false) } it { should belong_to(:academic_title_level).required(false) } From 57f60ce1ed5532e9e0e2d50417b7547d5b799784 Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Fri, 24 May 2024 13:22:07 -0300 Subject: [PATCH 02/32] ISSUE#448 - Add a link to affiliation at the professor controller, and adjustments on i18n --- app/controllers/affiliation_controller.rb | 27 +++++++++++++++++++++++ app/controllers/professors_controller.rb | 6 ++--- config/locales/affiliation.pt-BR.yml | 17 ++++++++++++++ config/locales/institution.pt-BR.yml | 1 + config/locales/professor.pt-BR.yml | 2 +- 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 app/controllers/affiliation_controller.rb create mode 100644 config/locales/affiliation.pt-BR.yml diff --git a/app/controllers/affiliation_controller.rb b/app/controllers/affiliation_controller.rb new file mode 100644 index 00000000..315e1b39 --- /dev/null +++ b/app/controllers/affiliation_controller.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class AffiliationController < ApplicationController + authorize_resource + + active_scaffold :affiliation do |config| + columns = [:professor, :institution, :start_date, :end_date, :active] + + config.list.columns = columns + config.create.columns = columns + config.update.columns = columns + config.show.columns = columns + + config.columns[:professor].form_ui = :record_select + config.columns[:institution].form_ui = :record_select + config.columns[:start_date].form_ui = :date_picker + config.columns[:active].form_ui = :radio_button + config.columns[:end_date].form_ui = :date_picker + + end + record_select( + per_page: 10, + search_on: [:name], + order_by: "name", + full_text_search: true + ) +end diff --git a/app/controllers/professors_controller.rb b/app/controllers/professors_controller.rb index 63054f84..9b9beaf2 100644 --- a/app/controllers/professors_controller.rb +++ b/app/controllers/professors_controller.rb @@ -29,7 +29,7 @@ class ProfessorsController < ApplicationController config.columns[:civil_status].options = { options: [["Solteiro(a)", "solteiro"], ["Casado(a)", "casado"]] } - config.columns[:institution].form_ui = :record_select + config.nested.add_link(:affiliations) config.columns[:sex].form_ui = :select config.columns[:sex].options = { options: [["Masculino", "M"], ["Feminino", "F"]] } @@ -54,9 +54,9 @@ class ProfessorsController < ApplicationController :address, :zip_code, :telephone1, :telephone2, :cpf, :identity_expedition_date, :identity_issuing_body, :identity_issuing_place, :identity_number, :enrollment_number, - :siape, :institution, :scholarships, :academic_title_level, + :siape, :scholarships, :academic_title_level, :academic_title_institution, :academic_title_country, - :academic_title_date, :obs, :professor_research_areas, + :academic_title_date, :obs, :professor_research_areas, :affiliations ] config.create.columns = form_columns diff --git a/config/locales/affiliation.pt-BR.yml b/config/locales/affiliation.pt-BR.yml new file mode 100644 index 00000000..f4a2db88 --- /dev/null +++ b/config/locales/affiliation.pt-BR.yml @@ -0,0 +1,17 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +pt-BR: + activerecord: + attributes: + affiliation: + institution: "Instituição" + professor: "Professor" + start_date: "Data de início" + end_date: "Data de fim" + active: "Ativo" + + models: + affiliation: + one: "Afiliação" + other: "Afiliações" \ No newline at end of file diff --git a/config/locales/institution.pt-BR.yml b/config/locales/institution.pt-BR.yml index 1cab52e2..b6fb5eda 100644 --- a/config/locales/institution.pt-BR.yml +++ b/config/locales/institution.pt-BR.yml @@ -8,6 +8,7 @@ pt-BR: code: "Sigla" majors: "Cursos" name: "Nome" + affiliations: "Afiliações" models: institution: diff --git a/config/locales/professor.pt-BR.yml b/config/locales/professor.pt-BR.yml index 7707c445..4a53c990 100644 --- a/config/locales/professor.pt-BR.yml +++ b/config/locales/professor.pt-BR.yml @@ -21,7 +21,7 @@ pt-BR: identity_issuing_body: "Órgão Expeditor" identity_issuing_place: "Local de Expedição" identity_number: "Número da identidade" - institution: "Instituição" + affiliations: "Afiliações" name: "Nome" neighborhood: "Bairro" professor_research_areas: "Áreas de Pesquisa" From 5907456da5a5ecd61ab2a4c8af9a564afcece925 Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Fri, 24 May 2024 16:08:34 -0300 Subject: [PATCH 03/32] ISSUE#448 - Little adjustments at affiliation controller and model --- app/controllers/affiliation_controller.rb | 3 +-- app/models/affiliation.rb | 4 ++++ spec/factories/factory_affiliation.rb | 1 + spec/models/affiliation_spec.rb | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/affiliation_controller.rb b/app/controllers/affiliation_controller.rb index 315e1b39..d987c8c4 100644 --- a/app/controllers/affiliation_controller.rb +++ b/app/controllers/affiliation_controller.rb @@ -14,9 +14,8 @@ class AffiliationController < ApplicationController config.columns[:professor].form_ui = :record_select config.columns[:institution].form_ui = :record_select config.columns[:start_date].form_ui = :date_picker - config.columns[:active].form_ui = :radio_button + config.columns[:active].form_ui = :checkbox config.columns[:end_date].form_ui = :date_picker - end record_select( per_page: 10, diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 4155cae5..54e930b0 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -6,4 +6,8 @@ class Affiliation < ApplicationRecord belongs_to :institution belongs_to :professor + validates :start_date, presence: true + validates :end_date, presence: true, unless: :active? + validates :active, presence: true, inclusion: { in: [true, false]} + end diff --git a/spec/factories/factory_affiliation.rb b/spec/factories/factory_affiliation.rb index 1425f5b6..bb3693d7 100644 --- a/spec/factories/factory_affiliation.rb +++ b/spec/factories/factory_affiliation.rb @@ -6,5 +6,6 @@ professor start_date { Time.now } end_date { Time.now } + active { true } end end diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb index 7ee5164d..1871cb70 100644 --- a/spec/models/affiliation_spec.rb +++ b/spec/models/affiliation_spec.rb @@ -6,4 +6,12 @@ it { should be_able_to_be_destroyed } it { should belong_to(:institution) } it { should belong_to(:professor) } + let(:affiliation) { FactoryBot.create :affiliation } + + subject { affiliation } + context "Validation" do + it { should be_valid } + it { should validate_presence_of(:active) } + it { should validate_presence_of(:start_date) } + end end From 8375ed1ee4d427fe756ad70ff581496e46f0fe05 Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Fri, 24 May 2024 17:28:14 -0300 Subject: [PATCH 04/32] ISSUE#448 - Validation tests --- app/controllers/affiliation_controller.rb | 18 ++++++++++ app/models/affiliation.rb | 2 +- spec/models/affiliation_spec.rb | 40 ++++++++++++++++++++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/app/controllers/affiliation_controller.rb b/app/controllers/affiliation_controller.rb index d987c8c4..08f3187c 100644 --- a/app/controllers/affiliation_controller.rb +++ b/app/controllers/affiliation_controller.rb @@ -23,4 +23,22 @@ class AffiliationController < ApplicationController order_by: "name", full_text_search: true ) + + def populate + professor_versions = PaperTrail::Version.where(item_type: "Professor") + + professor_versions.each do |version| + professor = version.reify + if version.event == "create" + Affiliation.create( + professor_id: professor.id, + institution_id: professor.institution_id, + start_date: version.created_at, + active: true + ) + else + + end + end + end end diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 54e930b0..6064998a 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -8,6 +8,6 @@ class Affiliation < ApplicationRecord validates :start_date, presence: true validates :end_date, presence: true, unless: :active? - validates :active, presence: true, inclusion: { in: [true, false]} + validates_uniqueness_of :active, if: :active?, scope: [:professor_id], message: "Apenas uma afiliação pode estar ativa por professor." end diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb index 1871cb70..2367a165 100644 --- a/spec/models/affiliation_spec.rb +++ b/spec/models/affiliation_spec.rb @@ -8,10 +8,48 @@ it { should belong_to(:professor) } let(:affiliation) { FactoryBot.create :affiliation } + subject { affiliation } context "Validation" do it { should be_valid } - it { should validate_presence_of(:active) } it { should validate_presence_of(:start_date) } + context "Active" do + let(:professor) { FactoryBot.create :professor} + let(:affiliation_active) { FactoryBot.create :affiliation, professor: professor, active: true} + let(:affiliation_inactive) { FactoryBot.create :affiliation, professor: professor, active: false} + let(:affiliation_teste_active) { FactoryBot.build :affiliation, professor: professor, active: true} + let(:affiliation_teste_inactive) { FactoryBot.build :affiliation, professor: professor, active: false} + + it "When active, do not add new affiliation active" do + affiliation_active + aff = FactoryBot.build(:affiliation, professor: professor, active: true) + expect(aff).to_not be_valid + end + context "When inactive, you can add new affiliation active/inactive" do + before do + affiliation_inactive + end + it { expect(affiliation_teste_active).to be_valid } + it { expect(affiliation_teste_inactive).to be_valid } + end + it "when inactive, you can add multiple affiliation" do + affiliation_inactive + expect(affiliation_inactive).to be_valid + affiliation_teste_inactive.save! + expect(Affiliation.all.count).to be_eql(2) + end + end + context "Active e End Date" do + let(:affiliation_active) { FactoryBot.create :affiliation, end_date: nil, active: true } + let(:affiliation_inactive_valid) { FactoryBot.create :affiliation, end_date: Time.now, active: false } + let(:affiliation_inactive_invalid) { FactoryBot.build :affiliation, end_date: nil, active: false } + context "When active, don't need end date" do + it { expect(affiliation_active).to be_valid } + end + context "When inactive, need an end date" do + it { expect(affiliation_inactive_valid).to be_valid } + it { expect(affiliation_inactive_invalid).to be_invalid } + end + end end end From 871875500ff955ec6bbfbcb2b11525e599dc5382 Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Fri, 24 May 2024 17:34:43 -0300 Subject: [PATCH 05/32] ISSUE#448 - Validation tests --- spec/models/affiliation_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb index 2367a165..95ec7ae5 100644 --- a/spec/models/affiliation_spec.rb +++ b/spec/models/affiliation_spec.rb @@ -23,7 +23,7 @@ it "When active, do not add new affiliation active" do affiliation_active aff = FactoryBot.build(:affiliation, professor: professor, active: true) - expect(aff).to_not be_valid + expect(aff).to be_invalid end context "When inactive, you can add new affiliation active/inactive" do before do From e4ac55de71f2733c81f92a94bba60322465fcf71 Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Mon, 27 May 2024 09:13:50 -0300 Subject: [PATCH 06/32] ISSUE #448 - Adds affiliation population logic based on old professor versions --- app/controllers/affiliation_controller.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/affiliation_controller.rb b/app/controllers/affiliation_controller.rb index 08f3187c..f956a3ae 100644 --- a/app/controllers/affiliation_controller.rb +++ b/app/controllers/affiliation_controller.rb @@ -26,18 +26,28 @@ class AffiliationController < ApplicationController def populate professor_versions = PaperTrail::Version.where(item_type: "Professor") - professor_versions.each do |version| professor = version.reify - if version.event == "create" + if version.event.eql?("create") Affiliation.create( professor_id: professor.id, institution_id: professor.institution_id, start_date: version.created_at, active: true ) - else - + elsif version.event.eql?("update") && + Affiliation.where(professor_id: professor.id, institution_id: professor.institution_id).blank? + aff = Affiliation.where(professor_id: professor.id).last + aff.update(end_date: version.created_at, active: false) + Affiliation.create( + professor_id: professor.id, + institution_id: professor.institution_id, + start_date: version.created_at, + active: true + ) + elsif version.event.eql?("destroy") + aff = Affiliation.where(professor_id: professor.id, institution_id: professor.institution_id).last + aff.update(end_date: version.created_at, active: false) end end end From 877dda7587d85a2e846b3d89fa9cc95ff2bc84af Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Mon, 27 May 2024 09:14:00 -0300 Subject: [PATCH 07/32] ISSUE #448 - Adds affiliation population logic based on old professor versions --- spec/controllers/affiliation_controller_spec_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 spec/controllers/affiliation_controller_spec_spec.rb diff --git a/spec/controllers/affiliation_controller_spec_spec.rb b/spec/controllers/affiliation_controller_spec_spec.rb new file mode 100644 index 00000000..d4f18700 --- /dev/null +++ b/spec/controllers/affiliation_controller_spec_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "spec_helper" + + +RSpec.describe "AffiliationControllerSpec" do + + context "Populate" do + + end +end From c7e4038c01060a593ff6bb8b136d06f19204a206 Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Mon, 27 May 2024 09:21:11 -0300 Subject: [PATCH 08/32] ISSUE #448 - Refactoring populate code --- app/controllers/affiliation_controller.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/affiliation_controller.rb b/app/controllers/affiliation_controller.rb index f956a3ae..7af78aba 100644 --- a/app/controllers/affiliation_controller.rb +++ b/app/controllers/affiliation_controller.rb @@ -29,25 +29,31 @@ def populate professor_versions.each do |version| professor = version.reify if version.event.eql?("create") + Affiliation.create( professor_id: professor.id, institution_id: professor.institution_id, start_date: version.created_at, active: true ) - elsif version.event.eql?("update") && - Affiliation.where(professor_id: professor.id, institution_id: professor.institution_id).blank? - aff = Affiliation.where(professor_id: professor.id).last - aff.update(end_date: version.created_at, active: false) + + elsif version.event.eql?("update") && Affiliation.where(professor_id: professor.id, institution_id: professor.institution_id)&.blank? + + Affiliation.where(professor_id: professor.id)&.last&.update(end_date: version.created_at, active: false) Affiliation.create( professor_id: professor.id, institution_id: professor.institution_id, start_date: version.created_at, active: true ) + elsif version.event.eql?("destroy") - aff = Affiliation.where(professor_id: professor.id, institution_id: professor.institution_id).last - aff.update(end_date: version.created_at, active: false) + + Affiliation.where(professor_id: professor.id, institution_id: professor.institution_id)&.last&.update( + end_date: version.created_at, + active: false + ) + end end end From d23f4e644641ffa3fd7e5c9465dff86f8291e380 Mon Sep 17 00:00:00 2001 From: Igor Monardez Date: Mon, 27 May 2024 17:28:52 -0300 Subject: [PATCH 09/32] ISSUE #448 - Add repopulation logic to ProgramLevel, and adjustments of enrollments pdf --- app/helpers/enrollments_pdf_helper.rb | 6 +- app/models/affiliation.rb | 1 + app/models/custom_variable.rb | 1 - app/models/program_level.rb | 13 ++++ .../20240527174758_create_program_level.rb | 68 +++++++++++++++++++ 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 app/models/program_level.rb create mode 100644 db/migrate/20240527174758_create_program_level.rb diff --git a/app/helpers/enrollments_pdf_helper.rb b/app/helpers/enrollments_pdf_helper.rb index b737bd8c..fee86597 100644 --- a/app/helpers/enrollments_pdf_helper.rb +++ b/app/helpers/enrollments_pdf_helper.rb @@ -614,10 +614,14 @@ def thesis_table(curr_pdf, options = {}) data_table_rows_defense_committee += [[ "#{I18n.t("pdf_content.enrollment.thesis.defense_committee")} " ]] + # TODO: modificar o institution para a affiliation thesis_desense_committee.each do |professor| + affiliation = Affiliation.where(professor_id: professor.id) + .where("start_date <= #{thesis_defense_date} AND (end_date >= #{thesis_defense_date} OR active = true)") + data_table_rows_defense_committee += [[ "#{professor.name} / #{rescue_blank_text( - professor.institution, method_call: :name + affiliation.institution, method_call: :name )}" ]] end diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 6064998a..3d6dfac3 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -7,6 +7,7 @@ class Affiliation < ApplicationRecord belongs_to :professor validates :start_date, presence: true + validates :level, presence: true validates :end_date, presence: true, unless: :active? validates_uniqueness_of :active, if: :active?, scope: [:professor_id], message: "Apenas uma afiliação pode estar ativa por professor." diff --git a/app/models/custom_variable.rb b/app/models/custom_variable.rb index ce95da97..27f5089f 100644 --- a/app/models/custom_variable.rb +++ b/app/models/custom_variable.rb @@ -10,7 +10,6 @@ class CustomVariable < ApplicationRecord VARIABLES = { "single_advisor_points" => :text, "multiple_advisor_points" => :text, - "program_level" => :text, "identity_issuing_country" => :text, "class_schedule_text" => :text, "redirect_email" => :text, diff --git a/app/models/program_level.rb b/app/models/program_level.rb new file mode 100644 index 00000000..2a3c5798 --- /dev/null +++ b/app/models/program_level.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ProgramLevel < ApplicationRecord + has_paper_trail + validates :level, presence: true, on: [:create, :update] + validates :start_date, presence: true, on: [:create, :update] + validates :end_date, presence: true, unless: :active?, on: [:create, :update] + validates_uniqueness_of :active, if: :active?, on: [:create, :update] + + def active? + active + end +end diff --git a/db/migrate/20240527174758_create_program_level.rb b/db/migrate/20240527174758_create_program_level.rb new file mode 100644 index 00000000..67530e9c --- /dev/null +++ b/db/migrate/20240527174758_create_program_level.rb @@ -0,0 +1,68 @@ +class CreateProgramLevel < ActiveRecord::Migration[7.0] + def up + create_table :program_levels do |t| + t.integer :level, null: false + t.datetime :start_date, null: false + t.datetime :end_date + t.boolean :active, null: false + + t.timestamps + end + CustomVariable.where(variable: "program_level").each do |pl| + ProgramLevel.create( + level: pl.value, + start_date: pl.updated_at, + active: true + ) + date = pl.updated_at + until pl.nil? do + pl = pl.paper_trail.previous_version + ProgramLevel.create( + level: pl&.value, + start_date: pl&.created_at, + end_date: date, + active: false + ) + end + end + cvs = PaperTrail::Version.where(item_type: "CustomVariable") + cvs.each do |c| + next unless c&.object&.variable.eql?("program_level") + + program_level = c&.object + if c&.event.eql?("create") && !program_level.in?(CustomVariable.all) + ProgramLevel.create( + level: program_level&.value, + start_date: c.updated_at, + active: true + ) + + elsif c.event.eql?("update") && !program_level&.previous_version.eql?(program_level) + ProgramLevel.last.update( + active: false, + end_date: c.created_at + ) + ProgramLevel.create( + level: program_level&.value, + start_date: c.created_at, + active: true + ) + elsif c.event.eql?("destroy") + ProgramLevel.last.update( + active: false, + end_date: c.created_at + ) + end + + end + end + def down + ProgramLevel.each do |pl| + CustomVariable.create( + variable: "program_level", + value: pl.level + ) + end + drop_table :program_levels + end +end From 89f1a9632f7ff40748e7331ead2847207d8f94e4 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Mon, 3 Jun 2024 12:21:49 -0300 Subject: [PATCH 10/32] ISSUE #448 - Add populate algorithm to ProgramLevel and Affiliation --- .../20240524135850_create_affiliation.rb | 39 +++++++++++ .../20240527174758_create_program_level.rb | 65 +++++++------------ db/schema.rb | 11 +++- 3 files changed, 72 insertions(+), 43 deletions(-) diff --git a/db/migrate/20240524135850_create_affiliation.rb b/db/migrate/20240524135850_create_affiliation.rb index 00fa027e..625288e5 100644 --- a/db/migrate/20240524135850_create_affiliation.rb +++ b/db/migrate/20240524135850_create_affiliation.rb @@ -9,6 +9,45 @@ def up t.timestamps end + Professor.all.each do |p| + start_date = p.updated_at + end_date = nil + institution_id = p.institution_id + institutions = [] + affiliation = Affiliation.create( + professor: p, + institution_id: institution_id, + start_date: start_date, + active: true + ) + professor = professor.paper_trail.previous_version + while professor.present? + if professor.institution_id != institution_id + if institution_id.present? # Não armazena afiliação em branco + institutions << { institution_id:, start_date:, end_date: } + end + end_date = start_date + start_date = professor.updated_at + institution_id = professor.institution_id + affiliation = Affiliation.create( + professor: p, + institution_id: institution_id, + start_date: start_date, + active: false, + end_date: end_date + ) + else + # Atualiza data de início para data da primeira mudança em que instituição foi definida com esse valor + start_date = professor.updated_at + affiliation.update(start_date: start_date) + end + professor = professor.paper_trail.previous_version + end + if institution_id.present? # Não armazena afiliação em branco + institutions << { institution_id:, start_date:, end_date: } + end + end + remove_column :professors, :institution_id end def down diff --git a/db/migrate/20240527174758_create_program_level.rb b/db/migrate/20240527174758_create_program_level.rb index 67530e9c..a218b3b1 100644 --- a/db/migrate/20240527174758_create_program_level.rb +++ b/db/migrate/20240527174758_create_program_level.rb @@ -9,58 +9,39 @@ def up t.timestamps end CustomVariable.where(variable: "program_level").each do |pl| - ProgramLevel.create( + level = pl.value + program_level = ProgramLevel.create( level: pl.value, start_date: pl.updated_at, active: true ) - date = pl.updated_at - until pl.nil? do - pl = pl.paper_trail.previous_version - ProgramLevel.create( - level: pl&.value, - start_date: pl&.created_at, - end_date: date, - active: false - ) + pl = pl.paper_trail.previous_version + while pl.present? + binding.pry + if pl.value != level + end_date = start_date + start_date = pl.updated_at + level = pl.value + program_level = ProgramLevel.create( + level: level, + end_date: end_date, + start_date: start_date, + active: false + ) + else + start_date = pl.updated_at + program_level.update(start_date: start_date) + end + pl.paper_trail.previous_version end end - cvs = PaperTrail::Version.where(item_type: "CustomVariable") - cvs.each do |c| - next unless c&.object&.variable.eql?("program_level") - - program_level = c&.object - if c&.event.eql?("create") && !program_level.in?(CustomVariable.all) - ProgramLevel.create( - level: program_level&.value, - start_date: c.updated_at, - active: true - ) - - elsif c.event.eql?("update") && !program_level&.previous_version.eql?(program_level) - ProgramLevel.last.update( - active: false, - end_date: c.created_at - ) - ProgramLevel.create( - level: program_level&.value, - start_date: c.created_at, - active: true - ) - elsif c.event.eql?("destroy") - ProgramLevel.last.update( - active: false, - end_date: c.created_at - ) - end - - end + CustomVariable.where(variable: "program_level").destroy_all end def down - ProgramLevel.each do |pl| + ProgramLevel.all.each do |pl| CustomVariable.create( variable: "program_level", - value: pl.level + value: pl.level, ) end drop_table :program_levels diff --git a/db/schema.rb b/db/schema.rb index c8da40e3..3fabffe0 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[7.0].define(version: 2024_05_24_135850) do +ActiveRecord::Schema[7.0].define(version: 2024_05_27_174758) do create_table "accomplishments", force: :cascade do |t| t.integer "enrollment_id" t.integer "phase_id" @@ -729,6 +729,15 @@ t.index ["user_id"], name: "index_professors_on_user_id" end + create_table "program_levels", force: :cascade do |t| + t.integer "level", null: false + t.datetime "start_date", null: false + t.datetime "end_date" + t.boolean "active", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "queries", force: :cascade do |t| t.string "name", limit: 255 t.text "sql" From 1cdaa045e8a376952d10861103cfa63f015ef86b Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 4 Jun 2024 10:38:17 -0300 Subject: [PATCH 11/32] ISSUE #448 - Fixes tests --- .../enrollments/_show_defense_committee_table.html.erb | 4 ++-- config/locales/professor.pt-BR.yml | 3 +++ spec/features/student_enrollment_spec.rb | 7 +++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/views/enrollments/_show_defense_committee_table.html.erb b/app/views/enrollments/_show_defense_committee_table.html.erb index 37bd476b..03fd8652 100644 --- a/app/views/enrollments/_show_defense_committee_table.html.erb +++ b/app/views/enrollments/_show_defense_committee_table.html.erb @@ -2,7 +2,7 @@ <%= I18n.t("activerecord.attributes.professor.name") %> - <%= I18n.t("activerecord.attributes.professor.institution") %> + <%= I18n.t("activerecord.attributes.professor.institution.one") %> @@ -12,7 +12,7 @@ <% tr_class = count.even? ? "even-record" : "" %> <%= professor.name %> - <%= rescue_blank_text(professor.institution, method_call: :name) %> + <%= rescue_blank_text(professor.affiliations.where(active: true).last, method_call: :name) %> <% end %> diff --git a/config/locales/professor.pt-BR.yml b/config/locales/professor.pt-BR.yml index 4a53c990..29a06c91 100644 --- a/config/locales/professor.pt-BR.yml +++ b/config/locales/professor.pt-BR.yml @@ -22,6 +22,9 @@ pt-BR: identity_issuing_place: "Local de Expedição" identity_number: "Número da identidade" affiliations: "Afiliações" + institution: + one: "Instituição" + other: "Instituições" name: "Nome" neighborhood: "Bairro" professor_research_areas: "Áreas de Pesquisa" diff --git a/spec/features/student_enrollment_spec.rb b/spec/features/student_enrollment_spec.rb index db72a664..b4988261 100644 --- a/spec/features/student_enrollment_spec.rb +++ b/spec/features/student_enrollment_spec.rb @@ -5,7 +5,7 @@ require "spec_helper" -RSpec.describe "StudentEnrollment features", type: :feature do +RSpec.describe "StudentEnrollment features", type: :feature, js: true do let(:url_path) { "/pendencies" } before(:all) do @destroy_later = [] @@ -459,9 +459,8 @@ it "should show the proper allocations" do # Two allocations in the same day - expect(page.all(".enroll-table tbody tr:nth-of-type(1) td.cell-segunda").map(&:text)).to eq [ - "11-13 14-16" - ] + expect(page.all(".enroll-table tbody tr:nth-of-type(1) td.cell-segunda").map(&:text)).to have_text "11-13" + expect(page.all(".enroll-table tbody tr:nth-of-type(1) td.cell-segunda").map(&:text)).to have_text "14-16" # No allocations for class expect(page.all(".enroll-table tbody tr:nth-of-type(2) td.cell-segunda").map(&:text)).to eq [ "*" From 359f072cf9d9e9ca6b8d6fe471db2cc43b78d3c2 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 4 Jun 2024 11:52:20 -0300 Subject: [PATCH 12/32] =?UTF-8?q?ISSUE=20#448=20-=20Modfica=C3=A7=C3=B5es?= =?UTF-8?q?=20nos=20dados=20do=20pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/enrollments_pdf_helper.rb | 6 ++---- app/models/affiliation.rb | 10 +++++++++- app/models/custom_variable.rb | 5 ----- app/models/program_level.rb | 4 ++++ config/routes.rb | 4 ++++ spec/features/professors_spec.rb | 1 + spec/models/custom_variable_spec.rb | 17 ----------------- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/app/helpers/enrollments_pdf_helper.rb b/app/helpers/enrollments_pdf_helper.rb index fee86597..b3c159c5 100644 --- a/app/helpers/enrollments_pdf_helper.rb +++ b/app/helpers/enrollments_pdf_helper.rb @@ -137,7 +137,7 @@ def enrollment_header(pdf, options = {}) pdf.line_width 0.5 common_header_part1(pdf, enrollment, [ - "#{i18n_eht(:program_level)} #{CustomVariable.program_level} " + "#{i18n_eht(:program_level)} #{ProgramLevel.date(enrollment.thesis_defense_date)&.level}" ]) common_header_part(pdf) do @@ -616,9 +616,7 @@ def thesis_table(curr_pdf, options = {}) ]] # TODO: modificar o institution para a affiliation thesis_desense_committee.each do |professor| - affiliation = Affiliation.where(professor_id: professor.id) - .where("start_date <= #{thesis_defense_date} AND (end_date >= #{thesis_defense_date} OR active = true)") - + affiliation = Affiliation.where(professor_id: professor.id).date(thesis_defense_date) data_table_rows_defense_committee += [[ "#{professor.name} / #{rescue_blank_text( affiliation.institution, method_call: :name diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 3d6dfac3..248cad9f 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -7,8 +7,16 @@ class Affiliation < ApplicationRecord belongs_to :professor validates :start_date, presence: true - validates :level, presence: true + validates :active, presence: true validates :end_date, presence: true, unless: :active? validates_uniqueness_of :active, if: :active?, scope: [:professor_id], message: "Apenas uma afiliação pode estar ativa por professor." + + def active? + active + end + + def date(instant_date) + Affiliation.where("start_date <= #{instant_date} AND (end_date >= #{instant_date} OR #{active?})")&.last + end end diff --git a/app/models/custom_variable.rb b/app/models/custom_variable.rb index 27f5089f..e7c6a6d3 100644 --- a/app/models/custom_variable.rb +++ b/app/models/custom_variable.rb @@ -38,11 +38,6 @@ def self.multiple_advisor_points config.blank? ? 0.5 : config.value.to_f end - def self.program_level - config = CustomVariable.find_by_variable(:program_level) - config.blank? ? nil : config.value.to_i - end - def self.identity_issuing_country config = CustomVariable.find_by_variable(:identity_issuing_country) config.blank? ? "" : config.value diff --git a/app/models/program_level.rb b/app/models/program_level.rb index 2a3c5798..646df121 100644 --- a/app/models/program_level.rb +++ b/app/models/program_level.rb @@ -10,4 +10,8 @@ class ProgramLevel < ApplicationRecord def active? active end + + def date(instant_date) + ProgramLevel.where("start_date <= #{instant_date} AND (end_date >= #{instant_date} OR #{active?})")&.last + end end diff --git a/config/routes.rb b/config/routes.rb index 8eaf23eb..ea20ce0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -160,6 +160,10 @@ end end + resources :affiliation do + concerns :active_scaffold + end + resources :professors do concerns :active_scaffold record_select_routes diff --git a/spec/features/professors_spec.rb b/spec/features/professors_spec.rb index 7afe7bd6..efbe4f94 100644 --- a/spec/features/professors_spec.rb +++ b/spec/features/professors_spec.rb @@ -74,6 +74,7 @@ fill_in "CPF", with: "1" end click_button "Salvar" + binding.pry expect(page).to have_css("tr:nth-child(1) td.name-column", text: "Ana") # Remove inserted record diff --git a/spec/models/custom_variable_spec.rb b/spec/models/custom_variable_spec.rb index bbfb18c5..7f7f0237 100644 --- a/spec/models/custom_variable_spec.rb +++ b/spec/models/custom_variable_spec.rb @@ -60,23 +60,6 @@ end end - context "program_level" do - it "should return nil when there is no variable defined" do - config = CustomVariable.find_by_variable(:program_level) - config.delete unless config.nil? - - expect(CustomVariable.program_level).to eq(nil) - end - - it "should return 5 when it is defined to 5" do - config = CustomVariable.find_by_variable(:program_level) - config.delete unless config.nil? - @destroy_later << CustomVariable.create(variable: :program_level, value: "5") - - expect(CustomVariable.program_level).to eq(5) - end - end - context "identity_issuing_country" do it "should return '' when there is no variable defined" do config = CustomVariable.find_by_variable(:identity_issuing_country) From cade02bc9bfe3610f68379fae80b2fb49a1e9ba7 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 4 Jun 2024 21:57:23 -0300 Subject: [PATCH 13/32] ISSUE #448 - Changes at validation --- Gemfile | 6 +++- app/controllers/affiliation_controller.rb | 34 ----------------------- app/models/affiliation.rb | 14 +++++++--- app/models/institution.rb | 2 +- app/models/professor.rb | 4 +-- spec/features/professors_spec.rb | 2 +- 6 files changed, 19 insertions(+), 43 deletions(-) diff --git a/Gemfile b/Gemfile index 6035ab20..a8b27d27 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem "sprockets-rails" gem "puma", ">= 6.4.2" # HTML and XML parser -gem "nokogiri", ">= 1.16.2" +gem "nokogiri", ">= 1.16.5" #Wrapp HTTP requests and responses gem "rack", "~> 2.2.8.1" @@ -28,6 +28,10 @@ gem "rack", "~> 2.2.8.1" # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] # gem "importmap-rails" +# Fix vulnerability +gem "actiontext", ">= 7.0.8.4" +gem "rexml", ">= 3.2.7" + # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] # gem "turbo-rails" diff --git a/app/controllers/affiliation_controller.rb b/app/controllers/affiliation_controller.rb index 7af78aba..d987c8c4 100644 --- a/app/controllers/affiliation_controller.rb +++ b/app/controllers/affiliation_controller.rb @@ -23,38 +23,4 @@ class AffiliationController < ApplicationController order_by: "name", full_text_search: true ) - - def populate - professor_versions = PaperTrail::Version.where(item_type: "Professor") - professor_versions.each do |version| - professor = version.reify - if version.event.eql?("create") - - Affiliation.create( - professor_id: professor.id, - institution_id: professor.institution_id, - start_date: version.created_at, - active: true - ) - - elsif version.event.eql?("update") && Affiliation.where(professor_id: professor.id, institution_id: professor.institution_id)&.blank? - - Affiliation.where(professor_id: professor.id)&.last&.update(end_date: version.created_at, active: false) - Affiliation.create( - professor_id: professor.id, - institution_id: professor.institution_id, - start_date: version.created_at, - active: true - ) - - elsif version.event.eql?("destroy") - - Affiliation.where(professor_id: professor.id, institution_id: professor.institution_id)&.last&.update( - end_date: version.created_at, - active: false - ) - - end - end - end end diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 248cad9f..211ba36d 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -3,12 +3,13 @@ class Affiliation < ApplicationRecord has_paper_trail - belongs_to :institution - belongs_to :professor + before_save :set_active_default + + belongs_to :institution, optional: true + belongs_to :professor, optional: true validates :start_date, presence: true - validates :active, presence: true - validates :end_date, presence: true, unless: :active? + validates :end_date, presence: true, if: :active? validates_uniqueness_of :active, if: :active?, scope: [:professor_id], message: "Apenas uma afiliação pode estar ativa por professor." @@ -19,4 +20,9 @@ def active? def date(instant_date) Affiliation.where("start_date <= #{instant_date} AND (end_date >= #{instant_date} OR #{active?})")&.last end + + private + def set_active_default + self.active = false if active.nil? + end end diff --git a/app/models/institution.rb b/app/models/institution.rb index c8459c02..c4664682 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -8,7 +8,7 @@ class Institution < ApplicationRecord has_paper_trail has_many :majors, dependent: :restrict_with_exception - has_many :affiliations, dependent: :restrict_with_exception + has_many :affiliations, dependent: :destroy has_many :professors, through: :affiliations diff --git a/app/models/professor.rb b/app/models/professor.rb index a12a8ab4..b1f85bef 100644 --- a/app/models/professor.rb +++ b/app/models/professor.rb @@ -18,8 +18,8 @@ class Professor < ApplicationRecord dependent: :restrict_with_exception has_many :thesis_defense_committee_enrollments, source: :enrollment, through: :thesis_defense_committee_participations - has_many :affiliations, dependent: :restrict_with_exception - has_many :institutions, through: :affiliations + has_many :affiliations, dependent: :nullify + has_many :institutions, through: :affiliations, dependent: :nullify belongs_to :city, optional: true belongs_to :academic_title_country, diff --git a/spec/features/professors_spec.rb b/spec/features/professors_spec.rb index efbe4f94..d4680fef 100644 --- a/spec/features/professors_spec.rb +++ b/spec/features/professors_spec.rb @@ -74,7 +74,6 @@ fill_in "CPF", with: "1" end click_button "Salvar" - binding.pry expect(page).to have_css("tr:nth-child(1) td.name-column", text: "Ana") # Remove inserted record @@ -133,6 +132,7 @@ fill_in "Nome", with: "teste" fill_in "CPF", with: "9" end + binding.pry click_button "Atualizar" expect(page).to have_css("td.name-column", text: "teste") expect(page).to have_css("td.cpf-column", text: "9") From ce3358faa521f5a168a079c1eaccceafc27e19d3 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Wed, 5 Jun 2024 16:54:12 -0300 Subject: [PATCH 14/32] ISSUE #448 - Changes at academic_transcript_pdf switching to data from affiliation and program_level --- app/controllers/concerns/shared_pdf_concern.rb | 3 ++- app/helpers/enrollments_pdf_helper.rb | 7 ++++--- app/models/affiliation.rb | 11 ++++++----- app/models/institution.rb | 2 +- app/models/professor.rb | 5 +++-- app/models/program_level.rb | 6 ++---- .../academic_transcript_pdf.pdf.prawn | 2 +- .../20240524135850_create_affiliation.rb | 18 ++++++++++-------- .../20240527174758_create_program_level.rb | 4 ++-- db/schema.rb | 8 ++++---- spec/models/affiliation_spec.rb | 4 ++-- spec/models/institution_spec.rb | 2 +- spec/models/professor_spec.rb | 4 ++-- 13 files changed, 40 insertions(+), 36 deletions(-) diff --git a/app/controllers/concerns/shared_pdf_concern.rb b/app/controllers/concerns/shared_pdf_concern.rb index 12b51ee3..7d576ba4 100644 --- a/app/controllers/concerns/shared_pdf_concern.rb +++ b/app/controllers/concerns/shared_pdf_concern.rb @@ -41,7 +41,7 @@ def render_enrollments_academic_transcript_pdf(enrollment) .order("course_classes.year", "course_classes.semester") accomplished_phases = enrollment.accomplishments.order(:conclusion_date) - + program_level = ProgramLevel.date(enrollment.thesis_defense_date).last render_to_string( template: "enrollments/academic_transcript_pdf", type: "application/pdf", @@ -50,6 +50,7 @@ def render_enrollments_academic_transcript_pdf(enrollment) enrollment: enrollment, class_enrollments: class_enrollments, accomplished_phases: accomplished_phases, + program_level: program_level } ) end diff --git a/app/helpers/enrollments_pdf_helper.rb b/app/helpers/enrollments_pdf_helper.rb index b3c159c5..8390aa24 100644 --- a/app/helpers/enrollments_pdf_helper.rb +++ b/app/helpers/enrollments_pdf_helper.rb @@ -132,12 +132,12 @@ def grades_report_header(pdf, options = {}) def enrollment_header(pdf, options = {}) enrollment ||= options[:enrollment] + program_level ||= options[:program_level] pdf.bounding_box([0, pdf.cursor - 3], width: 560) do pdf.font("FreeMono", size: 8) do pdf.line_width 0.5 - common_header_part1(pdf, enrollment, [ - "#{i18n_eht(:program_level)} #{ProgramLevel.date(enrollment.thesis_defense_date)&.level}" + "#{i18n_eht(:program_level)} #{program_level.level}" ]) common_header_part(pdf) do @@ -616,7 +616,8 @@ def thesis_table(curr_pdf, options = {}) ]] # TODO: modificar o institution para a affiliation thesis_desense_committee.each do |professor| - affiliation = Affiliation.where(professor_id: professor.id).date(thesis_defense_date) + affiliation = professor.affiliations.date(thesis_defense_date).last + binding.pry data_table_rows_defense_committee += [[ "#{professor.name} / #{rescue_blank_text( affiliation.institution, method_call: :name diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 211ba36d..fb9afa4b 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -9,18 +9,19 @@ class Affiliation < ApplicationRecord belongs_to :professor, optional: true validates :start_date, presence: true - validates :end_date, presence: true, if: :active? + validates :end_date, presence: true, unless: :active? + validates :end_date, presence: false, if: :active? + validates_uniqueness_of :active, if: :active?, scope: [:professor_id], message: "Apenas uma afiliação pode estar ativa por professor." + scope :date, ->(date) { where("start_date <= ? AND (end_date > ? OR active IS TRUE)", date, date) } + scope :professor, ->(professor) { where(professor_id: professor.id) } + scope :date_professor, ->(professor, date) { professor(professor).date(date) } def active? active end - def date(instant_date) - Affiliation.where("start_date <= #{instant_date} AND (end_date >= #{instant_date} OR #{active?})")&.last - end - private def set_active_default self.active = false if active.nil? diff --git a/app/models/institution.rb b/app/models/institution.rb index c4664682..6e894638 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -9,7 +9,7 @@ class Institution < ApplicationRecord has_many :majors, dependent: :restrict_with_exception has_many :affiliations, dependent: :destroy - has_many :professors, through: :affiliations + has_many :professors, through: :affiliations, dependent: :destroy validates :name, presence: true, uniqueness: true diff --git a/app/models/professor.rb b/app/models/professor.rb index b1f85bef..4fd7671d 100644 --- a/app/models/professor.rb +++ b/app/models/professor.rb @@ -18,8 +18,9 @@ class Professor < ApplicationRecord dependent: :restrict_with_exception has_many :thesis_defense_committee_enrollments, source: :enrollment, through: :thesis_defense_committee_participations - has_many :affiliations, dependent: :nullify - has_many :institutions, through: :affiliations, dependent: :nullify + has_many :affiliations, dependent: :restrict_with_exception + has_many :institutions, through: :affiliations, dependent: :restrict_with_exception + accepts_nested_attributes_for :affiliations, allow_destroy: true, reject_if: :all_blank belongs_to :city, optional: true belongs_to :academic_title_country, diff --git a/app/models/program_level.rb b/app/models/program_level.rb index 646df121..e2e84017 100644 --- a/app/models/program_level.rb +++ b/app/models/program_level.rb @@ -7,11 +7,9 @@ class ProgramLevel < ApplicationRecord validates :end_date, presence: true, unless: :active?, on: [:create, :update] validates_uniqueness_of :active, if: :active?, on: [:create, :update] + scope :date, -> (date) { where("program_levels.start_date <= ? AND program_levels.end_date > ? OR program_levels.active is true", date, date)} + def active? active end - - def date(instant_date) - ProgramLevel.where("start_date <= #{instant_date} AND (end_date >= #{instant_date} OR #{active?})")&.last - end end diff --git a/app/views/enrollments/academic_transcript_pdf.pdf.prawn b/app/views/enrollments/academic_transcript_pdf.pdf.prawn index c0f7ac6e..b590fe8c 100644 --- a/app/views/enrollments/academic_transcript_pdf.pdf.prawn +++ b/app/views/enrollments/academic_transcript_pdf.pdf.prawn @@ -15,7 +15,7 @@ new_document( ) do |pdf| enrollment_student_header(pdf, enrollment: @enrollment) - enrollment_header(pdf, enrollment: @enrollment) + enrollment_header(pdf, enrollment: @enrollment, program_level: @program_level) transcript_table(pdf, class_enrollments: @class_enrollments) diff --git a/db/migrate/20240524135850_create_affiliation.rb b/db/migrate/20240524135850_create_affiliation.rb index 625288e5..c42e11f5 100644 --- a/db/migrate/20240524135850_create_affiliation.rb +++ b/db/migrate/20240524135850_create_affiliation.rb @@ -3,19 +3,19 @@ def up create_table :affiliations do |t| t.belongs_to :professor, index: true t.belongs_to :institution, index: true + t.date :start_date + t.date :end_date t.boolean :active - t.datetime :start_date - t.datetime :end_date t.timestamps end - Professor.all.each do |p| - start_date = p.updated_at + Professor.all.each do |professor| + start_date = professor.updated_at end_date = nil - institution_id = p.institution_id + institution_id = professor.institution_id institutions = [] affiliation = Affiliation.create( - professor: p, + professor: professor, institution_id: institution_id, start_date: start_date, active: true @@ -30,7 +30,7 @@ def up start_date = professor.updated_at institution_id = professor.institution_id affiliation = Affiliation.create( - professor: p, + professor: professor, institution_id: institution_id, start_date: start_date, active: false, @@ -51,8 +51,10 @@ def up remove_column :professors, :institution_id end def down - drop_table :affiliations add_column :professors, :institution_id, :integer add_index :professors, :institution_id + affiliation = Affiliation.professor.where(active?).last + professor.update(institution_id: affiliation.institution_id) + drop_table :affiliations end end diff --git a/db/migrate/20240527174758_create_program_level.rb b/db/migrate/20240527174758_create_program_level.rb index a218b3b1..7de35189 100644 --- a/db/migrate/20240527174758_create_program_level.rb +++ b/db/migrate/20240527174758_create_program_level.rb @@ -2,8 +2,8 @@ class CreateProgramLevel < ActiveRecord::Migration[7.0] def up create_table :program_levels do |t| t.integer :level, null: false - t.datetime :start_date, null: false - t.datetime :end_date + t.date :start_date, null: false + t.date :end_date t.boolean :active, null: false t.timestamps diff --git a/db/schema.rb b/db/schema.rb index 3fabffe0..55e047b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -259,9 +259,9 @@ create_table "affiliations", force: :cascade do |t| t.integer "professor_id" t.integer "institution_id" + t.date "start_date" + t.date "end_date" t.boolean "active" - t.datetime "start_date" - t.datetime "end_date" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["institution_id"], name: "index_affiliations_on_institution_id" @@ -731,8 +731,8 @@ create_table "program_levels", force: :cascade do |t| t.integer "level", null: false - t.datetime "start_date", null: false - t.datetime "end_date" + t.date "start_date", null: false + t.date "end_date" t.boolean "active", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb index 95ec7ae5..c75da877 100644 --- a/spec/models/affiliation_spec.rb +++ b/spec/models/affiliation_spec.rb @@ -4,8 +4,8 @@ RSpec.describe Affiliation, type: :model do it { should be_able_to_be_destroyed } - it { should belong_to(:institution) } - it { should belong_to(:professor) } + it { should belong_to(:institution).required(:false) } + it { should belong_to(:professor).required(:false) } let(:affiliation) { FactoryBot.create :affiliation } diff --git a/spec/models/institution_spec.rb b/spec/models/institution_spec.rb index a4dadad2..c2a20f6c 100644 --- a/spec/models/institution_spec.rb +++ b/spec/models/institution_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Institution, type: :model do it { should be_able_to_be_destroyed } it { should have_many(:majors).dependent(:restrict_with_exception) } - it { should have_many(:affiliations).dependent(:restrict_with_exception) } + it { should have_many(:affiliations).dependent(:destroy) } it { should have_many(:professors).through(:affiliations) } let(:institution) { Institution.new(name: "instituicao") } diff --git a/spec/models/professor_spec.rb b/spec/models/professor_spec.rb index 2d77bf1a..6c8b45c2 100644 --- a/spec/models/professor_spec.rb +++ b/spec/models/professor_spec.rb @@ -16,8 +16,8 @@ it { should have_many(:course_classes).dependent(:restrict_with_exception) } it { should have_many(:thesis_defense_committee_participations).dependent(:restrict_with_exception) } it { should have_many(:thesis_defense_committee_enrollments).source(:enrollment).through(:thesis_defense_committee_participations) } - it { should have_many(:affiliations).dependent(:restrict_with_exception) } - it { should have_many(:institutions).through(:affiliations) } + it { should have_many(:affiliations).dependent(:destroy) } + it { should have_many(:institutions).through(:affiliations).dependent(:destroy) } before(:all) do @professor_role = FactoryBot.create :role_professor @destroy_later = [] From eaba6cb8f95ecbd448627e18fb5fc2a54272144d Mon Sep 17 00:00:00 2001 From: IMonardez Date: Thu, 6 Jun 2024 09:49:31 -0300 Subject: [PATCH 15/32] ISSUE #448 - Exclude active flag at affiliation and program_level --- app/controllers/affiliation_controller.rb | 3 +- app/controllers/enrollments_controller.rb | 1 + app/models/affiliation.rb | 27 ++++++++-------- app/models/program_level.rb | 9 ++---- config/routes.rb | 1 + .../20240524135850_create_affiliation.rb | 11 +++---- .../20240527174758_create_program_level.rb | 3 -- db/schema.rb | 2 -- spec/factories/factory_affiliation.rb | 1 - spec/features/professors_spec.rb | 1 - spec/models/affiliation_spec.rb | 31 ++++++++++++------- spec/models/professor_spec.rb | 4 +-- 12 files changed, 47 insertions(+), 47 deletions(-) diff --git a/app/controllers/affiliation_controller.rb b/app/controllers/affiliation_controller.rb index d987c8c4..fcdeae67 100644 --- a/app/controllers/affiliation_controller.rb +++ b/app/controllers/affiliation_controller.rb @@ -4,7 +4,7 @@ class AffiliationController < ApplicationController authorize_resource active_scaffold :affiliation do |config| - columns = [:professor, :institution, :start_date, :end_date, :active] + columns = [:professor, :institution, :start_date, :end_date] config.list.columns = columns config.create.columns = columns @@ -14,7 +14,6 @@ class AffiliationController < ApplicationController config.columns[:professor].form_ui = :record_select config.columns[:institution].form_ui = :record_select config.columns[:start_date].form_ui = :date_picker - config.columns[:active].form_ui = :checkbox config.columns[:end_date].form_ui = :date_picker end record_select( diff --git a/app/controllers/enrollments_controller.rb b/app/controllers/enrollments_controller.rb index b9e3fa90..cd206859 100644 --- a/app/controllers/enrollments_controller.rb +++ b/app/controllers/enrollments_controller.rb @@ -214,6 +214,7 @@ def to_pdf def academic_transcript_pdf enrollment = Enrollment.find(params[:id]) + respond_to do |format| format.pdf do title = I18n.t("pdf_content.enrollment.academic_transcript.title") diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index fb9afa4b..d6dbc357 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -3,27 +3,28 @@ class Affiliation < ApplicationRecord has_paper_trail - before_save :set_active_default - belongs_to :institution, optional: true belongs_to :professor, optional: true validates :start_date, presence: true - validates :end_date, presence: true, unless: :active? - validates :end_date, presence: false, if: :active? - + validates :end_date, presence: false + validates_uniqueness_of :start_date, scope: [:professor_id], + allow_nil: true, allow_blank: true, + message: "A afiliação só pode ser iniciada em uma data por professor" + validate :uniqueness_end_date - validates_uniqueness_of :active, if: :active?, scope: [:professor_id], message: "Apenas uma afiliação pode estar ativa por professor." - - scope :date, ->(date) { where("start_date <= ? AND (end_date > ? OR active IS TRUE)", date, date) } + scope :date, ->(date) { where("start_date <= ? AND (end_date > ? OR end_date IS null)", date, date) } scope :professor, ->(professor) { where(professor_id: professor.id) } scope :date_professor, ->(professor, date) { professor(professor).date(date) } - def active? - active - end private - def set_active_default - self.active = false if active.nil? + + def uniqueness_end_date + exists = Affiliation.where(professor_id: professor_id, end_date: end_date).where.not(id: id).exists? + if exists + errors.add(:end_date,"Apenas uma afiliação pode estar ativa por professor e só pode ter uma data de fim por professor") end + exists + end + end diff --git a/app/models/program_level.rb b/app/models/program_level.rb index e2e84017..5769d5d7 100644 --- a/app/models/program_level.rb +++ b/app/models/program_level.rb @@ -2,14 +2,11 @@ class ProgramLevel < ApplicationRecord has_paper_trail + validates :level, presence: true, on: [:create, :update] validates :start_date, presence: true, on: [:create, :update] - validates :end_date, presence: true, unless: :active?, on: [:create, :update] - validates_uniqueness_of :active, if: :active?, on: [:create, :update] + validates :end_date, presence: false - scope :date, -> (date) { where("program_levels.start_date <= ? AND program_levels.end_date > ? OR program_levels.active is true", date, date)} + scope :date, -> (date) { where("program_levels.start_date <= ? AND program_levels.end_date > ? OR program_levels.end_date is null", date, date)} - def active? - active - end end diff --git a/config/routes.rb b/config/routes.rb index ea20ce0b..fd36d65a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -162,6 +162,7 @@ resources :affiliation do concerns :active_scaffold + record_select_routes end resources :professors do diff --git a/db/migrate/20240524135850_create_affiliation.rb b/db/migrate/20240524135850_create_affiliation.rb index c42e11f5..4d40fc4e 100644 --- a/db/migrate/20240524135850_create_affiliation.rb +++ b/db/migrate/20240524135850_create_affiliation.rb @@ -5,7 +5,6 @@ def up t.belongs_to :institution, index: true t.date :start_date t.date :end_date - t.boolean :active t.timestamps end @@ -17,8 +16,7 @@ def up affiliation = Affiliation.create( professor: professor, institution_id: institution_id, - start_date: start_date, - active: true + start_date: start_date ) professor = professor.paper_trail.previous_version while professor.present? @@ -33,7 +31,6 @@ def up professor: professor, institution_id: institution_id, start_date: start_date, - active: false, end_date: end_date ) else @@ -53,8 +50,10 @@ def up def down add_column :professors, :institution_id, :integer add_index :professors, :institution_id - affiliation = Affiliation.professor.where(active?).last - professor.update(institution_id: affiliation.institution_id) + Professor.all.each do |p| + affiliation = Affiliation.professor(p).where(active: true).last + p.update(institution_id: affiliation.institution_id) + end drop_table :affiliations end end diff --git a/db/migrate/20240527174758_create_program_level.rb b/db/migrate/20240527174758_create_program_level.rb index 7de35189..91bfd1c5 100644 --- a/db/migrate/20240527174758_create_program_level.rb +++ b/db/migrate/20240527174758_create_program_level.rb @@ -4,7 +4,6 @@ def up t.integer :level, null: false t.date :start_date, null: false t.date :end_date - t.boolean :active, null: false t.timestamps end @@ -13,7 +12,6 @@ def up program_level = ProgramLevel.create( level: pl.value, start_date: pl.updated_at, - active: true ) pl = pl.paper_trail.previous_version while pl.present? @@ -26,7 +24,6 @@ def up level: level, end_date: end_date, start_date: start_date, - active: false ) else start_date = pl.updated_at diff --git a/db/schema.rb b/db/schema.rb index 55e047b2..3851fd3e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -261,7 +261,6 @@ t.integer "institution_id" t.date "start_date" t.date "end_date" - t.boolean "active" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["institution_id"], name: "index_affiliations_on_institution_id" @@ -733,7 +732,6 @@ t.integer "level", null: false t.date "start_date", null: false t.date "end_date" - t.boolean "active", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end diff --git a/spec/factories/factory_affiliation.rb b/spec/factories/factory_affiliation.rb index bb3693d7..1425f5b6 100644 --- a/spec/factories/factory_affiliation.rb +++ b/spec/factories/factory_affiliation.rb @@ -6,6 +6,5 @@ professor start_date { Time.now } end_date { Time.now } - active { true } end end diff --git a/spec/features/professors_spec.rb b/spec/features/professors_spec.rb index d4680fef..7afe7bd6 100644 --- a/spec/features/professors_spec.rb +++ b/spec/features/professors_spec.rb @@ -132,7 +132,6 @@ fill_in "Nome", with: "teste" fill_in "CPF", with: "9" end - binding.pry click_button "Atualizar" expect(page).to have_css("td.name-column", text: "teste") expect(page).to have_css("td.cpf-column", text: "9") diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb index c75da877..097c0f6c 100644 --- a/spec/models/affiliation_spec.rb +++ b/spec/models/affiliation_spec.rb @@ -4,8 +4,8 @@ RSpec.describe Affiliation, type: :model do it { should be_able_to_be_destroyed } - it { should belong_to(:institution).required(:false) } - it { should belong_to(:professor).required(:false) } + it { should belong_to(:institution).optional(true) } + it { should belong_to(:professor).optional(true) } let(:affiliation) { FactoryBot.create :affiliation } @@ -14,15 +14,21 @@ it { should be_valid } it { should validate_presence_of(:start_date) } context "Active" do - let(:professor) { FactoryBot.create :professor} - let(:affiliation_active) { FactoryBot.create :affiliation, professor: professor, active: true} - let(:affiliation_inactive) { FactoryBot.create :affiliation, professor: professor, active: false} - let(:affiliation_teste_active) { FactoryBot.build :affiliation, professor: professor, active: true} - let(:affiliation_teste_inactive) { FactoryBot.build :affiliation, professor: professor, active: false} + let(:professor) { FactoryBot.create :professor } + let(:affiliation_active) { FactoryBot.create :affiliation, professor: professor, start_date: Time.now} + let(:affiliation_inactive) { FactoryBot.create :affiliation, + professor: professor, + start_date: Time.now + 1.day, + end_date: Time.now + 2.day} + let(:affiliation_teste_active) { FactoryBot.build :affiliation, professor: professor, start_date: Time.now + 2.day } + let(:affiliation_teste_inactive) { FactoryBot.build :affiliation, + professor: professor, + start_date: Time.now + 3.day, + end_date: Time.now + 4.day } it "When active, do not add new affiliation active" do affiliation_active - aff = FactoryBot.build(:affiliation, professor: professor, active: true) + aff = FactoryBot.build(:affiliation, professor: professor, end_date: nil) expect(aff).to be_invalid end context "When inactive, you can add new affiliation active/inactive" do @@ -40,13 +46,16 @@ end end context "Active e End Date" do - let(:affiliation_active) { FactoryBot.create :affiliation, end_date: nil, active: true } - let(:affiliation_inactive_valid) { FactoryBot.create :affiliation, end_date: Time.now, active: false } - let(:affiliation_inactive_invalid) { FactoryBot.build :affiliation, end_date: nil, active: false } + let(:affiliation_active) { FactoryBot.create :affiliation, end_date: nil } + let(:affiliation_inactive_valid) { FactoryBot.create :affiliation, end_date: Time.now } + let(:affiliation_inactive_invalid) { FactoryBot.build :affiliation, professor: affiliation_active.professor, end_date: nil } context "When active, don't need end date" do it { expect(affiliation_active).to be_valid } end context "When inactive, need an end date" do + before(:each) do + affiliation_active + end it { expect(affiliation_inactive_valid).to be_valid } it { expect(affiliation_inactive_invalid).to be_invalid } end diff --git a/spec/models/professor_spec.rb b/spec/models/professor_spec.rb index 6c8b45c2..ee11ed0e 100644 --- a/spec/models/professor_spec.rb +++ b/spec/models/professor_spec.rb @@ -16,8 +16,8 @@ it { should have_many(:course_classes).dependent(:restrict_with_exception) } it { should have_many(:thesis_defense_committee_participations).dependent(:restrict_with_exception) } it { should have_many(:thesis_defense_committee_enrollments).source(:enrollment).through(:thesis_defense_committee_participations) } - it { should have_many(:affiliations).dependent(:destroy) } - it { should have_many(:institutions).through(:affiliations).dependent(:destroy) } + it { should have_many(:affiliations).dependent(:restrict_with_exception) } + it { should have_many(:institutions).through(:affiliations).dependent(:restrict_with_exception) } before(:all) do @professor_role = FactoryBot.create :role_professor @destroy_later = [] From 08fc416f8737941c5e71fc286f5ae429555d368f Mon Sep 17 00:00:00 2001 From: IMonardez Date: Thu, 6 Jun 2024 10:24:13 -0300 Subject: [PATCH 16/32] ISSUE #448 - Create program_level factory, fix the show of defense_comitee_table and tests --- .../enrollments/_show_defense_committee_table.html.erb | 2 +- app/views/student_enrollment/_show_dismissal.html.erb | 3 ++- spec/factories/factory_program_level_spec.rb | 9 +++++++++ spec/features/enrollments_spec.rb | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 spec/factories/factory_program_level_spec.rb diff --git a/app/views/enrollments/_show_defense_committee_table.html.erb b/app/views/enrollments/_show_defense_committee_table.html.erb index 03fd8652..9154900c 100644 --- a/app/views/enrollments/_show_defense_committee_table.html.erb +++ b/app/views/enrollments/_show_defense_committee_table.html.erb @@ -12,7 +12,7 @@ <% tr_class = count.even? ? "even-record" : "" %> <%= professor.name %> - <%= rescue_blank_text(professor.affiliations.where(active: true).last, method_call: :name) %> + <%= rescue_blank_text(professor.affiliations.date(thesis_defense_date), method_call: :name) %> <% end %> diff --git a/app/views/student_enrollment/_show_dismissal.html.erb b/app/views/student_enrollment/_show_dismissal.html.erb index 1827af75..11ad812b 100644 --- a/app/views/student_enrollment/_show_dismissal.html.erb +++ b/app/views/student_enrollment/_show_dismissal.html.erb @@ -34,7 +34,8 @@ <% unless thesis_defense_committee_professors.empty? %>

<%= t "activerecord.attributes.enrollment.thesis_defense_committee_professors" %>

<%= render partial: "enrollments/show_defense_committee_table", locals: { - thesis_defense_committee_professors: thesis_defense_committee_professors + thesis_defense_committee_professors: thesis_defense_committee_professors, + thesis_defense_date: enrollment.thesis_defense_date, } %> <% end %> diff --git a/spec/factories/factory_program_level_spec.rb b/spec/factories/factory_program_level_spec.rb new file mode 100644 index 00000000..a27eb995 --- /dev/null +++ b/spec/factories/factory_program_level_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :program_level do + sequence(:level) + start_date { Time.now } + end_date { nil } + end +end \ No newline at end of file diff --git a/spec/features/enrollments_spec.rb b/spec/features/enrollments_spec.rb index 53e991b6..a76f7e3d 100644 --- a/spec/features/enrollments_spec.rb +++ b/spec/features/enrollments_spec.rb @@ -37,6 +37,8 @@ @destroy_all << FactoryBot.create(:phase_duration, level: @level1, phase: @phase2, deadline_months: 3, deadline_days: 0) @destroy_all << FactoryBot.create(:phase_duration, level: @level1, phase: @phase3, deadline_months: 3, deadline_days: 0) + @destroy_all << FactoryBot.create(:program_level) + @destroy_all << @enrollment1 = FactoryBot.create(:enrollment, enrollment_number: "M02", student: @student1, level: @level2, enrollment_status: @enrollment_status1, admission_date: 3.years.ago.at_beginning_of_month.to_date) @destroy_all << @enrollment2 = FactoryBot.create(:enrollment, enrollment_number: "M01", student: @student2, level: @level2, enrollment_status: @enrollment_status2) @destroy_all << @enrollment3 = FactoryBot.create(:enrollment, enrollment_number: "M03", student: @student3, level: @level1, enrollment_status: @enrollment_status1, research_area: @reasearch_area1) From a73877b462558f5172932e61bb2fee774761da62 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Thu, 6 Jun 2024 10:53:02 -0300 Subject: [PATCH 17/32] ISSUE #448 - Fix github action --- Gemfile.lock | 122 +++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 57 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index be6d4777..59a4a4d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,61 +28,61 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (7.0.8.1) - actionpack (= 7.0.8.1) - activesupport (= 7.0.8.1) + actioncable (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.8.1) - actionpack (= 7.0.8.1) - activejob (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionmailbox (7.0.8.4) + actionpack (= 7.0.8.4) + activejob (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.8.1) - actionpack (= 7.0.8.1) - actionview (= 7.0.8.1) - activejob (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionmailer (7.0.8.4) + actionpack (= 7.0.8.4) + actionview (= 7.0.8.4) + activejob (= 7.0.8.4) + activesupport (= 7.0.8.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.8.1) - actionview (= 7.0.8.1) - activesupport (= 7.0.8.1) + actionpack (7.0.8.4) + actionview (= 7.0.8.4) + activesupport (= 7.0.8.4) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.8.1) - actionpack (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + actiontext (7.0.8.4) + actionpack (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.8.1) - activesupport (= 7.0.8.1) + actionview (7.0.8.4) + activesupport (= 7.0.8.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) active_scaffold_duplicate (1.1.4) active_scaffold (>= 3.6.0.pre) - activejob (7.0.8.1) - activesupport (= 7.0.8.1) + activejob (7.0.8.4) + activesupport (= 7.0.8.4) globalid (>= 0.3.6) - activemodel (7.0.8.1) - activesupport (= 7.0.8.1) - activerecord (7.0.8.1) - activemodel (= 7.0.8.1) - activesupport (= 7.0.8.1) + activemodel (7.0.8.4) + activesupport (= 7.0.8.4) + activerecord (7.0.8.4) + activemodel (= 7.0.8.4) + activesupport (= 7.0.8.4) activerecord-session_store (2.1.0) actionpack (>= 6.1) activerecord (>= 6.1) @@ -90,14 +90,14 @@ GEM multi_json (~> 1.11, >= 1.11.2) rack (>= 2.0.8, < 4) railties (>= 6.1) - activestorage (7.0.8.1) - actionpack (= 7.0.8.1) - activejob (= 7.0.8.1) - activerecord (= 7.0.8.1) - activesupport (= 7.0.8.1) + activestorage (7.0.8.4) + actionpack (= 7.0.8.4) + activejob (= 7.0.8.4) + activerecord (= 7.0.8.4) + activesupport (= 7.0.8.4) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.8.1) + activesupport (7.0.8.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -272,10 +272,12 @@ GEM net-smtp (0.4.0) net-protocol nio4r (2.5.9) - nokogiri (1.16.2) + nokogiri (1.16.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.16.2-x86-mingw32) + nokogiri (1.16.5-x86-mingw32) + racc (~> 1.4) + nokogiri (1.16.5-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) paper_trail (15.1.0) @@ -308,20 +310,20 @@ GEM rack (2.2.8.1) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.8.1) - actioncable (= 7.0.8.1) - actionmailbox (= 7.0.8.1) - actionmailer (= 7.0.8.1) - actionpack (= 7.0.8.1) - actiontext (= 7.0.8.1) - actionview (= 7.0.8.1) - activejob (= 7.0.8.1) - activemodel (= 7.0.8.1) - activerecord (= 7.0.8.1) - activestorage (= 7.0.8.1) - activesupport (= 7.0.8.1) + rails (7.0.8.4) + actioncable (= 7.0.8.4) + actionmailbox (= 7.0.8.4) + actionmailer (= 7.0.8.4) + actionpack (= 7.0.8.4) + actiontext (= 7.0.8.4) + actionview (= 7.0.8.4) + activejob (= 7.0.8.4) + activemodel (= 7.0.8.4) + activerecord (= 7.0.8.4) + activestorage (= 7.0.8.4) + activesupport (= 7.0.8.4) bundler (>= 1.15.0) - railties (= 7.0.8.1) + railties (= 7.0.8.4) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -334,9 +336,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.8.1) - actionpack (= 7.0.8.1) - activesupport (= 7.0.8.1) + railties (7.0.8.4) + actionpack (= 7.0.8.4) + activesupport (= 7.0.8.4) method_source rake (>= 12.2) thor (~> 1.0) @@ -357,7 +359,8 @@ GEM responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.2.6) + rexml (3.2.8) + strscan (>= 3.0.9) rouge (4.2.0) rspec-collection_matchers (1.2.1) rspec-expectations (>= 2.99.0.beta1) @@ -453,8 +456,10 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.6.8) mini_portile2 (~> 2.8.0) + sqlite3 (1.6.8-x86_64-linux) ssrf_filter (1.1.2) stringio (3.0.8) + strscan (3.1.0) thor (1.3.0) tilt (2.3.0) timeliness (0.4.5) @@ -487,8 +492,10 @@ GEM PLATFORMS ruby x86-mingw32 + x86_64-linux DEPENDENCIES + actiontext (>= 7.0.8.4) active_scaffold! active_scaffold_duplicate (>= 1.1.0) activerecord-session_store @@ -522,7 +529,7 @@ DEPENDENCIES net-http net-imap net-smtp - nokogiri (>= 1.16.2) + nokogiri (>= 1.16.5) paper_trail prawn prawn-rails @@ -536,6 +543,7 @@ DEPENDENCIES recaptcha recordselect redcarpet + rexml (>= 3.2.7) rspec-collection_matchers rspec-rails rubocop From 7a87d61b40e859bd50c7775511bfbe3cf7c97db0 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Thu, 6 Jun 2024 10:54:26 -0300 Subject: [PATCH 18/32] ISSUE #448 - Fix github action --- .../{factory_program_level_spec.rb => factory_program_level.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spec/factories/{factory_program_level_spec.rb => factory_program_level.rb} (97%) diff --git a/spec/factories/factory_program_level_spec.rb b/spec/factories/factory_program_level.rb similarity index 97% rename from spec/factories/factory_program_level_spec.rb rename to spec/factories/factory_program_level.rb index a27eb995..cbc232de 100644 --- a/spec/factories/factory_program_level_spec.rb +++ b/spec/factories/factory_program_level.rb @@ -6,4 +6,4 @@ start_date { Time.now } end_date { nil } end -end \ No newline at end of file +end From 3607c984e1c306f9899c0e1ed40e2bcfccb60e96 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Thu, 6 Jun 2024 18:17:42 -0300 Subject: [PATCH 19/32] ISSUE #448 - adjustments at schema --- db/schema.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index b3396468..3e0de5e8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -256,6 +256,17 @@ t.index ["professor_id"], name: "index_advisements_on_professor_id" end + create_table "affiliations", force: :cascade do |t| + t.integer "professor_id" + t.integer "institution_id" + t.date "start_date" + t.date "end_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["institution_id"], name: "index_affiliations_on_institution_id" + t.index ["professor_id"], name: "index_affiliations_on_professor_id" + end + create_table "allocations", force: :cascade do |t| t.string "day", limit: 255 t.string "room", limit: 255 @@ -619,6 +630,7 @@ t.string "subject", limit: 255 t.text "body" t.string "attachments_file_names" + t.string "reply_to", limit: 255 t.index ["notification_id"], name: "index_notification_logs_on_notification_id" end @@ -701,7 +713,6 @@ t.string "siape", limit: 255 t.string "enrollment_number", limit: 255 t.string "identity_issuing_place", limit: 255 - t.integer "institution_id" t.string "email", limit: 255 t.date "academic_title_date" t.integer "academic_title_country_id" @@ -715,10 +726,17 @@ t.index ["city_id"], name: "index_professors_on_city_id" t.index ["cpf"], name: "index_professors_on_cpf" t.index ["email"], name: "index_professors_on_email" - t.index ["institution_id"], name: "index_professors_on_institution_id" t.index ["user_id"], name: "index_professors_on_user_id" end + create_table "program_levels", force: :cascade do |t| + t.integer "level", null: false + t.date "start_date", null: false + t.date "end_date" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "queries", force: :cascade do |t| t.string "name", limit: 255 t.text "sql" From 64e933fc1a2dca60be064b0fbb11fff92dcb00f3 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Sat, 8 Jun 2024 20:46:31 -0300 Subject: [PATCH 20/32] ISSUE #448 - adjustments at gemfile --- Gemfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index a8b27d27..cb4f405d 100644 --- a/Gemfile +++ b/Gemfile @@ -27,11 +27,7 @@ gem "rack", "~> 2.2.8.1" # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] # gem "importmap-rails" - -# Fix vulnerability -gem "actiontext", ">= 7.0.8.4" -gem "rexml", ">= 3.2.7" - +# # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] # gem "turbo-rails" From dfaa00138a5fc40b035fe59fe97c09a9cf816e99 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Sat, 8 Jun 2024 20:58:44 -0300 Subject: [PATCH 21/32] ISSUE #448 - adjustments at gemfile --- Gemfile.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 59a4a4d5..e954b07c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -495,7 +495,6 @@ PLATFORMS x86_64-linux DEPENDENCIES - actiontext (>= 7.0.8.4) active_scaffold! active_scaffold_duplicate (>= 1.1.0) activerecord-session_store @@ -543,7 +542,6 @@ DEPENDENCIES recaptcha recordselect redcarpet - rexml (>= 3.2.7) rspec-collection_matchers rspec-rails rubocop From 8c7d5cd1d3373e8de390c5ba4636979ddebc6a8c Mon Sep 17 00:00:00 2001 From: IMonardez Date: Thu, 25 Jul 2024 11:57:56 -0300 Subject: [PATCH 22/32] issue #448 - Adjustment at gemfile.lock --- Gemfile.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6cf8cd1b..fb5c1392 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -494,7 +494,6 @@ PLATFORMS x86_64-linux DEPENDENCIES - actiontext (>= 7.0.8.4) active_scaffold! active_scaffold_duplicate (>= 1.1.0) activerecord-session_store @@ -542,7 +541,6 @@ DEPENDENCIES recaptcha recordselect redcarpet - rexml (>= 3.2.7) rspec-collection_matchers rspec-rails rubocop From fc19ed61d3b65ae520376dc359dc58726540d5e5 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Mon, 2 Sep 2024 19:42:24 -0300 Subject: [PATCH 23/32] ISSUE #448 - Fixed date format, changed names of "affiliation" and "program level" model scopes, changed tests and application of scopes in pdf and view --- app/controllers/concerns/shared_pdf_concern.rb | 2 +- app/helpers/enrollments_pdf_helper.rb | 4 +--- app/models/affiliation.rb | 6 +++--- app/models/program_level.rb | 2 +- .../_show_defense_committee_table.html.erb | 2 +- db/migrate/20240524135850_create_affiliation.rb | 6 +++--- .../20240527174758_create_program_level.rb | 5 ++--- db/schema.rb | 8 +++++--- spec/features/student_enrollment_spec.rb | 8 ++++++++ spec/models/affiliation_spec.rb | 16 +++++++++++++++- spec/rails_helper.rb | 2 +- 11 files changed, 41 insertions(+), 20 deletions(-) diff --git a/app/controllers/concerns/shared_pdf_concern.rb b/app/controllers/concerns/shared_pdf_concern.rb index 7d576ba4..3e62bcbb 100644 --- a/app/controllers/concerns/shared_pdf_concern.rb +++ b/app/controllers/concerns/shared_pdf_concern.rb @@ -41,7 +41,7 @@ def render_enrollments_academic_transcript_pdf(enrollment) .order("course_classes.year", "course_classes.semester") accomplished_phases = enrollment.accomplishments.order(:conclusion_date) - program_level = ProgramLevel.date(enrollment.thesis_defense_date).last + program_level = ProgramLevel.on_date(enrollment.thesis_defense_date).last render_to_string( template: "enrollments/academic_transcript_pdf", type: "application/pdf", diff --git a/app/helpers/enrollments_pdf_helper.rb b/app/helpers/enrollments_pdf_helper.rb index 8390aa24..b98031ac 100644 --- a/app/helpers/enrollments_pdf_helper.rb +++ b/app/helpers/enrollments_pdf_helper.rb @@ -614,10 +614,8 @@ def thesis_table(curr_pdf, options = {}) data_table_rows_defense_committee += [[ "#{I18n.t("pdf_content.enrollment.thesis.defense_committee")} " ]] - # TODO: modificar o institution para a affiliation thesis_desense_committee.each do |professor| - affiliation = professor.affiliations.date(thesis_defense_date).last - binding.pry + affiliation = Affiliation.date_professor(professor, thesis_defense_date) data_table_rows_defense_committee += [[ "#{professor.name} / #{rescue_blank_text( affiliation.institution, method_call: :name diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index d6dbc357..68e78780 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -13,9 +13,9 @@ class Affiliation < ApplicationRecord message: "A afiliação só pode ser iniciada em uma data por professor" validate :uniqueness_end_date - scope :date, ->(date) { where("start_date <= ? AND (end_date > ? OR end_date IS null)", date, date) } - scope :professor, ->(professor) { where(professor_id: professor.id) } - scope :date_professor, ->(professor, date) { professor(professor).date(date) } + scope :on_date, ->(date) { where("start_date <= ? AND (end_date > ? OR end_date IS null)", date, date).last } + scope :of_professor, ->(professor) { where(professor_id: professor.id) } + scope :date_professor, ->(professor, date) { of_professor(professor).on_date(date) } private diff --git a/app/models/program_level.rb b/app/models/program_level.rb index 5769d5d7..4997b29e 100644 --- a/app/models/program_level.rb +++ b/app/models/program_level.rb @@ -7,6 +7,6 @@ class ProgramLevel < ApplicationRecord validates :start_date, presence: true, on: [:create, :update] validates :end_date, presence: false - scope :date, -> (date) { where("program_levels.start_date <= ? AND program_levels.end_date > ? OR program_levels.end_date is null", date, date)} + scope :on_date, -> (date) { where("program_levels.start_date <= ? AND program_levels.end_date > ? OR program_levels.end_date is null", date, date)} end diff --git a/app/views/enrollments/_show_defense_committee_table.html.erb b/app/views/enrollments/_show_defense_committee_table.html.erb index 9154900c..1c278f06 100644 --- a/app/views/enrollments/_show_defense_committee_table.html.erb +++ b/app/views/enrollments/_show_defense_committee_table.html.erb @@ -12,7 +12,7 @@ <% tr_class = count.even? ? "even-record" : "" %> <%= professor.name %> - <%= rescue_blank_text(professor.affiliations.date(thesis_defense_date), method_call: :name) %> + <%= rescue_blank_text(Affiliation.date_professor(professor, thesis_defense_date)&.last&.institution, method_call: :name) %> <% end %> diff --git a/db/migrate/20240524135850_create_affiliation.rb b/db/migrate/20240524135850_create_affiliation.rb index 4d40fc4e..c9930fe7 100644 --- a/db/migrate/20240524135850_create_affiliation.rb +++ b/db/migrate/20240524135850_create_affiliation.rb @@ -3,8 +3,8 @@ def up create_table :affiliations do |t| t.belongs_to :professor, index: true t.belongs_to :institution, index: true - t.date :start_date - t.date :end_date + t.datetime :start_date + t.datetime :end_date t.timestamps end @@ -51,7 +51,7 @@ def down add_column :professors, :institution_id, :integer add_index :professors, :institution_id Professor.all.each do |p| - affiliation = Affiliation.professor(p).where(active: true).last + affiliation = Affiliation.of_professor(p).where(end_date: nil).last p.update(institution_id: affiliation.institution_id) end drop_table :affiliations diff --git a/db/migrate/20240527174758_create_program_level.rb b/db/migrate/20240527174758_create_program_level.rb index 91bfd1c5..daefeacd 100644 --- a/db/migrate/20240527174758_create_program_level.rb +++ b/db/migrate/20240527174758_create_program_level.rb @@ -2,8 +2,8 @@ class CreateProgramLevel < ActiveRecord::Migration[7.0] def up create_table :program_levels do |t| t.integer :level, null: false - t.date :start_date, null: false - t.date :end_date + t.datetime :start_date, null: false + t.datetime :end_date t.timestamps end @@ -15,7 +15,6 @@ def up ) pl = pl.paper_trail.previous_version while pl.present? - binding.pry if pl.value != level end_date = start_date start_date = pl.updated_at diff --git a/db/schema.rb b/db/schema.rb index 34843a69..c9c44de5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -128,7 +128,7 @@ t.boolean "candidate_can_see_member", default: false, null: false t.boolean "candidate_can_see_shared", default: false, null: false t.boolean "candidate_can_see_consolidation", default: false, null: false - t.index ["approval_condition_id"], name: "index_admission_phases_on_approval_condition_id" + t.index "\"ranking_config_id\"", name: "index_admission_phases_on_ranking_config_id" t.index ["candidate_form_id"], name: "index_admission_phases_on_candidate_form_id" t.index ["consolidation_form_id"], name: "index_admission_phases_on_consolidation_form_id" t.index ["keep_in_phase_condition_id"], name: "index_admission_phases_on_keep_in_phase_condition_id" @@ -259,8 +259,8 @@ create_table "affiliations", force: :cascade do |t| t.integer "professor_id" t.integer "institution_id" - t.date "start_date" - t.date "end_date" + t.datetime "start_date" + t.datetime "end_date" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["institution_id"], name: "index_affiliations_on_institution_id" @@ -950,6 +950,8 @@ t.string "photo", limit: 255 t.integer "birth_country_id" t.integer "user_id", limit: 8 + t.string "skin_color" + t.boolean "pcd" t.index ["birth_city_id"], name: "index_students_on_birth_city_id" t.index ["birth_country_id"], name: "index_students_on_birth_country_id" t.index ["birth_state_id"], name: "index_students_on_state_id" diff --git a/spec/features/student_enrollment_spec.rb b/spec/features/student_enrollment_spec.rb index b4988261..81d7a068 100644 --- a/spec/features/student_enrollment_spec.rb +++ b/spec/features/student_enrollment_spec.rb @@ -51,6 +51,12 @@ @destroy_all << @professor3 = FactoryBot.create(:professor, name: "Gi", cpf: "1") @destroy_all << @professor4 = FactoryBot.create(:professor, name: "Helena", cpf: "4") + @destroy_all << @institution = FactoryBot.create(:institution, name: 'UFF') + + @destroy_all << @affiliation1 = FactoryBot.create(:affiliation, institution: @institution, professor: @professor1, end_date: nil) + @destroy_all << @affiliation2 = FactoryBot.create(:affiliation, institution: @institution, professor: @professor2, end_date: nil) + @destroy_all << @affiliation3 = FactoryBot.create(:affiliation, institution: @institution, professor: @professor3, end_date: nil) + @destroy_all << FactoryBot.create(:advisement_authorization, professor: @professor1, level: @level1) @destroy_all << FactoryBot.create(:advisement_authorization, professor: @professor1, level: @level2) @destroy_all << FactoryBot.create(:advisement_authorization, professor: @professor2, level: @level1) @@ -184,6 +190,8 @@ "Nome", "Instituição" ] expect(page.all("tbody tr").size).to eq 3 + binding.pry + expect(page).to have_content "UFF" end end diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb index 097c0f6c..1ebccf4a 100644 --- a/spec/models/affiliation_spec.rb +++ b/spec/models/affiliation_spec.rb @@ -15,7 +15,7 @@ it { should validate_presence_of(:start_date) } context "Active" do let(:professor) { FactoryBot.create :professor } - let(:affiliation_active) { FactoryBot.create :affiliation, professor: professor, start_date: Time.now} + let(:affiliation_active) { FactoryBot.create :affiliation, professor: professor, start_date: Time.now, end_date: nil } let(:affiliation_inactive) { FactoryBot.create :affiliation, professor: professor, start_date: Time.now + 1.day, @@ -61,4 +61,18 @@ end end end + + context "Scope" do + context "date_professor" do + let!(:professor) { FactoryBot.create :professor } + let!(:affiliation_active) { FactoryBot.create :affiliation, professor: professor, start_date: Time.now, end_date: nil } + let!(:affiliation_inactive) do + FactoryBot.create :affiliation, professor: professor, start_date: Time.now - 1.day, end_date: Time.now + end + + + it { expect(Affiliation.date_professor(professor, Time.now)).to eq(affiliation_active) } + it { expect(Affiliation.date_professor(professor, Time.now - 5.hours)).to eq(affiliation_inactive) } + end + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 5af13cb9..cb25465e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -100,7 +100,7 @@ "text/csv,text/tsv,text/xml,text/plain,application/pdf,application/doc,application/docx,image/jpeg,application/gzip,application/x-gzip" options = Selenium::WebDriver::Firefox::Options.new options.profile = profile - options.args << "--headless" unless ENV["BROWSER"] + #options.args << "--headless" unless ENV["BROWSER"] Capybara::Selenium::Driver.new( app, From 24a180a88c03f8ade09eba34b36e033229d17ad3 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Mon, 2 Sep 2024 21:00:10 -0300 Subject: [PATCH 24/32] ISSUE #448 - Changes at rails_helper --- spec/rails_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index cb25465e..5af13cb9 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -100,7 +100,7 @@ "text/csv,text/tsv,text/xml,text/plain,application/pdf,application/doc,application/docx,image/jpeg,application/gzip,application/x-gzip" options = Selenium::WebDriver::Firefox::Options.new options.profile = profile - #options.args << "--headless" unless ENV["BROWSER"] + options.args << "--headless" unless ENV["BROWSER"] Capybara::Selenium::Driver.new( app, From fd94a6c15a97884a0de055641b9ead625220c707 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 3 Sep 2024 16:10:06 -0300 Subject: [PATCH 25/32] Issue #448 - Removing binding.pry --- spec/features/student_enrollment_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/student_enrollment_spec.rb b/spec/features/student_enrollment_spec.rb index 81d7a068..a556cddf 100644 --- a/spec/features/student_enrollment_spec.rb +++ b/spec/features/student_enrollment_spec.rb @@ -190,7 +190,6 @@ "Nome", "Instituição" ] expect(page.all("tbody tr").size).to eq 3 - binding.pry expect(page).to have_content "UFF" end end From 3aecccb5f16c64f7d02e46d09aa6ae68d06a8136 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 3 Sep 2024 16:42:03 -0300 Subject: [PATCH 26/32] Issue #448 - Changes in validation and migration to only create affiliation when there is an institution --- app/models/affiliation.rb | 4 ++-- db/migrate/20240524135850_create_affiliation.rb | 10 +++------- spec/models/affiliation_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 68e78780..1eef4474 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -3,8 +3,8 @@ class Affiliation < ApplicationRecord has_paper_trail - belongs_to :institution, optional: true - belongs_to :professor, optional: true + belongs_to :institution + belongs_to :professor validates :start_date, presence: true validates :end_date, presence: false diff --git a/db/migrate/20240524135850_create_affiliation.rb b/db/migrate/20240524135850_create_affiliation.rb index c9930fe7..5b93096a 100644 --- a/db/migrate/20240524135850_create_affiliation.rb +++ b/db/migrate/20240524135850_create_affiliation.rb @@ -8,7 +8,7 @@ def up t.timestamps end - Professor.all.each do |professor| + Professor.where.not(institution_id: nil).each do |professor| start_date = professor.updated_at end_date = nil institution_id = professor.institution_id @@ -21,9 +21,7 @@ def up professor = professor.paper_trail.previous_version while professor.present? if professor.institution_id != institution_id - if institution_id.present? # Não armazena afiliação em branco - institutions << { institution_id:, start_date:, end_date: } - end + institutions << { institution_id:, start_date:, end_date: } end_date = start_date start_date = professor.updated_at institution_id = professor.institution_id @@ -40,9 +38,7 @@ def up end professor = professor.paper_trail.previous_version end - if institution_id.present? # Não armazena afiliação em branco - institutions << { institution_id:, start_date:, end_date: } - end + institutions << { institution_id:, start_date:, end_date: } end remove_column :professors, :institution_id diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb index 1ebccf4a..971991d1 100644 --- a/spec/models/affiliation_spec.rb +++ b/spec/models/affiliation_spec.rb @@ -4,8 +4,8 @@ RSpec.describe Affiliation, type: :model do it { should be_able_to_be_destroyed } - it { should belong_to(:institution).optional(true) } - it { should belong_to(:professor).optional(true) } + it { should belong_to(:institution) } + it { should belong_to(:professor) } let(:affiliation) { FactoryBot.create :affiliation } From 45341a9dd960d5f4d9514e23a0a1c8d519d48707 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 3 Sep 2024 16:51:47 -0300 Subject: [PATCH 27/32] Issue #448 - Fixes at seeds and custom_variables tests --- db/seeds.rb | 3 ++- spec/features/custom_variables_spec.rb | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index a96c2d47..0671ab59 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -16,7 +16,7 @@ CustomVariable.create([ { description: "Pontos para orientador único", variable: "single_advisor_points", value: "1.0" }, { description: "Pontos para orientador múltiplo", variable: "multiple_advisor_points", value: "0.5" }, - { description: "Nível do Programa na CAPES", variable: "program_level", value: "5" }, + { description: "País padrão de emissão da identidade", variable: "identity_issuing_country", value: "Brasil" }, { description: "Texto no final do quadro de horários", variable: "class_schedule_text", value: "Alunos interessados em cursar disciplinas de Tópicos Avançados devem consultar os respectivos professores antes da matrícula." }, { description: "E-mail de redirecionamento para as notificações", variable: "redirect_email", value: "" }, @@ -33,6 +33,7 @@ { description: "Nota de reprovação por falta", variable: "grade_of_disapproval_for_absence", value: "0.0" }, { description: "Professor logado no sistema pode lançar notas. O valor yes habilita turmas do semestre atual, yes_all_semesters habilita qualquer semestre.", variable: "professor_login_can_post_grades", value: "no" }, ]) +ProgramLevel.create([{ value: "5", start_date: Time.now, end_date: nil }]) ReportConfiguration.create([ { name: "Boletim", scale: 1, x: 0, y: 0, order: 1, diff --git a/spec/features/custom_variables_spec.rb b/spec/features/custom_variables_spec.rb index 0f26a8c3..7d8ac606 100644 --- a/spec/features/custom_variables_spec.rb +++ b/spec/features/custom_variables_spec.rb @@ -15,7 +15,6 @@ @destroy_all << @role_adm = FactoryBot.create(:role_administrador) @destroy_all << @user = create_confirmed_user(@role_adm) - @destroy_all << FactoryBot.create(:custom_variable, variable: "program_level", value: "5") @destroy_all << @record = FactoryBot.create(:custom_variable, variable: "single_advisor_points", value: "1.0") @destroy_all << FactoryBot.create(:custom_variable, variable: "minimum_grade_for_approval", value: "6.0") end @@ -42,7 +41,7 @@ end it "should sort the list by variable, asc" do - expect(page.all("tr td.variable-column").map(&:text)).to eq ["minimum_grade_for_approval", "program_level", "single_advisor_points"] + expect(page.all("tr td.variable-column").map(&:text)).to eq ["minimum_grade_for_approval", "single_advisor_points"] end end @@ -64,12 +63,12 @@ expect(page).to have_css("tr:nth-child(1) td.variable-column", text: "identity_issuing_country") # Remove inserted record - expect(page.all("tr td.variable-column").map(&:text)).to eq ["identity_issuing_country", "minimum_grade_for_approval", "program_level", "single_advisor_points"] + expect(page.all("tr td.variable-column").map(&:text)).to eq ["identity_issuing_country", "minimum_grade_for_approval", "single_advisor_points"] record = model.last accept_confirm { find("#as_#{plural_name}-destroy-#{record.id}-link").click } sleep(0.2) visit current_path - expect(page.all("tr td.variable-column").map(&:text)).to eq ["minimum_grade_for_approval", "program_level", "single_advisor_points"] + expect(page.all("tr td.variable-column").map(&:text)).to eq ["minimum_grade_for_approval", "single_advisor_points"] end it "should have a selection for variable options" do From b2644e4cf0956770eb2ca9df0a09b71b248b599a Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 3 Sep 2024 18:57:44 -0300 Subject: [PATCH 28/32] Issue #448 - Controller and route for program_level created --- app/controllers/program_level_controller.rb | 46 +++++++++++++++++++++ app/models/affiliation.rb | 1 + app/models/program_level.rb | 1 + config/routes.rb | 4 ++ 4 files changed, 52 insertions(+) create mode 100644 app/controllers/program_level_controller.rb diff --git a/app/controllers/program_level_controller.rb b/app/controllers/program_level_controller.rb new file mode 100644 index 00000000..7f43ec36 --- /dev/null +++ b/app/controllers/program_level_controller.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +class ProgramLevelController < ApplicationController + authorize_resource + active_scaffold :program_level do |config| + config.create.columns = [:level] + config.update.columns = [:level] + config.show.columns = [:level, :start_date, :end_date] + config.list.columns = [:level, :start_date] + end + + protected + + def do_update + # BEFORE UPDATE + # cria o histórico + pl = ProgramLevel.last + unless pl.nil? + ProgramLevel.create!( + level: pl.level, + start_date: pl.start_date, + end_date: Time.now + ) + end + + super + # AFTER UPDATE + # atualiza a data de início + + pl = ProgramLevel.last + pl.update!(start_date: pl.updated_at) + end + + def do_create + super + # AFTER CREATE + # Coloca a data de início com a mesma do created_at + + pl = ProgramLevel.last + pl.update!(start_date: pl.created_at) + end + + def conditions_for_collection + ["end_date is null"] + end +end diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 1eef4474..60ec02e7 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -16,6 +16,7 @@ class Affiliation < ApplicationRecord scope :on_date, ->(date) { where("start_date <= ? AND (end_date > ? OR end_date IS null)", date, date).last } scope :of_professor, ->(professor) { where(professor_id: professor.id) } scope :date_professor, ->(professor, date) { of_professor(professor).on_date(date) } + scope :active, -> { where(end_date: nil) } private diff --git a/app/models/program_level.rb b/app/models/program_level.rb index 4997b29e..92722b8b 100644 --- a/app/models/program_level.rb +++ b/app/models/program_level.rb @@ -7,6 +7,7 @@ class ProgramLevel < ApplicationRecord validates :start_date, presence: true, on: [:create, :update] validates :end_date, presence: false + scope :active, -> { where(end_date: nil) } scope :on_date, -> (date) { where("program_levels.start_date <= ? AND program_levels.end_date > ? OR program_levels.end_date is null", date, date)} end diff --git a/config/routes.rb b/config/routes.rb index fd36d65a..6017eaa4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -236,6 +236,10 @@ concerns :active_scaffold end + resources :program_level do + concerns :active_scaffold + end + resources :thesis_defense_committee_participations do concerns :active_scaffold record_select_routes From fdbbd5c7f5b04a6184a69d0d35f878b7e8aa4208 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Wed, 4 Sep 2024 15:59:42 -0300 Subject: [PATCH 29/32] Issue #448 - Rename controller Program Level and route of program level at configuration --- ...l_controller.rb => program_levels_controller.rb} | 3 ++- app/models/ability.rb | 4 ++-- app/models/affiliation.rb | 13 ++++++------- config/locales/navigation.pt-BR.yml | 2 +- config/locales/program_level.pt-BR.yml | 12 ++++++++++++ config/navigation.rb | 1 + config/routes.rb | 2 +- 7 files changed, 25 insertions(+), 12 deletions(-) rename app/controllers/{program_level_controller.rb => program_levels_controller.rb} (94%) create mode 100644 config/locales/program_level.pt-BR.yml diff --git a/app/controllers/program_level_controller.rb b/app/controllers/program_levels_controller.rb similarity index 94% rename from app/controllers/program_level_controller.rb rename to app/controllers/program_levels_controller.rb index 7f43ec36..082e828a 100644 --- a/app/controllers/program_level_controller.rb +++ b/app/controllers/program_levels_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ProgramLevelController < ApplicationController +class ProgramLevelsController < ApplicationController authorize_resource active_scaffold :program_level do |config| config.create.columns = [:level] @@ -14,6 +14,7 @@ class ProgramLevelController < ApplicationController def do_update # BEFORE UPDATE # cria o histórico + pl = ProgramLevel.last unless pl.nil? ProgramLevel.create!( diff --git a/app/models/ability.rb b/app/models/ability.rb index 591dd693..f6c822af 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -46,7 +46,7 @@ class Ability CONFIGURATION_MODELS = [ User, Role, Version, Notification, EmailTemplate, Query, NotificationLog, CustomVariable, ReportConfiguration, - YearSemester + YearSemester, ProgramLevel ] def initialize(user) @@ -228,7 +228,7 @@ def initialize_configurations(user, roles) alias_action :execute_now, :execute_now, :notify, to: :update if roles[Role::ROLE_COORDENACAO] can :manage, (Ability::CONFIGURATION_MODELS - [ - CustomVariable, ReportConfiguration + CustomVariable, ReportConfiguration, ProgramLevel ]) end if roles[Role::ROLE_SECRETARIA] diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 60ec02e7..5dcc666a 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -19,13 +19,12 @@ class Affiliation < ApplicationRecord scope :active, -> { where(end_date: nil) } private - - def uniqueness_end_date - exists = Affiliation.where(professor_id: professor_id, end_date: end_date).where.not(id: id).exists? - if exists - errors.add(:end_date,"Apenas uma afiliação pode estar ativa por professor e só pode ter uma data de fim por professor") + def uniqueness_end_date + exists = Affiliation.where(professor_id: professor_id, end_date: end_date).where.not(id: id).exists? + if exists + errors.add(:end_date,"Apenas uma afiliação pode estar ativa por professor e só pode ter uma data de fim por professor") + end + exists end - exists - end end diff --git a/config/locales/navigation.pt-BR.yml b/config/locales/navigation.pt-BR.yml index 720d60b5..2ca25f64 100644 --- a/config/locales/navigation.pt-BR.yml +++ b/config/locales/navigation.pt-BR.yml @@ -10,7 +10,6 @@ pt-BR: student: Alunos dismissal: Desligamentos enrollment: Matrículas - enrollment: Matrículas enrollment_hold: Trancamentos level: Níveis dismissal_reason: Razões de Desligamento @@ -82,6 +81,7 @@ pt-BR: notification_log: Notificações Enviadas custom_variable: Variáveis report_configuration: Configurações de Relatório + program_level: Nível logout: label: 'Logout' diff --git a/config/locales/program_level.pt-BR.yml b/config/locales/program_level.pt-BR.yml new file mode 100644 index 00000000..afaa5d8c --- /dev/null +++ b/config/locales/program_level.pt-BR.yml @@ -0,0 +1,12 @@ +pt-BR: + activerecord: + attributes: + program_level: + level: Nível + start_date: Data de início + end_date: Data de fim + + models: + program_level: + one: Nível + other: Níveis \ No newline at end of file diff --git a/config/navigation.rb b/config/navigation.rb index d2505ce8..190d49f3 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -243,6 +243,7 @@ def can_read?(*args) submenu.modelitem NotificationLog submenu.modelitem CustomVariable submenu.modelitem ReportConfiguration + submenu.modelitem ProgramLevel end mainhelper.item :logout, destroy_user_session_path diff --git a/config/routes.rb b/config/routes.rb index 6017eaa4..6a1b347e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -236,7 +236,7 @@ concerns :active_scaffold end - resources :program_level do + resources :program_levels do concerns :active_scaffold end From cec3b6e045d4d981f114cb07666a69320bd90a25 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Wed, 4 Sep 2024 19:04:08 -0300 Subject: [PATCH 30/32] Issue #448 - Fixes at enrollments pdf and show --- app/controllers/concerns/shared_pdf_concern.rb | 2 +- app/helpers/enrollments_pdf_helper.rb | 6 +++--- app/models/affiliation.rb | 4 ++-- .../enrollments/_show_defense_committee_table.html.erb | 2 +- spec/features/student_enrollment_spec.rb | 7 +++++-- spec/models/affiliation_spec.rb | 4 ++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/controllers/concerns/shared_pdf_concern.rb b/app/controllers/concerns/shared_pdf_concern.rb index 3e62bcbb..967c3548 100644 --- a/app/controllers/concerns/shared_pdf_concern.rb +++ b/app/controllers/concerns/shared_pdf_concern.rb @@ -41,7 +41,7 @@ def render_enrollments_academic_transcript_pdf(enrollment) .order("course_classes.year", "course_classes.semester") accomplished_phases = enrollment.accomplishments.order(:conclusion_date) - program_level = ProgramLevel.on_date(enrollment.thesis_defense_date).last + program_level = ProgramLevel.on_date(enrollment.thesis_defense_date)&.last&.level || "" render_to_string( template: "enrollments/academic_transcript_pdf", type: "application/pdf", diff --git a/app/helpers/enrollments_pdf_helper.rb b/app/helpers/enrollments_pdf_helper.rb index b98031ac..b192b868 100644 --- a/app/helpers/enrollments_pdf_helper.rb +++ b/app/helpers/enrollments_pdf_helper.rb @@ -137,7 +137,7 @@ def enrollment_header(pdf, options = {}) pdf.font("FreeMono", size: 8) do pdf.line_width 0.5 common_header_part1(pdf, enrollment, [ - "#{i18n_eht(:program_level)} #{program_level.level}" + "#{i18n_eht(:program_level)} #{program_level}" ]) common_header_part(pdf) do @@ -615,10 +615,10 @@ def thesis_table(curr_pdf, options = {}) "#{I18n.t("pdf_content.enrollment.thesis.defense_committee")} " ]] thesis_desense_committee.each do |professor| - affiliation = Affiliation.date_professor(professor, thesis_defense_date) + affiliation = Affiliation.professor_date(professor, thesis_defense_date)&.last data_table_rows_defense_committee += [[ "#{professor.name} / #{rescue_blank_text( - affiliation.institution, method_call: :name + affiliation&.institution, method_call: :name )}" ]] end diff --git a/app/models/affiliation.rb b/app/models/affiliation.rb index 5dcc666a..58885356 100644 --- a/app/models/affiliation.rb +++ b/app/models/affiliation.rb @@ -13,9 +13,9 @@ class Affiliation < ApplicationRecord message: "A afiliação só pode ser iniciada em uma data por professor" validate :uniqueness_end_date - scope :on_date, ->(date) { where("start_date <= ? AND (end_date > ? OR end_date IS null)", date, date).last } + scope :on_date, ->(date) { where("DATE(start_date) <= ? AND (DATE(end_date) > ? OR end_date IS null)", date, date) } scope :of_professor, ->(professor) { where(professor_id: professor.id) } - scope :date_professor, ->(professor, date) { of_professor(professor).on_date(date) } + scope :professor_date, ->(professor, date) { of_professor(professor).on_date(date) } scope :active, -> { where(end_date: nil) } private diff --git a/app/views/enrollments/_show_defense_committee_table.html.erb b/app/views/enrollments/_show_defense_committee_table.html.erb index 1c278f06..eaeadda6 100644 --- a/app/views/enrollments/_show_defense_committee_table.html.erb +++ b/app/views/enrollments/_show_defense_committee_table.html.erb @@ -12,7 +12,7 @@ <% tr_class = count.even? ? "even-record" : "" %> <%= professor.name %> - <%= rescue_blank_text(Affiliation.date_professor(professor, thesis_defense_date)&.last&.institution, method_call: :name) %> + <%= rescue_blank_text(Affiliation.professor_date(professor, thesis_defense_date)&.last&.institution, method_call: :name) %> <% end %> diff --git a/spec/features/student_enrollment_spec.rb b/spec/features/student_enrollment_spec.rb index a556cddf..71ea4a90 100644 --- a/spec/features/student_enrollment_spec.rb +++ b/spec/features/student_enrollment_spec.rb @@ -51,7 +51,7 @@ @destroy_all << @professor3 = FactoryBot.create(:professor, name: "Gi", cpf: "1") @destroy_all << @professor4 = FactoryBot.create(:professor, name: "Helena", cpf: "4") - @destroy_all << @institution = FactoryBot.create(:institution, name: 'UFF') + @destroy_all << @institution = FactoryBot.create(:institution, name: "UFF") @destroy_all << @affiliation1 = FactoryBot.create(:affiliation, institution: @institution, professor: @professor1, end_date: nil) @destroy_all << @affiliation2 = FactoryBot.create(:affiliation, institution: @institution, professor: @professor2, end_date: nil) @@ -65,7 +65,10 @@ @destroy_all << FactoryBot.create(:advisement_authorization, professor: @professor3, level: @level2) @destroy_all << @student1 = FactoryBot.create(:student, name: "Ana") - @destroy_all << @enrollment1 = FactoryBot.create(:enrollment, enrollment_number: "M01", student: @student1, level: @level2, enrollment_status: @enrollment_status1, admission_date: 3.years.ago.at_beginning_of_month.to_date, research_area: @research_area1) + @destroy_all << @enrollment1 = FactoryBot.create(:enrollment, enrollment_number: "M01", student: @student1, + level: @level2, enrollment_status: @enrollment_status1, + admission_date: 3.years.ago.at_beginning_of_month.to_date, + research_area: @research_area1, thesis_defense_date: Time.now) @destroy_all << @enrollment2 = FactoryBot.create(:enrollment, enrollment_number: "M02", student: @student1, level: @level2, enrollment_status: @enrollment_status1) @destroy_all << @enrollment3 = FactoryBot.create(:enrollment, enrollment_number: "D01", student: @student1, level: @level1, enrollment_status: @enrollment_status1) @destroy_all << @enrollment4 = FactoryBot.create(:enrollment, enrollment_number: "D02", student: @student1, level: @level1, enrollment_status: @enrollment_status1) diff --git a/spec/models/affiliation_spec.rb b/spec/models/affiliation_spec.rb index 971991d1..8d1d7598 100644 --- a/spec/models/affiliation_spec.rb +++ b/spec/models/affiliation_spec.rb @@ -71,8 +71,8 @@ end - it { expect(Affiliation.date_professor(professor, Time.now)).to eq(affiliation_active) } - it { expect(Affiliation.date_professor(professor, Time.now - 5.hours)).to eq(affiliation_inactive) } + it { expect(Affiliation.professor_date(professor, Time.now).last).to eq(affiliation_active) } + it { expect(Affiliation.professor_date(professor, Time.now - 1.days).last).to eq(affiliation_inactive) } end end end From bbbc249308b689cb48029b8bf784accca6472f87 Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 24 Sep 2024 15:53:42 -0300 Subject: [PATCH 31/32] Issue #448 - Change of the name of the "level program" on the configuration screen, removal of the affiliation nested in teacher, in addition to the end and start dates in the program level show, update and create. --- app/controllers/professors_controller.rb | 3 +-- app/controllers/program_levels_controller.rb | 26 +++++++------------- app/models/professor.rb | 4 +-- config/locales/navigation.pt-BR.yml | 2 +- config/locales/professor.pt-BR.yml | 4 +-- config/locales/program_level.pt-BR.yml | 5 ++-- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/app/controllers/professors_controller.rb b/app/controllers/professors_controller.rb index cbca5c6a..9997fad9 100644 --- a/app/controllers/professors_controller.rb +++ b/app/controllers/professors_controller.rb @@ -29,7 +29,6 @@ class ProfessorsController < ApplicationController config.columns[:civil_status].options = { options: [["Solteiro(a)", "solteiro"], ["Casado(a)", "casado"]] } - config.nested.add_link(:affiliations) config.columns[:sex].form_ui = :select config.columns[:sex].options = { options: [["Masculino", "M"], ["Feminino", "F"]] } @@ -64,7 +63,7 @@ class ProfessorsController < ApplicationController config.show.columns = [ :name, :email, :cpf, :birthdate, :address, :birthdate, :civil_status, :identity_expedition_date, :identity_issuing_body, :identity_number, - :neighborhood, :sex, :enrollment_number, :siape, + :neighborhood, :sex, :enrollment_number, :siape, :institutions, :telephone1, :telephone2, :zip_code, :scholarships, :advisement_authorizations, :advisements_with_points, :academic_title_level, :academic_title_institution, diff --git a/app/controllers/program_levels_controller.rb b/app/controllers/program_levels_controller.rb index 082e828a..73722fd7 100644 --- a/app/controllers/program_levels_controller.rb +++ b/app/controllers/program_levels_controller.rb @@ -3,14 +3,19 @@ class ProgramLevelsController < ApplicationController authorize_resource active_scaffold :program_level do |config| - config.create.columns = [:level] - config.update.columns = [:level] + config.create.columns = [:level, :start_date, :end_date] + config.update.columns = [:level, :start_date, :end_date] config.show.columns = [:level, :start_date, :end_date] - config.list.columns = [:level, :start_date] + config.list.columns = [:level, :start_date, :end_date] + + config.actions.swap :search, :field_search + config.columns.add :active + config.field_search.columns = [:active] + + config.actions.exclude :deleted_records end protected - def do_update # BEFORE UPDATE # cria o histórico @@ -31,17 +36,4 @@ def do_update pl = ProgramLevel.last pl.update!(start_date: pl.updated_at) end - - def do_create - super - # AFTER CREATE - # Coloca a data de início com a mesma do created_at - - pl = ProgramLevel.last - pl.update!(start_date: pl.created_at) - end - - def conditions_for_collection - ["end_date is null"] - end end diff --git a/app/models/professor.rb b/app/models/professor.rb index 4fd7671d..49910236 100644 --- a/app/models/professor.rb +++ b/app/models/professor.rb @@ -18,8 +18,8 @@ class Professor < ApplicationRecord dependent: :restrict_with_exception has_many :thesis_defense_committee_enrollments, source: :enrollment, through: :thesis_defense_committee_participations - has_many :affiliations, dependent: :restrict_with_exception - has_many :institutions, through: :affiliations, dependent: :restrict_with_exception + has_many :affiliations + has_many :institutions, through: :affiliations accepts_nested_attributes_for :affiliations, allow_destroy: true, reject_if: :all_blank belongs_to :city, optional: true diff --git a/config/locales/navigation.pt-BR.yml b/config/locales/navigation.pt-BR.yml index 2ca25f64..1d7e58f3 100644 --- a/config/locales/navigation.pt-BR.yml +++ b/config/locales/navigation.pt-BR.yml @@ -81,7 +81,7 @@ pt-BR: notification_log: Notificações Enviadas custom_variable: Variáveis report_configuration: Configurações de Relatório - program_level: Nível + program_level: Conceito CAPES logout: label: 'Logout' diff --git a/config/locales/professor.pt-BR.yml b/config/locales/professor.pt-BR.yml index 29a06c91..17a6c80a 100644 --- a/config/locales/professor.pt-BR.yml +++ b/config/locales/professor.pt-BR.yml @@ -22,9 +22,7 @@ pt-BR: identity_issuing_place: "Local de Expedição" identity_number: "Número da identidade" affiliations: "Afiliações" - institution: - one: "Instituição" - other: "Instituições" + institutions: "Instituições" name: "Nome" neighborhood: "Bairro" professor_research_areas: "Áreas de Pesquisa" diff --git a/config/locales/program_level.pt-BR.yml b/config/locales/program_level.pt-BR.yml index afaa5d8c..de822339 100644 --- a/config/locales/program_level.pt-BR.yml +++ b/config/locales/program_level.pt-BR.yml @@ -2,11 +2,12 @@ pt-BR: activerecord: attributes: program_level: + active: Ativo? level: Nível start_date: Data de início end_date: Data de fim models: program_level: - one: Nível - other: Níveis \ No newline at end of file + one: Conceito CAPES + other: Conceito CAPES \ No newline at end of file From af1ff0f884810f77bff4ac21a7f9310ee388114c Mon Sep 17 00:00:00 2001 From: IMonardez Date: Tue, 24 Sep 2024 16:17:01 -0300 Subject: [PATCH 32/32] Issue #448 - Fixing tests --- config/locales/professor.pt-BR.yml | 3 +++ spec/models/professor_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config/locales/professor.pt-BR.yml b/config/locales/professor.pt-BR.yml index 17a6c80a..65f65bf4 100644 --- a/config/locales/professor.pt-BR.yml +++ b/config/locales/professor.pt-BR.yml @@ -22,6 +22,9 @@ pt-BR: identity_issuing_place: "Local de Expedição" identity_number: "Número da identidade" affiliations: "Afiliações" + institution: + one: "Instituição" + other: "Instituições" institutions: "Instituições" name: "Nome" neighborhood: "Bairro" diff --git a/spec/models/professor_spec.rb b/spec/models/professor_spec.rb index ee11ed0e..cc87f79a 100644 --- a/spec/models/professor_spec.rb +++ b/spec/models/professor_spec.rb @@ -16,8 +16,8 @@ it { should have_many(:course_classes).dependent(:restrict_with_exception) } it { should have_many(:thesis_defense_committee_participations).dependent(:restrict_with_exception) } it { should have_many(:thesis_defense_committee_enrollments).source(:enrollment).through(:thesis_defense_committee_participations) } - it { should have_many(:affiliations).dependent(:restrict_with_exception) } - it { should have_many(:institutions).through(:affiliations).dependent(:restrict_with_exception) } + it { should have_many(:affiliations) } + it { should have_many(:institutions).through(:affiliations) } before(:all) do @professor_role = FactoryBot.create :role_professor @destroy_later = []