mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-11-20 00:01:06 +00:00
feat(postgresql): add user and database authorization management (#14460)
* feat(postgresql): add user and database authorization management * fix(postgresql): reuse existing roles during app recovery
This commit is contained in:
@@ -297,6 +297,26 @@ export namespace Database {
|
||||
type: string;
|
||||
database: string;
|
||||
}
|
||||
export interface PostgresqlUser {
|
||||
username: string;
|
||||
password: string;
|
||||
description: string;
|
||||
superUser: boolean;
|
||||
protected: boolean;
|
||||
databases: string[];
|
||||
}
|
||||
export interface PostgresqlUserCreate {
|
||||
database: string;
|
||||
username: string;
|
||||
password: string;
|
||||
superUser: boolean;
|
||||
description: string;
|
||||
}
|
||||
export interface PostgresqlUserGrant {
|
||||
database: string;
|
||||
name: string;
|
||||
username: string;
|
||||
}
|
||||
export interface PostgresqlDBInfo {
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
@@ -316,6 +336,7 @@ export namespace Database {
|
||||
file: string;
|
||||
}
|
||||
export interface PostgresqlDBCreate {
|
||||
existingUser?: boolean;
|
||||
name: string;
|
||||
from: string;
|
||||
database: string;
|
||||
|
||||
@@ -258,3 +258,34 @@ export const deleteCheckDatabase = (id: number) => {
|
||||
export const deleteDatabase = (params: Database.DatabaseDelete) => {
|
||||
return http.post(`/databases/db/del`, params);
|
||||
};
|
||||
|
||||
export const searchPostgresqlUsers = (database: string) => {
|
||||
return http.post<Database.PostgresqlUser[]>('/databases/pg/users/search', { database });
|
||||
};
|
||||
export const createPostgresqlUser = (params: Database.PostgresqlUserCreate) => {
|
||||
const request = { ...params };
|
||||
encodeBase64Fields(request, ['password']);
|
||||
return http.post('/databases/pg/users', request);
|
||||
};
|
||||
export const updatePostgresqlUser = (params: Omit<Database.PostgresqlUserCreate, 'password'>) => {
|
||||
return http.post('/databases/pg/users/update', params);
|
||||
};
|
||||
export const changePostgresqlUserPassword = (params: { database: string; username: string; password: string }) => {
|
||||
const request = { ...params };
|
||||
encodeBase64Fields(request, ['password']);
|
||||
return http.post('/databases/pg/users/password', request);
|
||||
};
|
||||
export const savePostgresqlUserPassword = (params: { database: string; username: string; password: string }) => {
|
||||
const request = { ...params };
|
||||
encodeBase64Fields(request, ['password']);
|
||||
return http.post('/databases/pg/users/password/save', request);
|
||||
};
|
||||
export const deletePostgresqlUser = (params: { database: string; username: string }) => {
|
||||
return http.post('/databases/pg/users/del', params);
|
||||
};
|
||||
export const grantPostgresqlUser = (params: Database.PostgresqlUserGrant) => {
|
||||
return http.post('/databases/pg/grants', params);
|
||||
};
|
||||
export const revokePostgresqlUser = (params: Database.PostgresqlUserGrant) => {
|
||||
return http.post('/databases/pg/grants/del', params);
|
||||
};
|
||||
|
||||
@@ -621,6 +621,7 @@ const message = {
|
||||
'This port is the exposed port of the container. You need to save the modification separately and restart the container!',
|
||||
loadFromRemote: 'Sync from server',
|
||||
userBind: 'Bind user',
|
||||
connectionUser: 'Connection user',
|
||||
userAuthorization: 'User authorization',
|
||||
noUserAuthorization: 'Do not authorize',
|
||||
authorizedDatabaseCount: '{0} authorized database(s)',
|
||||
@@ -631,10 +632,13 @@ const message = {
|
||||
revokeAuthorization: 'Revoke authorization',
|
||||
revokeAuthorizationHelper: "Revoke user {0}'s access to database {1}?",
|
||||
supplementPassword: 'Add password',
|
||||
supplementPasswordHelper: 'This only saves the existing password to 1Panel and does not change it in MySQL.',
|
||||
supplementPasswordHelper:
|
||||
'This only saves the existing password to 1Panel and does not change the database user password.',
|
||||
noUserBind: 'No binding',
|
||||
pgBindHelper:
|
||||
'This operation is used to create a new user and bind it to the target database. Currently, selecting users already existing in the database is not supported.',
|
||||
pgAuthorizationHelper:
|
||||
'Superusers can access all databases in this instance without binding. Ordinary users receive database-level grants only, without table permissions.',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'Revoking authorization does not delete the user. Access through PUBLIC or other roles may remain.',
|
||||
pgSuperUser: 'Superuser',
|
||||
loadFromRemoteHelper: 'Sync databases, users, and authorizations from the server to 1Panel. Continue?',
|
||||
passwordHelper: 'Not available, click to update',
|
||||
|
||||
@@ -623,6 +623,7 @@ const message = {
|
||||
loadFromRemote: 'Sincronizar desde el servidor',
|
||||
userBind: 'Vincular usuario',
|
||||
noUserBind: 'Sin vinculación',
|
||||
connectionUser: 'Usuario de conexión',
|
||||
userAuthorization: 'Autorización de usuario',
|
||||
noUserAuthorization: 'No autorizar',
|
||||
authorizedDatabaseCount: '{0} base(s) de datos autorizada(s)',
|
||||
@@ -633,9 +634,12 @@ const message = {
|
||||
revokeAuthorization: 'Revocar autorización',
|
||||
revokeAuthorizationHelper: '¿Revocar el acceso del usuario {0} a la base de datos {1}?',
|
||||
supplementPassword: 'Añadir contraseña',
|
||||
supplementPasswordHelper: 'Solo guarda la contraseña existente en 1Panel; no cambia la contraseña en MySQL.',
|
||||
pgBindHelper:
|
||||
'Esta operación se utiliza para crear un nuevo usuario y vincularlo a la base de datos destino. Actualmente no se admite seleccionar usuarios ya existentes en la base de datos.',
|
||||
supplementPasswordHelper:
|
||||
'Solo guarda la contraseña existente en 1Panel, sin cambiar la contraseña del usuario de la base de datos.',
|
||||
pgAuthorizationHelper:
|
||||
'Los superusuarios acceden a todas las bases de datos de esta instancia sin vinculación. Para usuarios normales solo se gestionan permisos de base de datos, no de tablas.',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'Revocar la autorización no elimina al usuario. Puede conservar el acceso mediante PUBLIC u otros roles.',
|
||||
pgSuperUser: 'Superusuario',
|
||||
loadFromRemoteHelper:
|
||||
'Esto sincronizará las bases de datos, los usuarios y las autorizaciones del servidor con 1Panel. ¿Desea continuar?',
|
||||
|
||||
@@ -617,6 +617,7 @@ const message = {
|
||||
loadFromRemote: 'همگامسازی از سرور',
|
||||
userBind: 'اتصال کاربر',
|
||||
noUserBind: 'بدون اتصال',
|
||||
connectionUser: 'کاربر اتصال',
|
||||
userAuthorization: 'مجوز کاربر',
|
||||
noUserAuthorization: 'بدون اعطای مجوز',
|
||||
authorizedDatabaseCount: '{0} پایگاه داده مجاز',
|
||||
@@ -627,9 +628,12 @@ const message = {
|
||||
revokeAuthorization: 'لغو مجوز',
|
||||
revokeAuthorizationHelper: 'دسترسی کاربر {0} به پایگاه داده {1} لغو شود؟',
|
||||
supplementPassword: 'افزودن گذرواژه',
|
||||
supplementPasswordHelper: 'فقط گذرواژه فعلی را در 1Panel ذخیره میکند و گذرواژه MySQL را تغییر نمیدهد.',
|
||||
pgBindHelper:
|
||||
'این عملیات برای ایجاد کاربر جدید و اتصال آن به پایگاه داده هدف استفاده میشود. در حال حاضر انتخاب کاربرانی که از قبل در پایگاه داده وجود دارند پشتیبانی نمیشود.',
|
||||
supplementPasswordHelper:
|
||||
'فقط گذرواژه موجود را در 1Panel ذخیره میکند و گذرواژه کاربر پایگاه داده را تغییر نمیدهد.',
|
||||
pgAuthorizationHelper:
|
||||
'ابرکاربران بدون پیوند به همه پایگاههای داده این نمونه دسترسی دارند. برای کاربران عادی فقط مجوزهای سطح پایگاه داده مدیریت میشود، نه مجوز جدولها.',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'لغو مجوز کاربر را حذف نمیکند. دسترسی از طریق PUBLIC یا نقشهای دیگر ممکن است باقی بماند.',
|
||||
pgSuperUser: 'کاربر فوقالعاده',
|
||||
loadFromRemoteHelper: 'پایگاههای داده، کاربران و مجوزها از سرور با 1Panel همگام شوند؟',
|
||||
passwordHelper: 'در دسترس نیست، برای بهروزرسانی کلیک کنید',
|
||||
|
||||
@@ -622,6 +622,7 @@ const message = {
|
||||
loadFromRemote: '同期',
|
||||
userBind: 'バインドユーザー',
|
||||
noUserBind: '未バインド',
|
||||
connectionUser: '接続ユーザー',
|
||||
userAuthorization: 'ユーザー権限',
|
||||
noUserAuthorization: '権限を付与しない',
|
||||
authorizedDatabaseCount: '{0} データベースに権限付与済み',
|
||||
@@ -632,9 +633,12 @@ const message = {
|
||||
revokeAuthorization: '権限を取り消す',
|
||||
revokeAuthorizationHelper: 'ユーザー {0} のデータベース {1} へのアクセス権を取り消しますか?',
|
||||
supplementPassword: 'パスワードを登録',
|
||||
supplementPasswordHelper: '既存のパスワードを 1Panel に保存するだけで、MySQL のパスワードは変更しません。',
|
||||
pgBindHelper:
|
||||
'この操作は、新しいユーザーを作成し、ターゲットデータベースにバインドするために使用されます。現在、データベースに既存のユーザーを選択することはサポートされていません。',
|
||||
supplementPasswordHelper:
|
||||
'既存のパスワードを 1Panel に保存するだけで、データベースユーザーのパスワードは変更しません。',
|
||||
pgAuthorizationHelper:
|
||||
'スーパーユーザーは紐付けなしでこのインスタンスの全データベースにアクセスできます。一般ユーザーはデータベース単位の権限のみ管理し、テーブル権限は含みません。',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'権限を取り消してもユーザーは削除されません。PUBLIC や他のロール経由のアクセスが残る場合があります。',
|
||||
pgSuperUser: 'スーパーユーザー',
|
||||
loadFromRemoteHelper: 'サーバー上のデータベース、ユーザー、権限情報を 1Panel に同期します。続行しますか?',
|
||||
passwordHelper: '取得できません、クリックして修正',
|
||||
|
||||
@@ -615,6 +615,7 @@ const message = {
|
||||
loadFromRemote: '동기화',
|
||||
userBind: '사용자 바인딩',
|
||||
noUserBind: '바인딩 없음',
|
||||
connectionUser: '연결 사용자',
|
||||
userAuthorization: '사용자 권한',
|
||||
noUserAuthorization: '권한 부여 안 함',
|
||||
authorizedDatabaseCount: '데이터베이스 {0}개 권한 보유',
|
||||
@@ -625,9 +626,12 @@ const message = {
|
||||
revokeAuthorization: '권한 취소',
|
||||
revokeAuthorizationHelper: '사용자 {0}의 데이터베이스 {1} 접근 권한을 취소하시겠습니까?',
|
||||
supplementPassword: '비밀번호 추가',
|
||||
supplementPasswordHelper: '기존 비밀번호를 1Panel에만 저장하며 MySQL 비밀번호는 변경하지 않습니다.',
|
||||
pgBindHelper:
|
||||
'이 작업은 새 사용자를 생성하여 대상 데이터베이스에 바인딩하는 데 사용됩니다. 현재 데이터베이스에 이미 존재하는 사용자 선택은 지원되지 않습니다.',
|
||||
supplementPasswordHelper:
|
||||
'기존 비밀번호를 1Panel에 저장하기만 하며 데이터베이스 사용자 비밀번호는 변경하지 않습니다.',
|
||||
pgAuthorizationHelper:
|
||||
'슈퍼유저는 연결 설정 없이 이 인스턴스의 모든 데이터베이스에 접근합니다. 일반 사용자는 데이터베이스 권한만 관리하며 테이블 권한은 포함하지 않습니다.',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'권한을 철회해도 사용자는 삭제되지 않습니다. PUBLIC 또는 다른 역할을 통한 접근 권한은 남을 수 있습니다.',
|
||||
pgSuperUser: '슈퍼 사용자',
|
||||
loadFromRemoteHelper: '서버의 데이터베이스, 사용자 및 권한 정보를 1Panel로 동기화합니다. 계속하시겠습니까?',
|
||||
passwordHelper: '확인 불가, 수정하려면 클릭',
|
||||
|
||||
@@ -613,6 +613,7 @@ const message = {
|
||||
portHelper: 'ພອດນີ້ແມ່ນພອດທີ່ເປີດອອກຂອງຄອນເທນເນີ. ທ່ານຕ້ອງບັນທຶກການແກ້ໄຂແຍກຕ່າງຫາກ ແລະ ຣີສະຕາດຄອນເທນເນີ!',
|
||||
loadFromRemote: 'ຊິ້ງຄ໌ຈາກເຊີເວີ',
|
||||
userBind: 'ຜູກມັດຜູ້ໃຊ້',
|
||||
connectionUser: 'ຜູ້ໃຊ້ເຊື່ອມຕໍ່',
|
||||
userAuthorization: 'ການໃຫ້ສິດຜູ້ໃຊ້',
|
||||
noUserAuthorization: 'ບໍ່ໃຫ້ສິດ',
|
||||
authorizedDatabaseCount: 'ໄດ້ຮັບສິດ {0} ຖານຂໍ້ມູນ',
|
||||
@@ -623,10 +624,11 @@ const message = {
|
||||
revokeAuthorization: 'ຖອນສິດ',
|
||||
revokeAuthorizationHelper: 'ຖອນສິດຜູ້ໃຊ້ {0} ໃນຖານຂໍ້ມູນ {1} ຫຼືບໍ່?',
|
||||
supplementPassword: 'ເພີ່ມລະຫັດຜ່ານ',
|
||||
supplementPasswordHelper: 'ບັນທຶກລະຫັດຜ່ານປັດຈຸບັນໄວ້ໃນ 1Panel ເທົ່ານັ້ນ ແລະບໍ່ປ່ຽນລະຫັດ MySQL.',
|
||||
supplementPasswordHelper: 'ບັນທຶກລະຫັດຜ່ານທີ່ມີຢູ່ໃນ 1Panel ເທົ່ານັ້ນ ໂດຍບໍ່ປ່ຽນລະຫັດຜ່ານຜູ້ໃຊ້ຖານຂໍ້ມູນ.',
|
||||
noUserBind: 'ບໍ່ມີການຜູກມັດ',
|
||||
pgBindHelper:
|
||||
'ການດຳເນີນການນີ້ໃຊ້ເພື່ອສ້າງຜູ້ໃຊ້ໃໝ່ ແລະ ຜູກມັດກັບຖານຂໍ້ມູນເປົ້າໝາຍ. ໃນປັດຈຸບັນ, ຍັງບໍ່ຮອງຮັບການເລືອກຜູ້ໃຊ້ທີ່ມີຢູ່ແລ້ວໃນຖານຂໍ້ມູນ.',
|
||||
pgAuthorizationHelper:
|
||||
'ຜູ້ໃຊ້ຂັ້ນສູງເຂົ້າເຖິງທຸກຖານຂໍ້ມູນໃນອິນສະແຕນນີ້ໄດ້ໂດຍບໍ່ຕ້ອງຜູກ. ຜູ້ໃຊ້ທົ່ວໄປຈັດການສະເພາະສິດລະດັບຖານຂໍ້ມູນ ບໍ່ລວມສິດຕາຕະລາງ.',
|
||||
pgRevokeAuthorizationHelper: 'ການຍົກເລີກສິດບໍ່ລຶບຜູ້ໃຊ້. ການເຂົ້າເຖິງຜ່ານ PUBLIC ຫຼືບົດບາດອື່ນອາດຍັງຄົງຢູ່.',
|
||||
pgSuperUser: 'ຊຸບເປີຢູເຊີ',
|
||||
loadFromRemoteHelper: 'ຊິ້ງຄ໌ຖານຂໍ້ມູນ, ຜູ້ໃຊ້ ແລະສິດຈາກເຊີເວີມາຍັງ 1Panel ຫຼືບໍ່?',
|
||||
passwordHelper: 'ບໍ່ສາມາດໃຊ້ໄດ້, ຄລິກເພື່ອອັບເດດ',
|
||||
|
||||
@@ -628,6 +628,7 @@ const message = {
|
||||
'Port ini adalah port yang didedahkan oleh kontena. Anda perlu menyimpan pengubahsuaian secara berasingan dan memulakan semula kontena!',
|
||||
loadFromRemote: 'Selaras',
|
||||
userBind: 'Kaitkan pengguna',
|
||||
connectionUser: 'Pengguna sambungan',
|
||||
userAuthorization: 'Kebenaran pengguna',
|
||||
noUserAuthorization: 'Jangan beri kebenaran',
|
||||
authorizedDatabaseCount: '{0} pangkalan data dibenarkan',
|
||||
@@ -638,10 +639,13 @@ const message = {
|
||||
revokeAuthorization: 'Tarik balik kebenaran',
|
||||
revokeAuthorizationHelper: 'Tarik balik akses pengguna {0} kepada pangkalan data {1}?',
|
||||
supplementPassword: 'Tambah kata laluan',
|
||||
supplementPasswordHelper: 'Hanya menyimpan kata laluan sedia ada ke 1Panel dan tidak mengubahnya dalam MySQL.',
|
||||
supplementPasswordHelper:
|
||||
'Hanya menyimpan kata laluan sedia ada dalam 1Panel tanpa menukar kata laluan pengguna pangkalan data.',
|
||||
noUserBind: 'Tiada kaitan',
|
||||
pgBindHelper:
|
||||
'Operasi ini digunakan untuk mencipta pengguna baharu dan mengaitkannya dengan pangkalan data sasaran. Pada masa ini, memilih pengguna yang sudah wujud dalam pangkalan data tidak disokong.',
|
||||
pgAuthorizationHelper:
|
||||
'Pengguna super boleh mengakses semua pangkalan data dalam tika ini tanpa pautan. Pengguna biasa hanya mengurus kebenaran pangkalan data, bukan kebenaran jadual.',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'Pembatalan kebenaran tidak memadamkan pengguna. Akses melalui PUBLIC atau peranan lain mungkin kekal.',
|
||||
pgSuperUser: 'Pengguna Super',
|
||||
loadFromRemoteHelper:
|
||||
'Ini akan menyelaraskan pangkalan data, pengguna dan kebenaran dari pelayan ke 1Panel. Teruskan?',
|
||||
|
||||
@@ -621,6 +621,7 @@ const message = {
|
||||
'Esta porta é a porta exposta do container. Você precisa salvar a modificação separadamente e reiniciar o container!',
|
||||
loadFromRemote: 'Sincronizar',
|
||||
userBind: 'Vincular usuário',
|
||||
connectionUser: 'Usuário de conexão',
|
||||
userAuthorization: 'Autorização de usuário',
|
||||
noUserAuthorization: 'Não autorizar',
|
||||
authorizedDatabaseCount: '{0} banco(s) de dados autorizado(s)',
|
||||
@@ -631,10 +632,13 @@ const message = {
|
||||
revokeAuthorization: 'Revogar autorização',
|
||||
revokeAuthorizationHelper: 'Revogar o acesso do usuário {0} ao banco de dados {1}?',
|
||||
supplementPassword: 'Adicionar senha',
|
||||
supplementPasswordHelper: 'Apenas salva a senha existente no 1Panel; não altera a senha no MySQL.',
|
||||
supplementPasswordHelper:
|
||||
'Salva apenas a senha existente no 1Panel, sem alterar a senha do usuário do banco de dados.',
|
||||
noUserBind: 'Sem vínculo',
|
||||
pgBindHelper:
|
||||
'Esta operação cria um novo usuário e o vincula ao banco de dados alvo. A seleção de usuários já existentes no banco de dados não é suportada.',
|
||||
pgAuthorizationHelper:
|
||||
'Superusuários acessam todos os bancos desta instância sem vínculo. Para usuários comuns, são gerenciadas apenas permissões de banco, sem permissões de tabelas.',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'Revogar a autorização não exclui o usuário. O acesso por PUBLIC ou outros papéis pode permanecer.',
|
||||
pgSuperUser: 'Superusuário',
|
||||
loadFromRemoteHelper:
|
||||
'Isso sincronizará bancos de dados, usuários e autorizações do servidor com o 1Panel. Deseja continuar?',
|
||||
|
||||
@@ -615,6 +615,7 @@ const message = {
|
||||
'Этот порт является открытым портом контейнера. Вам нужно сохранить изменение отдельно и перезапустить контейнер!',
|
||||
loadFromRemote: 'Синхронизировать',
|
||||
userBind: 'Привязать пользователя',
|
||||
connectionUser: 'Пользователь подключения',
|
||||
userAuthorization: 'Доступ пользователя',
|
||||
noUserAuthorization: 'Не предоставлять доступ',
|
||||
authorizedDatabaseCount: 'Доступных баз данных: {0}',
|
||||
@@ -625,10 +626,13 @@ const message = {
|
||||
revokeAuthorization: 'Отозвать доступ',
|
||||
revokeAuthorizationHelper: 'Отозвать у пользователя {0} доступ к базе данных {1}?',
|
||||
supplementPassword: 'Добавить пароль',
|
||||
supplementPasswordHelper: 'Сохраняет текущий пароль только в 1Panel и не изменяет пароль в MySQL.',
|
||||
supplementPasswordHelper:
|
||||
'Сохраняет существующий пароль только в 1Panel, не изменяя пароль пользователя базы данных.',
|
||||
noUserBind: 'Нет привязки',
|
||||
pgBindHelper:
|
||||
'Эта операция используется для создания нового пользователя и привязки его к целевой базе данных. В настоящее время выбор уже существующих пользователей в базе данных не поддерживается.',
|
||||
pgAuthorizationHelper:
|
||||
'Суперпользователи имеют доступ ко всем базам экземпляра без привязки. Для обычных пользователей управляются только права уровня базы данных, без прав на таблицы.',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'Отзыв прав не удаляет пользователя. Доступ через PUBLIC или другие роли может сохраниться.',
|
||||
pgSuperUser: 'Суперпользователь',
|
||||
loadFromRemoteHelper: 'Синхронизировать базы данных, пользователей и права доступа с сервера в 1Panel?',
|
||||
passwordHelper: 'Не удается получить, нажмите для изменения',
|
||||
|
||||
@@ -622,6 +622,7 @@ const message = {
|
||||
'Bu port konteynerin açığa çıkan portudur. Değişikliği ayrı olarak kaydetmeniz ve konteyneri yeniden başlatmanız gerekir!',
|
||||
loadFromRemote: 'Sunucudan senkronize et',
|
||||
userBind: 'Kullanıcı bağla',
|
||||
connectionUser: 'Bağlantı kullanıcısı',
|
||||
userAuthorization: 'Kullanıcı yetkilendirmesi',
|
||||
noUserAuthorization: 'Yetki verme',
|
||||
authorizedDatabaseCount: '{0} veritabanı yetkisi',
|
||||
@@ -632,10 +633,13 @@ const message = {
|
||||
revokeAuthorization: 'Yetkiyi kaldır',
|
||||
revokeAuthorizationHelper: '{0} kullanıcısının {1} veritabanına erişimi kaldırılsın mı?',
|
||||
supplementPassword: 'Parola ekle',
|
||||
supplementPasswordHelper: 'Yalnızca mevcut parolayı 1Panel içine kaydeder; MySQL parolasını değiştirmez.',
|
||||
supplementPasswordHelper:
|
||||
'Yalnızca mevcut parolayı 1Panel içine kaydeder; veritabanı kullanıcısının parolasını değiştirmez.',
|
||||
noUserBind: 'Bağlantı yok',
|
||||
pgBindHelper:
|
||||
'Bu işlem yeni bir kullanıcı oluşturmak ve hedef veritabanına bağlamak için kullanılır. Şu anda veritabanında mevcut olan kullanıcıları seçmek desteklenmiyor.',
|
||||
pgAuthorizationHelper:
|
||||
'Süper kullanıcılar bu örnekteki tüm veritabanlarına bağlama gerekmeden erişir. Normal kullanıcılar için yalnızca veritabanı izinleri yönetilir, tablo izinleri dahil değildir.',
|
||||
pgRevokeAuthorizationHelper:
|
||||
'Yetkinin iptal edilmesi kullanıcıyı silmez. PUBLIC veya diğer roller üzerinden erişim devam edebilir.',
|
||||
pgSuperUser: 'Süper Kullanıcı',
|
||||
loadFromRemoteHelper:
|
||||
'Sunucudaki veritabanlarını, kullanıcıları ve yetkilendirmeleri 1Panel ile eşitler. Devam edilsin mi?',
|
||||
|
||||
@@ -596,6 +596,7 @@ const message = {
|
||||
confNotFound: '未能找到該應用設定檔,請在應用商店升級該應用至最新版本後重試',
|
||||
loadFromRemote: '從伺服器同步',
|
||||
userBind: '綁定使用者',
|
||||
connectionUser: '連線使用者',
|
||||
userAuthorization: '使用者授權',
|
||||
noUserAuthorization: '不授權',
|
||||
authorizedDatabaseCount: '已授權 {0} 個資料庫',
|
||||
@@ -606,9 +607,11 @@ const message = {
|
||||
revokeAuthorization: '撤銷授權',
|
||||
revokeAuthorizationHelper: '確定撤銷使用者 {0} 對資料庫 {1} 的存取授權嗎?',
|
||||
supplementPassword: '補充密碼',
|
||||
supplementPasswordHelper: '僅將現有密碼儲存到 1Panel,不會修改 MySQL 使用者密碼。',
|
||||
supplementPasswordHelper: '僅將現有密碼儲存至 1Panel,不會修改資料庫使用者密碼。',
|
||||
noUserBind: '未綁定',
|
||||
pgBindHelper: '此操作用於建立新使用者並將其綁定到目標資料庫,暫不支援選擇已存在於資料庫中的使用者。',
|
||||
pgAuthorizationHelper:
|
||||
'超級使用者可存取此執行個體的所有資料庫,無需單獨授權。一般使用者僅管理資料庫層級授權,不包含資料表權限。',
|
||||
pgRevokeAuthorizationHelper: '撤銷授權不會刪除使用者,使用者仍可能透過公共權限或其他角色存取此資料庫。',
|
||||
pgSuperUser: '超級使用者',
|
||||
loadFromRemoteHelper: '此操作將同步伺服器上的資料庫、使用者及授權資訊到 1Panel,是否繼續?',
|
||||
passwordHelper: '無法取得,可點選修改',
|
||||
|
||||
@@ -603,6 +603,7 @@ const message = {
|
||||
|
||||
loadFromRemote: '从服务器同步',
|
||||
userBind: '绑定用户',
|
||||
connectionUser: '连接用户',
|
||||
userAuthorization: '用户授权',
|
||||
noUserAuthorization: '不授权',
|
||||
authorizedDatabaseCount: '已授权 {0} 个数据库',
|
||||
@@ -613,9 +614,11 @@ const message = {
|
||||
revokeAuthorization: '撤销授权',
|
||||
revokeAuthorizationHelper: '确定撤销用户 {0} 对数据库 {1} 的访问授权吗?',
|
||||
supplementPassword: '补充密码',
|
||||
supplementPasswordHelper: '仅将现有密码保存到 1Panel,不会修改 MySQL 用户密码。',
|
||||
supplementPasswordHelper: '仅将现有密码保存到 1Panel,不会修改数据库用户密码。',
|
||||
noUserBind: '不绑定',
|
||||
pgBindHelper: '该操作用于创建新用户并将其绑定到目标数据库,暂不支持选择已存在于数据库中的用户。',
|
||||
pgAuthorizationHelper:
|
||||
'超级用户可访问此实例的所有数据库,无需单独授权。普通用户仅管理数据库级授权,不包含表级权限。',
|
||||
pgRevokeAuthorizationHelper: '撤销授权不会删除用户,用户仍可能通过公共权限或其他角色访问该数据库。',
|
||||
pgSuperUser: '超级用户',
|
||||
loadFromRemoteHelper: '此操作将同步服务器上的数据库、用户及授权信息到 1Panel,是否继续?',
|
||||
passwordHelper: '无法获取,可点击修改',
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
size="small"
|
||||
>
|
||||
<el-form v-loading="loading" ref="changeFormRef" :model="form" :rules="rules" label-position="top">
|
||||
<el-alert type="warning" :title="$t('database.pgBindHelper')" :closable="false" />
|
||||
<el-alert type="warning" :title="$t('database.pgAuthorizationHelper')" :closable="false" />
|
||||
<el-form-item class="mt-5" :label="$t('database.userBind')" prop="username">
|
||||
<el-input v-model="form.username" />
|
||||
</el-form-item>
|
||||
|
||||
@@ -1,14 +1,74 @@
|
||||
<template>
|
||||
<DrawerPro v-model="createVisible" :header="$t('commons.button.create')" @close="handleClose" size="small">
|
||||
<DrawerPro v-model="createVisible" :header="$t('commons.button.create')" @close="handleClose" size="normal">
|
||||
<div v-loading="loading">
|
||||
<el-form ref="formRef" label-position="top" :model="form" :rules="rules">
|
||||
<el-form-item :label="$t('commons.table.name')" prop="name">
|
||||
<el-input clearable v-model.trim="form.name" @input="form.username = form.name"></el-input>
|
||||
<el-input
|
||||
clearable
|
||||
v-model.trim="form.name"
|
||||
@input="!form.existingUser && (form.username = form.name)"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('database.userAuthorization')">
|
||||
<el-radio-group v-model="form.existingUser" @change="changeUserMode">
|
||||
<el-radio-button :value="true" :disabled="!users.length">
|
||||
{{ $t('commons.button.select') }}
|
||||
</el-radio-button>
|
||||
<el-radio-button :value="false">{{ $t('commons.button.create') }}</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('commons.login.username')" prop="username">
|
||||
<el-input clearable v-model.trim="form.username" />
|
||||
<el-select
|
||||
v-if="form.existingUser"
|
||||
v-model="form.username"
|
||||
filterable
|
||||
:fit-input-width="true"
|
||||
popper-class="postgresql-create-user-select-popper"
|
||||
>
|
||||
<el-option
|
||||
v-for="user in users"
|
||||
:key="user.username"
|
||||
:value="user.username"
|
||||
:label="user.username"
|
||||
class="user-select-option"
|
||||
>
|
||||
<div class="user-option-row">
|
||||
<div class="user-option">
|
||||
<div class="user-option-title">
|
||||
<el-tooltip :content="user.username" v-bind="TABLE_TOOLTIP_OPTIONS">
|
||||
<span class="user-name-text">{{ user.username }}</span>
|
||||
</el-tooltip>
|
||||
<el-tag v-if="user.superUser" class="superuser-tag" type="warning" size="small">
|
||||
{{ $t('database.pgSuperUser') }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<span v-if="user.description" class="user-option-description">
|
||||
{{ user.description }}
|
||||
</span>
|
||||
</div>
|
||||
<el-tag v-if="user.superUser" size="small">{{ $t('commons.table.all') }}</el-tag>
|
||||
<el-popover
|
||||
v-else
|
||||
:disabled="!user.databases.length"
|
||||
placement="right"
|
||||
trigger="hover"
|
||||
:width="220"
|
||||
>
|
||||
<template #reference>
|
||||
<el-button class="user-bound-button" size="small" @click.stop>
|
||||
{{ $t('database.authorizedDatabaseCount', [user.databases.length]) }}
|
||||
</el-button>
|
||||
</template>
|
||||
<div class="user-bound-list">
|
||||
<el-tag v-for="db in user.databases" :key="db" size="small">{{ db }}</el-tag>
|
||||
</div>
|
||||
</el-popover>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-input v-else clearable v-model.trim="form.username" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('commons.login.password')" prop="password">
|
||||
<el-form-item v-if="!form.existingUser" :label="$t('commons.login.password')" prop="password">
|
||||
<el-input type="password" clearable show-password v-model.trim="form.password">
|
||||
<template #append>
|
||||
<el-button @click="random">{{ $t('commons.button.random') }}</el-button>
|
||||
@@ -16,8 +76,9 @@
|
||||
</el-input>
|
||||
<span class="input-help">{{ $t('commons.rule.illegalChar') }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('database.permission')" prop="superUser">
|
||||
<el-form-item v-if="!form.existingUser" :label="$t('database.permission')" prop="superUser">
|
||||
<el-checkbox v-model="form.superUser">{{ $t('database.pgSuperUser') }}</el-checkbox>
|
||||
<span class="input-help">{{ $t('database.pgAuthorizationHelper') }}</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('commons.table.type')" prop="database">
|
||||
@@ -43,13 +104,16 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { computed, reactive, ref } from 'vue';
|
||||
import { TABLE_TOOLTIP_OPTIONS } from '@/components/table/shared';
|
||||
import { Rules } from '@/global/form-rules';
|
||||
import i18n from '@/lang';
|
||||
import { ElForm } from 'element-plus';
|
||||
import { addPostgresqlDB } from '@/api/modules/database';
|
||||
import { addPostgresqlDB, searchPostgresqlUsers } from '@/api/modules/database';
|
||||
import { MsgSuccess } from '@/utils/message';
|
||||
import { getRandomStr } from '@/utils/id';
|
||||
import { Database } from '@/api/interface/database';
|
||||
const users = ref<Database.PostgresqlUser[]>([]);
|
||||
const loading = ref();
|
||||
const createVisible = ref(false);
|
||||
const form = reactive({
|
||||
@@ -60,14 +124,15 @@ const form = reactive({
|
||||
format: '',
|
||||
username: '',
|
||||
password: '',
|
||||
superUser: true,
|
||||
superUser: false,
|
||||
existingUser: false,
|
||||
description: '',
|
||||
});
|
||||
const rules = reactive({
|
||||
const rules = computed(() => ({
|
||||
name: [Rules.requiredInput, Rules.dbName],
|
||||
username: [Rules.requiredInput, Rules.name],
|
||||
username: form.existingUser ? [Rules.requiredSelect] : [Rules.requiredInput, Rules.name],
|
||||
password: [Rules.requiredInput, Rules.databasePassword],
|
||||
});
|
||||
}));
|
||||
|
||||
type FormInstance = InstanceType<typeof ElForm>;
|
||||
const formRef = ref<FormInstance>();
|
||||
@@ -77,17 +142,32 @@ interface DialogProps {
|
||||
type: string;
|
||||
database: string;
|
||||
}
|
||||
const acceptParams = (params: DialogProps): void => {
|
||||
const acceptParams = async (params: DialogProps): Promise<void> => {
|
||||
form.name = '';
|
||||
form.from = params.from;
|
||||
form.type = params.type;
|
||||
form.database = params.database;
|
||||
form.format = 'UTF8';
|
||||
form.username = '';
|
||||
form.superUser = true;
|
||||
form.superUser = false;
|
||||
form.existingUser = false;
|
||||
users.value = [];
|
||||
form.description = '';
|
||||
random();
|
||||
createVisible.value = true;
|
||||
loading.value = true;
|
||||
try {
|
||||
users.value = (await searchPostgresqlUsers(params.database)).data || [];
|
||||
} catch {
|
||||
return;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
const changeUserMode = () => {
|
||||
form.username = form.existingUser ? users.value[0]?.username || '' : form.name;
|
||||
form.password = form.existingUser ? '' : getRandomStr(16);
|
||||
formRef.value?.clearValidate();
|
||||
};
|
||||
const handleClose = () => {
|
||||
createVisible.value = false;
|
||||
@@ -121,3 +201,70 @@ defineExpose({
|
||||
acceptParams,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(.user-select-option) {
|
||||
height: auto;
|
||||
min-height: 48px;
|
||||
}
|
||||
.user-option-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
.user-option {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 40px;
|
||||
padding: 4px 0;
|
||||
line-height: 18px;
|
||||
}
|
||||
.user-option-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
.user-name-text {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.user-option-description {
|
||||
margin-top: 3px;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
}
|
||||
.user-bound-button {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.superuser-tag {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
.postgresql-create-user-select-popper {
|
||||
min-width: 360px;
|
||||
|
||||
.user-select-option {
|
||||
height: auto;
|
||||
min-height: 48px;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
}
|
||||
.user-bound-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -34,6 +34,15 @@
|
||||
<el-button v-if="currentDB" @click="onChangeConn" type="primary" plain>
|
||||
{{ $t('database.databaseConnInfo') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="currentDB && (currentDB.from !== 'local' || postgresqlStatus === 'Running')"
|
||||
v-permission
|
||||
type="primary"
|
||||
plain
|
||||
@click="usersRef.acceptParams({ database: currentDBName })"
|
||||
>
|
||||
{{ $t('commons.table.user') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="currentDB && (currentDB.from !== 'local' || postgresqlStatus === 'Running')"
|
||||
v-permission
|
||||
@@ -114,7 +123,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('commons.login.username')" prop="username">
|
||||
<el-table-column :label="$t('database.connectionUser')" prop="username">
|
||||
<template #default="{ row }">
|
||||
<div class="flex items-center" v-if="row.username">
|
||||
<span>
|
||||
@@ -227,8 +236,7 @@
|
||||
</template>
|
||||
</DialogPro>
|
||||
|
||||
<PrivilegesDialog ref="privilegesRef" @search="search" />
|
||||
<BindDialog ref="bindRef" @search="search" />
|
||||
<UserDialog ref="usersRef" @search="search" />
|
||||
<PasswordDialog ref="passwordRef" @search="search" />
|
||||
<RootPasswordDialog ref="connRef" />
|
||||
<UploadDialog ref="uploadRef" />
|
||||
@@ -245,12 +253,11 @@
|
||||
<script lang="ts" setup>
|
||||
import { TABLE_TOOLTIP_OPTIONS } from '@/components/table/shared';
|
||||
import { useSearchState } from '@/utils/search-reset';
|
||||
import BindDialog from '@/views/database/postgresql/bind/index.vue';
|
||||
import UserDialog from '@/views/database/postgresql/user/index.vue';
|
||||
import OperateDialog from '@/views/database/postgresql/create/index.vue';
|
||||
import DeleteDialog from '@/views/database/postgresql/delete/index.vue';
|
||||
import PasswordDialog from '@/views/database/postgresql/password/index.vue';
|
||||
import TerminalDialog from '@/components/terminal/database.vue';
|
||||
import PrivilegesDialog from '@/views/database/postgresql/privileges/index.vue';
|
||||
import RootPasswordDialog from '@/views/database/postgresql/conn/index.vue';
|
||||
import AppResources from '@/views/database/postgresql/check/index.vue';
|
||||
import AppStatus from '@/components/app-status/index.vue';
|
||||
@@ -292,8 +299,7 @@ const currentDBName = ref();
|
||||
|
||||
const checkRef = ref();
|
||||
const deleteRef = ref();
|
||||
const bindRef = ref();
|
||||
const privilegesRef = ref();
|
||||
const usersRef = ref();
|
||||
const dialogTerminalRef = ref();
|
||||
|
||||
const dashboardName = ref();
|
||||
@@ -408,7 +414,7 @@ const onBind = async (row: Database.PostgresqlDBInfo) => {
|
||||
name: row.name,
|
||||
database: currentDBName.value,
|
||||
};
|
||||
bindRef.value.acceptParams(param);
|
||||
usersRef.value.acceptParams(param);
|
||||
};
|
||||
|
||||
const loadDB = async () => {
|
||||
@@ -551,20 +557,10 @@ const buttons = [
|
||||
},
|
||||
},
|
||||
{
|
||||
label: i18n.global.t('database.permission'),
|
||||
label: i18n.global.t('database.authorizationManagement'),
|
||||
permission: true,
|
||||
disabled: (row: Database.PostgresqlDBInfo) => {
|
||||
return !row.username || row.isDelete;
|
||||
},
|
||||
click: (row: Database.PostgresqlDBInfo) => {
|
||||
let param = {
|
||||
database: currentDBName.value,
|
||||
name: row.name,
|
||||
username: row.username,
|
||||
superUser: row.superUser,
|
||||
};
|
||||
privilegesRef.value.acceptParams(param);
|
||||
},
|
||||
disabled: (row: Database.PostgresqlDBInfo) => row.isDelete,
|
||||
click: (row: Database.PostgresqlDBInfo) => onBind(row),
|
||||
},
|
||||
{
|
||||
label: i18n.global.t('database.backupList'),
|
||||
|
||||
@@ -0,0 +1,567 @@
|
||||
<template>
|
||||
<DrawerPro
|
||||
v-model="visible"
|
||||
:header="name ? $t('database.authorizationManagement') : $t('commons.table.user')"
|
||||
:resource="name || database"
|
||||
size="60%"
|
||||
>
|
||||
<div v-loading="loading">
|
||||
<el-alert
|
||||
:title="$t('database.pgAuthorizationHelper')"
|
||||
type="info"
|
||||
:closable="false"
|
||||
class="authorization-hint"
|
||||
/>
|
||||
<div class="drawer-toolbar">
|
||||
<el-button v-if="!name" v-permission type="primary" @click="openEdit()">
|
||||
{{ $t('commons.button.create') }}
|
||||
</el-button>
|
||||
<el-button v-else v-permission type="primary" @click="openAddAuthorization">
|
||||
{{ $t('database.addUserAuthorization') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<ComplexTable :data="displayed" :heightDiff="260">
|
||||
<el-table-column :label="$t('commons.table.user')" prop="username" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<div class="user-name-row">
|
||||
<el-tooltip :content="row.username" v-bind="TABLE_TOOLTIP_OPTIONS">
|
||||
<span class="user-name-text">{{ row.username }}</span>
|
||||
</el-tooltip>
|
||||
<el-tag v-if="row.superUser" class="superuser-tag" type="warning" size="small">
|
||||
{{ $t('database.pgSuperUser') }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('commons.login.password')" prop="password" min-width="120">
|
||||
<template #default="{ row }">
|
||||
<div v-if="row.password" class="password-cell">
|
||||
<span v-if="!row.showPassword" class="password-text">**********</span>
|
||||
<Tooltip v-else class="password-text" :islink="false" :text="row.password" />
|
||||
<el-button
|
||||
link
|
||||
:icon="row.showPassword ? 'Hide' : 'View'"
|
||||
class="password-action"
|
||||
@click="row.showPassword = !row.showPassword"
|
||||
/>
|
||||
<CopyButton class="password-copy" :content="row.password" />
|
||||
</div>
|
||||
<div v-else-if="!row.protected" class="password-cell">
|
||||
<el-button v-permission link type="primary" @click="openSupplementPassword(row)">
|
||||
{{ $t('database.supplementPassword') }}
|
||||
</el-button>
|
||||
</div>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('menu.database')" min-width="160">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.superUser" size="small">{{ $t('commons.table.all') }}</el-tag>
|
||||
<span v-else-if="!row.databases.length">-</span>
|
||||
<div v-else class="bind-db-list">
|
||||
<el-tooltip
|
||||
v-for="db in row.databases.slice(0, 1)"
|
||||
:key="db"
|
||||
:content="db"
|
||||
v-bind="TABLE_TOOLTIP_OPTIONS"
|
||||
>
|
||||
<el-tag size="small">{{ db }}</el-tag>
|
||||
</el-tooltip>
|
||||
<el-popover v-if="row.databases.length > 1" placement="right" trigger="click" :width="260">
|
||||
<template #reference>
|
||||
<el-tag class="cursor-pointer" type="info" size="small">
|
||||
+{{ row.databases.length - 1 }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<div class="bind-db-popover">
|
||||
<el-tooltip
|
||||
v-for="db in row.databases"
|
||||
:key="db"
|
||||
:content="db"
|
||||
v-bind="TABLE_TOOLTIP_OPTIONS"
|
||||
>
|
||||
<el-tag size="small">{{ db }}</el-tag>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</el-popover>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
:label="$t('commons.table.description')"
|
||||
prop="description"
|
||||
show-overflow-tooltip
|
||||
min-width="120"
|
||||
/>
|
||||
<fu-table-operations
|
||||
:width="120"
|
||||
:buttons="userButtons"
|
||||
:label="$t('commons.table.operate')"
|
||||
fixed="right"
|
||||
fix
|
||||
/>
|
||||
</ComplexTable>
|
||||
</div>
|
||||
</DrawerPro>
|
||||
<DialogPro v-model="editing" :title="dialogTitle" size="small">
|
||||
<el-form ref="formRef" v-loading="saving" :model="form" :rules="rules" label-position="top">
|
||||
<el-form-item v-if="name && (mode === 'select' || mode === 'create')" :label="$t('commons.table.type')">
|
||||
<el-radio-group v-model="mode" @change="changeAuthorizationMode">
|
||||
<el-radio-button value="select">{{ $t('commons.button.select') }}</el-radio-button>
|
||||
<el-radio-button value="create">{{ $t('commons.button.create') }}</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="mode === 'select'" :label="$t('commons.login.username')" prop="username">
|
||||
<el-select
|
||||
v-model="form.username"
|
||||
filterable
|
||||
:fit-input-width="true"
|
||||
popper-class="postgresql-bind-user-select-popper"
|
||||
>
|
||||
<el-option
|
||||
v-for="user in available"
|
||||
:key="user.username"
|
||||
:value="user.username"
|
||||
:label="user.username"
|
||||
class="user-select-option"
|
||||
>
|
||||
<div class="user-option-row">
|
||||
<div class="user-option">
|
||||
<el-tooltip :content="user.username" v-bind="TABLE_TOOLTIP_OPTIONS">
|
||||
<span class="user-option-title">{{ user.username }}</span>
|
||||
</el-tooltip>
|
||||
<span v-if="user.description" class="user-option-description">
|
||||
{{ user.description }}
|
||||
</span>
|
||||
</div>
|
||||
<el-popover
|
||||
:disabled="!user.databases.length"
|
||||
placement="right"
|
||||
trigger="hover"
|
||||
:width="220"
|
||||
>
|
||||
<template #reference>
|
||||
<el-button class="user-bound-button" size="small" @click.stop>
|
||||
{{ $t('database.authorizedDatabaseCount', [user.databases.length]) }}
|
||||
</el-button>
|
||||
</template>
|
||||
<div class="user-bound-list">
|
||||
<el-tag v-for="db in user.databases" :key="db" size="small">{{ db }}</el-tag>
|
||||
</div>
|
||||
</el-popover>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<template v-else>
|
||||
<el-form-item :label="$t('commons.login.username')" prop="username">
|
||||
<el-input v-model.trim="form.username" :disabled="mode !== 'create'" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="mode !== 'supplement'" :label="$t('database.permission')">
|
||||
<el-checkbox v-model="form.superUser">{{ $t('database.pgSuperUser') }}</el-checkbox>
|
||||
<span class="input-help">{{ $t('database.pgAuthorizationHelper') }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('commons.login.password')" prop="password" :required="mode !== 'edit'">
|
||||
<el-input v-model.trim="form.password" type="password" clearable show-password />
|
||||
<span class="input-help">{{ $t('commons.rule.illegalChar') }}</span>
|
||||
<span v-if="mode === 'edit'" class="input-help">{{ $t('setting.passwordEmptyTip') }}</span>
|
||||
<span v-if="mode === 'supplement'" class="input-help">
|
||||
{{ $t('database.supplementPasswordHelper') }}
|
||||
</span>
|
||||
</el-form-item>
|
||||
</template>
|
||||
<template v-if="mode === 'create' || mode === 'edit'">
|
||||
<el-form-item :label="$t('commons.table.description')" prop="description">
|
||||
<el-input v-model="form.description" type="textarea" clearable />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button :disabled="saving" @click="editing = false">{{ $t('commons.button.cancel') }}</el-button>
|
||||
<el-button type="primary" :disabled="saving" @click="save">{{ $t('commons.button.confirm') }}</el-button>
|
||||
</template>
|
||||
</DialogPro>
|
||||
|
||||
<DialogPro
|
||||
v-model="deleteDialogVisible"
|
||||
:title="$t('commons.button.delete') + ' - ' + deleteUser.username"
|
||||
size="small"
|
||||
>
|
||||
<div v-loading="deleting">
|
||||
<div class="delete-user-title">{{ deleteUser.username }} {{ $t('database.userBoundDatabases') }}</div>
|
||||
<div class="delete-user-section">
|
||||
<el-tag v-if="deleteUser.superUser" size="small">{{ $t('commons.table.all') }}</el-tag>
|
||||
<div v-else-if="deleteUser.databases.length === 0" class="delete-user-empty">-</div>
|
||||
<div v-else class="bind-db-list delete-user-dbs">
|
||||
<el-tag v-for="item in deleteUser.databases" :key="item" size="small">
|
||||
{{ item }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
<div class="delete-user-section">
|
||||
<div>
|
||||
<span style="font-size: 12px">{{ $t('database.delete') }}</span>
|
||||
<span style="font-size: 12px; color: red; font-weight: 500">
|
||||
{{ deleteUser.username }}
|
||||
</span>
|
||||
<span style="font-size: 12px">{{ $t('database.deleteUserHelper') }}</span>
|
||||
</div>
|
||||
<el-input v-model="deleteConfirmInput" :placeholder="deleteUser.username" />
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="deleteDialogVisible = false" :disabled="deleting">
|
||||
{{ $t('commons.button.cancel') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
@click="remove()"
|
||||
:disabled="deleteConfirmInput !== deleteUser.username || deleting"
|
||||
>
|
||||
{{ $t('commons.button.confirm') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</DialogPro>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref } from 'vue';
|
||||
import Tooltip from '@/components/tooltip/index.vue';
|
||||
import { TABLE_TOOLTIP_OPTIONS } from '@/components/table/shared';
|
||||
import { ElMessageBox, type FormInstance } from 'element-plus';
|
||||
import { Database } from '@/api/interface/database';
|
||||
import {
|
||||
searchPostgresqlUsers,
|
||||
createPostgresqlUser,
|
||||
updatePostgresqlUser,
|
||||
changePostgresqlUserPassword,
|
||||
savePostgresqlUserPassword,
|
||||
deletePostgresqlUser,
|
||||
grantPostgresqlUser,
|
||||
revokePostgresqlUser,
|
||||
} from '@/api/modules/database';
|
||||
import { Rules } from '@/global/form-rules';
|
||||
import { MsgSuccess } from '@/utils/message';
|
||||
import i18n from '@/lang';
|
||||
|
||||
const visible = ref(false);
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const database = ref('');
|
||||
const name = ref('');
|
||||
const users = ref<Array<Database.PostgresqlUser & { showPassword?: boolean }>>([]);
|
||||
const displayed = computed(() =>
|
||||
users.value.filter((user) => !name.value || user.superUser || user.databases.includes(name.value)),
|
||||
);
|
||||
const available = computed(() =>
|
||||
users.value.filter((user) => !user.superUser && !user.protected && !user.databases.includes(name.value)),
|
||||
);
|
||||
const editing = ref(false);
|
||||
const mode = ref<'create' | 'edit' | 'select' | 'supplement'>('create');
|
||||
const dialogTitle = computed(() => {
|
||||
if (name.value && (mode.value === 'create' || mode.value === 'select')) {
|
||||
return i18n.global.t('database.addUserAuthorization');
|
||||
}
|
||||
if (mode.value === 'supplement') return i18n.global.t('database.supplementPassword');
|
||||
return i18n.global.t(mode.value === 'create' ? 'commons.table.user' : 'commons.button.edit');
|
||||
});
|
||||
const deleteDialogVisible = ref(false);
|
||||
const deleting = ref(false);
|
||||
const deleteConfirmInput = ref('');
|
||||
const deleteUser = reactive({ username: '', databases: [] as string[], superUser: false });
|
||||
const formRef = ref<FormInstance>();
|
||||
const form = reactive({ username: '', password: '', superUser: false, description: '' });
|
||||
const rules = computed(() => ({
|
||||
username:
|
||||
mode.value === 'create'
|
||||
? [Rules.requiredInput, Rules.name]
|
||||
: mode.value === 'select'
|
||||
? [Rules.requiredSelect]
|
||||
: [Rules.requiredInput],
|
||||
password: mode.value === 'edit' ? [Rules.databasePassword] : [Rules.requiredInput, Rules.databasePassword],
|
||||
}));
|
||||
const emit = defineEmits<{ (e: 'search'): void }>();
|
||||
|
||||
const load = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await searchPostgresqlUsers(database.value);
|
||||
users.value = res.data || [];
|
||||
} catch {
|
||||
return;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
const acceptParams = async (params: { database: string; name?: string }) => {
|
||||
database.value = params.database;
|
||||
name.value = params.name || '';
|
||||
users.value = [];
|
||||
visible.value = true;
|
||||
await load();
|
||||
};
|
||||
const openEdit = (user?: Database.PostgresqlUser) => {
|
||||
mode.value = user ? 'edit' : 'create';
|
||||
Object.assign(form, {
|
||||
username: user?.username || '',
|
||||
password: '',
|
||||
superUser: user?.superUser || false,
|
||||
description: user?.description || '',
|
||||
});
|
||||
editing.value = true;
|
||||
formRef.value?.clearValidate();
|
||||
};
|
||||
const openAddAuthorization = () => {
|
||||
openEdit();
|
||||
mode.value = 'select';
|
||||
};
|
||||
const changeAuthorizationMode = () => {
|
||||
Object.assign(form, { username: '', password: '', superUser: false, description: '' });
|
||||
formRef.value?.clearValidate();
|
||||
};
|
||||
const openDeleteUserDialog = (user: Database.PostgresqlUser) => {
|
||||
Object.assign(deleteUser, { username: user.username, databases: user.databases, superUser: user.superUser });
|
||||
deleteConfirmInput.value = '';
|
||||
deleteDialogVisible.value = true;
|
||||
};
|
||||
const openSupplementPassword = (user: Database.PostgresqlUser) => {
|
||||
openEdit(user);
|
||||
mode.value = 'supplement';
|
||||
};
|
||||
const save = async () => {
|
||||
if (!(await formRef.value?.validate().catch(() => false))) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
const params = { database: database.value, ...form };
|
||||
if (mode.value === 'create') {
|
||||
await createPostgresqlUser(params);
|
||||
mode.value = name.value && !form.superUser ? 'select' : 'edit';
|
||||
form.password = '';
|
||||
if (name.value && !form.superUser) {
|
||||
await grantPostgresqlUser({ database: database.value, name: name.value, username: form.username });
|
||||
}
|
||||
} else if (mode.value === 'supplement') {
|
||||
await savePostgresqlUserPassword({
|
||||
database: database.value,
|
||||
username: form.username,
|
||||
password: form.password,
|
||||
});
|
||||
} else if (mode.value === 'select') {
|
||||
await grantPostgresqlUser({ database: database.value, name: name.value, username: form.username });
|
||||
} else {
|
||||
await updatePostgresqlUser({
|
||||
database: database.value,
|
||||
username: form.username,
|
||||
superUser: form.superUser,
|
||||
description: form.description,
|
||||
});
|
||||
if (form.password) {
|
||||
await changePostgresqlUserPassword({
|
||||
database: database.value,
|
||||
username: form.username,
|
||||
password: form.password,
|
||||
});
|
||||
}
|
||||
}
|
||||
editing.value = false;
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
emit('search');
|
||||
} catch {
|
||||
return;
|
||||
} finally {
|
||||
saving.value = false;
|
||||
await load();
|
||||
}
|
||||
};
|
||||
const revoke = async (user: Database.PostgresqlUser) => {
|
||||
const confirmed = await ElMessageBox.confirm(
|
||||
`${i18n.global.t('database.revokeAuthorizationHelper', [user.username, name.value])} ${i18n.global.t('database.pgRevokeAuthorizationHelper')}`,
|
||||
i18n.global.t('commons.msg.infoTitle'),
|
||||
{
|
||||
type: 'warning',
|
||||
confirmButtonText: i18n.global.t('commons.button.confirm'),
|
||||
cancelButtonText: i18n.global.t('commons.button.cancel'),
|
||||
},
|
||||
).catch(() => false);
|
||||
if (!confirmed) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
await revokePostgresqlUser({ database: database.value, name: name.value, username: user.username });
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
emit('search');
|
||||
} catch {
|
||||
return;
|
||||
} finally {
|
||||
await load();
|
||||
}
|
||||
};
|
||||
const remove = async () => {
|
||||
if (deleteConfirmInput.value !== deleteUser.username) return;
|
||||
deleting.value = true;
|
||||
try {
|
||||
await deletePostgresqlUser({ database: database.value, username: deleteUser.username });
|
||||
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
|
||||
deleteDialogVisible.value = false;
|
||||
emit('search');
|
||||
} catch {
|
||||
return;
|
||||
} finally {
|
||||
deleting.value = false;
|
||||
await load();
|
||||
}
|
||||
};
|
||||
const userButtons = [
|
||||
{
|
||||
label: i18n.global.t('commons.button.edit'),
|
||||
permission: true,
|
||||
show: (row: Database.PostgresqlUser) => !row.protected,
|
||||
click: (row: Database.PostgresqlUser) => openEdit(row),
|
||||
},
|
||||
{
|
||||
label: i18n.global.t('database.revokeAuthorization'),
|
||||
permission: true,
|
||||
show: (row: Database.PostgresqlUser) => !!name.value && !row.superUser && !row.protected,
|
||||
click: (row: Database.PostgresqlUser) => revoke(row),
|
||||
},
|
||||
{
|
||||
label: i18n.global.t('commons.button.delete'),
|
||||
permission: true,
|
||||
show: (row: Database.PostgresqlUser) => !name.value && !row.protected,
|
||||
click: (row: Database.PostgresqlUser) => openDeleteUserDialog(row),
|
||||
},
|
||||
];
|
||||
defineExpose({ acceptParams });
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.authorization-hint {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.user-name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
.user-name-text {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.superuser-tag {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.drawer-toolbar {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.password-cell {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
max-width: 100%;
|
||||
}
|
||||
.password-text {
|
||||
overflow: hidden;
|
||||
max-width: 96px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.password-action {
|
||||
min-height: 20px;
|
||||
padding: 0;
|
||||
}
|
||||
.password-copy {
|
||||
margin-left: -2px;
|
||||
}
|
||||
.bind-db-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
.bind-db-popover {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
|
||||
:deep(.el-tag) {
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
.delete-user-title {
|
||||
overflow-wrap: anywhere;
|
||||
margin-bottom: 12px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
line-height: 20px;
|
||||
}
|
||||
.delete-user-section {
|
||||
margin-top: 12px;
|
||||
}
|
||||
.delete-user-empty {
|
||||
margin-top: 6px;
|
||||
}
|
||||
.delete-user-dbs {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
:deep(.user-select-option) {
|
||||
height: auto;
|
||||
min-height: 48px;
|
||||
}
|
||||
.user-option-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
.user-option {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 40px;
|
||||
padding: 4px 0;
|
||||
line-height: 18px;
|
||||
}
|
||||
.user-option-title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.user-option-description {
|
||||
margin-top: 3px;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
}
|
||||
.user-bound-button {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
.postgresql-bind-user-select-popper {
|
||||
min-width: 360px;
|
||||
|
||||
.user-select-option {
|
||||
height: auto;
|
||||
min-height: 48px;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
}
|
||||
.user-bound-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user