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.
educoder/app/controllers/live_links_controller.rb

43 lines
1.2 KiB

class LiveLinksController < ApplicationController
before_action :require_login
before_action :find_course, only: [:index, :create]
before_action :user_course_identity, :teacher_allowed, only: [:create]
def index
lives = @course.live_links.order("id desc")
@total_count = lives.size
@lives = paginate lives.includes(user: :user_extension)
end
def create
@course.live_links.create!( create_params.merge(user_id: current_user.id))
render_ok
end
def update
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
tip_exception("请勿重复开启") if current_live.on_status && params[:on_status].to_i == 1
ActiveRecord::Base.transaction do
current_live.update!(on_status: params[:on_status])
# 开启时发送消息,关闭直播时删除对应的消息
if params[:on_status].to_i == 1
LivePublishJob.perform_later(current_live.id)
else
current_live.tidings.destroy_all
end
end
render_ok
end
private
def create_params
params.permit(:url, :description)
end
def current_live
@_current_live = LiveLink.find params[:id]
end
end