fix: update user profile completed rule

This commit is contained in:
yystopf 2021-09-02 11:48:53 +08:00
parent c52458a7e3
commit a422aa638d
9 changed files with 29 additions and 2 deletions

View File

@ -250,6 +250,10 @@ class ApplicationController < ActionController::Base
tip_exception(411, "请完善资料后再操作") unless User.current.profile_completed
end
def require_user_profile_completed(user)
tip_exception(412, "请用户完善资料后再操作") unless user.profile_completed
end
# 异常提醒
def tip_exception(status = -1, message)
raise Educoder::TipException.new(status, message)

View File

@ -2,6 +2,7 @@ class MembersController < ApplicationController
before_action :require_login
before_action :load_project
before_action :find_user_with_id, only: %i[create remove change_role]
before_action :check_user_profile_completed, only: [:create]
before_action :operate!, except: %i[index]
before_action :check_member_exists!, only: %i[create]
before_action :check_member_not_exists!, only: %i[remove change_role]
@ -61,4 +62,8 @@ class MembersController < ApplicationController
def check_member_not_exists!
return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists?
end
def check_user_profile_completed
require_user_profile_completed(@user)
end
end

View File

@ -1,6 +1,7 @@
class Organizations::TeamUsersController < Organizations::BaseController
before_action :load_organization, :load_team
before_action :load_operate_user, only: [:create, :destroy]
before_action :check_user_profile_completed, only: [:create]
before_action :load_team_user, only: [:destroy]
before_action :check_user_can_edit_org, only: [:create, :destroy]
@ -83,4 +84,8 @@ class Organizations::TeamUsersController < Organizations::BaseController
tip_exception("组织团队成员不存在") if @team_user.nil?
end
def check_user_profile_completed
require_user_profile_completed(@operate_user)
end
end

View File

@ -1,5 +1,6 @@
class Projects::AppliedTransferProjectsController < Projects::BaseController
before_action :check_auth
before_action :check_user_profile_completed
def organizations
@organizations = Organization.includes(:organization_extension).joins(team_users: :team).where(team_users: {user_id: current_user.id}, teams: {authorize: %w(admin owner)})
@ -23,4 +24,10 @@ class Projects::AppliedTransferProjectsController < Projects::BaseController
def check_auth
return render_forbidden unless current_user.admin? ||@project.owner?(current_user)
end
def check_user_profile_completed
@owner = Owner.find_by(login: params[:owner_name])
return if @owner.is_a?(Organization)
require_user_profile_completed(@owner)
end
end

View File

@ -78,7 +78,6 @@ class UsersController < ApplicationController
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
@user.attributes = user_params.except(:image)
@user.profile_completed = true if @user.nickname.present? && @user.gender.present? && @user.mail.present? && @user.custom_department.present?
unless @user.save
render_error(@user.errors.full_messages.join(", "))
end

View File

@ -186,7 +186,7 @@ class User < Owner
:show_email, :show_location, :show_department,
:technical_title, :province, :city, :custom_department, to: :user_extension, allow_nil: true
before_save :update_hashed_password, :set_lastname
before_save :update_hashed_password, :set_lastname, :set_profile_completed
after_create do
SyncTrustieJob.perform_later("user", 1) if allow_sync_to_trustie?
end
@ -783,6 +783,10 @@ class User < Owner
def set_lastname
self.lastname = self.nickname if changes[:nickname].present?
end
def set_profile_completed
self.profile_completed = self.nickname.present? && self.gender.present? && self.mail.present? && self.custom_department.present?
end
end

View File

@ -24,6 +24,7 @@ class Projects::ApplyTransferService < ApplicationService
raise Error, '仓库标识不正确' if @project.identifier != params[:identifier]
raise Error, '该仓库正在迁移' if @project.is_transfering
raise Error, '新拥有者不存在' unless @owner.present?
raise Error, '新拥有者资料不完善' unless @owner.profile_completed
raise Error, '新拥有者已经存在同名仓库!' if Project.where(user_id: @owner.id, identifier: params[:identifier]).present?
raise Error, '未拥有转移权限' unless is_permit_owner
end

View File

@ -4,5 +4,6 @@ json.array! users do |user|
json.login user.login
json.user_id user.id
json.image_url url_to_avatar(user)
json.profile_completed user.profile_completed
end

View File

@ -1,5 +1,6 @@
json.username @user.full_name
json.real_name @user.real_name
json.nickname @user.nickname
json.gender @user.gender
json.login @user.login
json.user_id @user.id