Commit 85cc9047 authored by Taico Aerts's avatar Taico Aerts
Browse files

Merge branch 'development' into 'master'

Project Forum Release v2.8.13 - 18-10-2022

See merge request !886
parents 90de18c4 288b6742
......@@ -51,6 +51,7 @@ module Admin
delete_existing_groups if overwrite_existing_groups
notifications = create_groups(group_import_params[:groups], assign_leader, approve_group, notify)
rescue ActiveRecord::Rollback => e
Sentry.capture_exception(e)
error = e.message
raise e
end
......@@ -140,6 +141,7 @@ module Admin
Group.create(project: project)
end
unless group.persisted?
Sentry.capture_message("Unable to import group for project #{project.name}", level: :error)
error = "Unable to save group for project #{project.name} (with members #{members.map(&:full_name).join(', ')})"
raise ActiveRecord::Rollback, error
end
......@@ -158,10 +160,11 @@ module Admin
# Create membership and check if it saved correctly.
membership = Membership.create(group: group, user: member, role: role)
unless membership.persisted?
error = "Unable to save membership of #{member.full_name} for group for project #{project.name}"
raise ActiveRecord::Rollback, error
end
next if membership.persisted?
Sentry.capture_message("Unable to save membership of user #{member.id} for imported group for project #{project.id}", level: :error)
error = "Unable to save membership of #{member.full_name} for group for project #{project.name}"
raise ActiveRecord::Rollback, error
end
# Create an event (if we want to make notifications)
......
......@@ -47,6 +47,7 @@ module Admin
UserCourseSpecificRole.transaction do
assign_roles(group_role_import_params[:role_assignments], overwrite_existing_role_assignments)
rescue ActiveRecord::Rollback => e
Sentry.capture_exception(e)
error = e.message
raise e
end
......@@ -97,6 +98,7 @@ module Admin
users.each do |user|
ucsr = UserCourseSpecificRole.create(user: user, resource: group, course_specific_role: role)
unless ucsr.persisted?
Sentry.capture_message("Unable to import #{role.name} role for user #{user.id} for group #{group.id}", level: :error)
error = "Unable to assign #{role.name} role for #{user.full_name} for group #{group.id}"
raise ActiveRecord::Rollback, error
end
......
module Admin
module CourseEditions
class PreferencesController < Admin::ApplicationController
load_and_authorize_resource instance_name: 'user', class: 'User', parent: false, except: :export_all
load_and_authorize_resource :edition, instance_name: 'course_edition', class: 'CourseEdition'
before_action do
add_breadcrumb @course_edition.course.name, admin_course_path(@course_edition.course)
add_breadcrumb 'Editions', admin_course_path(@course_edition.course)
add_breadcrumb @course_edition.display_name, admin_course_edition_path(@course_edition.course_id, @course_edition)
add_breadcrumb 'Preferences', admin_course_edition_preferences_path(@course_edition.course_id, @course_edition)
end
before_action only: %i[show] do
add_breadcrumb @user.name, admin_course_edition_preference_path(@course_edition.course_id, @course_edition, @user)
end
def show
unless @course_edition.course_participations.exists?(user_id: @user.id)
raise CanCan::AccessDenied.new('User is not enrolled in this course edition', :show, @user)
end
@project_name = @course_edition.configuration.project_name_text(false, false)
@preferences = @user.project_preferences
.where(course_edition_id: @course_edition)
.where(project_id: @course_edition.projects.approved)
.order(:priority)
.includes(project: %i[interested_users])
@any_preferences = !@preferences.length.zero?
@no_preferences = @course_edition.projects
.approved
.where.not(id: Project.where(id: @preferences.except(:order).distinct.select(:project_id)))
@student_preferences = @user.student_preferences
.where(course_edition_id: @course_edition)
.includes(:student)
@project_popularity = ProjectPreference.project_popularity(@course_edition, 11, 15)
end
def export_all
@preferences = ProjectPreference.where(course_edition_id: @course_edition)
.where(project_id: @course_edition.projects.approved)
.includes(:project)
.includes(:user)
.preload(user: %i[sso_profile])
.order(%i[user_id priority])
@priority_limit = params[:priority_limit]&.to_i
@student_preferences = StudentPreference.where(course_edition_id: @course_edition)
.includes(:user)
.includes(:student)
.preload(user: %i[sso_profile], student: %i[sso_profile])
user_id = params[:user_id]
if user_id
@preferences = @preferences.where(user_id: user_id.to_i)
@student_preferences = @student_preferences.where(user_id: user_id.to_i)
end
render 'admin/course_editions/preferences/export_preferences'
end
protected
def page_title
case action_name
when 'show'
"#{@user.name} - Preferences - #{@course_edition.display_name} - Courses - #{super}"
else
"Preferences - #{@course_edition.display_name} - #{super}"
end
end
def filter_params
params.permit(
id: []
)
end
def preference_params
params.require(:course).permit(
course_params_keys
)
end
end
end
end
......@@ -17,7 +17,8 @@ module Admin
new_project = copy_project(project)
success_projects << new_project.id
success_projects << project.id
rescue StandardError
rescue StandardError => e
Sentry.capture_exception(e)
failed_projects << project.id
end
......
......@@ -47,6 +47,7 @@ module Admin
UserCourseSpecificRole.transaction do
assign_roles(project_role_import_params[:role_assignments], overwrite_existing_role_assignments)
rescue ActiveRecord::Rollback => e
Sentry.capture_exception(e)
error = e.message
raise e
end
......@@ -96,10 +97,11 @@ module Admin
# Create the role assignment.
users.each do |user|
ucsr = UserCourseSpecificRole.create(user: user, resource: project, course_specific_role: role)
unless ucsr.persisted?
error = "Unable to assign #{role.name} role for #{user.full_name} for project #{project.id}"
raise ActiveRecord::Rollback, error
end
next if ucsr.persisted?
Sentry.capture_message("Unable to import #{role.name} role for user #{user.id} for project #{project.id}", level: :error)
error = "Unable to assign #{role.name} role for #{user.full_name} for project #{project.id}"
raise ActiveRecord::Rollback, error
end
end
end
......
......@@ -36,6 +36,7 @@ module Admin
if failed.empty?
flash[:success] = "Successfully created experiment #{@experiment_project.name}"
else
Sentry.capture_message('Experiment was created, but teachers could not be set', level: :error)
flash[:danger] = 'Experiment was created, but teachers could not be set'
end
redirect_to admin_experiment_project_url(@experiment_project)
......
......@@ -20,6 +20,13 @@ module Admin
# =============================================================================================
def update
if params[:generic_project][:last_acknowledged_update] &&
(params[:generic_project][:last_acknowledged_update].to_i != @project.updated_at.to_i)
flash[:danger] = "Status update rejected: This #{@project.specific.model_name.human} has been updated " \
'since you opened the page. Please review the changes below before approving or rejecting it.'
redirect_to admin_generic_project_url(@specific_project)
return
end
if update_project(generic_project_params)
redirect_to admin_generic_project_url(@specific_project)
else
......
......@@ -115,6 +115,7 @@ module Admin
flash[:success] = "Successfully deleted group #{@group.id}."
redirect_to admin_groups_url
else
Sentry.capture_message("Failed to delete group #{@group.id}", level: :error)
flash[:danger] = "Failed to delete group #{@group.id}."
redirect_to admin_group_url(@group)
end
......
......@@ -63,7 +63,8 @@ module Admin
def run_import
begin
@import.safe_transition(params[:event])
rescue AASM::InvalidTransition
rescue AASM::InvalidTransition => e
Sentry.capture_exception(e)
flash[:danger] = 'You tried to perform an invalid action on this import'
end
redirect_to admin_import_url(@import)
......
......@@ -172,6 +172,7 @@ module Admin
flash[:success] = "Successfully deleted #{@specific_project.model_name.human}"
true
else
Sentry.capture_message("Failed to delete project #{@project.id}", level: :error)
flash[:danger] = "Failed to delete #{@specific_project.model_name.human}"
false
end
......
......@@ -9,6 +9,7 @@ module Admin
if @student_preference.destroyed?
flash[:success] = "Successfully deleted preference for #{student.name}"
else
Sentry.capture_message("Failed to delete student preference #{@student_preference.id} for user #{user.id} for student #{student.id}", level: :error)
flash[:danger] = 'Failed to delete student preference'
end
......
......@@ -32,6 +32,7 @@ module Admin
end
end
else
Sentry.capture_message("Failed to remove associated user #{@theme_associated_user.id}", level: :error)
respond_to do |format|
format.html do
flash[:danger] = 'Failed to remove the associated user'
......
......@@ -11,6 +11,7 @@ module Admin
send_notifications(current_user, theme_interest_reject_params[:message])
flash[:success] = 'Successfully rejected interested student'
else
Sentry.capture_message("Failed to destroy theme interest #{@theme_interest.id}", level: :error)
flash[:danger] = 'Failed to reject interested student'
end
......@@ -25,6 +26,7 @@ module Admin
if @theme_interest.save
flash[:success] = 'Successfully archived interested student'
else
Sentry.capture_message("Failed to archive theme interest #{@theme_interest.id}", level: :error)
flash[:danger] = 'Failed to archive interested student'
end
......
......@@ -32,6 +32,7 @@ module Admin
end
end
else
Sentry.capture_message("Failed to remove associated user #{@thesis_project_associated_user.id}", level: :error)
respond_to do |format|
format.html do
flash[:danger] = 'Failed to remove the associated user'
......
......@@ -11,6 +11,7 @@ module Admin
send_notifications(current_user, thesis_project_interest_params[:message])
flash[:success] = 'Successfully rejected interested student'
else
Sentry.capture_message("Failed to destroy thesis project interest #{@thesis_project_interest.id}", level: :error)
flash[:danger] = 'Failed to reject interested student'
end
......@@ -25,6 +26,7 @@ module Admin
if @thesis_project_interest.save
flash[:success] = 'Successfully archived interested student'
else
Sentry.capture_message("Failed to archive thesis project interest #{@thesis_project_interest.id}", level: :error)
flash[:danger] = 'Failed to archive interested student'
end
......
......@@ -6,6 +6,8 @@ module Companies
load_and_authorize_resource :company
def create
authorize! :manage_invitations, @company
email = role_invitation_params[:email].strip.downcase
match = email.match(/^.+ <(.+@.+\.[\w\-]+)>/)
email = match[1] if match
......@@ -21,6 +23,8 @@ module Companies
end
def destroy
authorize! :manage_invitations, @company
@role_invitation.destroy
flash[:success] = 'Successfully removed invitation.'
......@@ -75,6 +79,7 @@ module Companies
flash[:success] = 'Successfully sent the invitation.'
send_notifications
else
Sentry.capture_message("Creating role invitation for company #{@company.id} for user #{user.id} failed", level: :error)
flash[:danger] = 'Could not send the invite.'
end
end
......
......@@ -51,7 +51,8 @@ class CompaniesController < OfferersController
Image.model_name.human => -> { save_image },
Role.model_name.human => lambda do
current_user.add_role(:employee, @company).persisted?
rescue StandardError
rescue StandardError => e
Sentry.capture_exception(e)
false
end
},
......
......@@ -49,7 +49,10 @@ module TagUpdateable
next if tags.include?(tagging.tag.name)
destroyed = tagging.destroy
failed << tagging.tag.name unless destroyed
unless destroyed
Sentry.capture_message("Failed to destroy tagging #{tagging.id}", level: :error)
failed << tagging.tag.name
end
end
end
......@@ -63,6 +66,7 @@ module TagUpdateable
t = Tag.new(name: tag)
saved = t.save
unless saved
Sentry.capture_message("Failed to create tag #{tag}", level: :error)
failed << tag
next
end
......
......@@ -29,6 +29,7 @@ module CourseEditions
flash[:success] = 'You have been placed in the group.'
send_notifications(current_user)
else
Sentry.capture_message("Student could not join group #{@group.id}", level: :error)
flash[:danger] = "An error occurred while placing you in the group.
If you are trying to join a second group this
may be causing the error. If this persists or you are not joining
......@@ -55,6 +56,7 @@ module CourseEditions
redirect_to_group_page
end
else
Sentry.capture_message("Failed to destroy group membership #{@membership.id} for user #{user.id} for project #{@project.id}", level: :error)
flash[:danger] = "An error occurred while removing a user from the
group. If this persists, please contact your #{I18n.t('activerecord.attributes.role.names.course_coordinator', count: 1).downcase}."
redirect_to_overview
......
......@@ -220,6 +220,7 @@ module CourseEditions
flash[:success] = 'Successfully created a new group. You have been
placed in this group.'
else
Sentry.capture_message("Student could not be placed as leader in newly-created group #{@group.id}", level: :error)
flash[:danger] = "An error occurred while putting you into the
group. If this persists, please contact your #{I18n.t('activerecord.attributes.role.names.course_coordinator', count: 1).downcase}."
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment