Skip to content

Commit 7ecaee6

Browse files
committed
Add api endpoint to see studyright eligible students' infos
1 parent d3dc514 commit 7ecaee6

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

app/controllers/api/v8/apidocs_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class ApidocsController < ActionController::Base
159159
Api::V8::Organizations::Courses::PointsController,
160160
Api::V8::Organizations::Courses::SubmissionsController,
161161
Api::V8::Organizations::Courses::ExercisesController,
162+
Api::V8::Organizations::Courses::StudyrightEligibilityController,
162163
Api::V8::Organizations::Courses::Exercises::PointsController,
163164
Api::V8::Organizations::Courses::Exercises::Users::PointsController,
164165
Api::V8::Organizations::Courses::Users::PointsController,
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# frozen_string_literal: true
2+
3+
module Api
4+
module V8
5+
module Organizations
6+
module Courses
7+
class StudyrightEligibilityController < Api::V8::BaseController
8+
include Swagger::Blocks
9+
10+
swagger_path '/api/v8/org/{organization_slug}/courses/{course_name}/eligible_students' do
11+
operation :get do
12+
key :description, "Returns all users from the course who have at least 90% of every part's points and are applying for study right, in a json format. Course is searched by name, only 2019 programming mooc course is valid"
13+
key :produces, ['application/json']
14+
key :tags, ['point']
15+
parameter '$ref': '#/parameters/path_organization_slug'
16+
parameter '$ref': '#/parameters/path_course_name'
17+
response 403, '$ref': '#/responses/error'
18+
response 404, '$ref': '#/responses/error'
19+
response 200 do
20+
key :description, 'Users in json'
21+
schema do
22+
key :type, :array
23+
items do
24+
key :'$ref', :UserBasicInfo
25+
end
26+
end
27+
end
28+
end
29+
end
30+
31+
skip_authorization_check
32+
33+
def eligible_students
34+
unauthorize_guest!
35+
36+
return respond_with_error("This feature is only for MOOC-organization's 2019 programming MOOC") unless params[:course_name] == '2019-ohjelmointi' && params[:organization_slug] == 'mooc'
37+
38+
course = Course.find_by!(name: "#{params[:organization_slug]}-#{params[:course_name]}")
39+
40+
authorize! :read, course
41+
42+
applied_students = UserAppDatum.where(field_name: 'applies_for_study_right', value: 't', namespace: 'ohjelmoinnin-mooc-2019').each { |datum| datum.user_id }
43+
44+
authorize! :read, applied_students
45+
46+
eligible_student_ids = []
47+
48+
applied_students.map do |user|
49+
drop = false
50+
course.exercise_group_completion_counts_for_user(user).map do |group, info|
51+
if info[:progress] < 0.9
52+
drop = true
53+
end
54+
end
55+
eligible_student_ids.push(user) unless drop
56+
end
57+
58+
eligible_students = []
59+
60+
eligible_student_ids.map do |user_id|
61+
u = User.find(user_id)
62+
info = {
63+
id: u.id,
64+
username: u.login,
65+
email: u.email,
66+
administrator: u.administrator
67+
}
68+
eligible_students.push(info)
69+
end
70+
71+
render json: {
72+
eligible_students: eligible_students
73+
}
74+
end
75+
end
76+
end
77+
end
78+
end
79+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
resources :users, module: :courses, only: [] do
7474
resources :submissions, module: :users, only: :index
7575
end
76+
77+
get 'eligible_students', to: 'courses/studyright_eligibility#eligible_students'
7678
end
7779
end
7880

0 commit comments

Comments
 (0)