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