From e82ef836d5d103c23228dbe9f8e4b89187d1442d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 27 Aug 2019 14:26:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E9=80=89=E9=A2=98=E7=9A=84?= =?UTF-8?q?=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/gtopic_banks_controller.rb | 32 ++++++++++++++++++++++ app/views/gtopic_banks/show.json.jbuilder | 6 ++++ config/routes.rb | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 app/controllers/gtopic_banks_controller.rb create mode 100644 app/views/gtopic_banks/show.json.jbuilder diff --git a/app/controllers/gtopic_banks_controller.rb b/app/controllers/gtopic_banks_controller.rb new file mode 100644 index 000000000..3629b87bc --- /dev/null +++ b/app/controllers/gtopic_banks_controller.rb @@ -0,0 +1,32 @@ +class GtopicBanksController < 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(gtopic_bank_params) + Attachment.associate_container(params[:attachment_ids], @graduation_topic.id, @graduation_topic.class) if params[:attachment_ids] + end + + private + + def find_bank + @bank = GtopicBank.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 gtopic_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 diff --git a/app/views/gtopic_banks/show.json.jbuilder b/app/views/gtopic_banks/show.json.jbuilder new file mode 100644 index 000000000..9c5226930 --- /dev/null +++ b/app/views/gtopic_banks/show.json.jbuilder @@ -0,0 +1,6 @@ +json.(@bank, :id, :name, :description, :is_public, :topic_type, :topic_source, :topic_property_first, :topic_property_second, + :source_unit, :topic_repeat, :province, :city) + +json.attachment_list @bank_attachments do |attachment| + json.partial! "attachments/attachment_simple", locals: {attachment: attachment} +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2081f47d2..c160cf938 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -641,6 +641,8 @@ Rails.application.routes.draw do end end + resources :gtopic_banks + resources :attachments resources :schools do