From e6662d0ee6dd50f578767900782c6bb570a982ae Mon Sep 17 00:00:00 2001 From: Joao Felipe Pimentel Date: Wed, 3 Jan 2024 22:15:38 -0300 Subject: [PATCH] Notify exception. Only show admission page to committee professors --- .../admissions/admission_processes_controller.rb | 7 +++++-- app/models/admissions/ability.rb | 1 + config/navigation.rb | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/controllers/admissions/admission_processes_controller.rb b/app/controllers/admissions/admission_processes_controller.rb index 4a824c72..40893f40 100644 --- a/app/controllers/admissions/admission_processes_controller.rb +++ b/app/controllers/admissions/admission_processes_controller.rb @@ -202,7 +202,9 @@ def consolidate_phase @message += ". #{I18n.t("#{i18n_prefix}.not_approved", count: @not_approved.count)}" end end - + rescue => err + ExceptionNotifier.notify_exception(err) + @exception = "Erro ao consolidar fase: #{err}" ensure params.each_key do |key| if !["authenticity_token", "controller", "action"].include? key @@ -224,7 +226,8 @@ def calculate_ranking @ranking = @admission_process.rankings.where(id: params[:admission_process_ranking_id]).first @candidates = @ranking.generate_ranking rescue => exception - @errors = exception + ExceptionNotifier.notify_exception(exception) + @errors = "Erro ao calcular ranking: #{exception}" end params.each_key do |key| diff --git a/app/models/admissions/ability.rb b/app/models/admissions/ability.rb index 659eaea2..92720f55 100644 --- a/app/models/admissions/ability.rb +++ b/app/models/admissions/ability.rb @@ -52,6 +52,7 @@ def initialize_admissions(user, roles) can :override, Admissions::AdmissionApplication can :cancel, Admissions::AdmissionApplication can :configuration, Admissions::AdmissionApplication + can :read_all, Admissions::AdmissionApplication end if roles[Role::ROLE_ADMINISTRADOR] || roles[Role::ROLE_COORDENACAO] can :manage, ADMISSION_MODELS diff --git a/config/navigation.rb b/config/navigation.rb index 21d79a13..d2505ce8 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -205,7 +205,18 @@ def can_read?(*args) Admissions::RankingMachine, Admissions::AdmissionApplication, ] - mainhelper.listitem :admissions, admission_models do |submenu| + check_admission_application = -> { + return true if can?(:read_all, Admissions::AdmissionApplication) + return false if !can?(:read, Admissions::AdmissionApplication) + applications = Admissions::AdmissionApplication.includes(:pendencies) + .where(pendencies: { user_id: current_user.id }) + applications.size > 0 + } + admissions_if = -> { can_read?( + admission_models - [Admissions::AdmissionApplication] + ).call || check_admission_application.call } + + mainhelper.listitem :admissions, admission_models, if: admissions_if do |submenu| submenu.modelitem Admissions::AdmissionProcess submenu.modelitem Admissions::FormTemplate submenu.item(:consolidation_template, consolidation_templates_path, @@ -214,7 +225,8 @@ def can_read?(*args) submenu.modelitem Admissions::AdmissionPhase submenu.modelitem Admissions::RankingConfig submenu.modelitem Admissions::RankingMachine - submenu.modelitem Admissions::AdmissionApplication + submenu.modelitem(Admissions::AdmissionApplication, + if: check_admission_application) end config_models = [