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; disableGuestLogin?: boolean;
/**
*
*/
disableCreateGroup?: boolean;
} }
export function getGlobalConfig(): GlobalConfig { export function getGlobalConfig(): GlobalConfig {

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

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

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

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

@ -50,6 +50,7 @@ export const config = {
disableLogger: checkEnvTrusty(process.env.DISABLE_LOGGER), // 是否关闭日志 disableLogger: checkEnvTrusty(process.env.DISABLE_LOGGER), // 是否关闭日志
disableUserRegister: checkEnvTrusty(process.env.DISABLE_USER_REGISTER), // 是否关闭用户注册功能 disableUserRegister: checkEnvTrusty(process.env.DISABLE_USER_REGISTER), // 是否关闭用户注册功能
disableGuestLogin: checkEnvTrusty(process.env.DISABLE_GUEST_LOGIN), // 是否关闭用户游客登录功能 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, emailVerification: config.emailVerification,
disableUserRegister: config.feature.disableUserRegister, disableUserRegister: config.feature.disableUserRegister,
disableGuestLogin: config.feature.disableGuestLogin, disableGuestLogin: config.feature.disableGuestLogin,
disableCreateGroup: config.feature.disableCreateGroup,
...persistConfig, ...persistConfig,
}; };
} }

@ -20,6 +20,7 @@ import {
PERMISSION, PERMISSION,
GroupPanelType, GroupPanelType,
PanelFeature, PanelFeature,
config,
} from 'tailchat-server-sdk'; } from 'tailchat-server-sdk';
import moment from 'moment'; import moment from 'moment';
@ -273,6 +274,12 @@ class GroupService extends TcService {
const name = ctx.params.name; const name = ctx.params.name;
const panels = ctx.params.panels; const panels = ctx.params.panels;
const userId = ctx.meta.userId; 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({ const group = await this.adapter.model.createGroup({
name, 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_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_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_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 > 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_LOGGER | - | 是否禁用日志输出, 如果为 "1" 或者 "true" 则在运行中关闭日志 |
| DISABLE_USER_REGISTER | - | 是否关闭用户注册功能, 如果为 "1" 或者 "true" 则关闭该功能 | | DISABLE_USER_REGISTER | - | 是否关闭用户注册功能, 如果为 "1" 或者 "true" 则关闭该功能 |
| DISABLE_GUEST_LOGIN | - | 是否关闭用户游客登录功能, 如果为 "1" 或者 "true" 则关闭该功能 | | DISABLE_GUEST_LOGIN | - | 是否关闭用户游客登录功能, 如果为 "1" 或者 "true" 则关闭该功能 |
| DISABLE_CREATE_GROUP | - | 是否关闭用户创建群组功能, 如果为 "1" 或者 "true" 则关闭该功能 |
> 部分环境变量示例可见: https://github.com/msgbyte/tailchat/blob/master/server/.env.example > 部分环境变量示例可见: https://github.com/msgbyte/tailchat/blob/master/server/.env.example

Loading…
Cancel
Save