diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 601ebb8a..0e783c74 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -61,6 +61,9 @@ class ApplicationController < ActionController::Base
# rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
rescue_from ::Unauthorized, :with => :deny_access
rescue_from ::ActionView::MissingTemplate, :with => :missing_template
+ rescue_from ::ActiveRecord::RecordNotFound do
+ render_404
+ end
include Redmine::Search::Controller
include Redmine::MenuManager::MenuController
diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb
index c1d918f6..c890ff6b 100644
--- a/app/controllers/competitions_controller.rb
+++ b/app/controllers/competitions_controller.rb
@@ -20,6 +20,8 @@ class CompetitionsController < ApplicationController
def show
@images = @competition.attachments
+ @user = current_user
+ @enrolled = @user && @user.logged? && @competition.team_members.exists?(user_id: @user.id)
end
def index
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index a850d16c..b830776b 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -2404,17 +2404,17 @@ class CoursesController < ApplicationController
homeworks.where(:homework_type => 4).each do |homework|
sheet1[4,current_col+=1] = "#{homework.name}"
end
- for i in 0 ... homeworks.where(:homework_type => 1).size
- sheet1[4,current_col+=1] = "普通作业第"+(i+1).to_s+"次"
+ homeworks.where(:homework_type => 1).each do |homework|
+ sheet1[4,current_col+=1] = "#{homework.name}"
end
- for i in 0 ... homeworks.where(:homework_type => 3).size
- sheet1[4,current_col+=1] = "分组作业第"+(i+1).to_s+"次"
+ homeworks.where(:homework_type => 3).each do |homework|
+ sheet1[4,current_col+=1] = "#{homework.name}"
end
- for i in 0 ... exercises.size
- sheet1[4,current_col+=1] = "试卷第"+(i+1).to_s+"次"
+ exercises.each do |exercise|
+ sheet1[4,current_col+=1] = "#{exercise.exercise_name}"
end
- for i in 0 ... tasks.size
- sheet1[4,current_col+=1] = "毕设任务第"+(i+1).to_s+"次"
+ tasks.each do |task|
+ sheet1[4,current_col+=1] = "#{task.name}"
end
sheet1[4,current_col+=1] = "实训作业总得分"
@@ -2434,7 +2434,7 @@ class CoursesController < ApplicationController
sheet1[count_row,column+=1] = member.user.login
sheet1[count_row,column+=1] = member.user.mail
sheet1[count_row,column+=1] = member.user.user_extensions.student_id
- sheet1[count_row,column+=1] = member.course_group_id == 0 ? "暂无" : member.course_group.name
+ sheet1[count_row,column+=1] = member.course_group_id == 0 ? "暂无" : member.course_group.try(:name)
# current_col = 5
shixun_score = 0
homeworks.where(:homework_type => 4).each do |homework|
@@ -2550,7 +2550,7 @@ class CoursesController < ApplicationController
sheet2[count_row,1] = act_member.user.show_real_name
sheet2[count_row,2] = act_member.user.login
sheet2[count_row,3] = act_member.user.user_extensions.student_id
- sheet2[count_row,4] = act_member.course_group_id == 0 ? "暂无" : act_member.course_group.name
+ sheet2[count_row,4] = act_member.course_group_id == 0 ? "暂无" : act_member.course_group.try(:name)
sheet2[count_row,5]= act_member.homework_num.to_i + act_member.graduation_num.to_i
sheet2[count_row,6]= act_member.exercise_num
sheet2[count_row,7]= act_member.poll_num
@@ -2598,7 +2598,7 @@ class CoursesController < ApplicationController
end
homeworks.where(:homework_type => 1).includes(:score_student_works).each_with_index do |home, i|
- sheet = book.create_worksheet :name => "普通作业第#{i+1}次"
+ sheet = book.create_worksheet :name => "#{home.name}"
sheet[0,0] = "课程编号"
sheet[0,1] = course.id
sheet[1,0] = "课程名称"
@@ -2645,7 +2645,7 @@ class CoursesController < ApplicationController
end
homeworks.where(:homework_type => 3).includes(:score_student_works).each_with_index do |home, i|
- sheet = book.create_worksheet :name => "分组作业第#{i+1}次"
+ sheet = book.create_worksheet :name => "#{home.name}"
sheet[0,0] = "课程编号"
sheet[0,1] = course.id
sheet[1,0] = "课程名称"
@@ -2693,7 +2693,7 @@ class CoursesController < ApplicationController
end
exercises.includes(:score_exercise_users).each_with_index do |exercise, i|
- sheet = book.create_worksheet :name => "试卷第#{i+1}次"
+ sheet = book.create_worksheet :name => "#{exercise.exercise_name}"
sheet[0,0] = "课程编号"
sheet[0,1] = course.id
sheet[1,0] = "课程名称"
@@ -2724,7 +2724,7 @@ class CoursesController < ApplicationController
end
tasks.each_with_index do |task, i|
- sheet = book.create_worksheet :name => "毕设任务第#{i+1}次"
+ sheet = book.create_worksheet :name => "#{task.name}"
sheet[0,0] = "课程编号"
sheet[0,1] = course.id
sheet[1,0] = "课程名称"
diff --git a/app/controllers/libraries_controller.rb b/app/controllers/libraries_controller.rb
index f3559b05..1d72f158 100644
--- a/app/controllers/libraries_controller.rb
+++ b/app/controllers/libraries_controller.rb
@@ -21,7 +21,7 @@ class LibrariesController < ApplicationController
end
def show
- @library = Library.find(params[:id])
+ @library = current_library
return render_403 unless admin_or_self? || @library.published?
@library_applies = @library.library_applies.where(status: :refused).order('created_at desc')
@@ -40,7 +40,7 @@ class LibrariesController < ApplicationController
redirect_to publish_success_libraries_path
else
flash[:message] = '保存成功'
- render 'new'
+ redirect_to edit_library_path(id: @library.id)
end
rescue ActiveRecord::RecordInvalid => _
render 'new'
@@ -50,11 +50,13 @@ class LibrariesController < ApplicationController
end
def edit
+ return render_403 unless admin_or_self?
@library = current_library
- redirect_to library_path(id: @library.id) unless @library.editable?
end
def update
+ return render_403 unless admin_or_self?
+
@library = current_library
Libraries::SaveService.new(@library, current_user, form_params).call
if with_publish?
@@ -62,7 +64,7 @@ class LibrariesController < ApplicationController
redirect_to publish_success_libraries_path
else
flash[:message] = '保存成功'
- render 'edit'
+ redirect_to edit_library_path(id: @library.id)
end
rescue ActiveRecord::RecordInvalid => _
render 'edit'
@@ -71,6 +73,24 @@ class LibrariesController < ApplicationController
render 'edit'
end
+ def destroy
+ if admin_or_business?
+ current_library.destroy
+ elsif current_library.user_id == current_user.id
+ unless current_library.pending?
+ render json: { status: -1, message: '只有草稿才能删除' }
+ return
+ end
+
+ current_library.destroy
+ else
+ render_403
+ return
+ end
+
+ render json: { status: 0, message: 'success' }
+ end
+
def publish
Libraries::SubmitService.new(current_library).call
render json: { status: 0 }
@@ -84,7 +104,7 @@ class LibrariesController < ApplicationController
private
def current_library
- @_current_library ||= current_user.libraries.find(params[:id])
+ @_current_library ||= Library.find(params[:id])
end
def form_params
@@ -100,6 +120,6 @@ class LibrariesController < ApplicationController
end
def admin_or_self?
- @library.user_id == current_user.id || current_user.admin?
+ current_library.user_id == current_user.id || admin_or_business?
end
end
\ No newline at end of file
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 672b3c66..b65a2fa8 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -3015,9 +3015,9 @@ module ApplicationHelper
elsif params[:controller] == "courses" && params[:action] == "index"
title << ("翻转课堂")
elsif params[:controller] == "competitions" && params[:action] == "index"
- title << ("竞赛")
+ title << ("在线竞赛")
elsif @competition
- title << (@competition.name.nil? ? "竞赛" : @competition.name)
+ title << (@competition.name.nil? ? "在线竞赛" : @competition.name)
elsif @contest
title << (@contest.name.nil? ? "创新源于实践" : @contest.name)
elsif @shixun
@@ -3027,13 +3027,13 @@ module ApplicationHelper
elsif params[:controller] == "shixuns" && params[:action] == "index"
title << ("开发社区")
elsif @subject
- title << (@subject.name.nil? ? "实训课程" : @subject.name)
+ title << (@subject.name.nil? ? "实践课程" : @subject.name)
elsif params[:controller] == "subjects" && params[:action] == "index"
- title << ("实训课程")
+ title << ("实践课程")
elsif @organization
title << (@organization.name.nil? ? "创新源于实践" : @organization.name)
elsif @forum || params[:controller] == "forums"
- title << "讨论区"
+ title << "交流问答"
elsif @my_syllabuses
title << "我的课堂"
elsif params[:controller] == 'ecs'
diff --git a/app/models/library.rb b/app/models/library.rb
index 78bc7fc5..63df5c91 100644
--- a/app/models/library.rb
+++ b/app/models/library.rb
@@ -45,8 +45,4 @@ class Library < ActiveRecord::Base
def increment_visited_count!
Library.connection.execute("update libraries set visited_count = COALESCE(visited_count, 0) + 1 where id = #{id}")
end
-
- def editable?
- pending? || refused?
- end
end
\ No newline at end of file
diff --git a/app/services/libraries/save_service.rb b/app/services/libraries/save_service.rb
index 3a81d379..db244836 100644
--- a/app/services/libraries/save_service.rb
+++ b/app/services/libraries/save_service.rb
@@ -17,7 +17,7 @@ class Libraries::SaveService
library.generate_uuid
end
- attachment_ids = params.delete(:attachment_ids)
+ attachment_ids = params.delete(:attachment_ids).try(:compact)
ActiveRecord::Base.transaction do
library.assign_attributes(params)
@@ -32,6 +32,6 @@ class Libraries::SaveService
private
def validate_params!
- raise Error, '附件不能为空' if params[:attachment_ids].blank?
+ raise Error, '附件不能为空' if params[:attachment_ids].try(:compact).blank?
end
end
diff --git a/app/services/libraries/submit_service.rb b/app/services/libraries/submit_service.rb
index 965ba673..0beec7de 100644
--- a/app/services/libraries/submit_service.rb
+++ b/app/services/libraries/submit_service.rb
@@ -8,6 +8,8 @@ class Libraries::SubmitService
end
def call
+ return if library.processing? || library.published?
+
raise Error, '该状态下不能提交审核' unless library.may_submit?
ActiveRecord::Base.transaction do
diff --git a/app/views/attachments/_from_libraries.html.erb b/app/views/attachments/_from_libraries.html.erb
index 4abb3c80..a6fe347d 100644
--- a/app/views/attachments/_from_libraries.html.erb
+++ b/app/views/attachments/_from_libraries.html.erb
@@ -16,6 +16,7 @@
<%= number_to_human_size attachment.filesize %>
<%= link_to(''.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') unless attachment.id.nil? %>
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
+ <%= hidden_field_tag "attachments[p#{i}][attachment_id]", attachment.id %>
<% end %>
<% container.saved_attachments.each_with_index do |attachment, i| %>
diff --git a/app/views/competitions/_gq_second_code_competition.html.erb b/app/views/competitions/_gq_second_code_competition.html.erb
index 35c5dd17..65b0befc 100644
--- a/app/views/competitions/_gq_second_code_competition.html.erb
+++ b/app/views/competitions/_gq_second_code_competition.html.erb
@@ -5,6 +5,11 @@
<% index += 1 %>
<%
+ challenge_description_extra = [
+ "模拟赛选择了第一届标注大赛正式赛第一阶段的三个项目供大家体验熟悉平台、学习其他人的标注,模拟赛标注不计分。",
+ "第一阶段比赛得分占正赛总比分的30%。",
+ "第二阶段比赛得分占正赛总比分的70%。"
+ ]
data = [
[
{
@@ -12,21 +17,21 @@
description: "Weka是基于Java的机器学习与数据挖掘平台,汇集了最前沿的机器学习算法,包括处理标准数据挖掘问题的几乎所有方法:回归、分类、聚类、关联规则以及属性选择等,是Java机器学习入门的首选平台。
本项目的Clusters目录中包含了K-Means、层次聚类等多种聚类算法以及相应的聚类效果评估方法的java实现",
task: '标注../weka/clusterers/目录下的所有代码文件。',
link_name: 'CSDN,经典聚类算法',
- link_url: 'javascript:void(0)'
+ link_url: 'https://blog.csdn.net/qq_30262201/article/details/78799926'
},
{
name: 'C++项目',
description: "该项目是GitHub上最受欢迎的C++语言实现经典算法与数据结构的项目之一,内容涵盖排序、链表、树结构、图搜索、贪心算法等。学习这些算法的代码实现,可以深刻理解和掌握算法的核心思想,感受算法之美,代码之美,是人工智能时代的基础入门一课。
本项目的sort_search_problems目录涵盖了冒泡排序、快速排序等各类经典排序算法的C++实现。",
task: '标注../sort_search_problems目录下的所有代码文件及对应引用的../include目录中自定义的头文件。',
link_name: 'CSDN,十大经典排序算法',
- link_url: 'javascript:void(0)'
+ link_url: 'https://blog.csdn.net/wfq784967698/article/details/79551476'
},
{
name: 'Python项目',
description: "该项目是GitHub上最受欢迎的Python语言实现经典算法的项目之一,包含了前沿的神经网络和经典数据结构及算法的Python实现。项目具有兼顾经典和前沿的特点。学习经典算法的源码实现,感受经典算法的思想之美、代码之美。
本项目的Sorts目录中包含了冒泡排序、快速排序等各类经典排序算法的Python实现。",
task: '标注../sorts/目录下的所有代码文件。',
link_name: 'CSDN,十大经典排序算法',
- link_url: 'javascript:void(0)'
+ link_url: 'https://blog.csdn.net/wfq784967698/article/details/79551476'
},
],
[{},{},{}],
@@ -56,7 +61,7 @@
- 标注说明:每个小组选择一种编程语言的题目,针对标注任务中指定的标注模块,要求对代码模块、模块中的代码文件, 以及文件中的函数必须进行标注,关键代码块、代码行及关键变量等由参赛者自由选择进行标注。 正式赛第一阶段的比赛在标注阶段就开放查看所有人的标注,请大家根据个人理解,写出自己的风格。我们将综合考虑标注的原创性、准确性、 完整性和多样性等不同的维度对标注质量进行评分。第一阶段比赛得分占正赛总比分的30%。 + 标注说明:每个小组选择一种编程语言的题目,针对标注任务中指定的标注模块,要求对代码模块、模块中的代码文件, 以及文件中的函数必须进行标注,关键代码块、代码行及关键变量等由参赛者自由选择进行标注。 正式赛第一阶段的比赛在标注阶段就开放查看所有人的标注,请大家根据个人理解,写出自己的风格。我们将综合考虑标注的原创性、准确性、 完整性和多样性等不同的维度对标注质量进行评分。<%= challenge_description_extra[i] %>