mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-20 11:43:40 +09:00
feat: manage bot accounts from the admin UI, API and CLI (#38966)
Adds first-class bot accounts (`UserTypeBot`): local, password-less
users for automation that authenticate only with access tokens.
1. Admin UI: create bots, filter users by type, manage a bot's access
tokens, convert between user and bot
2. API: `POST /admin/users/{username}/convert-type`, and user objects
gain a GitHub-compatible `type` (`User`, `Organization`, `Bot`)
3. CLI: `gitea admin user change-type`, `--user-type` accepts `User` or
`Bot` case-insensitively
4. Converting keeps the password, 2FA, OAuth2 grants and access tokens,
and since sign-in rejects bots, converting back restores the account.
Only local, non-admin accounts can be converted, and conversions are
audited
5. Session, reverse proxy, SSPI, external source and password reset
sign-in reject non-individual users, so a bot never gets an interactive
session
6. Bots receive no notifications or emails
Co-authored-by: Nicolas <bircni@icloud.com>
Co-authored-by: joestump <joe@joestump.net>
Co-authored-by: Joe Stump <joe@stu.mp>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
co-authored by
Nicolas
joestump
Joe Stump
silverwind
Lunny Xiao
parent
db7dbd5a6b
commit
3bec08f998
@@ -55,31 +55,34 @@ function initAdminRunnerBulk(toolbar: HTMLElement) {
|
||||
|
||||
function initAdminUser() {
|
||||
const pageContent = document.querySelector('.page-content.admin.edit.user, .page-content.admin.new.user');
|
||||
if (!pageContent) return;
|
||||
const elLoginType = document.querySelector<HTMLInputElement>('#login_type');
|
||||
if (!pageContent || !elLoginType) return;
|
||||
const isNew = pageContent.classList.contains('new');
|
||||
const elUserType = document.querySelector<HTMLInputElement>('#user_type');
|
||||
const elUserName = document.querySelector<HTMLInputElement>('#user_name')!;
|
||||
const elLoginName = document.querySelector<HTMLInputElement>('#login_name')!;
|
||||
const elPassword = document.querySelector<HTMLInputElement>('#password')!;
|
||||
|
||||
document.querySelector<HTMLInputElement>('#login_type')?.addEventListener('change', function () {
|
||||
if (this.value?.startsWith('0')) {
|
||||
document.querySelector<HTMLInputElement>('#user_name')?.removeAttribute('disabled');
|
||||
document.querySelector<HTMLInputElement>('#login_name')?.removeAttribute('required');
|
||||
hideElem('.non-local');
|
||||
showElem('.local');
|
||||
document.querySelector<HTMLInputElement>('#user_name')?.focus();
|
||||
|
||||
if (this.getAttribute('data-password') === 'required') {
|
||||
document.querySelector('#password')?.setAttribute('required', 'required');
|
||||
}
|
||||
} else {
|
||||
if (document.querySelector<HTMLDivElement>('.admin.edit.user')) {
|
||||
document.querySelector<HTMLInputElement>('#user_name')?.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
document.querySelector<HTMLInputElement>('#login_name')?.setAttribute('required', 'required');
|
||||
showElem('.non-local');
|
||||
hideElem('.local');
|
||||
document.querySelector<HTMLInputElement>('#login_name')?.focus();
|
||||
|
||||
document.querySelector<HTMLInputElement>('#password')?.removeAttribute('required');
|
||||
const syncFields = (focusField: boolean) => {
|
||||
const isBot = elUserType?.value === 'Bot';
|
||||
const isLocal = !isBot && elLoginType.value.startsWith('0'); // login type 0 is a local account without auth source
|
||||
toggleElem('.js-non-bot', !isBot);
|
||||
if (!isBot) {
|
||||
toggleElem('.js-local', isLocal);
|
||||
toggleElem('.js-non-local', !isLocal);
|
||||
}
|
||||
});
|
||||
elLoginName.toggleAttribute('required', !isBot && !isLocal);
|
||||
if (isNew) {
|
||||
elPassword.toggleAttribute('required', isLocal);
|
||||
} else {
|
||||
elUserName.toggleAttribute('disabled', !isBot && !isLocal);
|
||||
}
|
||||
if (focusField) (isBot || isLocal ? elUserName : elLoginName).focus();
|
||||
};
|
||||
|
||||
elUserType?.addEventListener('change', () => syncFields(true));
|
||||
elLoginType.addEventListener('change', () => syncFields(true));
|
||||
if (isNew) syncFields(false);
|
||||
}
|
||||
|
||||
function initAdminAuthentication() {
|
||||
|
||||
@@ -22,7 +22,7 @@ export function initAdminUserListSearchForm(): void {
|
||||
});
|
||||
}
|
||||
|
||||
const resetButtons = form.querySelectorAll<HTMLAnchorElement>('.j-reset-status-filter');
|
||||
const resetButtons = form.querySelectorAll<HTMLAnchorElement>('.js-reset-status-filter');
|
||||
for (const button of resetButtons) {
|
||||
button.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user