From 9492c32c5b7e29ced58ade7eb94fc4c8a185bf20 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 27 Dec 2019 17:47:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../examination_banks_controller.rb | 26 +++++++++++++++++++ config/routes.rb | 4 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/controllers/examination_banks_controller.rb b/app/controllers/examination_banks_controller.rb index 9d5732fdc..98dfc57bb 100644 --- a/app/controllers/examination_banks_controller.rb +++ b/app/controllers/examination_banks_controller.rb @@ -1,5 +1,8 @@ class ExaminationBanksController < ApplicationController + include PaginateHelper before_action :require_login + before_action :find_exam, except: [:index, :create] + before_action :edit_auth, only: [:update, :destroy, :set_public] def index exams = ExaminationBankQuery.call(params) @@ -43,9 +46,32 @@ class ExaminationBanksController < ApplicationController end + def update + + end + + def destroy + @exam.destroy! + render_ok + end + + def set_public + tip_exception(-1, "该试卷已公开") if @exam.public? + @exam.update_attributes!(public: 1) + render_ok + end + private def form_params params.permit(:discipline_id, :sub_discipline_id, :difficulty, :name, :duration, tag_discipline_id: []) end + + def find_exam + @exam = ExaminationBank.find_by!(id: params[:id]) + end + + def edit_auth + current_user.admin_or_business? || @exam.user == current_user + end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c36d78741..5ad8f8211 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -76,7 +76,9 @@ Rails.application.routes.draw do end resources :examination_banks do - + member do + post :set_public + end end resources :hacks, path: :problems, param: :identifier do