feat: add env `DISABLE_CREATE_GROUP` which can control user allow create group

pull/100/head
moonrailgun 2 years ago
parent 449845315e
commit 2e56139925

@ -35,6 +35,11 @@ export interface GlobalConfig {
*
*/
disableGuestLogin?: boolean;
/**
*
*/
disableCreateGroup?: boolean;
}
export function getGlobalConfig(): GlobalConfig {

@ -24,4 +24,5 @@ export const defaultGlobalConfig: GlobalConfig = {
serverName: 'Tailchat',
disableUserRegister: false,
disableGuestLogin: false,
disableCreateGroup: false,
};

@ -7,6 +7,7 @@ import {
showSuccessToasts,
t,
useAppSelector,
useGlobalConfigStore,
useGroupAck,
} from 'tailchat-shared';
import { NavbarNavItem } from './NavItem';
@ -75,6 +76,10 @@ export const GroupNav: React.FC = React.memo(() => {
openModal(<ModalCreateGroup />);
}, []);
const { disableCreateGroup } = useGlobalConfigStore((state) => ({
disableCreateGroup: state.disableCreateGroup,
}));
return (
<div className="space-y-2" data-tc-role="navbar-groups">
{Array.isArray(groups) &&
@ -84,15 +89,16 @@ export const GroupNav: React.FC = React.memo(() => {
</div>
))}
{/* 创建群组 */}
<NavbarNavItem
className="bg-green-500"
name={t('创建群组')}
onClick={handleCreateGroup}
data-testid="create-group"
>
<Icon className="text-3xl text-white" icon="mdi:plus" />
</NavbarNavItem>
{!disableCreateGroup && (
<NavbarNavItem
className="bg-green-500"
name={t('创建群组')}
onClick={handleCreateGroup}
data-testid="create-group"
>
<Icon className="text-3xl text-white" icon="mdi:plus" />
</NavbarNavItem>
)}
</div>
);
});

@ -52,6 +52,7 @@ export const i18n: TushanContextProps['i18n'] = {
emailVerification: 'Mandatory Email Verification',
allowGuestLogin: 'Allow Guest Login',
allowUserRegister: 'Allow User Register',
allowCreateGroup: 'Allow Create Group',
serverName: 'Server Name',
serverEntryImage: 'Server Entry Page Image',
},
@ -210,6 +211,7 @@ export const i18n: TushanContextProps['i18n'] = {
emailVerification: '邮箱强制验证',
allowGuestLogin: '允许访客登录',
allowUserRegister: '允许用户注册',
allowCreateGroup: '允许创建群组',
serverName: '服务器名',
serverEntryImage: '服务器登录图',
},

@ -116,6 +116,10 @@ export const SystemConfig: React.FC = React.memo(() => {
{!config.disableUserRegister ? <IconCheck /> : <IconClose />}
</Form.Item>
<Form.Item label={t('custom.config.allowCreateGroup')}>
{!config.disableCreateGroup ? <IconCheck /> : <IconClose />}
</Form.Item>
<Form.Item label={t('custom.config.serverName')}>
<Input
value={serverName}

@ -50,6 +50,7 @@ export const config = {
disableLogger: checkEnvTrusty(process.env.DISABLE_LOGGER), // 是否关闭日志
disableUserRegister: checkEnvTrusty(process.env.DISABLE_USER_REGISTER), // 是否关闭用户注册功能
disableGuestLogin: checkEnvTrusty(process.env.DISABLE_GUEST_LOGIN), // 是否关闭用户游客登录功能
disableCreateGroup: checkEnvTrusty(process.env.DISABLE_CREATE_GROUP), // 是否禁用用户创建群组功能
},
};

@ -81,6 +81,7 @@ class ConfigService extends TcService {
emailVerification: config.emailVerification,
disableUserRegister: config.feature.disableUserRegister,
disableGuestLogin: config.feature.disableGuestLogin,
disableCreateGroup: config.feature.disableCreateGroup,
...persistConfig,
};
}

@ -20,6 +20,7 @@ import {
PERMISSION,
GroupPanelType,
PanelFeature,
config,
} from 'tailchat-server-sdk';
import moment from 'moment';
@ -273,6 +274,12 @@ class GroupService extends TcService {
const name = ctx.params.name;
const panels = ctx.params.panels;
const userId = ctx.meta.userId;
const t = ctx.meta.t;
if (config.feature.disableCreateGroup === true) {
// 环境变量禁止创建群组
throw new NoPermissionError(t('创建群组功能已被管理员禁用'));
}
const group = await this.adapter.model.createGroup({
name,

@ -24,6 +24,7 @@ title: Environment Variable
| DISABLE_LOGGER | - | Whether to disable the log output, if "1" or "true" turn off the log on the fly |
| DISABLE_USER_REGISTER | - | Whether to disable the user register, if "1" or "true" turn off this method |
| DISABLE_GUEST_LOGIN | - | Whether to disable the guest login, if "1" or "true" turn off this method |
| DISABLE_CREATE_GROUP | - | Whether to disable user create group, if "1" or "true" turn off this method |
> Some examples of environment variables can be seen: https://github.com/msgbyte/tailchat/blob/master/server/.env.example

@ -24,6 +24,7 @@ title: 环境变量
| DISABLE_LOGGER | - | 是否禁用日志输出, 如果为 "1" 或者 "true" 则在运行中关闭日志 |
| DISABLE_USER_REGISTER | - | 是否关闭用户注册功能, 如果为 "1" 或者 "true" 则关闭该功能 |
| DISABLE_GUEST_LOGIN | - | 是否关闭用户游客登录功能, 如果为 "1" 或者 "true" 则关闭该功能 |
| DISABLE_CREATE_GROUP | - | 是否关闭用户创建群组功能, 如果为 "1" 或者 "true" 则关闭该功能 |
> 部分环境变量示例可见: https://github.com/msgbyte/tailchat/blob/master/server/.env.example

Loading…
Cancel
Save