You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/models/unit.rb
+54-45Lines changed: 54 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -566,6 +566,10 @@ def employ_staff(user, role)
566
566
end
567
567
end
568
568
569
+
defunit_role_for(user)
570
+
unit_roles.find_by(user: user)
571
+
end
572
+
569
573
# Adds a user to this project.
570
574
defenrol_student(user,campus)
571
575
# Validates that a student is not already assigned to the unit
@@ -1727,54 +1731,59 @@ def tasks_as_hash(data)
1727
1731
deftutorial_enrolment_subquery
1728
1732
tutorial_enrolments
1729
1733
.joins(:tutorial)
1730
-
.select('tutorials.tutorial_stream_id as tutorial_stream_id','tutorials.id as tutorial_id','project_id').to_sql
1734
+
.select('tutorials.tutorial_stream_id as tutorial_stream_id','tutorials.id as tutorial_id','project_id','tutorials.unit_role_id as unit_role_id').to_sql
1731
1735
end
1732
1736
1733
1737
#
1734
1738
# Return all tasks from the database for this unit and given user
1735
1739
#
1736
-
defget_all_tasks_for(user)
1737
-
student_tasks.
1738
-
joins(:task_status).
1739
-
joins("LEFT OUTER JOIN (#{tutorial_enrolment_subquery}) as sq ON sq.project_id = projects.id AND (sq.tutorial_stream_id = task_definitions.tutorial_stream_id OR sq.tutorial_stream_id IS NULL)").
1740
-
joins("LEFT JOIN task_comments ON task_comments.task_id = tasks.id AND (task_comments.type IS NULL OR task_comments.type <> 'TaskStatusComment')").
1741
-
joins("LEFT JOIN comments_read_receipts crr ON crr.task_comment_id = task_comments.id AND crr.user_id = #{user.id}").
1742
-
joins("LEFT JOIN task_pins ON task_pins.task_id = tasks.id AND task_pins.user_id = #{user.id}").
1743
-
joins('LEFT OUTER JOIN task_similarities ON tasks.id = task_similarities.task_id').
1744
-
select(
1745
-
'sq.tutorial_id AS tutorial_id',
1746
-
'sq.tutorial_stream_id AS tutorial_stream_id',
1747
-
'tasks.id',
1748
-
"SUM(case when crr.user_id is null AND NOT task_comments.id is null then 1 else 0 end) as number_unread",
1749
-
'COUNT(distinct task_pins.task_id) != 0 as pinned',
1750
-
"SUM(case when task_comments.date_extension_assessed IS NULL AND task_comments.type = 'ExtensionComment' AND NOT task_comments.id IS NULL THEN 1 ELSE 0 END) > 0 as has_extensions",
1751
-
'project_id',
1752
-
'tasks.id as task_id',
1753
-
'task_definition_id',
1754
-
'task_definitions.start_date as start_date',
1755
-
'task_statuses.id as status_id',
1756
-
'completion_date',
1757
-
'times_assessed',
1758
-
'submission_date',
1759
-
'tasks.grade as grade',
1760
-
'quality_pts',
1761
-
'SUM(case when task_similarities.flagged then 1 else 0 end) as similar_to_count'
joins("LEFT OUTER JOIN (#{tutorial_enrolment_subquery}) as sq ON sq.project_id = projects.id AND (sq.tutorial_stream_id = task_definitions.tutorial_stream_id OR sq.tutorial_stream_id IS NULL)").
1744
+
joins("LEFT JOIN task_comments ON task_comments.task_id = tasks.id AND (task_comments.type IS NULL OR task_comments.type <> 'TaskStatusComment')").
1745
+
joins("LEFT JOIN comments_read_receipts crr ON crr.task_comment_id = task_comments.id AND crr.user_id = #{user.id}").
1746
+
joins("LEFT JOIN task_pins ON task_pins.task_id = tasks.id AND task_pins.user_id = #{user.id}").
1747
+
joins('LEFT OUTER JOIN task_similarities ON tasks.id = task_similarities.task_id').
1748
+
select(
1749
+
'sq.tutorial_id AS tutorial_id',
1750
+
'sq.tutorial_stream_id AS tutorial_stream_id',
1751
+
'tasks.id',
1752
+
"SUM(case when crr.user_id is null AND NOT task_comments.id is null then 1 else 0 end) as number_unread",
1753
+
'COUNT(distinct task_pins.task_id) != 0 as pinned',
1754
+
"SUM(case when task_comments.date_extension_assessed IS NULL AND task_comments.type = 'ExtensionComment' AND NOT task_comments.id IS NULL THEN 1 ELSE 0 END) > 0 as has_extensions",
1755
+
'project_id',
1756
+
'tasks.id as task_id',
1757
+
'task_definition_id',
1758
+
'task_definitions.start_date as start_date',
1759
+
'task_statuses.id as status_id',
1760
+
'completion_date',
1761
+
'times_assessed',
1762
+
'submission_date',
1763
+
'tasks.grade as grade',
1764
+
'quality_pts',
1765
+
'SUM(case when task_similarities.flagged then 1 else 0 end) as similar_to_count'
.having('task_statuses.id IN (:ids) OR COUNT(task_pins.task_id) > 0 OR SUM(case when crr.user_id is null AND NOT task_comments.id is null then 1 else 0 end) > 0',ids: [TaskStatus.ready_for_feedback,TaskStatus.need_help])
0 commit comments