Skip to content

Commit

Permalink
Merge pull request #157 from portabilis/portabilis-patch-2024-02-22
Browse files Browse the repository at this point in the history
Portabilis patch 22/02/2024
  • Loading branch information
AnaPerola authored Feb 22, 2024
2 parents cc0ad82 + 0afaa79 commit 81ec4ac
Show file tree
Hide file tree
Showing 34 changed files with 260 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.rbc
capybara-*.html
/log
/coverage
/tmp
/db/*.sqlite3
/public/system
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ group :test do
gem 'rspec-sidekiq', '3.0.3'
gem 'rspec-wait', '0.0.9'
gem 'selenium-webdriver', '~> 3.0'
gem 'shoulda-matchers', '3.0.1'
gem 'shoulda-matchers', '~> 3.1', '>= 3.1.0'
gem 'timecop', '0.8.1'
gem 'turnip', '1.3.1'
gem 'vcr', '3.0.0'
gem 'webdrivers', '3.6.0'
gem 'webmock', '3.14.0'
gem 'simplecov', require: false
end

group :test, :development do
Expand Down
14 changes: 13 additions & 1 deletion app/assets/javascripts/views/discipline_lesson_plans/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ $(function () {
return { id: discipline['id'], text: discipline['description'] };
});

$discipline.select2({ data: selectedDisciplines });
$discipline.select2({ data: selectedDisciplines});
$discipline.val(selectedDisciplines[0].id).trigger('change');
};

function handleFetchDisciplinesError() {
Expand Down Expand Up @@ -183,6 +184,11 @@ $(function () {
event.preventDefault();
copyFromTeachingPlanAlert.style.display = 'none';

if (!$classroom.val() || !$discipline.val()) {
flashMessages.error('É necessário preenchimento das disciplinas e turmas para realizar a cópia.');
return false;
}

if (!startAtInput.value || !endAtInput.value) {
flashMessages.error('É necessário preenchimento das datas para realizar a cópia.');
return false;
Expand Down Expand Up @@ -234,6 +240,12 @@ $(function () {
flashMessages.error('É necessário preenchimento das datas para realizar a cópia.');
return false;
}

if (!$classroom.val() || !$discipline.val()) {
flashMessages.error('É necessário preenchimento das disciplinas e turmas para realizar a cópia.');
return false;
}

const url = Routes.teaching_plan_objectives_discipline_lesson_plans_en_path();
const params = {
classroom_id: $classroom.val(),
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/daily_frequencies_in_batchs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def authorize_daily_frequency
end

def view_data
@period = current_teacher_period != Periods::FULL.to_i ? current_teacher_period : nil
@period = current_teacher_period != Periods::FULL.to_i ? current_teacher_period : @classroom.period
@general_configuration = GeneralConfiguration.current
@frequency_type = current_frequency_type(@classroom)
params['dates'] = allocation_dates(@dates)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class Dashboard::TeacherPendingAvaliationsController < ApplicationController
before_action :require_current_teacher
before_action :require_current_classroom

def index
render json: TeacherPendingAvaliationsFetcher.new(teacher: current_teacher,
classroom: current_user_classroom,
Expand Down
18 changes: 11 additions & 7 deletions app/controllers/descriptive_exams_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class DescriptiveExamsController < ApplicationController
before_action :require_current_classroom
before_action :require_teacher
before_action :adjusted_period, only: [:edit, :update]
before_action :require_allow_to_modify_prev_years, only: :update
before_action :view_data, only: [:edit, :show]

Expand Down Expand Up @@ -47,14 +46,15 @@ def update
@descriptive_exam.assign_attributes(resource_params)
@descriptive_exam.step_id = find_step_id unless opinion_type_by_year?
@descriptive_exam.teacher_id = current_teacher_id
adjusted_period

regular_expression = /contenteditable(([ ]*)?\=?([ ]*)?("(.*)"|'(.*)'))/
@descriptive_exam.students.each do |exam_student|
value_by_student = resource_params[:students_attributes].values.detect do |student|
value_by_student = resource_params[:students_attributes].values.detect do |student|
student[:student_id] == exam_student.student_id.to_s
end
exam_student.value = value_by_student['value']

exam_student.value = value_by_student['value'] if value_by_student.present?
exam_student.value.gsub!(regular_expression, '') if exam_student.value.present?
end

Expand Down Expand Up @@ -325,16 +325,19 @@ def any_student_exempted_from_discipline?
(@students || []).any?(&:exempted_from_discipline)
end

def current_teacher_period
def current_teacher_period(classroom_id, discipline_id)
TeacherPeriodFetcher.new(
current_teacher.id,
current_user.current_classroom_id,
current_user.current_discipline_id
classroom_id,
discipline_id
).teacher_period
end

def adjusted_period
teacher_period = current_teacher_period
teacher_period = current_teacher_period(
@descriptive_exam.classroom_id,
@descriptive_exam.discipline_id,
)
@period = teacher_period != Periods::FULL.to_i ? teacher_period : nil
end

Expand Down Expand Up @@ -362,6 +365,7 @@ def view_data

authorize @descriptive_exam

adjusted_period
fetch_students
end
end
2 changes: 2 additions & 0 deletions app/controllers/discipline_content_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class DisciplineContentRecordsController < ApplicationController
has_scope :page, default: 1
has_scope :per, default: 10

before_action :require_current_classroom, only: [:index, :new, :edit, :create, :update]
before_action :require_current_teacher
before_action :require_current_classroom, only: [:index, :new, :create, :edit, :update]
before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy, :clone]

def index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class DisciplineLessonPlanReportController < ApplicationController
DISCIPLINE_LESSON_PLAN_REPORT = "1"
DISCIPLINE_CONTENT_RECORD = "2"

before_action :require_current_classroom, only: [:form, :lesson_plan_report, :content_record_report]
before_action :require_current_teacher

def form
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/discipline_lesson_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class DisciplineLessonPlansController < ApplicationController
has_scope :page, default: 1
has_scope :per, default: 10

before_action :require_current_classroom, only: [:new, :edit, :create, :update]
before_action :require_current_classroom, only: [:index, :new, :edit, :create, :update]
before_action :require_current_teacher
before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy, :clone]
before_action :require_allows_copy_experience_fields_in_lesson_plans, only: [:new, :edit]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/discipline_teaching_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DisciplineTeachingPlansController < ApplicationController
before_action :require_current_teacher, unless: :current_user_is_employee_or_administrator?
before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy]
before_action :yearly_term_type_id, only: [:show, :edit, :new]
before_action :require_current_classroom, only: [:index]
before_action :require_current_classroom, only: [:index, :new, :create, :edit, :update]
before_action :require_allows_copy_experience_fields_in_lesson_plans, only: [:new, :edit]

def index
Expand Down
1 change: 1 addition & 0 deletions app/controllers/final_recovery_diary_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def fetch_recovery_diary_records_by_user
.includes(recovery_diary_record: [:unity, :classroom, :discipline])
.filter(filtering_params(params[:search]))
.by_unity_id(current_unity.id)
.by_teacher_id(current_teacher.id)
.by_classroom_id(@classrooms.map(&:id))
.by_discipline_id(@disciplines.map(&:id))
.ordered
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/knowledge_area_content_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class KnowledgeAreaContentRecordsController < ApplicationController
has_scope :page, default: 1
has_scope :per, default: 10

before_action :require_current_classroom, only: [:index, :new, :edit, :create, :update]
before_action :require_current_teacher
before_action :require_current_classroom, only: [:index, :new, :create, :edit, :update, :show]
before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy, :clone]

def index
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class KnowledgeAreaLessonPlanReportController < ApplicationController
before_action :require_current_teacher
before_action :require_current_classroom, only: [:form, :lesson_plan_report, :content_record_report]

def form
@knowledge_area_lesson_plan_report_form = KnowledgeAreaLessonPlanReportForm.new(
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/knowledge_area_lesson_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class KnowledgeAreaLessonPlansController < ApplicationController
has_scope :page, default: 1
has_scope :per, default: 10

before_action :require_current_classroom, only: [:new, :edit, :create, :update]
before_action :require_current_classroom, only: [:index, :new, :edit, :create, :update]
before_action :require_current_teacher
before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy, :clone]

Expand Down
5 changes: 3 additions & 2 deletions app/controllers/knowledge_area_teaching_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class KnowledgeAreaTeachingPlansController < ApplicationController
before_action :require_current_teacher, unless: :current_user_is_employee_or_administrator?
before_action :require_allow_to_modify_prev_years, only: [:create, :update, :destroy]
before_action :yearly_term_type_id, only: [:show, :edit, :new]
before_action :require_current_classroom, only: [:index]
before_action :require_current_classroom, only: [:index, :new, :create, :edit, :update]

def index
params[:filter] ||= {}
Expand Down Expand Up @@ -164,7 +164,8 @@ def copy
teaching_plan: @knowledge_area_teaching_plan.teaching_plan
)

fetch_knowledge_areas
set_options_by_user
set_knowledge_area_by_classroom(@classrooms.map(&:id))
end

def do_copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def set_school_term_recovery_diary_records
.by_classroom_id(@classrooms.map(&:id))
.by_discipline_id(@disciplines.map(&:id))
.ordered
.distinct

unless @admin_or_teacher
@school_term_recovery_diary_records = @school_term_recovery_diary_records.by_teacher_id(current_teacher.id).distinct
Expand Down
1 change: 1 addition & 0 deletions app/controllers/teacher_report_cards_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class TeacherReportCardsController < ApplicationController
before_action :require_current_teacher
before_action :require_current_classroom

def form
@teacher_report_card_form = TeacherReportCardForm.new(
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/transfer_notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,16 @@ def fetch_linked_by_teacher
def update_daily_note_student(daily_note_students_attributes)
ActiveRecord::Base.transaction do
daily_note_students_attributes.values.each do |data|
record = DailyNoteStudent.find_or_initialize_by(
record = DailyNoteStudent.with_discarded.find_or_initialize_by(
daily_note_id: data[:daily_note_id],
student_id: data[:student_id]
).localized

record.assign_attributes(
note: data[:note],
transfer_note_id: @transfer_note.id
transfer_note_id: @transfer_note.id,
discarded_at: '',
active: true
)
record.save!
end
Expand Down
15 changes: 14 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ class UsersController < ApplicationController
has_scope :per, default: 10

def index
params[:search][:by_name] = params[:search][:by_name].squish if params[:search].present?
unless valid_search_params?(params[:search])
redirect_to root_path, status: 302
return
end

if params[:search]&.dig(:by_name).present?
params[:search][:by_name] = params[:search][:by_name].squish
end

@users = apply_scopes(User.filter(filtering_params params[:search]).ordered)

Expand Down Expand Up @@ -156,4 +163,10 @@ def valid_update

false
end

def valid_search_params?(params_search)
return true if params_search.blank?

params_search.values.any?(&:present?)
end
end
2 changes: 0 additions & 2 deletions app/models/school_term_recovery_diary_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class SchoolTermRecoveryDiaryRecord < ApplicationRecord
validate :recovery_type_must_allow_recovery_for_classroom
validate :uniqueness_of_school_term_recovery_diary_record

delegate :classroom, :classroom_id, :discipline_id, :discipline, to: :recovery_diary_record

def test_date
recorded_at
end
Expand Down
5 changes: 2 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class User < ApplicationRecord

after_save :update_fullname_tokens
before_save :remove_spaces_from_name
after_validation :status_changed

before_destroy :clear_allocation
before_validation :verify_receive_news_fields
Expand Down Expand Up @@ -67,13 +68,11 @@ class User < ApplicationRecord
validates_associated :user_roles

validate :valid_password
validate :status_changed
validate :email_reserved_for_student
validate :presence_of_email_or_cpf
validate :validate_receive_news_fields, if: :has_to_validate_receive_news_fields?
validate :can_not_be_a_cpf
validate :can_not_be_an_email
validate :status_changed

scope :ordered, -> { order(arel_table[:fullname].asc) }
scope :email_ordered, -> { order(email: :asc) }
Expand Down Expand Up @@ -204,7 +203,7 @@ def update_last_password_change
end

def update_last_activity_at
update_column :last_activity_at, Date.current
self.last_activity_at = Date.current
end

def can_show?(feature)
Expand Down
4 changes: 2 additions & 2 deletions app/reports/attendance_record_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ def is_school_day?(date)

def set_teacher(teacher, classroom_id, current_user)
return teacher unless current_user.current_role_is_admin_or_employee?
return teacher if teacher.daily_frequencies.where(classroom_id: classroom_id).any?

Classroom.find(classroom_id).teacher_discipline_classrooms.first.teacher
teachers = Classroom.find(classroom_id).teacher_discipline_classrooms.map(&:teacher)
teachers.include?(teacher) ? teacher : teachers.first
end
end
1 change: 1 addition & 0 deletions app/services/copy_discipline_teaching_plan_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def create_copies_discipline_teaching_plans(
copy_teaching_plan = teaching_plan.dup
copy_teaching_plan.unity_id = unity_id
copy_teaching_plan.grade_id = grade_id
copy_teaching_plan.year = year
copy_teaching_plan.contents_created_at_position = @contents_created_at_position
copy_teaching_plan.objectives_created_at_position = @objectives_created_at_position
copy_teaching_plan.content_ids = @content_ids
Expand Down
19 changes: 18 additions & 1 deletion app/services/ieducar_synchronizers/exam_rules_synchronizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def update_exam_rules(exam_rules)
exam_rule.parallel_exams_calculation_type =
exam_rule_record.tipo_calculo_recuperacao_paralela.to_i ||
ParallelExamsCalculationTypes::SUBSTITUTION
exam_rule.save! if exam_rule.changed?

if exam_rule.changed?
exam_rule.save!
update_descriptive_exams(exam_rule) if exam_rule.persisted?
end

if exam_rule_record.regra_diferenciada_id.present?
differentiated_exam_rules << [
Expand All @@ -56,4 +60,17 @@ def update_differentiated_exam_rules(differentiated_exam_rules)
end
end
end

def update_descriptive_exams(exam_rule)
return unless exam_rule.attribute_changed?("opinion_type")

classroom_ids = ClassroomsGrade.where(exam_rule_id: exam_rule.id)
.pluck(:classroom_id)
.uniq

DescriptiveExam.where(classroom_id: classroom_ids)
.where.not(opinion_type: exam_rule.opinion_type)
.destroy_all
DescriptiveExamStudent.by_classroom(classroom_ids).destroy_all
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def update_or_create_steps(school_calendar_steps, school_calendar_id)
start_date_for_posting = school_calendar_step.start_date_for_posting
end_date_for_posting = school_calendar_step.end_date_for_posting

if new_record || end_date_for_posting < start_at || end_date_for_posting < start_date_for_posting
if new_record || end_date_for_posting < start_at || end_date_for_posting < start_date_for_posting ||
end_date_for_posting > end_at
school_calendar_step.end_date_for_posting = end_at
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ def create_or_destroy_teacher_disciplines_classrooms(
discipline_id: fake_discipline.id,
discipline_api_code: "grouper:#{fake_discipline.id}",
classroom_id: teacher_discipline_classroom.classroom_id,
classroom_api_code: "grouper:#{fake_discipline.id}"
classroom_api_code: "grouper:#{fake_discipline.id}",
period: teacher_discipline_classroom.period
)

link_teacher.undiscard if link_teacher.discarded?
Expand Down
Loading

0 comments on commit 81ec4ac

Please sign in to comment.