Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
c31c07b453
@ -0,0 +1,39 @@
|
||||
class Users::AuthAttachmentsController < Users::BaseAccountController
|
||||
before_action :private_user_resources!
|
||||
before_action :convert_image!, only: [:update]
|
||||
|
||||
def update
|
||||
image_temp_path = auth_image_path + 'temp' # 上传文件保存至临时文件,提交申请时再移到正常目录
|
||||
|
||||
File.delete(image_temp_path) if File.exist?(image_temp_path) # 删除之前的临时文件
|
||||
|
||||
Util.write_file(@image, image_temp_path)
|
||||
|
||||
render_ok
|
||||
rescue StandardError => ex
|
||||
logger_error(ex)
|
||||
render_error('上传失败')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def convert_image!
|
||||
max_size = EduSetting.get('upload_avatar_max_size') || 10 * 1024 * 1024 # 10M
|
||||
if params[:image].class == ActionDispatch::Http::UploadedFile
|
||||
@image = params[:image]
|
||||
render_error('请上传文件') if @image.size.zero?
|
||||
render_error('文件大小超过限制') if @image.size > max_size
|
||||
else
|
||||
image = params[:image].to_s.strip
|
||||
return render_error('请上传正确的图片') if image.blank?
|
||||
@image = Util.convert_base64_image(image, max_size: max_size)
|
||||
end
|
||||
rescue Base64ImageConverter::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
|
||||
def auth_image_path
|
||||
url_method = params[:type] == 'professional' ? :disk_professional_auth_filename : :disk_real_name_auth_filename
|
||||
ApplicationController.helpers.send(url_method, observed_user.id)
|
||||
end
|
||||
end
|
@ -0,0 +1,16 @@
|
||||
class Users::AuthenticationAppliesController < Users::BaseAccountController
|
||||
before_action :private_user_resources!
|
||||
|
||||
def create
|
||||
Users::ApplyAuthenticationService.call(observed_user, create_params)
|
||||
render_ok
|
||||
rescue Users::ApplyAuthenticationService::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_params
|
||||
params.permit(:name, :id_number, :upload_image)
|
||||
end
|
||||
end
|
@ -0,0 +1,16 @@
|
||||
class Users::ProfessionalAuthAppliesController < Users::BaseAccountController
|
||||
before_action :private_user_resources!
|
||||
|
||||
def create
|
||||
Users::ApplyProfessionalAuthService.call(observed_user, create_params)
|
||||
render_ok
|
||||
rescue Users::ApplyProfessionalAuthService::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_params
|
||||
params.permit(:school_id, :department_id, :identity, :extra, :upload_image)
|
||||
end
|
||||
end
|
@ -0,0 +1,8 @@
|
||||
class Users::ApplyAuthenticationForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :name, :id_number, :upload_image
|
||||
|
||||
validates :name, presence: true
|
||||
validates :id_number, presence: true
|
||||
end
|
@ -0,0 +1,10 @@
|
||||
class Users::ApplyProfessionalAuthForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :school_id, :department_id, :identity, :extra, :upload_image
|
||||
|
||||
validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
||||
validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true
|
||||
validates :identity, presence: true, inclusion: { in: %w(student teacher professional) }
|
||||
validates :extra, presence: true
|
||||
end
|
@ -0,0 +1,19 @@
|
||||
class CourseDeleteStudentDeleteWorksJob < ApplicationJob
|
||||
queue_as :course_member
|
||||
|
||||
def perform(course_id, student_ids)
|
||||
course = Course.find_by(id: course_id)
|
||||
return if course.blank?
|
||||
|
||||
student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id})
|
||||
student_works.update_all(is_delete: 1)
|
||||
|
||||
exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id})
|
||||
exercise_users.update_all(is_delete: 1)
|
||||
|
||||
poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id})
|
||||
poll_users.update_all(is_delete: 1)
|
||||
|
||||
course.graduation_works.where(user_id: student_ids).update_all(is_delete: 1)
|
||||
end
|
||||
end
|
@ -0,0 +1,52 @@
|
||||
class Users::ApplyAuthenticationService < ApplicationService
|
||||
Error = Class.new(StandardError)
|
||||
|
||||
attr_reader :user, :params
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
Users::ApplyAuthenticationForm.new(params).validate!
|
||||
raise Error, '您已经申请过实名认证了' if ApplyUserAuthentication.real_name_auth.processing.exists?(user_id: user.id)
|
||||
|
||||
user.lastname = params[:name].to_s.strip
|
||||
user.firstname = ''
|
||||
user.ID_number = params[:id_number].to_s.strip.presence
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
user.authentication = false
|
||||
user.save!
|
||||
|
||||
user.apply_user_authentication.create!(auth_type: 1, status: 0)
|
||||
|
||||
move_image_file! unless params[:upload_image].to_s == 'false'
|
||||
|
||||
sms_notify_admin
|
||||
end
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def move_image_file!
|
||||
image_url = ApplicationController.helpers.disk_real_name_auth_filename(user.id)
|
||||
temp_image_url = image_url + 'temp'
|
||||
|
||||
FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url)
|
||||
rescue RuntimeError => ex
|
||||
Util.logger_error(ex)
|
||||
raise Error, '申请失败'
|
||||
ensure
|
||||
File.delete(temp_image_url) if File.exist?(temp_image_url)
|
||||
end
|
||||
|
||||
def sms_notify_admin
|
||||
Educoder::Sms.notify_admin(send_type: 'apply_auth')
|
||||
rescue => ex
|
||||
Util.logger_error(ex)
|
||||
end
|
||||
end
|
@ -0,0 +1,62 @@
|
||||
class Users::ApplyProfessionalAuthService < ApplicationService
|
||||
Error = Class.new(StandardError)
|
||||
|
||||
attr_reader :user, :params
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
Users::ApplyProfessionalAuthForm.new(params).validate!
|
||||
raise Error, '您已经申请过职业认证了' if ApplyUserAuthentication.professional_auth.processing.exists?(user_id: user.id)
|
||||
|
||||
user.professional_certification = false
|
||||
|
||||
extension = user.user_extension
|
||||
extension.school_id = params[:school_id]
|
||||
extension.department_id = params[:department_id]
|
||||
extension.identity = params[:identity]
|
||||
|
||||
extra = params[:extra].to_s.strip.presence
|
||||
if extension.identity.to_s == 'student'
|
||||
extension.technical_title = nil
|
||||
extension.student_id = extra
|
||||
else
|
||||
extension.technical_title = extra
|
||||
extension.student_id = nil
|
||||
end
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
user.save!
|
||||
extension.save!
|
||||
|
||||
user.apply_user_authentication.create!(auth_type: 2, status: 0)
|
||||
|
||||
move_image_file! unless params[:upload_image].to_s == 'false'
|
||||
|
||||
sms_notify_admin
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def move_image_file!
|
||||
image_url = ApplicationController.helpers.disk_professional_auth_filename(user.id)
|
||||
temp_image_url = image_url + 'temp'
|
||||
|
||||
FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url)
|
||||
rescue RuntimeError => ex
|
||||
Util.logger_error(ex)
|
||||
raise Error, '申请失败'
|
||||
ensure
|
||||
File.delete(temp_image_url) if File.exist?(temp_image_url)
|
||||
end
|
||||
|
||||
def sms_notify_admin
|
||||
Educoder::Sms.notify_admin(send_type: 'apply_pro_certification')
|
||||
rescue => ex
|
||||
Util.logger_error(ex)
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
json.choose_answers do
|
||||
json.array! @challenge_chooses do |choose|
|
||||
json.position choose.position
|
||||
json.answer choose.answer.blank? ? choose.standard_answer : choose.answer
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
json.choose_answers do
|
||||
json.array! @challenge_chooses do |choose|
|
||||
json.position choose.position
|
||||
json.answer choose.answer.blank? ? choose.standard_answer : choose.answer
|
||||
end
|
||||
end
|
@ -0,0 +1,7 @@
|
||||
'zh-CN':
|
||||
activemodel:
|
||||
attributes:
|
||||
users/apply_authentication_form:
|
||||
name: 姓名
|
||||
id_number: 身份证号
|
||||
|
@ -0,0 +1,9 @@
|
||||
'zh-CN':
|
||||
activemodel:
|
||||
attributes:
|
||||
users/apply_professional_auth_form:
|
||||
school_id: 学校/单位
|
||||
department_id: 学院/部门
|
||||
identity: 职业
|
||||
extra: 职称/学号
|
||||
|
@ -0,0 +1,5 @@
|
||||
class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :challenges, :praises_count, :integer, :default => 0
|
||||
end
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
challenges = Challenge.where(nil).unscoped
|
||||
challenges.find_each do |c|
|
||||
praises_count = c.praise_treads.where(praise_or_tread: 1).count
|
||||
c.update_column(:praises_count, praises_count)
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddPraisesCountForDiscuess < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :discusses, :praises_count, :integer, :default => 0
|
||||
end
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
class ModifyPraisesCountForDiscuess < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
discusses = Discuss.includes(:praise_treads).unscoped
|
||||
discusses.find_each do |d|
|
||||
praises_count = d.praise_treads.liker.count
|
||||
d.update_column(:praises_count, praises_count)
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CourseAddStudentCreateWorksJob, type: :job do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CourseDeleteStudentDeleteWorksJob, type: :job do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in new issue