新增:后台管理更改用户信息邮箱需同步至gitea

This commit is contained in:
yystopf 2022-12-09 11:45:31 +08:00
parent dfa0f1161d
commit bc2992cc3d
2 changed files with 15 additions and 4 deletions

View File

@ -15,13 +15,14 @@ class Admins::UpdateUserService < ApplicationService
user.firstname = ''
user.password = params[:password] if params[:password].present?
user.user_extension.assign_attributes(user_extension_attributes)
user.user_extension.assign_attributes(user_extension_attributes) if user.user_extension.present?
old_login = user.login
ActiveRecord::Base.transaction do
user.save!
user.user_extension.save!
user.user_extension.save! if user.user_extension.present?
update_gitea_user(old_login)
update_gitea_user_email(user.previous_changes[:mail])
end
user
@ -65,4 +66,14 @@ class Admins::UpdateUserService < ApplicationService
Util.logger_error(ex)
raise Error, '保存失败'
end
def update_gitea_user_email(change_options)
return if change_options.blank?
return if user.gitea_uid.blank? || user.gitea_token.blank?
$gitea_client.delete_user_emails({body: {emails: [change_options[0]]}.to_json, query: {access_token: user.gitea_token}})
$gitea_client.post_user_emails({body: {emails: [change_options[1]]}.to_json, query: {access_token: user.gitea_token}})
rescue Exception => ex
Util.logger_error(ex)
raise Error, '保存失败'
end
end

View File

@ -68,12 +68,12 @@
<%= f.label :identity, label: '职业' %>
<%= select_tag('user[identity]', [], class: 'form-control identity-select optional', 'data-value': @user.user_extension&.identity, 'data-first-title': '请选择') %>
</div>
<div class="form-group technical-title-select-wrapper optional col-md-1" style="<%= @user.user_extension.student? ? 'display:none;' : '' %>">
<div class="form-group technical-title-select-wrapper optional col-md-1" style="<%= @user&.user_extension&.student? ? 'display:none;' : '' %>">
<%= f.label :technical_title, label: '职称' %>
<%= select_tag('user[technical_title]', [], class: 'form-control technical-title-select optional', 'data-value': @user.technical_title) %>
</div>
<%= f.input :student_id, as: :tel, label: '学号', wrapper_html: { class: 'col-md-2', style: @user.user_extension.student? ? '' : 'display:none;' }, input_html: { class: 'student-id-input' } %>
<%= f.input :student_id, as: :tel, label: '学号', wrapper_html: { class: 'col-md-2', style: @user&.user_extension&.student? ? '' : 'display:none;' }, input_html: { class: 'student-id-input' } %>
</div>
<div class="form-row">