Skip to content

Commit bc66af2

Browse files
committed
Move old courses to their own page
1 parent 417a059 commit bc66af2

File tree

6 files changed

+88
-24
lines changed

6 files changed

+88
-24
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Api
4+
module V8
5+
module Users
6+
class RequestDeletionController < Api::V8::BaseController
7+
skip_authorization_check
8+
9+
def index
10+
return respond_access_denied unless current_user.administrator?
11+
render json: { changes: RecentlyChangedUserDetail.all }
12+
end
13+
end
14+
end
15+
end
16+
end

app/controllers/organizations_controller.rb

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1+
# frozen_string_literal: true
2+
13
require 'natsort'
24

35
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]
57

6-
skip_authorization_check only: [:index, :new]
8+
skip_authorization_check only: %i[index new]
79

810
def index
911
ordering = 'hidden, LOWER(name)'
1012
@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) }
1416
@my_organizations = Organization.taught_organizations(current_user).select { |org| org.visibility_allowed?(request, current_user) }
1517
@my_organizations |= Organization.assisted_organizations(current_user).select { |org| org.visibility_allowed?(request, current_user) }
1618
@my_organizations |= Organization.participated_organizations(current_user).select { |org| org.visibility_allowed?(request, current_user) }
1719
@my_organizations.natsort_by!(&:name)
1820
@courses_under_initial_refresh = Course.where(initial_refresh_ready: false)
1921
@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) }
2527
render layout: 'landing'
2628
end
2729

@@ -30,6 +32,31 @@ def show
3032
ordering = 'hidden, disabled_status, LOWER(courses.name)'
3133
@my_courses = Course.participated_courses(current_user, @organization).order(ordering).select { |c| c.visible_to?(current_user) }
3234
@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) }
3360
@ongoing_courses = @organization.courses.ongoing.order(ordering).select { |c| c.visible_to?(current_user) }
3461
@expired_courses = @organization.courses.expired.order(ordering).select { |c| c.visible_to?(current_user) }
3562
# @my_courses_percent_completed = percent_completed_hash(@my_courses, current_user)

app/views/courses/index.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<% end %>
77
</h2>
88

9-
<% if can?(:teach, @organization) && !@expired_courses.empty? %>
9+
<% if can?(:teach, @organization) && @expired_courses && !@expired_courses.empty? %>
1010
<h3>Ongoing courses</h3>
1111
<% end %>
12-
<% unless @ongoing_courses.empty? %>
12+
<% if @ongoing_courses && !@ongoing_courses.empty? %>
1313
<div class="row">
1414
<div class="col-md-12">
1515
<%= render 'courses/list', :locals => { organization_id: @organization.slug, courses: @ongoing_courses, list_id: 'ongoing-courses' } %>
@@ -19,7 +19,7 @@
1919
<p>No available courses.</p>
2020
<% end %>
2121

22-
<% if can?(:teach, @organization) && !@expired_courses.empty? %>
22+
<% if can?(:teach, @organization) && @expired_courses && !@expired_courses.empty? %>
2323
<h3>Expired courses</h3>
2424
<div class="row">
2525
<div class="col-md-12">
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h1>
2+
<%= @organization.name %>
3+
<%= image_tag @organization.logo.url(:small_logo) if @organization.logo? %>
4+
</h1>
5+
6+
<p>
7+
<%= @organization.information %>
8+
</p>
9+
10+
11+
<div>
12+
<%= render template: 'courses/index', locals: { title: 'All courses' } %>
13+
</div>

app/views/organizations/show.html.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,11 @@
136136
<% all_courses_title = @my_courses.empty? && @my_assisted_courses.empty? ? 'Courses' : 'All courses' %>
137137

138138
<div>
139-
<%= render template: 'courses/index', locals: { title: all_courses_title } %>
139+
<%= render template: 'courses/index', locals: { title: 'Courses' } %>
140140
</div>
141+
142+
<% if can? :teach, @organization %>
143+
<%= link_to 'View all courses', all_courses_organization_path(@organization), class: 'btn btn-secondary'%>
144+
<% end %>
145+
146+
<br>

config/routes.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,31 +127,33 @@
127127

128128
resources :organizations, except: [:destroy, :create, :edit, :update], path: 'org' do
129129

130-
resources :exercises, only: [:show] do
131-
member do
132-
post 'toggle_submission_result_visibility'
133-
end
134-
resources :submissions, only: [:create]
135-
resource :solution, only: [:show]
136-
resources :feedback_answers, only: [:index]
137-
end
138130
member do
139131
post 'verify'
140132
post 'disable'
141133
get 'disable_reason_input'
142134
post 'toggle_visibility'
135+
get 'all_courses'
143136
end
144137

145138
collection do
146139
get 'list_requests'
147140
end
148141

142+
get 'course_templates', to: 'course_templates#list_for_teachers'
143+
144+
resources :exercises, only: [:show] do
145+
member do
146+
post 'toggle_submission_result_visibility'
147+
end
148+
resources :submissions, only: [:create]
149+
resource :solution, only: [:show]
150+
resources :feedback_answers, only: [:index]
151+
end
152+
149153
resources :participants, only: [:index]
150154

151155
resources :teachers, only: [:index, :create, :destroy]
152156

153-
get 'course_templates', to: 'course_templates#list_for_teachers'
154-
155157
resources :courses, except: [:new, :create] do
156158
member do
157159
get 'refresh'

0 commit comments

Comments
 (0)