From 668555626d5a48916f095948fae97042f07415a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com>
Date: Sat, 29 Jun 2019 18:06:43 +0800
Subject: [PATCH 01/34] b
---
public/react/src/modules/tpm/NewHeader.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/react/src/modules/tpm/NewHeader.js b/public/react/src/modules/tpm/NewHeader.js
index 79eccf2b..9969141a 100644
--- a/public/react/src/modules/tpm/NewHeader.js
+++ b/public/react/src/modules/tpm/NewHeader.js
@@ -294,7 +294,7 @@ class NewHeader extends Component {
-
From 050466c703006d97fb79385c3459188dcd65e174 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com>
Date: Mon, 1 Jul 2019 11:25:20 +0800
Subject: [PATCH 03/34] b
---
public/react/src/modules/forums/ForumsIndex.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/react/src/modules/forums/ForumsIndex.js b/public/react/src/modules/forums/ForumsIndex.js
index 14d31d69..1c446725 100644
--- a/public/react/src/modules/forums/ForumsIndex.js
+++ b/public/react/src/modules/forums/ForumsIndex.js
@@ -104,7 +104,7 @@ class ForumsIndex extends Component {
componentDidMount() {
- window.document.title = '问答'
+ window.document.title = '交流问答'
}
From b1290f9f01d4fa326f3988640bd11548609dc421 Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Mon, 1 Jul 2019 14:04:39 +0800
Subject: [PATCH 04/34] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E7=8E=AF=E5=A2=83?=
=?UTF-8?q?=E3=80=91=E5=AD=A6=E7=94=9F=E5=88=97=E8=A1=A8=E7=9A=84=E6=88=90?=
=?UTF-8?q?=E7=BB=A9=E5=AF=BC=E5=87=BA=EF=BC=8C=E2=80=9C=E6=99=AE=E9=80=9A?=
=?UTF-8?q?=E4=BD=9C=E4=B8=9A1=E2=80=9D=E2=80=9C=E8=AF=95=E5=8D=B71?=
=?UTF-8?q?=E2=80=9D=E7=AD=89=E6=9B=B4=E6=8D=A2=E6=88=90=E4=BD=9C=E4=B8=9A?=
=?UTF-8?q?=E6=A0=87=E9=A2=98=E5=AF=BC=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/courses_controller.rb | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index a850d16c..a35860f2 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] = "实训作业总得分"
@@ -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] = "课程名称"
From 4cd076a9269c1577d0f10743d05b9c59a8735a64 Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Mon, 1 Jul 2019 14:48:43 +0800
Subject: [PATCH 05/34] =?UTF-8?q?t=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/courses_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index a35860f2..221acf3c 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -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|
From 91219c9e990e1034649a3bdf8b1902fceb14b0e3 Mon Sep 17 00:00:00 2001
From: p31729568
Date: Mon, 1 Jul 2019 14:50:40 +0800
Subject: [PATCH 06/34] modify library edit && add delete library
---
app/controllers/application_controller.rb | 3 +
app/controllers/libraries_controller.rb | 28 +++++++--
app/models/library.rb | 4 --
app/services/libraries/save_service.rb | 4 +-
app/services/libraries/submit_service.rb | 2 +
.../attachments/_from_libraries.html.erb | 1 +
app/views/layouts/base_library.html.erb | 6 ++
app/views/libraries/_form.html.erb | 59 +++++++++----------
app/views/libraries/index.html.erb | 4 +-
app/views/libraries/show.html.erb | 34 +++++++++--
10 files changed, 97 insertions(+), 48 deletions(-)
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/libraries_controller.rb b/app/controllers/libraries_controller.rb
index f3559b05..68b36df0 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')
@@ -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?
@@ -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/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..6af3284b 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?
+
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/layouts/base_library.html.erb b/app/views/layouts/base_library.html.erb
index 766069bb..ebc56f4d 100644
--- a/app/views/layouts/base_library.html.erb
+++ b/app/views/layouts/base_library.html.erb
@@ -67,5 +67,11 @@