Skip to content

Commit

Permalink
fix(duplication): remove load source courses data
Browse files Browse the repository at this point in the history
  • Loading branch information
bivanalhar committed May 2, 2024
1 parent d518438 commit a750a8b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
17 changes: 3 additions & 14 deletions app/controllers/course/object_duplications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Course::ObjectDuplicationsController < Course::ComponentController
helper Course::Achievement::AchievementsHelper

def new
load_source_courses_data
load_destination_courses_data
load_items_data
load_destination_instances_data
Expand All @@ -20,23 +19,13 @@ def create
protected

def authorize_duplication
authorize!(:duplicate_from, current_course)
unless can?(:duplicate_from, current_course) || can?(:duplicate_across_instances, current_tenant)
raise CanCan::AccessDenied
end
end

private

def load_source_courses_data
ActsAsTenant.without_tenant do
# Workaround to get Courses where current user is allowed to duplicate contents from
# without having to use accessible_by, which can take up to 5 minutes with includes
course_copiers = CourseUser.where(user: current_user).
where(role: CourseUser::MANAGER_ROLES.to_a) +
CourseUser.where(user: current_user).
where(role: :observer)
@source_courses = Course.includes(:instance).find(course_copiers.map(&:course_id))
end
end

def load_destination_courses_data
ActsAsTenant.without_tenant do
# Workaround to get Courses where current user plays one of manager roles
Expand Down
5 changes: 0 additions & 5 deletions app/views/course/object_duplications/new.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# frozen_string_literal: true
json.currentHost current_tenant.host

json.sourceCourses @source_courses do |course|
json.(course, :id, :title)
json.host course.instance.host
end

json.destinationCourses @destination_courses do |course|
json.(course, :id, :title)
json.path course_path(course)
Expand Down
2 changes: 0 additions & 2 deletions client/app/api/course/Duplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export default class DuplicationAPI extends BaseCourseAPI {
* currentHost: string,
* destinationCourses: Array.<courseShape>,
* destinationInstances: Array.<instanceShape>,
* sourceCourses: courseListingShape,
* sourceCourse: sourceCourseShape,
* assessmentComponent: Array.<categoryShape>,
* surveyComponent: Array.<surveyShape>,
* achievementsComponent: Array.<achievementShape>,
Expand Down

0 comments on commit a750a8b

Please sign in to comment.