diff --git a/Gemfile.lock b/Gemfile.lock index e06c683537..65e8f18db5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -509,6 +509,7 @@ GEM zeitwerk (2.6.15) PLATFORMS + aarch64-linux-gnu aarch64-linux-musl arm-linux @@ -523,6 +524,7 @@ PLATFORMS x86_64-linux-gnu x86_64-linux-musl + DEPENDENCIES better_errors bootsnap diff --git a/app/api/users_api.rb b/app/api/users_api.rb index ffcf6a42fd..21a21692fc 100644 --- a/app/api/users_api.rb +++ b/app/api/users_api.rb @@ -67,8 +67,8 @@ class UsersApi < Grape::API change_self = (params[:id] == current_user.id) params[:receive_portfolio_notifications] = true if params.key?(:receive_portfolio_notifications) && params[:receive_portfolio_notifications].nil? - params[:receive_portfolio_notifications] = true if params.key?(:receive_feedback_notifications) && params[:receive_feedback_notifications].nil? - params[:receive_portfolio_notifications] = true if params.key?(:receive_task_notifications) && params[:receive_task_notifications].nil? + params[:receive_feedback_notifications] = true if params.key?(:receive_feedback_notifications) && params[:receive_feedback_notifications].nil? + params[:receive_task_notifications] = true if params.key?(:receive_task_notifications) && params[:receive_task_notifications].nil? # can only modify if current_user.id is same as :id provided # (i.e., user wants to update their own data) or if update_user token diff --git a/app/models/task.rb b/app/models/task.rb index e75815f90b..9900f07619 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -132,6 +132,7 @@ def specific_permission_hash(role, perm_hash, _other) delegate :update_task_stats, to: :project after_update :update_task_stats, if: :saved_change_to_task_status_id? # TODO: consider moving to async task + after_update :send_feedback_notification, if: :saved_change_to_task_status_id? validates :task_definition_id, uniqueness: { scope: :project, message: 'must be unique within the project' } @@ -1362,6 +1363,20 @@ def read_file_from_done(idx) nil end + def send_feedback_notification + return unless task_status.in?([TaskStatus.redo, TaskStatus.fail, TaskStatus.fix_and_resubmit, TaskStatus.feedback_exceeded, TaskStatus.discuss, TaskStatus.demonstrate, TaskStatus.complete]) + return unless project.student.receive_feedback_notifications + return unless unit&.send_notifications + + begin + logger.info "Checking feedback email for project #{project.id}" + logger.info "Emailing feedback notification to #{project.student.name}" + PortfolioEvidenceMailer.task_feedback_ready(project, [self]).deliver + rescue => e + logger.error "Failed to send feedback notification email. Error: #{e.message}" + end + end + private def delete_associated_files diff --git a/config/environments/development.rb b/config/environments/development.rb index 0b4ebb1644..e9be2ded69 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -53,7 +53,8 @@ # Store uploaded files on the local file system (see config/storage.yml for options). # config.active_storage.service = :local - # Don't care if the mailer can't send. + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false