Skip to content

Commit

Permalink
Merge branch 'master' into docker-firewall
Browse files Browse the repository at this point in the history
  • Loading branch information
evanyeyeye authored Apr 15, 2024
2 parents a97f9a8 + 5d05222 commit ee3b340
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/base_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def authorize_user_for_course
raise ApiError.new("User is not in this course", :forbidden)
end

if @course.disabled? && !@cud.has_auth_level?(:instructor)
if @course.is_disabled? && !@cud.has_auth_level?(:instructor)
raise ApiError.new("Your course has been disabled by your instructor. "\
"Please contact them directly if you have any questions", :forbidden)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index

if params.has_key?(:state)
if params[:state] == "disabled"
courses_for_user = courses_for_user.select { |course| course.disabled? }
courses_for_user = courses_for_user.select { |course| course.is_disabled?}
elsif ["completed", "current", "upcoming"].include? params[:state]
state = params[:state].to_sym
courses_for_user = courses_for_user.select { |course| course.temporal_status == state }
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def authorize_user_for_course
end

# check if course was disabled
if @course.disabled? && !@cud.has_auth_level?(:instructor)
if @course.is_disabled? && !@cud.has_auth_level?(:instructor)
flash[:error] = "Your course has been disabled by your instructor.
Please contact them directly if you have any questions"
redirect_to(controller: :courses, action: :index) && return
Expand Down Expand Up @@ -301,7 +301,7 @@ def set_breadcrumbs
@breadcrumbs = []
return unless @course

@breadcrumbs << if @course.disabled?
@breadcrumbs << if @course.is_disabled?
(view_context.link_to "#{@course.full_name} (Course Disabled)",
[@course], id: "courseTitle")
else
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/assessments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def index
.or(announcements_tmp.where(system: true)).order(:start_date)
# Only display course attachments on course landing page
@course_attachments = if @cud.instructor?
@course.attachments.where(assessment_id: nil)
@course.attachments.where(assessment_id: nil).ordered
else
@course.attachments.where(assessment_id: nil).released
@course.attachments.where(assessment_id: nil).released.ordered
end
end

Expand Down Expand Up @@ -584,9 +584,9 @@ def show
@cud
end
@attachments = if @cud.instructor?
@assessment.attachments
@assessment.attachments.ordered
else
@assessment.attachments.released
@assessment.attachments.released.ordered
end
@submissions = @assessment.submissions.where(course_user_datum_id: @effectiveCud.id)
.order("version DESC")
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def edit_course_params
att = params.require(:editCourse).permit(:semester, :website, :late_slack,
:grace_days, :display_name, :start_date, :end_date,
:disabled, :exam_in_progress, :allow_self_enrollment,
:version_threshold, :gb_message,
:version_threshold, :gb_message, :disable_on_end,
late_penalty_attributes: %i[kind value],
version_penalty_attributes: %i[kind value])

Expand Down
58 changes: 57 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,50 @@ def edit
@breadcrumbs << (view_context.link_to @user.display_name, user_path(@user))
end

action_auth_level :download_all_submissions, :student
def download_all_submissions
user = User.find(params[:id])
submissions = if params[:final]
Submission.latest.where(course_user_datum: CourseUserDatum.where(user_id: user))
else
Submission.where(course_user_datum: CourseUserDatum.where(user_id: user))
end
submissions = submissions.select do |s|
p = s.handin_file_path
is_disabled = s.course_user_datum.course.disabled
!p.nil? && File.exist?(p) && File.readable?(p) && !is_disabled
end
if submissions.empty?
flash[:error] = "There are no submissions to download."
redirect_to(user_path(user)) && return
end

current_time = Time.current
filename = if params[:final]
"autolab_final_submissions_#{current_time.strftime('%Y-%m-%d')}"
else
"autolab_all_submissions_#{current_time.strftime('%Y-%m-%d')}"
end

temp_file = Tempfile.new("autolab_submissions.zip")
Zip::File.open(temp_file.path, Zip::File::CREATE) do |zipfile|
submissions.each do |s|
p = s.handin_file_path
course_name = s.course_user_datum.course.name
assignment_name = s.assessment.name
course_directory = "#{filename}/#{course_name}"
assignment_directory = "#{course_directory}/#{assignment_name}"
entry_name = download_filename(p, assignment_name)
zipfile.add(File.join(assignment_directory, entry_name), p)
end
end

send_file(temp_file.path,
type: "application/zip",
disposition: "attachment", # tell browser to download
filename: "#{filename}.zip")
end

# PATCH users/:id/
action_auth_level :update, :student
def update
Expand Down Expand Up @@ -226,7 +270,7 @@ def lti_launch_initialize
@listing = { current: [], completed: [], upcoming: [] }

courses_for_user.each do |course|
next if course.disabled?
next if course.is_disabled?

course_cud = CourseUserDatum.find_cud_for_course(course, @user.id)
next unless course_cud.has_auth_level?(:course_assistant)
Expand Down Expand Up @@ -389,6 +433,18 @@ def update_display_settings

private

# Given the path to a file, return the filename to use when the user downloads it
# path should be of the form .../<ver>_<handin> or .../annotated_<ver>_<handin>
# returns <course_name>_<assignment_name>_<ver>_<handin>
# or annotated_<course_name>_<assignment_name>_<ver>_<handin>
def download_filename(path, assignment_name)
basename = File.basename path
basename_parts = basename.split("_")
basename_parts.insert(-3, assignment_name)
download_name = basename_parts[-3..]
download_name.join("_")
end

def new_user_params
params.require(:user).permit(:email, :first_name, :last_name)
end
Expand Down
12 changes: 10 additions & 2 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,20 @@ def temporal_status(now = DateTime.now)
if now < start_date
:upcoming
elsif now > end_date
:completed
if disable_on_end
:disabled
else
:completed
end
else
:current
end
end

def is_disabled?
disabled? or (disable_on_end? && DateTime.now > end_date)
end

def current_assessments(now = DateTime.now)
assessments.where("start_at < :now AND end_at > :now", now:)
end
Expand Down Expand Up @@ -427,7 +435,7 @@ def serialize(include_metrics)

GENERAL_SERIALIZABLE = Set.new %w[name semester late_slack grace_days display_name start_date
end_date disabled exam_in_progress version_threshold
gb_message website]
gb_message website disable_on_end]
def serialize_general
Utilities.serializable attributes, GENERAL_SERIALIZABLE
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/assessments/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% @title = if @course.disabled?
<% @title = if @course.is_disabled?
"#{@course.full_name} (Course Disabled)"
else
@course.full_name
Expand Down Expand Up @@ -195,7 +195,7 @@
<div class="row">
<% attachment_categories = @course_attachments.distinct.pluck(:category_name).sort %>
<% attachment_categories.each_with_index do |cat| %>
<% attachments = @course_attachments.from_category(cat).ordered %>
<% attachments = @course_attachments.from_category(cat) %>
<% if attachments.any? %>
<div class="col s12 m4 attachments">
<div class="card hoverable">
Expand Down
3 changes: 3 additions & 0 deletions app/views/courses/_courseFields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
help_text: "If this box is checked, then students won't be able download labs
or upload submissions." %>

<%= f.check_box :disable_on_end,
help_text: "If this box is checked, the course will be disabled after the course ends." %>

<%= f.check_box :exam_in_progress, help_text: "While checked, students are not allowed to view their previous
submissions for any assessment in this class." %>
<%= label_tag(:allow_self_enrollment) do %>
Expand Down
15 changes: 15 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,19 @@
</ul>
<%= f.submit 'Save', { class: "btn primary" } %>
<% end %>
<h4>Download Submissions</h4>
<%= link_to download_all_submissions_user_path(@user, final: true),
{ title: "Download all your final submissions",
class: "" } do %>
<span class="btn primary">
Download Final
</span>
<% end %>
<%= link_to download_all_submissions_user_path(@user),
{ title: "Download all your submissions",
class: "" } do %>
<span class="btn primary">
Download All
</span>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@

resources :users do
get "admin"
get "download_all_submissions", on: :member
get "github_oauth", on: :member
get "lti_launch_initialize", on: :member
post "lti_launch_link_course", on: :member
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20240316162826_add_disableon_end_to_courses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddDisableonEndToCourses < ActiveRecord::Migration[6.1]
def self.up
add_column :courses, :disable_on_end, :boolean, default: false
end

def self.down
remove_column :courses, :disable_on_end
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
t.text "gb_message"
t.string "website"
t.string "access_code"
t.boolean "disable_on_end", default: false
end

create_table "extensions", force: :cascade do |t|
Expand Down

0 comments on commit ee3b340

Please sign in to comment.