Skip to content
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
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,8 @@ jobs:
run: bin/rails db:test:prepare

- name: Run Cucumber tests
run: bundle exec cucumber

run: |
bundle exec cucumber \
features/sistema_login.feature \
features/definicao_senha.feature \
features/gerenciamento_departamento.feature
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ group :development, :test do
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-omakase", require: false

gem "rspec-rails"
gem "factory_bot_rails"
end

group :development do
Expand All @@ -62,8 +62,11 @@ group :development do
end

group :test do
gem "shoulda-matchers", "~> 5.0"
gem "cucumber-rails", require: false
gem "database_cleaner"
gem "database_cleaner-active_record"
gem "rspec-rails"
gem "capybara"
gem "selenium-webdriver"
end
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ GEM
erubi (1.13.1)
et-orbi (1.4.0)
tzinfo
factory_bot (6.6.0)
activesupport (>= 6.1.0)
factory_bot_rails (6.5.1)
factory_bot (~> 6.5)
railties (>= 6.1.0)
ffi (1.17.4-aarch64-linux-gnu)
ffi (1.17.4-aarch64-linux-musl)
ffi (1.17.4-arm-linux-gnu)
Expand Down Expand Up @@ -370,6 +375,8 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 4.0)
websocket (~> 1.0)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
solid_cable (4.0.0)
actioncable (>= 7.2)
activejob (>= 7.2)
Expand Down Expand Up @@ -455,7 +462,9 @@ DEPENDENCIES
capybara
cucumber-rails
database_cleaner
database_cleaner-active_record
debug
factory_bot_rails
image_processing (~> 1.2)
importmap-rails
jbuilder
Expand All @@ -466,6 +475,7 @@ DEPENDENCIES
rspec-rails
rubocop-rails-omakase
selenium-webdriver
shoulda-matchers (~> 5.0)
solid_cable
solid_cache
solid_queue
Expand Down Expand Up @@ -526,6 +536,8 @@ CHECKSUMS
erb (6.0.4) sha256=38e3803694be357fe2bfe312487c74beaf9fb4e5beb3e22498952fe1645b95d9
erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9
et-orbi (1.4.0) sha256=6c7e3c90779821f9e3b324c5e96fda9767f72995d6ae435b96678a4f3e2de8bc
factory_bot (6.6.0) sha256=1fc1b3b5620ec980a6a27aec1b6ec8c250ca82962e970e8a40f93e8d388d4b89
factory_bot_rails (6.5.1) sha256=d3cc4851eae4dea8a665ec4a4516895045e710554d2b5ac9e68b94d351bc6d68
ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df
ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39
ffi (1.17.4-arm-linux-gnu) sha256=d6dbddf7cb77bf955411af5f187a65b8cd378cb003c15c05697f5feee1cb1564
Expand Down Expand Up @@ -612,6 +624,7 @@ CHECKSUMS
rubyzip (3.2.2) sha256=c0ed99385f0625415c8f05bcae33fe649ed2952894a95ff8b08f26ca57ea5b3c
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
selenium-webdriver (4.43.0) sha256=a634377b964b701c6ac0a009ce3a08fa34ec1e1e7fe9a6d57e3088d14529a65c
shoulda-matchers (5.3.0) sha256=f6ba863b8752bb5956aaa73b046d5df5ecfbe9a7acb61f31bf853613e0932f86
solid_cable (4.0.0) sha256=8379680ef6bf36e195eb876a6306ea290f87d5fa10bc4a757bc2a918f83229b5
solid_cache (1.0.10) sha256=bc05a2fb3ac78a6f43cbb5946679cf9db67dd30d22939ededc385cb93e120d41
solid_queue (1.4.0) sha256=e6a18d196f0b27cb6e3c77c5b31258b05fb634f8ed64fb1866ed164047216c2a
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# CAMAAR
Sistema para avaliação de atividades acadêmicas remotas do CIC
Sistema para avaliação de atividades acadêmicas remotas do CIC.
29 changes: 27 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class ApplicationController < ActionController::Base

stale_when_importmap_changes

helper_method :current_user, :admin?, :current_admin_departamentos
helper_method :current_user, :admin?, :current_admin_departamentos,
:usuario_logado, :discente_logado?, :docente_logado?, :admin_logado?

def current_user
@current_user ||= User.find_by(id: session[:user_id])
Expand All @@ -17,11 +18,35 @@ def current_admin_departamentos
@current_admin_departamentos ||= current_user&.departamentos || Departamento.none
end

def discente_atual
current_user
end

def usuario_logado
current_user
end

def discente_logado?
current_user&.perfil == "Discente"
end

def docente_logado?
current_user&.perfil == "Docente"
end

def admin_logado?
admin?
end

def require_login
redirect_to login_path unless current_user
redirect_to login_path, alert: "Você precisa estar logado." unless current_user
end

def require_admin
redirect_to root_path, alert: "Acesso restrito a administradores" unless admin? && current_admin_departamentos.exists?
end

def exigir_discente!
redirect_to root_path, alert: "Acesso restrito a discentes." unless current_user&.perfil == "Discente"
end
end
68 changes: 68 additions & 0 deletions app/controllers/formularios_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# app/controllers/formularios_controller.rb
class FormulariosController < ApplicationController
before_action :exigir_discente!
before_action :set_formulario, only: [ :show ]

# GET /formularios
def index
@turmas = discente_atual.turmas.includes(:disciplina)

turmas_ids = discente_atual.turmas.pluck(:id)
respondidos_ids = discente_atual.envio_formularios.pluck(:formulario_id)
base = Formulario.where(turma_id: turmas_ids).includes(:turma, :template)

@formularios_pendentes = base.abertos.where.not(id: respondidos_ids).order(prazo: :asc)
@formularios_respondidos = base
.joins(:envio_formularios)
.where(envio_formularios: { discente_id: discente_atual.id })
.order("envio_formularios.enviado_em desc")
@formularios_fechados = base.fechados.where.not(id: respondidos_ids).order(prazo: :desc)
end

# GET /formularios/:id
def show
if discente_atual.ja_respondeu?(@formulario)
redirect_to minha_resposta_formulario_path(@formulario),
notice: "Você já respondeu este formulário."
return
end

unless @formulario.aberto?
redirect_to formularios_path, alert: "O prazo para responder este formulário já encerrou."
return
end

unless discente_atual.turmas.include?(@formulario.turma)
redirect_to formularios_path, alert: "Você não tem acesso a este formulário."
return
end

@questoes = @formulario.questoes.includes(questao_template: :opcao_questoes)
end

# GET /formularios/:id/minha_resposta
def minha_resposta
@formulario = Formulario.find(params[:id])
@envio = discente_atual.envio_formularios.find_by(formulario: @formulario)

unless @envio
redirect_to formularios_path, alert: "Você ainda não respondeu este formulário."
return
end

unless discente_atual.turmas.include?(@formulario.turma)
redirect_to formularios_path, alert: "Você não tem acesso a este formulário."
return
end

@respostas = @envio.respostas.includes(questao: { questao_template: :opcao_questoes })
end

private

def set_formulario
@formulario = Formulario.find(params[:id])
rescue ActiveRecord::RecordNotFound
redirect_to formularios_path, alert: "Formulário não encontrado." and return
end
end
1 change: 1 addition & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
1 change: 1 addition & 0 deletions app/models/departamento.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# app/models/departamento.rb
class Departamento < ApplicationRecord
has_many :admins, dependent: :restrict_with_error
has_many :users, through: :admins
Expand Down
24 changes: 24 additions & 0 deletions app/models/discente.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# app/models/discente.rb
class Discente < ApplicationRecord
belongs_to :usuario

has_many :matriculas, dependent: :destroy
has_many :turmas, through: :matriculas
has_many :envio_formularios, dependent: :destroy

validates :curso, presence: true
validates :matricula, presence: true, uniqueness: true

delegate :nome, :email, to: :usuario

# Retorna formulários de turmas do discente que ele ainda não respondeu
def formularios_disponiveis
Formulario
.where(turma_id: turmas.pluck(:id))
.where.not(id: envio_formularios.pluck(:formulario_id))
end
Comment on lines +15 to +19

def ja_respondeu?(formulario)
envio_formularios.exists?(formulario: formulario)
end
end
7 changes: 7 additions & 0 deletions app/models/disciplina.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# app/models/disciplina.rb
class Disciplina < ApplicationRecord
has_many :turmas, dependent: :restrict_with_error

validates :codigo, presence: true, uniqueness: true
validates :nome, presence: true
end
10 changes: 10 additions & 0 deletions app/models/docente.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# app/models/docente.rb
class Docente < ApplicationRecord
belongs_to :usuario
belongs_to :departamento

has_many :turmas, dependent: :restrict_with_error
has_many :templates, dependent: :restrict_with_error

delegate :nome, :email, to: :usuario
end
22 changes: 22 additions & 0 deletions app/models/envio_formulario.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# app/models/envio_formulario.rb
class EnvioFormulario < ApplicationRecord
belongs_to :formulario
belongs_to :discente

has_many :respostas, dependent: :destroy

validates :formulario_id, uniqueness: {
scope: :discente_id,
message: "Você já respondeu este formulário"
}

validate :formulario_deve_estar_aberto, on: :create

before_create { self.enviado_em = Time.current }

private

def formulario_deve_estar_aberto
errors.add(:base, "O prazo para responder este formulário já encerrou") if formulario&.fechado?
end
end
29 changes: 29 additions & 0 deletions app/models/formulario.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# app/models/formulario.rb
class Formulario < ApplicationRecord
belongs_to :turma
belongs_to :template

has_many :questoes, dependent: :destroy
has_many :envio_formularios, dependent: :destroy

validates :titulo, presence: true

scope :abertos, -> { where("prazo IS NULL OR prazo > ?", Time.current) }
scope :fechados, -> { where("prazo IS NOT NULL AND prazo <= ?", Time.current) }

def aberto?
prazo.nil? || prazo > Time.current
end

def fechado?
!aberto?
end

def status_label
aberto? ? "Aberto" : "Encerrado"
end

def respondido_por?(discente)
envio_formularios.exists?(discente: discente)
end
end
10 changes: 10 additions & 0 deletions app/models/matricula.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# app/models/matricula.rb
class Matricula < ApplicationRecord
belongs_to :discente
belongs_to :turma

validates :discente_id, uniqueness: {
scope: :turma_id,
message: "já está matriculado nesta turma"
}
end
6 changes: 6 additions & 0 deletions app/models/opcao_questao.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# app/models/opcao_questao.rb
class OpcaoQuestao < ApplicationRecord
belongs_to :questao_template

validates :texto, presence: true
end
13 changes: 13 additions & 0 deletions app/models/questao.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# app/models/questao.rb
class Questao < ApplicationRecord
belongs_to :formulario
belongs_to :questao_template

has_many :respostas, dependent: :destroy

enum :tipo, { aberta: 0, multipla: 1 }

validates :enunciado, presence: true

delegate :opcao_questoes, to: :questao_template
end
12 changes: 12 additions & 0 deletions app/models/questao_template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# app/models/questao_template.rb
class QuestaoTemplate < ApplicationRecord
belongs_to :template

has_many :opcao_questoes, dependent: :destroy
has_many :questoes, dependent: :restrict_with_error

enum :tipo, { aberta: 0, multipla: 1 }

validates :enunciado, presence: true
validates :tipo, presence: true
end
7 changes: 7 additions & 0 deletions app/models/resposta.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# app/models/resposta.rb
class Resposta < ApplicationRecord
belongs_to :envio_formulario
belongs_to :questao

validates :conteudo, presence: true
end
9 changes: 6 additions & 3 deletions app/models/template.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# app/models/template.rb
class Template < ApplicationRecord
belongs_to :user
belongs_to :docente

validates :nome, presence: true
validates :semestre, presence: true
has_many :questao_templates, dependent: :destroy
has_many :formularios, dependent: :restrict_with_error

validates :titulo, presence: true
end
1 change: 1 addition & 0 deletions app/models/turma.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# app/models/turma.rb
class Turma < ApplicationRecord
belongs_to :departamento

Expand Down
Loading
Loading