Skip to content

Commit

Permalink
Merge pull request #65 from portabilis/portabilis-patch-2020-03-30
Browse files Browse the repository at this point in the history
Portabilis patch 30/03/2021
  • Loading branch information
jayata authored Mar 30, 2021
2 parents 4b28aff 3bd5681 commit d3c0769
Show file tree
Hide file tree
Showing 57 changed files with 412 additions and 165 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@ ruby '2.4.10'
gem 'active_model_serializers', '0.9.3'
gem 'activerecord-connections', git: 'https://github.com/ricardohsd/activerecord-connections.git'
gem 'activerecord-tableless', '2.0.0'
gem 'audited-activerecord', '4.0.0.rc1', git: 'https://github.com/portabilis/audited.git'
gem 'audited', git: 'https://github.com/portabilis/audited.git'
gem 'aws-sdk-s3', '~>1.83.0'
gem 'backbone-nested-attributes', '0.3.0', git: 'https://github.com/samuelsimoes/backbone-nested-attributes.git'
gem 'binding_of_caller', '1.0.0'
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 114,16 @@ development:
SMTP_PASSWORD: SMTP_PASSWORD
NO_REPLY_ADDRESS: NO_REPLY_ADDRESS
EMAIL_SKIP_DOMAINS: EMAIL_SKIP_DOMAINS
STUDENT_DOMAIN: STUDENT_DOMAIN
```
_Nota: Você pode gerar uma chave secreta usando o comando `bundle exec rake secret`_

_Nota: Use `EMAIL_SKIP_DOMAINS` para informar domínios (separadas por virgula e sem espaço) para os quais não quer
que o sistema faça envio de emails_

_Nota: Use `STUDENT_DOMAIN` para informar o domínio que vai ser usado para criar as contas de usuarios dos alunos na sincronização. Se não for informado, o checkbox que permite essa funcionalidade na tela de configurações não vai ser apresentado_

- Crie o banco de dados:

```bash
Expand Down Expand Up @@ -205,7 208,8 @@ Entity.last.using_connection {
password_confirmation: '123456789',
status: 'active',
kind: 'employee',
admin: true
admin: true,
first_name: 'Admin'
)
}
```
Expand Down
Binary file removed app/assets/images/finger.png
Binary file not shown.
16 changes: 16 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 28,7 @@ class ApplicationController < ActionController::Base
before_action :check_for_current_user_role, if: :user_signed_in?
before_action :set_current_unity_id, if: :user_signed_in?
before_action :set_current_user_role_id, if: :user_signed_in?
before_action :check_user_has_name, if: :user_signed_in?

has_scope :q do |controller, scope, value|
scope.search(value).limit(10)
Expand Down Expand Up @@ -378,4 379,19 @@ def send_pdf(prefix, pdf_to_s)
def report_name(prefix)
"/relatorios/#{prefix}-#{SecureRandom.hex}.pdf"
end

def check_user_has_name
return if current_user.first_name.present?
return if target_path?

flash[:alert] = t('errors.general.check_user_has_name')

redirect_to edit_user_path(current_user)
end

def target_path?
request_path = Rails.application.routes.recognize_path(request.path, method: request.env['REQUEST_METHOD'])

request_path[:controller] == 'users' && (request_path[:action] == 'edit' || request_path[:action] == 'update')
end
end
9 changes: 5 additions & 4 deletions app/controllers/discipline_lesson_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 122,11 @@ def history
end

def clone
@form = DisciplineLessonPlanClonerForm.new(clone_params.merge(teacher: current_teacher))
if @form.clone!
flash[:success] = "Plano de aula por disciplina copiado com sucesso!"
end
@form = DisciplineLessonPlanClonerForm.new(
clone_params.merge(teacher: current_teacher, entity_id: current_entity.id)
)

flash[:success] = t('.messages.copy_succeed') if @form.clone!
end

def teaching_plan_contents
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/knowledge_area_lesson_plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 142,11 @@ def history
end

def clone
@form = KnowledgeAreaLessonPlanClonerForm.new(clone_params.merge(teacher: current_teacher))
@form = KnowledgeAreaLessonPlanClonerForm.new(
clone_params.merge(teacher: current_teacher, entity_id: current_entity.id)
)

flash[:success] = t('messages.copy_succeed') if @form.clone!
flash[:success] = t('.messages.copy_succeed') if @form.clone!
end

def teaching_plan_contents
Expand Down
94 changes: 55 additions & 39 deletions app/forms/discipline_lesson_plan_cloner_form.rb
Original file line number Diff line number Diff line change
@@ -1,59 1,75 @@
class DisciplineLessonPlanClonerForm < ActiveRecord::Base
has_no_table

attr_accessor :discipline_lesson_plan_id, :teacher
attr_accessor :discipline_lesson_plan_id, :teacher, :entity_id

validates :discipline_lesson_plan_id, presence: true
has_many :discipline_lesson_plan_item_cloner_form
accepts_nested_attributes_for :discipline_lesson_plan_item_cloner_form, allow_destroy: true

def clone!
if valid?
begin
ActiveRecord::Base.transaction do
@classrooms = Classroom.where(id: discipline_lesson_plan_item_cloner_form.map(&:classroom_id).uniq)
discipline_lesson_plan_item_cloner_form.each_with_index do |item, index|
@current_item_index = index
new_lesson_plan = discipline_lesson_plan.dup
new_lesson_plan.teacher_id = teacher.id
new_lesson_plan.lesson_plan = discipline_lesson_plan.lesson_plan.dup
new_lesson_plan.lesson_plan.teacher = teacher
new_lesson_plan.lesson_plan.original_contents = discipline_lesson_plan.lesson_plan.contents
new_lesson_plan.lesson_plan.contents_created_at_position = {}
new_lesson_plan.lesson_plan.original_contents.each_with_index do |content, position|
new_lesson_plan.lesson_plan.contents_created_at_position[content.id] = position
end

new_lesson_plan.lesson_plan.original_objectives = discipline_lesson_plan.lesson_plan.objectives
new_lesson_plan.lesson_plan.objectives_created_at_position = {}
new_lesson_plan.lesson_plan.original_objectives.each_with_index do |objective, position|
new_lesson_plan.lesson_plan.objectives_created_at_position[objective.id] = position
end

new_lesson_plan.lesson_plan.start_at = item.start_at
new_lesson_plan.lesson_plan.end_at = item.end_at
new_lesson_plan.lesson_plan.classroom = @classrooms.find_by_id(item.classroom_id)
discipline_lesson_plan.lesson_plan.lesson_plan_attachments.each do |lesson_plan_attachment|
new_lesson_plan.lesson_plan.lesson_plan_attachments << LessonPlanAttachment.new(
attachment: lesson_plan_attachment.attachment
)
end
new_lesson_plan.save!
return unless valid?

begin
ActiveRecord::Base.transaction do
@classrooms = Classroom.where(id: discipline_lesson_plan_item_cloner_form.map(&:classroom_id).uniq)
discipline_lesson_plan_item_cloner_form.each_with_index do |item, index|
@current_item_index = index
new_lesson_plan = discipline_lesson_plan.dup
new_lesson_plan.teacher_id = teacher.id
new_lesson_plan.lesson_plan = discipline_lesson_plan.lesson_plan.dup
new_lesson_plan.lesson_plan.teacher = teacher
new_lesson_plan.lesson_plan.original_contents = discipline_lesson_plan.lesson_plan.contents
new_lesson_plan.lesson_plan.contents_created_at_position = {}
new_lesson_plan.lesson_plan.original_contents.each_with_index do |content, position|
new_lesson_plan.lesson_plan.contents_created_at_position[content.id] = position
end

new_lesson_plan.lesson_plan.original_objectives = discipline_lesson_plan.lesson_plan.objectives
new_lesson_plan.lesson_plan.objectives_created_at_position = {}
new_lesson_plan.lesson_plan.original_objectives.each_with_index do |objective, position|
new_lesson_plan.lesson_plan.objectives_created_at_position[objective.id] = position
end

new_lesson_plan.lesson_plan.start_at = item.start_at
new_lesson_plan.lesson_plan.end_at = item.end_at
new_lesson_plan.lesson_plan.classroom = @classrooms.find_by(id: item.classroom_id)

original_attachments = {}
discipline_lesson_plan.lesson_plan.lesson_plan_attachments.each do |lesson_plan_attachment|
original_attachments[lesson_plan_attachment.attachment.filename] = lesson_plan_attachment.id
new_lesson_plan.lesson_plan.lesson_plan_attachments << lesson_plan_attachment.dup
end
return true
new_lesson_plan.save!

copy_attachments(new_lesson_plan.id, original_attachments)
end
rescue ActiveRecord::RecordInvalid => e
message = e.to_s
message.slice!("A validação falhou: ")
errors.add(:classroom_id, "Turma #{e.record.lesson_plan.try(:classroom)}: #{message}")
discipline_lesson_plan_item_cloner_form[@current_item_index].errors.add(:classroom_id, message)
return false

return true
end
rescue ActiveRecord::RecordInvalid => e
message = e.to_s
message.slice!('A validação falhou: ')
errors.add(:classroom_id, "Turma #{e.record.lesson_plan.try(:classroom)}: #{message}")
discipline_lesson_plan_item_cloner_form[@current_item_index].errors.add(:classroom_id, message)

return false
end
end

def discipline_lesson_plan
@discipline_lesson_plan ||= DisciplineLessonPlan.includes(lesson_plan: [:objectives, :contents])
.find(discipline_lesson_plan_id)
end

def copy_attachments(new_lesson_plan_id, original_attachments)
return if new_lesson_plan_id.blank? || original_attachments.blank?

LessonPlanAttachmentCopierWorker.perform_async(
entity_id,
new_lesson_plan_id,
DisciplineLessonPlan,
original_attachments
)
end
end
104 changes: 60 additions & 44 deletions app/forms/knowledge_area_lesson_plan_cloner_form.rb
Original file line number Diff line number Diff line change
@@ -1,62 1,78 @@
class KnowledgeAreaLessonPlanClonerForm < ActiveRecord::Base
has_no_table

attr_accessor :knowledge_area_lesson_plan_id, :teacher
attr_accessor :knowledge_area_lesson_plan_id, :teacher, :entity_id

validates :knowledge_area_lesson_plan_id, presence: true
validates :knowledge_area_lesson_plan_id, presence: true
has_many :knowledge_area_lesson_plan_item_cloner_form
accepts_nested_attributes_for :knowledge_area_lesson_plan_item_cloner_form, :allow_destroy => true
accepts_nested_attributes_for :knowledge_area_lesson_plan_item_cloner_form, allow_destroy: true

def clone!
if valid?
begin
ActiveRecord::Base.transaction do
@classrooms = Classroom.where(id: knowledge_area_lesson_plan_item_cloner_form.map(&:classroom_id).uniq)
knowledge_area_lesson_plan_item_cloner_form.each_with_index do |item, index|
@current_item_index = index
new_lesson_plan = knowledge_area_lesson_plan.dup
new_lesson_plan.teacher_id = teacher.id
new_lesson_plan.lesson_plan = knowledge_area_lesson_plan.lesson_plan.dup
new_lesson_plan.lesson_plan.teacher = teacher
new_lesson_plan.knowledge_areas = knowledge_area_lesson_plan.knowledge_areas
new_lesson_plan.lesson_plan.original_contents = knowledge_area_lesson_plan.lesson_plan.contents
new_lesson_plan.lesson_plan.contents_created_at_position = {}

new_lesson_plan.lesson_plan.original_contents.each_with_index do |content, position|
new_lesson_plan.lesson_plan.contents_created_at_position[content.id] = position
end

new_lesson_plan.lesson_plan.original_objectives = knowledge_area_lesson_plan.lesson_plan.objectives
new_lesson_plan.lesson_plan.objectives_created_at_position = {}
new_lesson_plan.lesson_plan.original_objectives.each_with_index do |objective, position|
new_lesson_plan.lesson_plan.objectives_created_at_position[objective.id] = position
end

new_lesson_plan.lesson_plan.start_at = item.start_at
new_lesson_plan.lesson_plan.end_at = item.end_at
new_lesson_plan.lesson_plan.classroom = @classrooms.find_by_id(item.classroom_id)
knowledge_area_lesson_plan.lesson_plan.lesson_plan_attachments.each do |lesson_plan_attachment|
new_lesson_plan.lesson_plan.lesson_plan_attachments << LessonPlanAttachment.new(
attachment: lesson_plan_attachment.attachment
)
end
new_lesson_plan.save!
return unless valid?

begin
ActiveRecord::Base.transaction do
@classrooms = Classroom.where(id: knowledge_area_lesson_plan_item_cloner_form.map(&:classroom_id).uniq)
knowledge_area_lesson_plan_item_cloner_form.each_with_index do |item, index|
@current_item_index = index
new_lesson_plan = knowledge_area_lesson_plan.dup
new_lesson_plan.teacher_id = teacher.id
new_lesson_plan.lesson_plan = knowledge_area_lesson_plan.lesson_plan.dup
new_lesson_plan.lesson_plan.teacher = teacher
new_lesson_plan.knowledge_areas = knowledge_area_lesson_plan.knowledge_areas
new_lesson_plan.lesson_plan.original_contents = knowledge_area_lesson_plan.lesson_plan.contents
new_lesson_plan.lesson_plan.contents_created_at_position = {}

new_lesson_plan.lesson_plan.original_contents.each_with_index do |content, position|
new_lesson_plan.lesson_plan.contents_created_at_position[content.id] = position
end

new_lesson_plan.lesson_plan.original_objectives = knowledge_area_lesson_plan.lesson_plan.objectives
new_lesson_plan.lesson_plan.objectives_created_at_position = {}
new_lesson_plan.lesson_plan.original_objectives.each_with_index do |objective, position|
new_lesson_plan.lesson_plan.objectives_created_at_position[objective.id] = position
end

new_lesson_plan.lesson_plan.start_at = item.start_at
new_lesson_plan.lesson_plan.end_at = item.end_at
new_lesson_plan.lesson_plan.classroom = @classrooms.find_by(id: item.classroom_id)

original_attachments = {}
knowledge_area_lesson_plan.lesson_plan.lesson_plan_attachments.each do |lesson_plan_attachment|
original_attachments[lesson_plan_attachment.attachment.filename] = lesson_plan_attachment.id
new_lesson_plan.lesson_plan.lesson_plan_attachments << lesson_plan_attachment.dup
end
return true
new_lesson_plan.save!

copy_attachments(new_lesson_plan.id, original_attachments)
end
rescue ActiveRecord::RecordInvalid => e
message = e.to_s
message.slice!("A validação falhou: ")
message.slice!("Áreas de conhecimento ")
errors.add(:classroom_id, "Turma #{e.record.lesson_plan.try(:classroom)}: #{message}")
knowledge_area_lesson_plan_item_cloner_form[@current_item_index].errors.add(:classroom_id, message)
return false

return true
end
rescue ActiveRecord::RecordInvalid => e
message = e.to_s
message.slice!('A validação falhou: ')
message.slice!('Áreas de conhecimento ')
errors.add(:classroom_id, "Turma #{e.record.lesson_plan.try(:classroom)}: #{message}")
knowledge_area_lesson_plan_item_cloner_form[@current_item_index].errors.add(:classroom_id, message)

return false
end
end

def knowledge_area_lesson_plan
@knowledge_area_lesson_plan ||= KnowledgeAreaLessonPlan.includes(lesson_plan: [:objectives, :contents])
.find(knowledge_area_lesson_plan_id)
end

def copy_attachments(new_lesson_plan_id, original_attachments)
return if new_lesson_plan_id.blank? || original_attachments.blank?

LessonPlanAttachmentCopierWorker.perform_async(
entity_id,
new_lesson_plan_id,
KnowledgeAreaLessonPlan,
original_attachments
)
end
end
4 changes: 1 addition & 3 deletions app/mailers/receipt_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,8 1,6 @@
class ReceiptMailer < BaseMailer
def notify_daily_frequency_success(user, url, date)
@name = user.first_name if user.first_name.present?
@name = "#{@name} #{user.last_name}" if user.last_name.present?
@name ||= user
@name = user.first_name
@url = url

return unless (email = user.email)
Expand Down
6 changes: 1 addition & 5 deletions app/models/absence_justification_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 3,5 @@ class AbsenceJustificationAttachment < ActiveRecord::Base

mount_uploader :attachment, DocUploader

validates :attachment, presence: true

def filename
attachment&.path&.split('/')&.last
end
delegate :filename, to: :attachment
end
6 changes: 1 addition & 5 deletions app/models/lesson_plan_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 5,5 @@ class LessonPlanAttachment < ActiveRecord::Base

mount_uploader :attachment, DocUploader

validates :attachment, presence: true

def filename
attachment&.path&.split('/')&.last
end
delegate :filename, to: :attachment
end
6 changes: 1 addition & 5 deletions app/models/observation_diary_record_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 5,5 @@ class ObservationDiaryRecordAttachment < ActiveRecord::Base

mount_uploader :attachment, DocUploader

validates :attachment, presence: true

def filename
attachment&.path&.split('/')&.last
end
delegate :filename, to: :attachment
end
2 changes: 1 addition & 1 deletion app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 15,6 @@ def self.permissions_list
end

def self.all_audits
Audited::Adapters::ActiveRecord::Audit.where(auditable_type: 'Profile').reorder("id DESC")
Audited::Audit.where(auditable_type: 'Profile').reorder("id DESC")
end
end
6 changes: 1 addition & 5 deletions app/models/teaching_plan_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 3,5 @@ class TeachingPlanAttachment < ActiveRecord::Base

mount_uploader :attachment, DocUploader

validates :attachment, presence: true

def filename
attachment&.path&.split('/')&.last
end
delegate :filename, to: :attachment
end
Loading

0 comments on commit d3c0769

Please sign in to comment.