forked from Gitlink/forgeplus
FIX 后台管理修改用户信息时同步git用户
This commit is contained in:
parent
1008f17849
commit
9f31dc02f4
|
@ -1,4 +1,6 @@
|
|||
class Admins::UsersController < Admins::BaseController
|
||||
before_action :finder_user, except: [:index]
|
||||
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
|
@ -8,12 +10,9 @@ class Admins::UsersController < Admins::BaseController
|
|||
end
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
|
||||
Admins::UpdateUserService.call(@user, update_params)
|
||||
flash[:success] = '保存成功'
|
||||
redirect_to edit_admins_user_path(@user)
|
||||
|
@ -26,43 +25,47 @@ class Admins::UsersController < Admins::BaseController
|
|||
end
|
||||
|
||||
def destroy
|
||||
User.find(params[:id]).destroy!
|
||||
@user.destroy!
|
||||
Gitea::User::DeleteService.call(@user.login)
|
||||
|
||||
render_delete_success
|
||||
end
|
||||
|
||||
def lock
|
||||
User.find(params[:id]).lock!
|
||||
@user.lock!
|
||||
|
||||
render_ok
|
||||
end
|
||||
|
||||
def unlock
|
||||
User.find(params[:id]).activate!
|
||||
@user.activate!
|
||||
|
||||
render_ok
|
||||
end
|
||||
|
||||
def reward_grade
|
||||
user = User.find(params[:user_id])
|
||||
return render_unprocessable_entity('金币数量必须大于0') if params[:grade].to_i <= 0
|
||||
|
||||
RewardGradeService.call(user, container_id: user.id, container_type: 'Feedback', score: params[:grade].to_i, not_unique: true)
|
||||
RewardGradeService.call(@user, container_id: @user.id, container_type: 'Feedback', score: params[:grade].to_i, not_unique: true)
|
||||
|
||||
render_ok(grade: user.grade)
|
||||
render_ok(grade: @user.grade)
|
||||
end
|
||||
|
||||
def reset_login_times
|
||||
User.find(params[:id]).reset_login_times!
|
||||
@user.reset_login_times!
|
||||
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def finder_user
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def update_params
|
||||
params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id is_shixun_marker
|
||||
mail phone location location_city school_id department_id admin business is_test
|
||||
password professional_certification authentication])
|
||||
password professional_certification authentication login])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -116,8 +116,6 @@ class User < Owner
|
|||
enumerize :platform, in: [:forge, :educoder, :trustie, :military], default: :forge, scope: :shallow
|
||||
|
||||
belongs_to :laboratory, optional: true
|
||||
has_many :composes, dependent: :destroy
|
||||
has_many :compose_users, dependent: :destroy
|
||||
has_one :user_extension, dependent: :destroy
|
||||
has_many :open_users, dependent: :destroy
|
||||
has_one :wechat_open_user, class_name: 'OpenUsers::Wechat'
|
||||
|
@ -434,6 +432,7 @@ class User < Owner
|
|||
|
||||
def activate!
|
||||
update_attribute(:status, STATUS_ACTIVE)
|
||||
prohibit_gitea_user_login!(false)
|
||||
end
|
||||
|
||||
def register!
|
||||
|
@ -442,6 +441,12 @@ class User < Owner
|
|||
|
||||
def lock!
|
||||
update_attribute(:status, STATUS_LOCKED)
|
||||
prohibit_gitea_user_login!
|
||||
end
|
||||
|
||||
def prohibit_gitea_user_login!(prohibit_login = true)
|
||||
Gitea::User::UpdateInteractor.call(self.login,
|
||||
{email: self.mail, prohibit_login: prohibit_login})
|
||||
end
|
||||
|
||||
# 课程用户身份
|
||||
|
|
|
@ -15,19 +15,13 @@ class Admins::UpdateUserService < ApplicationService
|
|||
user.firstname = ''
|
||||
user.password = params[:password] if params[:password].present?
|
||||
|
||||
if params[:identity].to_s == 'student'
|
||||
params[:technical_title] = nil
|
||||
else
|
||||
params[:student_id] = nil
|
||||
end
|
||||
user.user_extension.assign_attributes(user_extension_attributes)
|
||||
|
||||
old_login = user.login
|
||||
ActiveRecord::Base.transaction do
|
||||
user.save!
|
||||
user.user_extension.save!
|
||||
user.update!(is_shixun_marker: true) if user.is_certification_teacher
|
||||
|
||||
update_gitlab_password if params[:password].present?
|
||||
update_gitea_user(old_login)
|
||||
end
|
||||
|
||||
user
|
||||
|
@ -36,7 +30,7 @@ class Admins::UpdateUserService < ApplicationService
|
|||
private
|
||||
|
||||
def user_attributes
|
||||
params.slice(*%i[lastname nickname mail phone admin business is_test
|
||||
params.slice(*%i[lastname nickname mail phone admin business is_test login
|
||||
professional_certification authentication is_shixun_marker])
|
||||
end
|
||||
|
||||
|
@ -44,10 +38,29 @@ class Admins::UpdateUserService < ApplicationService
|
|||
params.slice(*%i[gender identity technical_title student_id location location_city school_id department_id])
|
||||
end
|
||||
|
||||
def update_gitlab_password
|
||||
return if user.gid.blank?
|
||||
# 同步修改gitlab密码
|
||||
Gitlab.client.edit_user(user.gid, password: params[:password])
|
||||
def gitea_user_params
|
||||
hash = {
|
||||
password: params[:password].to_s.presence,
|
||||
email: user.mail,
|
||||
login_name: params[:login].to_s.presence,
|
||||
admin: boolean_admin
|
||||
}.compact
|
||||
|
||||
hash.delete_if {|_,v| v.to_s.strip == ''}
|
||||
end
|
||||
|
||||
def boolean_admin
|
||||
admin = params[:admin].to_s.presence
|
||||
case admin
|
||||
when "0" then false
|
||||
when "1" then true
|
||||
end
|
||||
end
|
||||
|
||||
def update_gitea_user(old_login)
|
||||
return if user.gitea_uid.blank?
|
||||
|
||||
Gitea::User::UpdateInteractor.call(old_login, gitea_user_params)
|
||||
rescue Exception => ex
|
||||
Util.logger_error(ex)
|
||||
raise Error, '保存失败'
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
<div class="box user-edit-container">
|
||||
<div class="user-info mb-4 row">
|
||||
<%= link_to "/users/#{@user.login}", class: 'user-info-avatar col-md-1', target: '_blank', data: { toggle: 'tooltip', title: '个人中心' } do %>
|
||||
<img src="/images/<%= url_to_avatar(@user) %>" class="rounded-circle" width="80" height="80" />
|
||||
<%= link_to "/#{@user.login}", class: 'user-info-avatar col-md-1', target: '_blank', data: { toggle: 'tooltip', title: '个人中心' } do %>
|
||||
<img src="/<%= url_to_avatar(@user) %>" class="rounded-circle" width="80" height="80" />
|
||||
<% end %>
|
||||
<div class="d-flex flex-column justify-content-between col-md-3 user-info-content">
|
||||
<div class="user-info-name flex"><%= @user.real_name %> | <%= @user.id %> | <%= @user.login %></div>
|
||||
|
@ -50,6 +50,10 @@
|
|||
|
||||
<div><h6>基本信息</h6></div>
|
||||
<div class="form-group px-2">
|
||||
<div class="form-row">
|
||||
<%= f.input :login, label: '登录名', wrapper_html: { class: 'col-md-3' }, input_html: { readonly: true, class: 'col-md-11', value: @user.login } %>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<%= f.input :lastname, label: '姓名', wrapper_html: { class: 'col-md-3' }, input_html: { class: 'col-md-11', value: @user.only_real_name } %>
|
||||
</div>
|
||||
|
@ -109,7 +113,6 @@
|
|||
<div class="d-flex">
|
||||
<%= f.input :professional_certification, as: :boolean, label: '职业认证', checked_value: 1, unchecked_value: 0 %>
|
||||
<%= f.input :authentication, as: :boolean, label: '实名认证', wrapper_html: { class: 'ml-3' }, checked_value: 1, unchecked_value: 0 %>
|
||||
<%= f.input :is_shixun_marker, as: :boolean, label: '实训制作', wrapper_html: { class: 'ml-3' }, checked_value: 1, unchecked_value: 0 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<tr class="user-item-<%= user.id %>">
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td class="text-left">
|
||||
<%= link_to "/users/#{user.login}", target: '_blank' do %>
|
||||
<%= link_to "/#{user.login}", target: '_blank' do %>
|
||||
<%= overflow_hidden_span user.real_name, width: 100 %>
|
||||
<% end %>
|
||||
</td>
|
||||
|
@ -44,7 +44,6 @@
|
|||
<div class="d-inline">
|
||||
<%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
|
||||
<div class="dropdown-menu more-action-dropdown">
|
||||
<%= javascript_void_link('奖励', class: 'dropdown-item reward-grade-action', data: { toggle: 'modal', target: '.admin-users-reward-grade-modal', id: user.id }) %>
|
||||
|
||||
<%= javascript_void_link '恢复禁密账号', class: 'dropdown-item reset-login-times-action', data: { id: user.id } %>
|
||||
|
||||
|
|
Loading…
Reference in New Issue