Skip to content
Snippets Groups Projects
Commit 68474603 authored by Renāts Jurševskis's avatar Renāts Jurševskis
Browse files

Add scope to retrieve descendants of a recurrent course edition

parent 1423e492
Branches
Tags
2 merge requests!787Project Forum Release 2.8.2,!782Resolve "Use periods in preferences"
...@@ -23,11 +23,11 @@ module CourseEditions ...@@ -23,11 +23,11 @@ module CourseEditions
# If the user has any preferences stored # If the user has any preferences stored
@any_preferences = current_user.project_preferences?(@course_edition) @any_preferences = current_user.project_preferences?(@course_edition)
if @course_edition.recurrent_edition.nil? @other_preferences = if @course_edition.recurrent_edition.nil?
@other_preferences = false false
else else
@other_preferences = ProjectPreference.where(user: current_user, ProjectPreference.where(user: current_user,
course_edition: CourseEdition.where(recurrent_edition: @course_edition.recurrent_edition)).any? course_edition: CourseEdition.descendants_of(@course_edition.recurrent_edition)).any?
end end
@project_name = @course_edition.configuration.project_name_text(false, false) @project_name = @course_edition.configuration.project_name_text(false, false)
......
...@@ -54,9 +54,10 @@ module CourseEditions ...@@ -54,9 +54,10 @@ module CourseEditions
ProjectInterest.joins(:project) ProjectInterest.joins(:project)
.where(user: current_user, .where(user: current_user,
projects: { projects: {
course_edition_id: CourseEdition.where(recurrent_edition: @course_edition.recurrent_edition) course_edition_id: CourseEdition.descendants_of(@course_edition.recurrent_edition)
}) })
.any? .any?
end
apply_filters apply_filters
apply_ordering apply_ordering
paginate_projects paginate_projects
......
...@@ -223,6 +223,11 @@ class CourseEdition < ApplicationRecord ...@@ -223,6 +223,11 @@ class CourseEdition < ApplicationRecord
where(recurrent: false) where(recurrent: false)
}) })
# Descendants of recurrent course edition
scope :descendants_of, lambda { |course_edition|
where(recurrent_edition: course_edition)
}
def display_name def display_name
"#{course.name} #{name}" "#{course.name} #{name}"
end end
......
...@@ -84,7 +84,7 @@ class Project < ApplicationRecord ...@@ -84,7 +84,7 @@ class Project < ApplicationRecord
before_update :unset_approved_at, if: (-> { status_changed?(to: 'rejected') }) before_update :unset_approved_at, if: (-> { status_changed?(to: 'rejected') })
def assign_to_recurrent_editions def assign_to_recurrent_editions
CourseEdition.where(recurrent_edition_id: course_edition.id).find_each do |course_edition| CourseEdition.descendants_of(course_edition).find_each do |course_edition|
if periods.select { |period| period.id == course_edition.active_period.id }.any? if periods.select { |period| period.id == course_edition.active_period.id }.any?
copy_project(course_edition) copy_project(course_edition)
end end
...@@ -412,7 +412,7 @@ class Project < ApplicationRecord ...@@ -412,7 +412,7 @@ class Project < ApplicationRecord
def set_approved_at def set_approved_at
self.approved_at = updated_at self.approved_at = updated_at
unless !course_edition.recurrent || unless !course_edition.recurrent ||
Project.where(original_project: self, course_edition: CourseEdition.where(recurrent_edition: course_edition)).any? Project.where(original_project: self, course_edition: CourseEdition.descendants_of(course_edition)).any?
assign_to_recurrent_editions assign_to_recurrent_editions
end end
end end
......
...@@ -188,8 +188,8 @@ ...@@ -188,8 +188,8 @@
<td><%= period.starts_at %></td> <td><%= period.starts_at %></td>
<td><%= period.ends_at %></td> <td><%= period.ends_at %></td>
<td> <td>
<% if CourseEdition.where(recurrent_edition_id: @course_edition.id).where(active_period: period).any? %> <% if CourseEdition.descendants_of(@course_edition).where(active_period: period).any? %>
<% CourseEdition.where(recurrent_edition_id: @course_edition.id) <% CourseEdition.descendants_of(@course_edition)
.where(active_period: period) .where(active_period: period)
.includes(:course) .includes(:course)
.each do |e| %> .each do |e| %>
......
...@@ -8,9 +8,8 @@ ...@@ -8,9 +8,8 @@
<br/> <br/>
If you want the changes to also apply to current instances of the <%= @project_name %>, you can select them here: If you want the changes to also apply to current instances of the <%= @project_name %>, you can select them here:
<%= f.collection_select :projects_modify, <%= f.collection_select :projects_modify,
Project.where(course_edition: CourseEdition.where(recurrent_edition_id: @specific_project.course_edition.id), original_project_id: @project.id) Project.where(course_edition: CourseEdition.descendants_of(@specific_project.course_edition), original_project_id: @project.id)
.accessible_by(current_ability, :update) .accessible_by(current_ability, :update),
,
:id, :id,
->(project) { "#{project.name} (#{project.course_edition.display_name})" }, ->(project) { "#{project.name} (#{project.course_edition.display_name})" },
{ required: false, hide_label: true }, { required: false, hide_label: true },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment