From 05174348d1ef3c9af4fab0c9182674b7ed06ba8f Mon Sep 17 00:00:00 2001 From: Joao Felipe Pimentel Date: Fri, 6 Dec 2024 02:49:51 -0300 Subject: [PATCH] #505: add paper page for quadrenial --- .../paper_professors_controller.rb | 16 ++++ app/controllers/paper_students_controller.rb | 16 ++++ app/controllers/papers_controller.rb | 90 +++++++++++++++++++ app/helpers/paper_professors_helper.rb | 7 ++ app/helpers/paper_students_helper.rb | 7 ++ app/helpers/papers_helper.rb | 31 +++++++ app/models/ability.rb | 13 ++- app/models/custom_variable.rb | 7 ++ app/models/paper.rb | 56 ++++++++++++ app/models/paper_professor.rb | 15 ++++ app/models/paper_student.rb | 10 +++ app/views/papers/_header_form_column.html.erb | 10 +++ .../_reason_group_end_form_column.html.erb | 4 + .../papers/_reason_group_form_column.html.erb | 25 ++++++ config/locales/navigation.pt-BR.yml | 1 + config/locales/paper.pt-BR.yml | 56 ++++++++++++ config/locales/paper_professor.pt-BR.yml | 17 ++++ config/locales/paper_student.pt-BR.yml | 17 ++++ config/navigation.rb | 1 + config/routes.rb | 12 +++ db/migrate/20241206024033_create_papers.rb | 34 +++++++ .../20241206024127_create_paper_students.rb | 15 ++++ .../20241206024146_create_paper_professors.rb | 15 ++++ ...4047_create_quadrennial_period_variable.rb | 16 ++++ db/schema.rb | 71 ++++++++++----- db/seeds.rb | 1 + spec/factories/factory_paper.rb | 18 ++++ spec/factories/factory_paper_professor.rb | 11 +++ spec/factories/factory_paper_student.rb | 11 +++ spec/models/paper_professor_spec.rb | 37 ++++++++ spec/models/paper_spec.rb | 55 ++++++++++++ spec/models/paper_student_spec.rb | 37 ++++++++ 32 files changed, 711 insertions(+), 21 deletions(-) create mode 100644 app/controllers/paper_professors_controller.rb create mode 100644 app/controllers/paper_students_controller.rb create mode 100644 app/controllers/papers_controller.rb create mode 100644 app/helpers/paper_professors_helper.rb create mode 100644 app/helpers/paper_students_helper.rb create mode 100644 app/helpers/papers_helper.rb create mode 100644 app/models/paper.rb create mode 100644 app/models/paper_professor.rb create mode 100644 app/models/paper_student.rb create mode 100644 app/views/papers/_header_form_column.html.erb create mode 100644 app/views/papers/_reason_group_end_form_column.html.erb create mode 100644 app/views/papers/_reason_group_form_column.html.erb create mode 100644 config/locales/paper.pt-BR.yml create mode 100644 config/locales/paper_professor.pt-BR.yml create mode 100644 config/locales/paper_student.pt-BR.yml create mode 100644 db/migrate/20241206024033_create_papers.rb create mode 100644 db/migrate/20241206024127_create_paper_students.rb create mode 100644 db/migrate/20241206024146_create_paper_professors.rb create mode 100644 db/migrate/20241206034047_create_quadrennial_period_variable.rb create mode 100644 spec/factories/factory_paper.rb create mode 100644 spec/factories/factory_paper_professor.rb create mode 100644 spec/factories/factory_paper_student.rb create mode 100644 spec/models/paper_professor_spec.rb create mode 100644 spec/models/paper_spec.rb create mode 100644 spec/models/paper_student_spec.rb diff --git a/app/controllers/paper_professors_controller.rb b/app/controllers/paper_professors_controller.rb new file mode 100644 index 00000000..5a032626 --- /dev/null +++ b/app/controllers/paper_professors_controller.rb @@ -0,0 +1,16 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class PaperProfessorsController < ApplicationController + authorize_resource + + active_scaffold :paper_professor do |config| + config.create.label = :create_paper_professor_label + config.columns = [:paper, :professor] + config.columns[:professor].form_ui = :record_select + + config.actions.exclude :deleted_records + end +end diff --git a/app/controllers/paper_students_controller.rb b/app/controllers/paper_students_controller.rb new file mode 100644 index 00000000..7c2681b0 --- /dev/null +++ b/app/controllers/paper_students_controller.rb @@ -0,0 +1,16 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class PaperStudentsController < ApplicationController + authorize_resource + + active_scaffold :paper_student do |config| + config.create.label = :create_paper_student_label + config.columns = [:paper, :student] + config.columns[:student].form_ui = :record_select + + config.actions.exclude :deleted_records + end +end diff --git a/app/controllers/papers_controller.rb b/app/controllers/papers_controller.rb new file mode 100644 index 00000000..feb89caf --- /dev/null +++ b/app/controllers/papers_controller.rb @@ -0,0 +1,90 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class PapersController < ApplicationController + authorize_resource + + active_scaffold :paper do |config| + config.create.label = :create_paper_label + config.actions.swap :search, :field_search + config.list.sorting = { period: "DESC", owner: "ASC", order: "ASC" } + + config.columns.add :header + config.columns.add :reason_group + config.columns.add :reason_group_end + form_columns = [ + :header, + :period, :owner, :reference, :order, :kind, :doi_issn_event, + :paper_professors, :paper_students, :other_authors, + :reason_group, + :reason_impact_factor, + :reason_international_list, + :reason_citations, + :reason_national_interest, + :reason_international_interest, + :reason_national_representativeness, + :reason_scientific_contribution, + :reason_tech_contribution, + :reason_innovation_contribution, + :reason_social_contribution, + :reason_other, + :reason_justify, + :impact_factor, + :reason_group_end, + :other, + ] + config.create.columns = form_columns + config.update.columns = form_columns + config.show.columns = [ + :period, :owner, :reference, :kind, :doi_issn_event, + :paper_professors, :paper_students, :other_authors, + :reason_impact_factor, + :reason_international_list, + :reason_citations, + :reason_national_interest, + :reason_international_interest, + :reason_national_representativeness, + :reason_scientific_contribution, + :reason_tech_contribution, + :reason_innovation_contribution, + :reason_social_contribution, + :reason_other, + :reason_justify, + :impact_factor, + :order, + :other, + ] + config.list.columns = [ + :period, :owner, :order, :reference + ] + + config.columns[:owner].form_ui = :record_select + config.columns[:kind].form_ui = :select + config.columns[:kind].options = { + options: Paper::KINDS, + include_blank: I18n.t("active_scaffold._select_") + } + config.columns[:order].form_ui = :select + config.columns[:order].options = { + options: Paper::ORDERS, + include_blank: I18n.t("active_scaffold._select_") + } + + + config.columns[:paper_students].show_blank_record = false + config.columns[:paper_professors].show_blank_record = false + + config.actions.exclude :deleted_records + end + + protected + def do_new + super + @record.period = CustomVariable.quadrennial_period + unless current_user.professor.blank? + @record.owner = current_user.professor + end + end +end diff --git a/app/helpers/paper_professors_helper.rb b/app/helpers/paper_professors_helper.rb new file mode 100644 index 00000000..5e2d8c7e --- /dev/null +++ b/app/helpers/paper_professors_helper.rb @@ -0,0 +1,7 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +module PaperProfessorsHelper +end \ No newline at end of file diff --git a/app/helpers/paper_students_helper.rb b/app/helpers/paper_students_helper.rb new file mode 100644 index 00000000..2e20d80a --- /dev/null +++ b/app/helpers/paper_students_helper.rb @@ -0,0 +1,7 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +module PaperStudentsHelper +end \ No newline at end of file diff --git a/app/helpers/papers_helper.rb b/app/helpers/papers_helper.rb new file mode 100644 index 00000000..c1366ca5 --- /dev/null +++ b/app/helpers/papers_helper.rb @@ -0,0 +1,31 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +module PapersHelper + def owner_form_column(record, options) + if can?(:edit_professor, record) + record_select_field :owner, record.owner || Professor.new, options + else + options[:value] = record.owner_id + label( + :record_value_1_params, record.id, record.owner.name + ) + hidden_field(:record, :owner, options) + end + end + + def period_form_column(record, options) + if can?(:edit_professor, record) + text_field :record, :period, options + else + label( + :record_value_1_params, record.id, record.period + ) + hidden_field(:record, :period, options) + end + end + + def reason_group_form_column(record, options) + "aaaa" + end +end \ No newline at end of file diff --git a/app/models/ability.rb b/app/models/ability.rb index 95d66b3c..b84d5833 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -16,7 +16,7 @@ class Ability PROFESSOR_MODELS = [ Professor, Advisement, AdvisementAuthorization, ThesisDefenseCommitteeParticipation, - ProfessorResearchArea, Grant + ProfessorResearchArea, Grant, Paper, PaperProfessor, PaperStudent ] SCHOLARSHIP_MODELS = [ @@ -146,8 +146,19 @@ def initialize_professors(user, roles) if roles[Role::ROLE_PROFESSOR] can :read, Ability::PROFESSOR_MODELS cannot :edit_professor, Grant + cannot :edit_professor, Paper can :create, Grant can :update, Grant, professor: user.professor + can :destroy, Grant, professor: user.professor + can :create, Paper + can :update, Paper, owner: user.professor + can :create, PaperProfessor + can :create, PaperStudent + can :update, PaperProfessor, paper: { owner: user.professor } + can :update, PaperStudent, paper: { owner: user.professor } + can :destroy, PaperProfessor, paper: { owner: user.professor } + can :destroy, PaperStudent, paper: { owner: user.professor } + can :destroy, Paper, owner: user.professor end end diff --git a/app/models/custom_variable.rb b/app/models/custom_variable.rb index 4ed0fee1..09277ac1 100644 --- a/app/models/custom_variable.rb +++ b/app/models/custom_variable.rb @@ -25,6 +25,7 @@ class CustomVariable < ApplicationRecord "year_semester_range" => :text, "past_calendar_range" => :text, "academic_calendar_range" => :text, + "quadrennial_period" => :text, } validates :variable, presence: true @@ -115,6 +116,12 @@ def self.academic_calendar_range self.parse_calendar_range(config, [20, 10, false]) end + def self.quadrennial_period + config = CustomVariable.find_by_variable(:quadrennial_period) + config.blank? ? "Not defined" : config.value + end + + def to_label self.variable.to_s end diff --git a/app/models/paper.rb b/app/models/paper.rb new file mode 100644 index 00000000..34d06364 --- /dev/null +++ b/app/models/paper.rb @@ -0,0 +1,56 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class Paper < ApplicationRecord + has_paper_trail + + attr_accessor :reason_group, :reason_group_end, :header + + belongs_to :owner, optional: false, class_name: "Professor" + has_many :paper_professors, dependent: :destroy + has_many :paper_students, dependent: :destroy + has_many :professors, through: :paper_professors + has_many :students, through: :paper_students + + JOURNAL = I18n.translate( + "activerecord.attributes.paper.kinds.journal" + ) + CONFERENCE = I18n.translate( + "activerecord.attributes.paper.kinds.conference" + ) + KINDS = [JOURNAL, CONFERENCE] + + ORDERS = [1, 2, 3, 4, 5, 6, 7, 8] + + validates :reference, presence: true + validates :kind, presence: true, inclusion: { in: KINDS } + validates :doi_issn_event, presence: true + validates :reason_justify, presence: true + validates :impact_factor, presence: true + validates :order, presence: true, inclusion: { in: ORDERS }, uniqueness: { + scope: [:period, :owner_id], message: :order_uniqueness + } + + validate :that_professor_cannot_edit_other_papers, if: -> { cannot?(:edit_professor, self) } + + def that_professor_cannot_edit_other_papers + current_professor = current_user&.professor + return if current_professor.nil? + if self.changes[:owner_id].present? && self.changes[:owner_id] != [nil, current_professor.id] + self.errors.add(:owner, :cannot_edit_other_papers) + end + end + + def to_label + "[#{self.owner.to_label}] #{self.reference}" + end + + private + delegate :can?, :cannot?, to: :ability + + def ability + @ability ||= Ability.new(current_user) + end +end diff --git a/app/models/paper_professor.rb b/app/models/paper_professor.rb new file mode 100644 index 00000000..733596ca --- /dev/null +++ b/app/models/paper_professor.rb @@ -0,0 +1,15 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class PaperProfessor < ApplicationRecord + has_paper_trail + + belongs_to :paper, optional: false + belongs_to :professor, optional: false + + def to_label + "#{self.professor.to_label} - #{self.paper.to_label}" + end +end diff --git a/app/models/paper_student.rb b/app/models/paper_student.rb new file mode 100644 index 00000000..675ac399 --- /dev/null +++ b/app/models/paper_student.rb @@ -0,0 +1,10 @@ +class PaperStudent < ApplicationRecord + has_paper_trail + + belongs_to :paper + belongs_to :student + + def to_label + "#{self.student.to_label} - #{self.paper.to_label}" + end +end diff --git a/app/views/papers/_header_form_column.html.erb b/app/views/papers/_header_form_column.html.erb new file mode 100644 index 00000000..f14930ed --- /dev/null +++ b/app/views/papers/_header_form_column.html.erb @@ -0,0 +1,10 @@ +Lembre que o relatório final é a coleção de artigos do programa. Assim: + + + +
+
\ No newline at end of file diff --git a/app/views/papers/_reason_group_end_form_column.html.erb b/app/views/papers/_reason_group_end_form_column.html.erb new file mode 100644 index 00000000..d0203440 --- /dev/null +++ b/app/views/papers/_reason_group_end_form_column.html.erb @@ -0,0 +1,4 @@ + + + +
  • \ No newline at end of file diff --git a/app/views/papers/_reason_group_form_column.html.erb b/app/views/papers/_reason_group_form_column.html.erb new file mode 100644 index 00000000..398c96d2 --- /dev/null +++ b/app/views/papers/_reason_group_form_column.html.erb @@ -0,0 +1,25 @@ +
  • + + +<% id ||= "group_#{SecureRandom.random_number(1_000_000)}" %> +
    Motivos Ocultar
    +
    + Quais aspectos atribui ao artigo para que ele entre na sua lista? +
  • \ No newline at end of file diff --git a/config/locales/navigation.pt-BR.yml b/config/locales/navigation.pt-BR.yml index a8809e2c..1e493224 100644 --- a/config/locales/navigation.pt-BR.yml +++ b/config/locales/navigation.pt-BR.yml @@ -22,6 +22,7 @@ pt-BR: advisement_authorization: Credenciamentos thesis_defense_committee_participation: Bancas grant: Coordenações de Projetos + paper: Avaliação quadrienal - 4N scholarships: label: Bolsas diff --git a/config/locales/paper.pt-BR.yml b/config/locales/paper.pt-BR.yml new file mode 100644 index 00000000..e20cf0d0 --- /dev/null +++ b/config/locales/paper.pt-BR.yml @@ -0,0 +1,56 @@ +# 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: + paper: + period: Avaliação quadrienal - 4N + owner: "Professor" + reference: "Referência completa" + kind: "Tipo" + kinds: + journal: "Periódico" + conference: "Conferência" + doi_issn_event: "DOI ou ISSN ou Sigla Evento" + students: "Autores discentes da Pós ou egressos" + paper_students: "Autores discentes da Pós ou egressos" + professors: "Autores docentes da Pós" + paper_professors: "Autores docentes da Pós" + other_authors: "Outros autores separados por ';'" + reasons: "Quais aspectos atribui ao artigo para que ele entre na sua lista?" + reason_impact_factor: "Valor quantitativo do fórum (fator de impacto, h-index)" + reason_international_list: "Fórum em alguma lista de referência internacional (p.ex. CSRankings)" + reason_citations: "Número elevado de citações para a sua área" + reason_national_interest: "Receptividade da comunidade nacional (p.ex, se seu artigo teve muito interesse ao ser apresentado em um evento nacional, ou se muitas pessoas no Brasil te perguntaram sobre ele)" + reason_international_interest: "Recepetividade da comunidade internacional (p.ex, se seu artigo teve muito interesse ao ser apresentado em um evento internacional, ou se muitas pessoas fora do Brasil te perguntaram sobre ele)" + reason_national_representativeness: "Representatividade nacional (p.ex., se é um fórum que poucos brasileiros conseguem publicar)" + reason_scientific_contribution: "Contribuição científica (p.ex., é uma contribuição original de um método, um algoritmo, uma prova matemática, uma investigação científica)" + reason_tech_contribution: "Contribuição tecnológica (p.ex. é um produto de software de código aberto)" + reason_innovation_contribution: "Contribuição de inovação (p.ex., se o artigo poderia ser uma ideia inicial para uma startup)" + reason_social_contribution: "Contribuição social (p.ex., se o artigo apresenta uma solução inovadora para um problema da sociedade)" + reason_other: "Outro aspecto" + reason_justify: "Justifique brevemente as suas marcações na pergunta anterior" + impact_factor: "Valor quantitativo do fórum (fator de impacto, h-index, JCR, etc)" + order: "Relevância" + other: "Caso queira, descreva brevemente qualquer outro ponto que ache relevante para o artigo." + description: + paper: + reference: "(conforme informado para o Sucupira)" + doi_issn_event: "(conforme informado na Sucupira)" + other_authors: "(caso não tenha, informar NA)" + order: "Considerando o conjunto que você selecionou (1 é o mais relevante)" + + errors: + models: + paper: + cannot_edit_other_papers: "não pode ser editado por este usuário" + order_uniqueness: "deve ser única para professor no período quadrienal" + + models: + paper: + one: "Avaliação quadrienal - 4N" + other: "Artigo" + + active_scaffold: + create_paper_label: "Adicionar Artigo" diff --git a/config/locales/paper_professor.pt-BR.yml b/config/locales/paper_professor.pt-BR.yml new file mode 100644 index 00000000..73873d8f --- /dev/null +++ b/config/locales/paper_professor.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: + paper_professor: + paper: "Artigo" + professor: "Docente" + + models: + paper_professor: + one: "Docente Autor" + other: "Docentes Autores" + + active_scaffold: + create_paper_professor_label: "Adicionar Docente Autor" diff --git a/config/locales/paper_student.pt-BR.yml b/config/locales/paper_student.pt-BR.yml new file mode 100644 index 00000000..f58806a3 --- /dev/null +++ b/config/locales/paper_student.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: + paper_student: + paper: "Artigo" + student: "Discente" + + models: + paper_student: + one: "Discente Autor" + other: "Discentes Autores" + + active_scaffold: + create_paper_student_label: "Adicionar Discente Autor" diff --git a/config/navigation.rb b/config/navigation.rb index 640a3206..71455181 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -150,6 +150,7 @@ def can_read?(*args) submenu.modelitem AdvisementAuthorization submenu.modelitem ThesisDefenseCommitteeParticipation submenu.modelitem Grant + submenu.modelitem Paper end scholar_models = [Scholarship, ScholarshipType, ScholarshipDuration] diff --git a/config/routes.rb b/config/routes.rb index 0ef13e69..14a0c2f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -538,4 +538,16 @@ concerns :active_scaffold end + resources :paper_professors do + concerns :active_scaffold + end + + resources :paper_students do + concerns :active_scaffold + end + + resources :papers do + concerns :active_scaffold + end + end diff --git a/db/migrate/20241206024033_create_papers.rb b/db/migrate/20241206024033_create_papers.rb new file mode 100644 index 00000000..0166ff24 --- /dev/null +++ b/db/migrate/20241206024033_create_papers.rb @@ -0,0 +1,34 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class CreatePapers < ActiveRecord::Migration[7.0] + def change + create_table :papers do |t| + t.string :period + t.text :reference + t.string :kind + t.string :doi_issn_event + t.references :owner, null: false, foreign_key: { to_table: :professors } + t.text :other_authors + t.boolean :reason_impact_factor, null: false, default: false + t.boolean :reason_international_list, null: false, default: false + t.boolean :reason_citations, null: false, default: false + t.boolean :reason_national_interest, null: false, default: false + t.boolean :reason_international_interest, null: false, default: false + t.boolean :reason_national_representativeness, null: false, default: false + t.boolean :reason_scientific_contribution, null: false, default: false + t.boolean :reason_tech_contribution, null: false, default: false + t.boolean :reason_innovation_contribution, null: false, default: false + t.boolean :reason_social_contribution, null: false, default: false + t.text :reason_other + t.text :reason_justify + t.string :impact_factor + t.integer :order + t.text :other + + t.timestamps + end + end +end diff --git a/db/migrate/20241206024127_create_paper_students.rb b/db/migrate/20241206024127_create_paper_students.rb new file mode 100644 index 00000000..02760866 --- /dev/null +++ b/db/migrate/20241206024127_create_paper_students.rb @@ -0,0 +1,15 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class CreatePaperStudents < ActiveRecord::Migration[7.0] + def change + create_table :paper_students do |t| + t.references :paper, null: false, foreign_key: true + t.references :student, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20241206024146_create_paper_professors.rb b/db/migrate/20241206024146_create_paper_professors.rb new file mode 100644 index 00000000..dc699d4f --- /dev/null +++ b/db/migrate/20241206024146_create_paper_professors.rb @@ -0,0 +1,15 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class CreatePaperProfessors < ActiveRecord::Migration[7.0] + def change + create_table :paper_professors do |t| + t.references :paper, null: false, foreign_key: true + t.references :professor, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20241206034047_create_quadrennial_period_variable.rb b/db/migrate/20241206034047_create_quadrennial_period_variable.rb new file mode 100644 index 00000000..d23a74e8 --- /dev/null +++ b/db/migrate/20241206034047_create_quadrennial_period_variable.rb @@ -0,0 +1,16 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +class CreateQuadrennialPeriodVariable < ActiveRecord::Migration[7.0] + def up + CustomVariable.where( + variable: "quadrennial_period" + ).first || CustomVariable.create( + description: "Periodo da Avaliação Quadrienal", + variable: "quadrennial_period", + value: "2021 - 2024" + ) + end +end diff --git a/db/schema.rb b/db/schema.rb index 2d4d0379..08c0faaf 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_11_29_022042) do +ActiveRecord::Schema[7.0].define(version: 2024_12_06_034047) do create_table "accomplishments", force: :cascade do |t| t.integer "enrollment_id" t.integer "phase_id" @@ -256,17 +256,6 @@ 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.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 @@ -665,6 +654,51 @@ t.index ["query_id"], name: "index_notifications_on_query_id" end + create_table "paper_professors", force: :cascade do |t| + t.integer "paper_id", null: false + t.integer "professor_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["paper_id"], name: "index_paper_professors_on_paper_id" + t.index ["professor_id"], name: "index_paper_professors_on_professor_id" + end + + create_table "paper_students", force: :cascade do |t| + t.integer "paper_id", null: false + t.integer "student_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["paper_id"], name: "index_paper_students_on_paper_id" + t.index ["student_id"], name: "index_paper_students_on_student_id" + end + + create_table "papers", force: :cascade do |t| + t.string "period" + t.text "reference" + t.string "kind" + t.string "doi_issn_event" + t.integer "owner_id", null: false + t.text "other_authors" + t.boolean "reason_impact_factor", default: false, null: false + t.boolean "reason_international_list", default: false, null: false + t.boolean "reason_citations", default: false, null: false + t.boolean "reason_national_interest", default: false, null: false + t.boolean "reason_international_interest", default: false, null: false + t.boolean "reason_national_representativeness", default: false, null: false + t.boolean "reason_scientific_contribution", default: false, null: false + t.boolean "reason_tech_contribution", default: false, null: false + t.boolean "reason_innovation_contribution", default: false, null: false + t.boolean "reason_social_contribution", default: false, null: false + t.text "reason_other" + t.text "reason_justify" + t.string "impact_factor" + t.integer "order" + t.text "other" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["owner_id"], name: "index_papers_on_owner_id" + end + create_table "phase_completions", force: :cascade do |t| t.integer "enrollment_id" t.integer "phase_id" @@ -745,14 +779,6 @@ 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.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" @@ -1044,6 +1070,11 @@ end add_foreign_key "grants", "professors" + add_foreign_key "paper_professors", "papers" + add_foreign_key "paper_professors", "professors" + add_foreign_key "paper_students", "papers" + add_foreign_key "paper_students", "students" + add_foreign_key "papers", "professors", column: "owner_id" add_foreign_key "reports", "carrier_wave_files", column: "carrierwave_file_id" add_foreign_key "reports", "users", column: "generated_by_id" end diff --git a/db/seeds.rb b/db/seeds.rb index a96c2d47..9f89bc0e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -32,6 +32,7 @@ { description: "Nota mínima para aprovação", variable: "minimum_grade_for_approval", value: "6.0" }, { 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" }, + { description: "Periodo da Avaliação Quadrienal", variable: "quadrennial_period", value: "2021 - 2021" }, ]) ReportConfiguration.create([ diff --git a/spec/factories/factory_paper.rb b/spec/factories/factory_paper.rb new file mode 100644 index 00000000..412018df --- /dev/null +++ b/spec/factories/factory_paper.rb @@ -0,0 +1,18 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +FactoryBot.define do + factory :paper do + period { "2021 - 2024" } + reference { "Autor. Artigo. Ano"} + kind { "Periódico" } + doi_issn_event { "10000000" } + owner { create(:professor) } + reason_international_list { true } + reason_justify { "Internacional" } + impact_factor { "1" } + order { 1 } + end +end diff --git a/spec/factories/factory_paper_professor.rb b/spec/factories/factory_paper_professor.rb new file mode 100644 index 00000000..612a0dab --- /dev/null +++ b/spec/factories/factory_paper_professor.rb @@ -0,0 +1,11 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +FactoryBot.define do + factory :paper_professor do + paper + professor + end +end diff --git a/spec/factories/factory_paper_student.rb b/spec/factories/factory_paper_student.rb new file mode 100644 index 00000000..5a5f5d80 --- /dev/null +++ b/spec/factories/factory_paper_student.rb @@ -0,0 +1,11 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +FactoryBot.define do + factory :paper_student do + paper + student + end +end diff --git a/spec/models/paper_professor_spec.rb b/spec/models/paper_professor_spec.rb new file mode 100644 index 00000000..93d11402 --- /dev/null +++ b/spec/models/paper_professor_spec.rb @@ -0,0 +1,37 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe PaperProfessor, type: :model do + it { should be_able_to_be_destroyed } + it { should belong_to(:paper).required(true) } + it { should belong_to(:professor).required(true) } + + let(:professor) { FactoryBot.build(:professor) } + let(:paper) { FactoryBot.build(:paper) } + let(:paper_professor) do + PaperProfessor.new( + paper: paper, + professor: professor + ) + end + subject { paper_professor } + describe "Validations" do + it { should be_valid } + it { should validate_presence_of(:paper) } + it { should validate_presence_of(:professor) } + end + describe "Methods" do + describe "to_label" do + it "should return 'professor - paper'" do + professor.name = "Bia" + paper.owner.name = "Ana" + paper.reference = "Ana. Artigo. 2024" + expect(paper_professor.to_label).to eq("Bia - [Ana] Ana. Artigo. 2024") + end + end + end +end diff --git a/spec/models/paper_spec.rb b/spec/models/paper_spec.rb new file mode 100644 index 00000000..79f5ed20 --- /dev/null +++ b/spec/models/paper_spec.rb @@ -0,0 +1,55 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Paper, type: :model do + it { should be_able_to_be_destroyed } + it { should belong_to(:owner).required(true) } + it { should have_many(:paper_professors).dependent(:destroy) } + it { should have_many(:paper_students).dependent(:destroy) } + it { should have_many(:professors).through(:paper_professors) } + it { should have_many(:students).through(:paper_students) } + + let(:professor) { FactoryBot.build(:professor) } + let(:user) { FactoryBot.build(:user, professor: professor) } + let(:paper) do + Paper.new( + period: "2021 - 2024", + reference: "Autor. Artigo. Ano", + kind: Paper::JOURNAL, + doi_issn_event: "10000000", + owner: professor, + reason_international_list: true, + reason_justify: "Internacional", + impact_factor: "1", + order: 1 + ) + end + subject { paper } + describe "Validations" do + it { should be_valid } + it { should validate_presence_of(:reference) } + it { should validate_inclusion_of(:kind).in_array(Paper::KINDS) } + it { should validate_presence_of(:kind) } + it { should validate_inclusion_of(:order).in_array(Paper::ORDERS) } + it { should validate_uniqueness_of(:order).scoped_to([:period, :owner_id]).with_message(:order_uniqueness) } + it { should validate_presence_of(:order) } + it { should validate_presence_of(:doi_issn_event) } + it { should validate_presence_of(:reason_justify) } + it { should validate_presence_of(:impact_factor) } + # ToDo: professor cannot edit other papers + + end + describe "Methods" do + describe "to_label" do + it "should return '[professor] reference'" do + paper.owner.name = "Ana" + paper.reference = "Ana. Artigo. 2024" + expect(paper.to_label).to eq("[Ana] Ana. Artigo. 2024") + end + end + end +end diff --git a/spec/models/paper_student_spec.rb b/spec/models/paper_student_spec.rb new file mode 100644 index 00000000..23a35b2a --- /dev/null +++ b/spec/models/paper_student_spec.rb @@ -0,0 +1,37 @@ +# Copyright (c) Universidade Federal Fluminense (UFF). +# This file is part of SAPOS. Please, consult the license terms in the LICENSE file. + +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe PaperStudent, type: :model do + it { should be_able_to_be_destroyed } + it { should belong_to(:paper).required(true) } + it { should belong_to(:student).required(true) } + + let(:student) { FactoryBot.build(:student) } + let(:paper) { FactoryBot.build(:paper) } + let(:paper_student) do + PaperStudent.new( + paper: paper, + student: student + ) + end + subject { paper_student } + describe "Validations" do + it { should be_valid } + it { should validate_presence_of(:paper) } + it { should validate_presence_of(:student) } + end + describe "Methods" do + describe "to_label" do + it "should return 'student - paper'" do + student.name = "Bia" + paper.owner.name = "Ana" + paper.reference = "Ana. Artigo. 2024" + expect(paper_student.to_label).to eq("Bia - [Ana] Ana. Artigo. 2024") + end + end + end +end