mirror of https://github.com/msgbyte/tailchat
feat: 权限列表的创建与保存
parent
5e07b02c9c
commit
9631081b65
@ -0,0 +1,8 @@
|
||||
export * as common from './common';
|
||||
export * as config from './config';
|
||||
export * as converse from './converse';
|
||||
export * as friend from './friend';
|
||||
export * as group from './group';
|
||||
export * as message from './message';
|
||||
export * as plugin from './plugin';
|
||||
export * as user from './user';
|
@ -0,0 +1,10 @@
|
||||
import { t } from 'tailchat-shared';
|
||||
|
||||
export const permissionList = [
|
||||
{
|
||||
key: 'core.message',
|
||||
title: t('发送消息'),
|
||||
desc: t('允许成员在文字频道发送消息'),
|
||||
default: true,
|
||||
},
|
||||
];
|
@ -0,0 +1,34 @@
|
||||
import { model, t, useAsyncRequest } from 'tailchat-shared';
|
||||
import { permissionList } from './const';
|
||||
|
||||
export function useRoleActions(groupId: string, roleId: string) {
|
||||
const [{ loading: loading1 }, handleCreateRole] =
|
||||
useAsyncRequest(async () => {
|
||||
await model.group.createGroupRole(
|
||||
groupId,
|
||||
t('新身份组'),
|
||||
permissionList.filter((p) => p.default).map((p) => p.key)
|
||||
);
|
||||
}, [groupId]);
|
||||
|
||||
const [{ loading: loading2 }, handleSavePermission] = useAsyncRequest(
|
||||
async (permissions: string[]) => {
|
||||
await model.group.updateGroupRolePermission(groupId, roleId, permissions);
|
||||
},
|
||||
[groupId, roleId]
|
||||
);
|
||||
|
||||
const [{ loading: loading3 }, handleChangeRoleName] = useAsyncRequest(
|
||||
async (newRoleName: string) => {
|
||||
await model.group.updateGroupRoleName(groupId, roleId, newRoleName);
|
||||
},
|
||||
[groupId, roleId]
|
||||
);
|
||||
|
||||
return {
|
||||
loading: loading1 || loading2 || loading3,
|
||||
handleCreateRole,
|
||||
handleSavePermission,
|
||||
handleChangeRoleName,
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue