diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c3865f3f..e44005a4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -376,7 +376,7 @@ class ApplicationController < ActionController::Base def require_admin return unless require_login - if !User.current.admin? && @shixun.status > 1 + if !User.current.admin? render_403 return false end diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 13c24a3e..d5852fce 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -32,6 +32,14 @@ class ManagementsController < ApplicationController # 实训课程等级体系 def subject_level_system @levels = SubjectLevelSystem.all + respond_to do |format| + format.html + format.xls{ + time = Time.now.strftime("%Y%m%d") + filename = "实训课程体系#{time}.xls" + send_data(export_subject_level_system(), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) + } + end end # 创建课程等级体系 @@ -4286,6 +4294,33 @@ end return sheet.rows end + def export_subject_level_system + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "实训课程等级体系" + blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 + sheet1.row(0).default_format = blue + count_row = 1 + sheet1.row(0).concat(["序号", "等级", "实训课程名称", "实训课程url", "实训名称"]) + levels = SubjectLevelSystem.includes(subjects: [stage_shixuns: :shixun]).where(nil) + levels.each_with_index do |level, i| + sheet1[count_row, 0] = i + 1 + sheet1[count_row, 1] = level.level + level.subjects.each do |subject| + sheet1[count_row, 2] = subject.name + sheet1[count_row, 3] = "#{subject_path(subject)}" + count_row += 1 + subject.shixuns.each do |shixun| + sheet1[count_row, 4] = shixun.name + count_row += 1 + end + end + count_row += 1 + end + book.write xls_report + xls_report.string + end + def shixun_feedback_xls shixun_ids, beginTime, endTime xls_report = StringIO.new book = Spreadsheet::Workbook.new diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 56766264..e47938ac 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -10,7 +10,7 @@ class ShixunsController < ApplicationController before_filter :view_allow, :only => [:collaborators, :propaedeutics, :shixun_discuss, :ranking_list] before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators, :update, :destroy] before_filter :validation_email, :only => [:new] - before_filter :require_admin, :only => [:destroy] + #before_filter :require_manager, :only => [:destroy] # 移动云ToC模式权限控制 # before_filter :ecloud_auth, :except => [:show, :index] @@ -1117,6 +1117,7 @@ class ShixunsController < ApplicationController end def destroy + render_403 if @shixun.status > 1 && !User.current.admin? ActiveRecord::Base.transaction do g = Gitlab.client g.delete_project(@shixun.gpid) if @shixun.try(:gpid).present? diff --git a/app/views/managements/_subject_level_list.html.erb b/app/views/managements/_subject_level_list.html.erb index 1a4bf6d7..0988bd6e 100644 --- a/app/views/managements/_subject_level_list.html.erb +++ b/app/views/managements/_subject_level_list.html.erb @@ -1,3 +1,6 @@ +
+ " class="fr task-btn task-btn-orange ml5" >导出excel +
等级