mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-11 23:49:03 +08:00
Bugfix/invitemailmultilangs (#2257)
Co-authored-by: crazywoola <427733928@qq.com>
This commit is contained in:
parent
5a6cb69951
commit
7076d41b29
@ -56,6 +56,7 @@ class MemberInviteEmailApi(Resource):
|
||||
|
||||
invitee_emails = args['emails']
|
||||
invitee_role = args['role']
|
||||
interface_language = args['language']
|
||||
if invitee_role not in ['admin', 'normal']:
|
||||
return {'code': 'invalid-role', 'message': 'Invalid role'}, 400
|
||||
|
||||
@ -64,8 +65,7 @@ class MemberInviteEmailApi(Resource):
|
||||
console_web_url = current_app.config.get("CONSOLE_WEB_URL")
|
||||
for invitee_email in invitee_emails:
|
||||
try:
|
||||
token = RegisterService.invite_new_member(inviter.current_tenant, invitee_email, role=invitee_role,
|
||||
inviter=inviter)
|
||||
token = RegisterService.invite_new_member(inviter.current_tenant, invitee_email, interface_language, role=invitee_role, inviter=inviter)
|
||||
invitation_results.append({
|
||||
'status': 'success',
|
||||
'email': invitee_email,
|
||||
|
@ -138,8 +138,9 @@ class AccountService:
|
||||
return account
|
||||
|
||||
@staticmethod
|
||||
def create_account(email: str, name: str, password: str = None,
|
||||
interface_language: str = languages[0], interface_theme: str = 'light',
|
||||
def create_account(email: str, name: str, interface_language: str,
|
||||
password: str = None,
|
||||
interface_theme: str = 'light',
|
||||
timezone: str = 'America/New_York', ) -> Account:
|
||||
"""create account"""
|
||||
account = Account()
|
||||
@ -429,7 +430,7 @@ class RegisterService:
|
||||
db.session.begin_nested()
|
||||
"""Register account"""
|
||||
try:
|
||||
account = AccountService.create_account(email, name, password)
|
||||
account = AccountService.create_account(email, name, interface_language=languages[0], password=password)
|
||||
account.status = AccountStatus.ACTIVE.value
|
||||
account.initialized_at = datetime.utcnow()
|
||||
|
||||
@ -452,15 +453,14 @@ class RegisterService:
|
||||
return account
|
||||
|
||||
@classmethod
|
||||
def invite_new_member(cls, tenant: Tenant, email: str, role: str = 'normal',
|
||||
inviter: Account = None) -> str:
|
||||
def invite_new_member(cls, tenant: Tenant, email: str, language: str, role: str = 'normal', inviter: Account = None) -> str:
|
||||
"""Invite new member"""
|
||||
account = Account.query.filter_by(email=email).first()
|
||||
|
||||
if not account:
|
||||
TenantService.check_member_permission(tenant, inviter, None, 'add')
|
||||
name = email.split('@')[0]
|
||||
account = AccountService.create_account(email, name)
|
||||
account = AccountService.create_account(email, name, interface_language=language)
|
||||
account.status = AccountStatus.PENDING.value
|
||||
db.session.commit()
|
||||
|
||||
|
@ -14,6 +14,8 @@ import { inviteMember } from '@/service/common'
|
||||
import { emailRegex } from '@/config'
|
||||
import { ToastContext } from '@/app/components/base/toast'
|
||||
import type { InvitationResult } from '@/models/common'
|
||||
import I18n from '@/context/i18n'
|
||||
import { getModelRuntimeSupported } from '@/utils/language'
|
||||
|
||||
import 'react-multi-email/dist/style.css'
|
||||
type IInviteModalProps = {
|
||||
@ -29,6 +31,9 @@ const InviteModal = ({
|
||||
const [emails, setEmails] = useState<string[]>([])
|
||||
const { notify } = useContext(ToastContext)
|
||||
|
||||
const { locale } = useContext(I18n)
|
||||
const language = getModelRuntimeSupported(locale)
|
||||
|
||||
const InvitingRoles = useMemo(() => [
|
||||
{
|
||||
name: 'normal',
|
||||
@ -42,11 +47,11 @@ const InviteModal = ({
|
||||
const [role, setRole] = useState(InvitingRoles[0])
|
||||
|
||||
const handleSend = useCallback(async () => {
|
||||
if (emails.map(email => emailRegex.test(email)).every(Boolean)) {
|
||||
if (emails.map((email: string) => emailRegex.test(email)).every(Boolean)) {
|
||||
try {
|
||||
const { result, invitation_results } = await inviteMember({
|
||||
url: '/workspaces/current/members/invite-email',
|
||||
body: { emails, role: role.name },
|
||||
body: { emails, role: role.name, language },
|
||||
})
|
||||
|
||||
if (result === 'success') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user