1
+ # frozen_string_literal: true
2
+
1
3
require 'natsort'
2
4
3
5
class OrganizationsController < ApplicationController
4
- before_action :set_organization , only : [ : show, : destroy, : verify, : disable, : disable_reason_input, : toggle_visibility]
6
+ before_action :set_organization , only : %i[ show destroy verify disable disable_reason_input toggle_visibility all_courses ]
5
7
6
- skip_authorization_check only : [ : index, : new]
8
+ skip_authorization_check only : %i[ index new ]
7
9
8
10
def index
9
11
ordering = 'hidden, LOWER(name)'
10
12
@organizations = Organization
11
- . accepted_organizations
12
- . order ( ordering )
13
- . reject { |org | org . hidden? && !can? ( :view_hidden_organizations , nil ) || !org . visibility_allowed? ( request , current_user ) }
13
+ . accepted_organizations
14
+ . order ( ordering )
15
+ . reject { |org | org . hidden? && !can? ( :view_hidden_organizations , nil ) || !org . visibility_allowed? ( request , current_user ) }
14
16
@my_organizations = Organization . taught_organizations ( current_user ) . select { |org | org . visibility_allowed? ( request , current_user ) }
15
17
@my_organizations |= Organization . assisted_organizations ( current_user ) . select { |org | org . visibility_allowed? ( request , current_user ) }
16
18
@my_organizations |= Organization . participated_organizations ( current_user ) . select { |org | org . visibility_allowed? ( request , current_user ) }
17
19
@my_organizations . natsort_by! ( &:name )
18
20
@courses_under_initial_refresh = Course . where ( initial_refresh_ready : false )
19
21
@pinned_organizations = Organization
20
- . accepted_organizations
21
- . where ( pinned : true )
22
- . order ( ordering )
23
- . select { |org | org . visibility_allowed? ( request , current_user ) }
24
- . reject { |org | org . hidden? && !can? ( :view_hidden_organizations , nil ) }
22
+ . accepted_organizations
23
+ . where ( pinned : true )
24
+ . order ( ordering )
25
+ . select { |org | org . visibility_allowed? ( request , current_user ) }
26
+ . reject { |org | org . hidden? && !can? ( :view_hidden_organizations , nil ) }
25
27
render layout : 'landing'
26
28
end
27
29
@@ -30,6 +32,31 @@ def show
30
32
ordering = 'hidden, disabled_status, LOWER(courses.name)'
31
33
@my_courses = Course . participated_courses ( current_user , @organization ) . order ( ordering ) . select { |c | c . visible_to? ( current_user ) }
32
34
@my_assisted_courses = Course . assisted_courses ( current_user , @organization ) . order ( ordering ) . select { |c | c . visible_to? ( current_user ) }
35
+ @ongoing_courses = @organization
36
+ . courses
37
+ . ongoing
38
+ . enabled
39
+ . order ( ordering )
40
+ . select { |c | c . visible_to? ( current_user ) }
41
+ . to_a
42
+ if can? :teach , @organization
43
+ recently_updated_disabled_courses = @organization . courses
44
+ . ongoing
45
+ . disabled
46
+ . where ( updated_at : Time . current . all_quarter )
47
+ . to_a
48
+ @ongoing_courses += recently_updated_disabled_courses
49
+ end
50
+ authorize! :read , @ongoing_courses
51
+ end
52
+
53
+ def all_courses
54
+ return respond_access_denied ( 'Submissions for this exercise are no longer accepted.' ) unless current_user . administrator?
55
+ add_organization_breadcrumb
56
+ add_breadcrumb 'All Courses'
57
+ ordering = 'hidden, disabled_status, LOWER(courses.name)'
58
+ @my_courses = Course . participated_courses ( current_user , @organization ) . order ( ordering ) . select { |c | c . visible_to? ( current_user ) }
59
+ @my_assisted_courses = Course . assisted_courses ( current_user , @organization ) . order ( ordering ) . select { |c | c . visible_to? ( current_user ) }
33
60
@ongoing_courses = @organization . courses . ongoing . order ( ordering ) . select { |c | c . visible_to? ( current_user ) }
34
61
@expired_courses = @organization . courses . expired . order ( ordering ) . select { |c | c . visible_to? ( current_user ) }
35
62
# @my_courses_percent_completed = percent_completed_hash(@my_courses, current_user)
0 commit comments