Skip to content

Commit

Permalink
feat: move login_required wrapper outside (#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
takatost authored Oct 8, 2023
1 parent b711ce3 commit 0242508
Show file tree
Hide file tree
Showing 32 changed files with 44 additions and 65 deletions.
2 changes: 1 addition & 1 deletion api/controllers/console/apikey.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
import flask_restful
from flask_restful import Resource, fields, marshal_with
from werkzeug.exceptions import Forbidden
Expand Down
7 changes: 2 additions & 5 deletions api/controllers/console/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import logging
from datetime import datetime

import flask
from flask_login import current_user
from core.login.login import login_required
from flask_restful import Resource, reqparse, fields, marshal_with, abort, inputs
from libs.login import login_required
from flask_restful import Resource, reqparse, marshal_with, abort, inputs
from werkzeug.exceptions import Forbidden

from constants.model_template import model_templates, demo_model_templates
Expand All @@ -17,11 +16,9 @@
from core.model_providers.error import ProviderTokenNotInitError, LLMBadRequestError
from core.model_providers.model_factory import ModelFactory
from core.model_providers.model_provider_factory import ModelProviderFactory
from core.model_providers.models.entity.model_params import ModelType
from events.app_event import app_was_created, app_was_deleted
from fields.app_fields import app_pagination_fields, app_detail_fields, template_list_fields, \
app_detail_fields_with_site
from libs.helper import TimestampField
from extensions.ext_database import db
from models.model import App, AppModelConfig, Site
from services.app_model_config_service import AppModelConfigService
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/app/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging

from flask import request
from core.login.login import login_required
from werkzeug.exceptions import InternalServerError, NotFound
from libs.login import login_required
from werkzeug.exceptions import InternalServerError

import services
from controllers.console import api
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/app/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import flask_login
from flask import Response, stream_with_context
from core.login.login import login_required
from libs.login import login_required
from werkzeug.exceptions import InternalServerError, NotFound

import services
Expand Down
6 changes: 3 additions & 3 deletions api/controllers/console/app/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytz
from flask_login import current_user
from core.login.login import login_required
from flask_restful import Resource, reqparse, fields, marshal_with
from libs.login import login_required
from flask_restful import Resource, reqparse, marshal_with
from flask_restful.inputs import int_range
from sqlalchemy import or_, func
from sqlalchemy.orm import joinedload
Expand All @@ -15,7 +15,7 @@
from controllers.console.wraps import account_initialization_required
from fields.conversation_fields import conversation_pagination_fields, conversation_detail_fields, \
conversation_message_detail_fields, conversation_with_summary_pagination_fields
from libs.helper import TimestampField, datetime_string, uuid_value
from libs.helper import datetime_string
from extensions.ext_database import db
from models.model import Message, MessageAnnotation, Conversation

Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/app/generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, reqparse

from controllers.console import api
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/app/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from controllers.console.wraps import account_initialization_required
from core.model_providers.error import LLMRateLimitError, LLMBadRequestError, LLMAuthorizationError, LLMAPIConnectionError, \
ProviderTokenNotInitError, LLMAPIUnavailableError, QuotaExceededError, ModelCurrentlyNotSupportError
from core.login.login import login_required
from libs.login import login_required
from fields.conversation_fields import message_detail_fields
from libs.helper import uuid_value, TimestampField
from libs.helper import uuid_value
from libs.infinite_scroll_pagination import InfiniteScrollPagination
from extensions.ext_database import db
from models.model import MessageAnnotation, Conversation, Message, MessageFeedback
Expand Down
3 changes: 1 addition & 2 deletions api/controllers/console/app/model_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding:utf-8 -*-
import json

from flask import request
from flask_restful import Resource
Expand All @@ -9,7 +8,7 @@
from controllers.console.app import _get_app
from controllers.console.setup import setup_required
from controllers.console.wraps import account_initialization_required
from core.login.login import login_required
from libs.login import login_required
from events.app_event import app_model_config_was_updated
from extensions.ext_database import db
from models.model import AppModelConfig
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/app/site.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding:utf-8 -*-
from flask_login import current_user
from core.login.login import login_required
from flask_restful import Resource, reqparse, fields, marshal_with
from libs.login import login_required
from flask_restful import Resource, reqparse, marshal_with
from werkzeug.exceptions import NotFound, Forbidden

from controllers.console import api
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/app/statistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytz
from flask import jsonify
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, reqparse

from controllers.console import api
Expand Down
7 changes: 2 additions & 5 deletions api/controllers/console/auth/data_source_oauth.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import logging
from datetime import datetime
from typing import Optional

import flask_login
import requests
from flask import request, redirect, current_app, session
from flask import request, redirect, current_app
from flask_login import current_user

from flask_restful import Resource
from werkzeug.exceptions import Forbidden

from core.login.login import login_required
from libs.login import login_required
from libs.oauth_data_source import NotionOAuth
from controllers.console import api
from ..setup import setup_required
Expand Down
7 changes: 3 additions & 4 deletions api/controllers/console/datasets/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import json

from cachetools import TTLCache
from flask import request, current_app
from flask import request
from flask_login import current_user
from core.login.login import login_required
from flask_restful import Resource, marshal_with, fields, reqparse, marshal
from libs.login import login_required
from flask_restful import Resource, marshal_with, reqparse
from werkzeug.exceptions import NotFound

from controllers.console import api
Expand All @@ -15,7 +15,6 @@
from core.indexing_runner import IndexingRunner
from extensions.ext_database import db
from fields.data_source_fields import integrate_notion_info_list_fields, integrate_list_fields
from libs.helper import TimestampField
from models.dataset import Document
from models.source import DataSourceBinding
from services.dataset_service import DatasetService, DocumentService
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/datasets/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from flask_login import current_user

from controllers.console.apikey import api_key_list, api_key_fields
from core.login.login import login_required
from flask_restful import Resource, reqparse, fields, marshal, marshal_with
from libs.login import login_required
from flask_restful import Resource, reqparse, marshal, marshal_with
from werkzeug.exceptions import NotFound, Forbidden
import services
from controllers.console import api
Expand Down
4 changes: 1 addition & 3 deletions api/controllers/console/datasets/datasets_document.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding:utf-8 -*-
import random
from datetime import datetime
from typing import List

from flask import request, current_app
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, fields, marshal, marshal_with, reqparse
from sqlalchemy import desc, asc
from werkzeug.exceptions import NotFound, Forbidden
Expand All @@ -25,7 +24,6 @@
from extensions.ext_redis import redis_client
from fields.document_fields import document_with_segments_fields, document_fields, \
dataset_and_document_fields, document_status_fields
from libs.helper import TimestampField
from extensions.ext_database import db
from models.dataset import DatasetProcessRule, Dataset
from models.dataset import Document, DocumentSegment
Expand Down
3 changes: 1 addition & 2 deletions api/controllers/console/datasets/datasets_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
from controllers.console.wraps import account_initialization_required
from core.model_providers.error import LLMBadRequestError, ProviderTokenNotInitError
from core.model_providers.model_factory import ModelFactory
from core.login.login import login_required
from libs.login import login_required
from extensions.ext_database import db
from extensions.ext_redis import redis_client
from fields.segment_fields import segment_fields
from models.dataset import DocumentSegment

from libs.helper import TimestampField
from services.dataset_service import DatasetService, DocumentService, SegmentService
from tasks.enable_segment_to_index_task import enable_segment_to_index_task
from tasks.disable_segment_from_index_task import disable_segment_from_index_task
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/console/datasets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from flask import request, current_app

import services
from core.login.login import login_required
from flask_restful import Resource, marshal_with, fields
from libs.login import login_required
from flask_restful import Resource, marshal_with

from controllers.console import api
from controllers.console.datasets.error import NoFileUploadedError, TooManyFilesError, FileTooLargeError, \
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/datasets/hit_testing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, reqparse, marshal
from werkzeug.exceptions import InternalServerError, NotFound, Forbidden

Expand Down
5 changes: 2 additions & 3 deletions api/controllers/console/explore/installed_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from datetime import datetime

from flask_login import current_user
from core.login.login import login_required
from flask_restful import Resource, reqparse, fields, marshal_with, inputs
from libs.login import login_required
from flask_restful import Resource, reqparse, marshal_with, inputs
from sqlalchemy import and_
from werkzeug.exceptions import NotFound, Forbidden, BadRequest

Expand All @@ -12,7 +12,6 @@
from controllers.console.wraps import account_initialization_required
from extensions.ext_database import db
from fields.installed_app_fields import installed_app_list_fields
from libs.helper import TimestampField
from models.model import App, InstalledApp, RecommendedApp
from services.account_service import TenantService

Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/explore/recommended_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding:utf-8 -*-
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, fields, marshal_with
from sqlalchemy import and_

Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/explore/wraps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource
from functools import wraps

Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/universal_chat/wraps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import wraps

from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource
from controllers.console.setup import setup_required
from controllers.console.wraps import account_initialization_required
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/workspace/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytz
from flask import current_app, request
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, reqparse, fields, marshal_with

from services.errors.account import CurrentPasswordIncorrectError as ServiceCurrentPasswordIncorrectError
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/workspace/members.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding:utf-8 -*-
from flask import current_app
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, reqparse, marshal_with, abort, fields, marshal

import services
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/workspace/model_providers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, reqparse
from werkzeug.exceptions import Forbidden

Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/workspace/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, reqparse

from controllers.console import api
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/workspace/providers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding:utf-8 -*-
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, reqparse
from werkzeug.exceptions import Forbidden

Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/workspace/tool_providers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, abort, reqparse
from werkzeug.exceptions import Forbidden

Expand Down
3 changes: 1 addition & 2 deletions api/controllers/console/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from flask import request
from flask_login import current_user
from core.login.login import login_required
from libs.login import login_required
from flask_restful import Resource, fields, marshal_with, reqparse, marshal, inputs
from flask_restful.inputs import int_range

from controllers.console import api
from controllers.console.admin import admin_required
Expand Down
5 changes: 1 addition & 4 deletions api/controllers/service_api/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
from controllers.service_api import api
from controllers.service_api.dataset.error import DatasetNameDuplicateError
from controllers.service_api.wraps import DatasetApiResource
from core.login.login import current_user
from libs.login import current_user
from core.model_providers.models.entity.model_params import ModelType
from extensions.ext_database import db
from fields.dataset_fields import dataset_detail_fields
from models.account import Account, TenantAccountJoin
from models.dataset import Dataset
from services.dataset_service import DatasetService
from services.provider_service import ProviderService

Expand Down
8 changes: 2 additions & 6 deletions api/controllers/service_api/dataset/document.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import datetime
import json
import uuid

from flask import current_app, request
from flask import request
from flask_restful import reqparse, marshal
from sqlalchemy import desc
from werkzeug.exceptions import NotFound
Expand All @@ -13,13 +11,11 @@
from controllers.service_api.dataset.error import ArchivedDocumentImmutableError, DocumentIndexingError, \
NoFileUploadedError, TooManyFilesError
from controllers.service_api.wraps import DatasetApiResource
from core.login.login import current_user
from libs.login import current_user
from core.model_providers.error import ProviderTokenNotInitError
from extensions.ext_database import db
from extensions.ext_storage import storage
from fields.document_fields import document_fields, document_status_fields
from models.dataset import Dataset, Document, DocumentSegment
from models.model import UploadFile
from services.dataset_service import DocumentService
from services.file_service import FileService

Expand Down
3 changes: 1 addition & 2 deletions api/controllers/service_api/wraps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from flask_restful import Resource
from werkzeug.exceptions import NotFound, Unauthorized

from core.login.login import _get_user
from libs.login import _get_user
from extensions.ext_database import db
from models.account import Tenant, TenantAccountJoin, Account
from models.dataset import Dataset
from models.model import ApiToken, App


Expand Down
File renamed without changes.

0 comments on commit 0242508

Please sign in to comment.