mirror of https://github.com/langgenius/dify.git
refactor(api): fix pyright check
- Replaced `is_editor` checks with `has_edit_permission` in `workflow_trigger.py` and `workflow.py` to enhance clarity and consistency in permission handling. - Updated the rate limiter to use `datetime.now(UTC)` instead of `datetime.utcnow()` for accurate time handling. - Added `__all__` declaration in `trigger/__init__.py` for better module export management. - Initialized `debug_dispatched` variable in `trigger_processing_tasks.py` to ensure proper tracking during workflow dispatching. These changes improve code readability and maintainability while ensuring correct permission checks and time management.
This commit is contained in:
parent
aef862d9ce
commit
452588dded
|
|
@ -1041,7 +1041,7 @@ class DraftWorkflowTriggerNodeApi(Resource):
|
|||
"""
|
||||
Poll for trigger events and execute single node when event arrives
|
||||
"""
|
||||
if not isinstance(current_user, Account) or not current_user.is_editor:
|
||||
if not isinstance(current_user, Account) or not current_user.has_edit_permission:
|
||||
raise Forbidden()
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
|
|
@ -1119,7 +1119,7 @@ class DraftWorkflowTriggerRunApi(Resource):
|
|||
"""
|
||||
Poll for trigger events and execute full workflow when event arrives
|
||||
"""
|
||||
if not isinstance(current_user, Account) or not current_user.is_editor:
|
||||
if not isinstance(current_user, Account) or not current_user.has_edit_permission:
|
||||
raise Forbidden()
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class AppTriggerEnableApi(Resource):
|
|||
|
||||
assert isinstance(current_user, Account)
|
||||
assert current_user.current_tenant_id is not None
|
||||
if not current_user.is_editor:
|
||||
if not current_user.has_edit_permission:
|
||||
raise Forbidden()
|
||||
|
||||
trigger_id = args["trigger_id"]
|
||||
|
|
|
|||
|
|
@ -5,3 +5,8 @@ bp = Blueprint("trigger", __name__, url_prefix="/triggers")
|
|||
|
||||
# Import routes after blueprint creation to avoid circular imports
|
||||
from . import trigger, webhook
|
||||
|
||||
__all__ = [
|
||||
"trigger",
|
||||
"webhook",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Day-based rate limiter for workflow executions.
|
|||
Implements UTC-based daily quotas that reset at midnight UTC for consistent rate limiting.
|
||||
"""
|
||||
|
||||
from datetime import datetime, time, timedelta
|
||||
from datetime import UTC, datetime, time, timedelta
|
||||
from typing import Union
|
||||
|
||||
import pytz
|
||||
|
|
@ -173,7 +173,7 @@ class TenantDailyRateLimiter:
|
|||
Datetime when quota resets (next UTC midnight in tenant's timezone)
|
||||
"""
|
||||
tz = pytz.timezone(timezone_str)
|
||||
utc_now = datetime.utcnow()
|
||||
utc_now = datetime.now(UTC)
|
||||
|
||||
# Get next midnight in UTC, then convert to tenant's timezone
|
||||
next_utc_midnight = datetime.combine(utc_now.date() + timedelta(days=1), time.min)
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ def dispatch_triggered_workflows_async(
|
|||
continue
|
||||
|
||||
# Dispatch to debug sessions after processing all triggers
|
||||
debug_dispatched = 0
|
||||
try:
|
||||
debug_dispatched = TriggerDebugService.dispatch_debug_event(
|
||||
tenant_id=subscription.tenant_id,
|
||||
|
|
|
|||
Loading…
Reference in New Issue