Merge remote-tracking branch 'origin/dev_aliyun' into dev_aliyun

dev_hjm_a
杨树明 5 years ago
commit ec43d209b9

@ -3,7 +3,8 @@ class Ecs::CourseManagersController < Ecs::CourseBaseController
before_action :check_major_manager_permission!, only: [:create, :destroy]
def create
@user = Ecs::CreateCourseManagerService.call(current_course, params[:user_id])
Ecs::CreateCourseManagerService.call(current_course, params[:user_ids])
render_ok
rescue Ecs::CreateCourseManagerService::Error => ex
render_error(ex.message)
end

@ -0,0 +1,5 @@
class TemplatesController < ApplicationController
def show
@template = EcTemplate.find_by_name!(params[:name])
end
end

@ -0,0 +1,11 @@
class Wechat::App
class << self
attr_accessor :appid, :secret
delegate :access_token, :jscode2session, to: :client
def client
@_client ||= Wechat::Client.new(appid, secret)
end
end
end

@ -34,6 +34,10 @@ class Wechat::Client
jsapi_ticket
end
def jscode2session(code)
request(:get, '/sns/jscode2session', appid: appid, secret: secret, js_code: code, grant_type: 'authorization_code')
end
def access_token_cache_key
"#{base_cache_key}/access_token"
end
@ -49,7 +53,7 @@ class Wechat::Client
private
def request(method, url, **params)
Rails.logger.error("[wechat] request: #{method} #{url} #{params.inspect}")
Rails.logger.error("[wechat] request: #{method} #{url} #{params.except(:secret).inspect}")
client = Faraday.new(url: BASE_SITE)
response = client.public_send(method, url, params)

@ -2,20 +2,14 @@ class Wechat::OfficialAccount
class << self
attr_accessor :appid, :secret
delegate :access_token, :jsapi_ticket, to: :client
def js_sdk_signature(url, noncestr, timestamp)
data = { jsapi_ticket: jsapi_ticket, noncestr: noncestr, timestamp: timestamp, url: url }
str = data.map { |k, v| "#{k}=#{v}" }.join('&')
Digest::SHA1.hexdigest(str)
end
def access_token
client.access_token
end
def jsapi_ticket
client.jsapi_ticket
end
def client
@_client ||= Wechat::Client.new(appid, secret)
end

@ -3,27 +3,29 @@ class Ecs::CreateCourseManagerService < ApplicationService
COURSE_MANAGER_COUNT_LIMIT = 2 # 课程管理员数量限制
attr_reader :ec_course, :user_id
attr_reader :ec_course, :user_ids
def initialize(ec_course, user_id)
def initialize(ec_course, user_ids)
@ec_course = ec_course
@user_id = user_id
@user_ids = user_ids
end
def call
user = User.find_by(id: params[:user_id])
raise Error, '该用户不存在' if user.blank?
users_count = User.where(id: user_ids).count
raise Error, '用户不存在' if users_count != user_ids.size
if ec_course.ec_course_users.exists?(user_id: user.id)
raise Error, '用户已经是该课程的管理员'
if ec_course.ec_course_users.exists?(user_id: user_ids)
raise Error, '用户已经是该课程的管理员'
end
if ec_course.ec_course_users.count >= COURSE_MANAGER_COUNT_LIMIT
raise Error, '该课程管理员数量已达上限'
if ec_course.ec_course_users.count + user_ids.size > COURSE_MANAGER_COUNT_LIMIT
raise Error, "课程管理员数量过多(最多#{COURSE_MANAGER_COUNT_LIMIT}"
end
ec_course.ec_course_users.create!(user: user)
user
ActiveRecord::Base.transaction do
user_ids.each do |user_id|
ec_course.ec_course_users.create!(user_id: user_id)
end
end
end
end

@ -1 +0,0 @@
json.partial! 'ecs/shared/user', user: @user

@ -0,0 +1,3 @@
json.template do
json.partial! 'attachments/attachment_simple', attachment: @template.attachments.last
end

@ -818,6 +818,7 @@ Rails.application.routes.draw do
post :feedback
end
end
resource :template, only: [:show]
end
namespace :admins do

Loading…
Cancel
Save