mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-12 04:16:54 +08:00
feat: support re-invite email. (#2107)
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
from flask import current_app
|
||||||
|
from flask_login import current_user
|
||||||
|
from flask_restful import Resource, abort, fields, marshal_with, reqparse
|
||||||
|
|
||||||
import services
|
import services
|
||||||
from controllers.console import api
|
from controllers.console import api
|
||||||
from controllers.console.setup import setup_required
|
from controllers.console.setup import setup_required
|
||||||
from controllers.console.wraps import account_initialization_required, cloud_edition_billing_resource_check
|
from controllers.console.wraps import account_initialization_required, cloud_edition_billing_resource_check
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from flask import current_app
|
|
||||||
from flask_login import current_user
|
|
||||||
from flask_restful import Resource, abort, fields, marshal, marshal_with, reqparse
|
|
||||||
from libs.helper import TimestampField
|
from libs.helper import TimestampField
|
||||||
from libs.login import login_required
|
from libs.login import login_required
|
||||||
from models.account import Account, TenantAccountJoin
|
from models.account import Account
|
||||||
from services.account_service import RegisterService, TenantService
|
from services.account_service import RegisterService, TenantService
|
||||||
|
|
||||||
account_fields = {
|
account_fields = {
|
||||||
@@ -65,17 +66,11 @@ class MemberInviteEmailApi(Resource):
|
|||||||
try:
|
try:
|
||||||
token = RegisterService.invite_new_member(inviter.current_tenant, invitee_email, role=invitee_role,
|
token = RegisterService.invite_new_member(inviter.current_tenant, invitee_email, role=invitee_role,
|
||||||
inviter=inviter)
|
inviter=inviter)
|
||||||
account = db.session.query(Account, TenantAccountJoin.role).join(
|
|
||||||
TenantAccountJoin, Account.id == TenantAccountJoin.account_id
|
|
||||||
).filter(Account.email == invitee_email).first()
|
|
||||||
account, role = account
|
|
||||||
invitation_results.append({
|
invitation_results.append({
|
||||||
'status': 'success',
|
'status': 'success',
|
||||||
'email': invitee_email,
|
'email': invitee_email,
|
||||||
'url': f'{console_web_url}/activate?email={invitee_email}&token={token}'
|
'url': f'{console_web_url}/activate?email={invitee_email}&token={token}'
|
||||||
})
|
})
|
||||||
account = marshal(account, account_fields)
|
|
||||||
account['role'] = role
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
invitation_results.append({
|
invitation_results.append({
|
||||||
'status': 'failed',
|
'status': 'failed',
|
||||||
|
|||||||
@@ -464,17 +464,22 @@ class RegisterService:
|
|||||||
account = AccountService.create_account(email, name)
|
account = AccountService.create_account(email, name)
|
||||||
account.status = AccountStatus.PENDING.value
|
account.status = AccountStatus.PENDING.value
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
TenantService.create_tenant_member(tenant, account, role)
|
||||||
else:
|
else:
|
||||||
TenantService.check_member_permission(tenant, inviter, account, 'add')
|
TenantService.check_member_permission(tenant, inviter, account, 'add')
|
||||||
ta = TenantAccountJoin.query.filter_by(
|
ta = TenantAccountJoin.query.filter_by(
|
||||||
tenant_id=tenant.id,
|
tenant_id=tenant.id,
|
||||||
account_id=account.id
|
account_id=account.id
|
||||||
).first()
|
).first()
|
||||||
if ta:
|
|
||||||
raise AccountAlreadyInTenantError("Account already in tenant.")
|
|
||||||
|
|
||||||
|
if not ta:
|
||||||
TenantService.create_tenant_member(tenant, account, role)
|
TenantService.create_tenant_member(tenant, account, role)
|
||||||
|
|
||||||
|
# Support resend invitation email when the account is pending status
|
||||||
|
if account.status != AccountStatus.PENDING.value:
|
||||||
|
raise AccountAlreadyInTenantError("Account already in tenant.")
|
||||||
|
|
||||||
token = cls.generate_invite_token(tenant, account)
|
token = cls.generate_invite_token(tenant, account)
|
||||||
|
|
||||||
# send email
|
# send email
|
||||||
|
|||||||
Reference in New Issue
Block a user