mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 06:35:55 +08:00
feat: add workspace/member limit errors and enforce email login restriction
- Add WorkspacesLimitExceededError and WorkspaceMembersLimitExceededError - Add workspace creation limit for email login
This commit is contained in:
parent
67b7d87cc9
commit
1c549ddbaa
@ -7,7 +7,12 @@ from flask_restful import Resource, reqparse # type: ignore
|
||||
from constants.languages import languages
|
||||
from controllers.console import api
|
||||
from controllers.console.auth.error import EmailCodeError, InvalidEmailError, InvalidTokenError, PasswordMismatchError
|
||||
from controllers.console.error import AccountInFreezeError, AccountNotFound, EmailSendIpLimitError
|
||||
from controllers.console.error import (
|
||||
AccountInFreezeError,
|
||||
AccountNotFound,
|
||||
EmailSendIpLimitError,
|
||||
WorkspacesLimitExceeded,
|
||||
)
|
||||
from controllers.console.wraps import setup_required
|
||||
from events.tenant_event import tenant_was_created
|
||||
from extensions.ext_database import db
|
||||
@ -18,7 +23,6 @@ from services.account_service import AccountService, TenantService
|
||||
from services.errors.account import AccountRegisterError
|
||||
from services.errors.workspace import WorkSpaceNotAllowedCreateError, WorkspacesLimitExceededError
|
||||
from services.feature_service import FeatureService
|
||||
from controllers.console.error import WorkspacesLimitExceeded
|
||||
|
||||
|
||||
class ForgotPasswordSendEmailApi(Resource):
|
||||
|
@ -60,7 +60,7 @@ class MemberInviteEmailApi(Resource):
|
||||
workspace_members = FeatureService.get_features(tenant_id=inviter.current_tenant.id).workspace_members
|
||||
if (
|
||||
FeatureService.get_system_features().license.product_id == "DIFY_ENTERPRISE_STANDARD"
|
||||
and workspace_members.limit != 0 # if limit == 0, it means unlimited
|
||||
and workspace_members.limit != 0 # if limit == 0, it means unlimited
|
||||
and len(invitee_emails) > workspace_members.limit - workspace_members.size
|
||||
):
|
||||
raise WorkspaceMembersLimitExceeded()
|
||||
|
@ -14,7 +14,7 @@ class EnterpriseMail(Resource):
|
||||
@inner_api_only
|
||||
def post(self):
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument("to", type=str, action='append', required=True)
|
||||
parser.add_argument("to", type=str, action="append", required=True)
|
||||
parser.add_argument("subject", type=str, required=True)
|
||||
parser.add_argument("body", type=str, required=True)
|
||||
parser.add_argument("substitutions", type=dict, required=False)
|
||||
|
@ -53,9 +53,7 @@ from services.errors.workspace import WorkSpaceNotAllowedCreateError, Workspaces
|
||||
from services.feature_service import FeatureService
|
||||
from tasks.delete_account_task import delete_account_task
|
||||
from tasks.mail_account_deletion_task import send_account_deletion_verification_code
|
||||
from tasks.mail_email_code_login import send_email_code_login_mail_task
|
||||
from tasks.mail_invite_member_task import send_invite_member_mail_task
|
||||
from tasks.mail_reset_password_task import send_reset_password_mail_task
|
||||
|
||||
|
||||
class TokenPair(BaseModel):
|
||||
@ -590,7 +588,7 @@ class TenantService:
|
||||
workspaces = FeatureService.get_system_features().license.workspaces
|
||||
if (
|
||||
FeatureService.get_system_features().license.product_id == "DIFY_ENTERPRISE_STANDARD"
|
||||
and workspaces.limit != 0 # if limit == 0, it means unlimited
|
||||
and workspaces.limit != 0 # if limit == 0, it means unlimited
|
||||
and workspaces.limit - workspaces.size <= 0
|
||||
):
|
||||
raise WorkspacesLimitExceededError()
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
from typing import Dict, List
|
||||
|
||||
from pydantic import BaseModel
|
||||
@ -14,13 +13,8 @@ class DifyMail(BaseModel):
|
||||
|
||||
|
||||
class EnterpriseMailService:
|
||||
|
||||
@classmethod
|
||||
def send_mail(cls, mail: DifyMail):
|
||||
|
||||
send_enterprise_email_task.delay(
|
||||
to=mail.to,
|
||||
subject=mail.subject,
|
||||
body=mail.body,
|
||||
substitutions=mail.substitutions
|
||||
to=mail.to, subject=mail.subject, body=mail.body, substitutions=mail.substitutions
|
||||
)
|
||||
|
@ -10,4 +10,4 @@ class WorkSpaceNotFoundError(BaseServiceError):
|
||||
|
||||
|
||||
class WorkspacesLimitExceededError(BaseServiceError):
|
||||
pass
|
||||
pass
|
||||
|
@ -13,9 +13,7 @@ def send_enterprise_email_task(to, subject, body, substitutions):
|
||||
if not mail.is_inited():
|
||||
return
|
||||
|
||||
logging.info(
|
||||
click.style("Start enterprise mail to {} with subject {}".format(to, subject), fg="green")
|
||||
)
|
||||
logging.info(click.style("Start enterprise mail to {} with subject {}".format(to, subject), fg="green"))
|
||||
start_at = time.perf_counter()
|
||||
|
||||
try:
|
||||
@ -29,9 +27,7 @@ def send_enterprise_email_task(to, subject, body, substitutions):
|
||||
|
||||
end_at = time.perf_counter()
|
||||
logging.info(
|
||||
click.style(
|
||||
"Send enterprise mail to {} succeeded: latency: {}".format(to, end_at - start_at), fg="green"
|
||||
)
|
||||
click.style("Send enterprise mail to {} succeeded: latency: {}".format(to, end_at - start_at), fg="green")
|
||||
)
|
||||
except Exception:
|
||||
logging.exception("Send enterprise mail to {} failed".format(to))
|
||||
|
Loading…
x
Reference in New Issue
Block a user