Merge pull request '新增重置用户gitea token' (#34) from KingChan/forgeplus:chenjing into feature_gitea_upgrade

This commit is contained in:
yystopf 2023-03-20 16:15:09 +08:00
commit 565dc5f837
5 changed files with 35 additions and 3 deletions

View File

@ -94,6 +94,20 @@ $(document).on('turbolinks:load', function(){
} }
}); });
}); });
// reset user login times
$('.users-list-container').on('click', '.fresh-gitea-token-action', function(){
var $action = $(this);
var userId = $action.data('id');
$.ajax({
url: '/admins/users/' + userId + '/fresh_gitea_token',
method: 'POST',
dataType: 'json',
success: function() {
showSuccessNotify();
}
});
});
// ***************** reward grade modal ***************** // ***************** reward grade modal *****************
var $rewardGradeModal = $('.admin-users-reward-grade-modal'); var $rewardGradeModal = $('.admin-users-reward-grade-modal');

View File

@ -57,6 +57,12 @@ class Admins::UsersController < Admins::BaseController
render_ok render_ok
end end
def fresh_gitea_token
@user.fresh_gitea_token
render_ok
end
private private
def finder_user def finder_user

View File

@ -449,6 +449,19 @@ class User < Owner
self.status = STATUS_EDIT_INFO self.status = STATUS_EDIT_INFO
end end
def fresh_gitea_token
result = $gitea_client.get_users_tokens_by_username(self.login, {query: {sudo: self.login}})
if result[:data].present?
result[:data].map{ |e|
$gitea_client.delete_users_tokens_by_username_token(self.login, e["name"], {query: {sudo: self.login} })
}
end
new_result = $gitea_client.post_users_tokens_by_username(self.login, { query: {sudo: self.login}, body:{ name: self.login} })
if new_result["sha1"].present?
update(gitea_token: new_result["sha1"])
end
end
def activate! def activate!
update_attribute(:status, STATUS_ACTIVE) update_attribute(:status, STATUS_ACTIVE)
prohibit_gitea_user_login!(false) prohibit_gitea_user_login!(false)

View File

@ -5,7 +5,6 @@
<th width="8%" class="text-left">昵称</th> <th width="8%" class="text-left">昵称</th>
<th width="13%">邮件地址</th> <th width="13%">邮件地址</th>
<th width="10%">手机号码</th> <th width="10%">手机号码</th>
<th width="7%">角色</th>
<th width="10%"><%= sort_tag('创建于', name: 'created_on', path: admins_users_path) %></th> <th width="10%"><%= sort_tag('创建于', name: 'created_on', path: admins_users_path) %></th>
<th width="10%"><%= sort_tag('最后登录', name: 'last_login_on', path: admins_users_path) %></th> <th width="10%"><%= sort_tag('最后登录', name: 'last_login_on', path: admins_users_path) %></th>
<th width="12%">项目数</th> <th width="12%">项目数</th>
@ -43,9 +42,8 @@
<div class="d-inline"> <div class="d-inline">
<%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %> <%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
<div class="dropdown-menu more-action-dropdown"> <div class="dropdown-menu more-action-dropdown">
<%= javascript_void_link '恢复禁密账号', class: 'dropdown-item reset-login-times-action', data: { id: user.id } %> <%= javascript_void_link '恢复禁密账号', class: 'dropdown-item reset-login-times-action', data: { id: user.id } %>
<%= javascript_void_link '重置Gitea Token', class: 'dropdown-item fresh-gitea-token-action', data: { id: user.id } %>
<%= delete_link '删除', admins_user_path(user, element: ".user-item-#{user.id}"), class: 'dropdown-item delete-user-action' %> <%= delete_link '删除', admins_user_path(user, element: ".user-item-#{user.id}"), class: 'dropdown-item delete-user-action' %>
</div> </div>
</div> </div>

View File

@ -824,6 +824,7 @@ Rails.application.routes.draw do
post :unlock post :unlock
post :active post :active
post :reset_login_times post :reset_login_times
post :fresh_gitea_token
end end
end end
resource :import_disciplines, only: [:create] resource :import_disciplines, only: [:create]