Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portabilis patch 26/06/2024 #170

Merged
merged 12 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/controllers/api/v2/teaching_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class TeachingPlansController < Api::V2::BaseController
def index
return unless params[:teacher_id]

@unities = Unity.by_teacher(params[:teacher_id]).ordered.uniq
@unities = Unity.by_teacher(params[:teacher_id]).ordered.distinct
@unities = @unities.select do |unity|
TeachingPlan.by_unity_id(unity.id).exists?
end
@teacher_id = params[:teacher_id]
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def teacher_discipline_score_type_by_exam_rule(exam_rule, classroom = nil, disci
classroom: classroom,
teacher: current_teacher,
discipline: discipline
).score_type
)&.score_type
end

def set_user_current
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/disciplines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def disciplines_to_select2(classroom_id)
.not_descriptor

if current_user.teacher?
disciplines = disciplines.by_teacher_id(current_teacher.id)
disciplines = disciplines.by_teacher_id(current_teacher.id, current_school_year)
end

disciplines.map do |discipline|
Expand Down
5 changes: 3 additions & 2 deletions app/services/student_enrollment_classrooms_retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def call

enrollment_classrooms = search_by_dates(enrollment_classrooms) if include_date_range

# Nao filtra as enturmacoes caso municipio tenha DATABASE
if enrollment_classrooms.show_as_inactive.blank?
enrollment_classrooms = search_by_search_type(enrollment_classrooms)
enrollment_classrooms = reject_duplicated_students(enrollment_classrooms)
Expand Down Expand Up @@ -99,7 +98,9 @@ def search_by_search_type(enrollment_classrooms)
def reject_duplicated_students(enrollment_classrooms)
return enrollment_classrooms if show_inactive_enrollments

last_student_classroom = enrollment_classrooms.select{ |ec| ec.left_at.blank? }
last_student_classroom = enrollment_classrooms.select do |ec|
ec.left_at.blank? || ec.left_at.to_date.between?(start_at.to_date, end_at.to_date)
end
end

def show_inactive_enrollments
Expand Down
14 changes: 7 additions & 7 deletions app/services/user_by_csv_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def file_not_found
end

def create_users(entity)
errors = []
ActiveRecord::Base.transaction do
CSV.foreach(file, col_sep: ',', skip_blanks: true) do |new_user|
User.find_or_initialize_by(login: new_user[3]).tap do |user|
Expand All @@ -59,9 +60,10 @@ def create_users(entity)
first_name: new_user[0],
last_name: new_user[1])

user.save if user.changed?

raise invalid_user_error(user) if user.errors.any?
if user.changed? && !user.save
errors << invalid_user_error(user)
next
end

if set_admin_role(user) && send_mail
UserMailer.delay.by_csv(user.login, user.first_name, user.email, password, entity.domain)
Expand All @@ -70,11 +72,9 @@ def create_users(entity)
end
true
end
errors.empty? || puts(errors.join("\n"))
rescue ActiveRecord::RecordInvalid
false
rescue InvalidUserError => e
puts e.message
false
end

def set_admin_role(user)
Expand Down Expand Up @@ -103,6 +103,6 @@ def error
end

def invalid_user_error(user)
raise InvalidUserError, "Não foi possivel criar os usuarios devido ao erro #{user.errors.messages} para o usuario #{user.login}"
"Não foi possivel criar os usuarios devido ao erro #{user.errors.messages} para o usuario #{user.login}"
end
end
66 changes: 1 addition & 65 deletions spec/services/student_enrollment_classrooms_retriever_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
end
end

describe 'when the client works with DATA BASE' do
describe 'when the client works or not with DATA BASE' do
before do
# DATA BASE=(show_as_inactive_when_not_in_date:TRUE)
create_student_enrollment_classrooms_with_status_and_date_base
Expand Down Expand Up @@ -347,70 +347,6 @@
end
end

describe 'when the client does not works with DATA BASE' do
before do
# DATA BASE=(show_as_inactive_when_not_in_date:FALSE)
create_student_enrollment_classrooms_with_status_without_date_base
end

context 'and show_inactive checkbox is enabled in settings' do
before do
GeneralConfiguration.current.update(show_inactive_enrollments: true)
end

subject(:list_student_enrollment_classrooms) {
StudentEnrollmentClassroomsRetriever.call(
search_type: :by_date_range,
classrooms: classroom_grade.classroom_id,
disciplines: discipline,
start_at: '2023-03-03',
end_at: '2023-06-03'
)
}

let!(:status) {
list_student_enrollment_classrooms.map { |ec|
ec[:student_enrollment_classroom].student_enrollment.status
}.uniq
}

it 'should return student_enrollment_classrooms with all status' do
transferred = @enrollment_classroom_inactive.student_enrollment.status
studying = @enrollment_classroom_active.student_enrollment.status

expect(status).to match_array([studying, transferred])
end
end

context 'and show_inactive checkbox is not enabled in settings' do
before do
GeneralConfiguration.current.update(show_inactive_enrollments: false)
end

subject(:list_student_enrollment_classrooms) {
StudentEnrollmentClassroomsRetriever.call(
search_type: :by_date_range,
classrooms: classroom_grade.classroom_id,
disciplines: discipline,
start_at: '2023-03-03',
end_at: '2023-06-03'
)
}

let!(:status) {
list_student_enrollment_classrooms.map { |ec|
ec[:student_enrollment_classroom].student_enrollment.status
}.uniq
}

it 'should return student_enrollment_classrooms with all status' do
studying = @enrollment_classroom_active.student_enrollment.status

expect(status).to match_array([studying])
end
end
end

context 'when grade params exist' do
let!(:classroom_grade_without_liked) { create(:classrooms_grade) }

Expand Down
Loading