You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.2 KiB
33 lines
1.2 KiB
5 years ago
|
class TaskBanksController < ApplicationController
|
||
|
before_action :require_login
|
||
|
before_action :find_bank
|
||
|
before_action :bank_admin, only: [:update]
|
||
|
|
||
|
def show
|
||
|
@bank_attachments = @bank.attachments
|
||
|
end
|
||
|
|
||
|
def update
|
||
|
@bank.update_attributes(gtask_bank_params)
|
||
|
Attachment.associate_container(params[:attachment_ids], @graduation_topic.id, @graduation_topic.class) if params[:attachment_ids]
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def find_bank
|
||
|
@bank = GtaskBank.find_by!(id: params[:id])
|
||
|
tip_exception(403, "无权限") unless (current_user.certification_teacher? && (@bank.is_public || @bank.user_id == current_user.id)) || current_user.admin?
|
||
|
end
|
||
|
|
||
|
def bank_admin
|
||
|
tip_exception(403, "无权限") unless (current_user.certification_teacher? && @bank.user_id == current_user.id) || current_user.admin?
|
||
|
end
|
||
|
|
||
|
def gtask_bank_params
|
||
|
tip_exception("name参数不能为空") if params[:gtopic_bank][:name].blank?
|
||
|
tip_exception("description参数不能为空") if params[:gtopic_bank][:description].blank?
|
||
|
params.require(:gtopic_bank).permit(:name, :topic_type, :topic_source, :topic_property_first, :description,
|
||
|
:topic_property_second, :source_unit, :topic_repeat, :province, :city)
|
||
|
end
|
||
|
end
|