Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat: support re-invite email. (#2107)

Garfield Dai51f23c5dc2df
diff --git a/api/controllers/console/workspace/members.py b/api/controllers/console/workspace/members.py
index 9c6745db88d..54b307ae080 100644
--- a/api/controllers/console/workspace/members.py
+++ b/api/controllers/console/workspace/members.py
@@ -1,15 +1,16 @@
# -*- 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
from controllers.console import api
from controllers.console.setup import setup_required
from controllers.console.wraps import account_initialization_required, cloud_edition_billing_resource_check
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.login import login_required
-from models.account import Account, TenantAccountJoin
+from models.account import Account
from services.account_service import RegisterService, TenantService
account_fields = {
@@ -64,18 +65,12 @@ class MemberInviteEmailApi(Resource):
for invitee_email in invitee_emails:
try:
token = RegisterService.invite_new_member(inviter.current_tenant, invitee_email, role=invitee_role,
- 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
+ inviter=inviter)
invitation_results.append({
'status': 'success',
'email': invitee_email,
'url': f'{console_web_url}/activate?email={invitee_email}&token={token}'
})
- account = marshal(account, account_fields)
- account['role'] = role
except Exception as e:
invitation_results.append({
'status': 'failed',
diff --git a/api/services/account_service.py b/api/services/account_service.py
index a3dade998e1..b67796bf47e 100644
--- a/api/services/account_service.py
+++ b/api/services/account_service.py
@@ -464,16 +464,21 @@ class RegisterService:
account = AccountService.create_account(email, name)
account.status = AccountStatus.PENDING.value
db.session.commit()
+
+ TenantService.create_tenant_member(tenant, account, role)
else:
TenantService.check_member_permission(tenant, inviter, account, 'add')
ta = TenantAccountJoin.query.filter_by(
tenant_id=tenant.id,
account_id=account.id
).first()
- if ta:
- raise AccountAlreadyInTenantError("Account already in tenant.")
- TenantService.create_tenant_member(tenant, account, role)
+ if not ta:
+ 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)