Преглед на файлове

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

Garfield Dai преди 1 година
родител
ревизия
51f23c5dc2
променени са 2 файла, в които са добавени 14 реда и са изтрити 14 реда
  1. 6 11
      api/controllers/console/workspace/members.py
  2. 8 3
      api/services/account_service.py

+ 6 - 11
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',

+ 8 - 3
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)