diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 99b988cb5..6848fffaa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 097da69db..7fb211e38 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -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 diff --git a/app/controllers/organizations/team_users_controller.rb b/app/controllers/organizations/team_users_controller.rb index 0c27e0701..43ed10708 100644 --- a/app/controllers/organizations/team_users_controller.rb +++ b/app/controllers/organizations/team_users_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/projects/applied_transfer_projects_controller.rb b/app/controllers/projects/applied_transfer_projects_controller.rb index e62033f21..dc47acb6b 100644 --- a/app/controllers/projects/applied_transfer_projects_controller.rb +++ b/app/controllers/projects/applied_transfer_projects_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f41a8a4ca..a0184a348 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index cbf0c66f7..1a7cdeecc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/services/projects/apply_transfer_service.rb b/app/services/projects/apply_transfer_service.rb index ca26f86c4..0d9d41e7d 100644 --- a/app/services/projects/apply_transfer_service.rb +++ b/app/services/projects/apply_transfer_service.rb @@ -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 diff --git a/app/views/users/_user_small.json.jbuilder b/app/views/users/_user_small.json.jbuilder index 54107b0e3..b8033ba77 100644 --- a/app/views/users/_user_small.json.jbuilder +++ b/app/views/users/_user_small.json.jbuilder @@ -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 diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 50296f524..067019ef9 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -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