Skip to content

Commit

Permalink
Move permissions to own module to avoid circular imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Aug 25, 2023
1 parent 7d56588 commit b756bb3
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 24 deletions.
22 changes: 8 additions & 14 deletions pydatalab/pydatalab/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Sequence, Type
from typing import TYPE_CHECKING, Dict, Sequence, Type

# These app imports will be replaced by dynamic plugins in a future version
from pydatalab.apps.chat.blocks import ChatBlock
Expand All @@ -8,17 +8,13 @@
from pydatalab.apps.raman import RamanBlock
from pydatalab.apps.tga import MassSpecBlock
from pydatalab.apps.xrd import XRDBlock
from pydatalab.blocks.base import (
DataBlock,
)
from pydatalab.blocks.common import (
CommentBlock,
MediaBlock,
NotSupportedBlock,
)

BLOCKS: Sequence[Type[DataBlock]] = (
DataBlock,
if TYPE_CHECKING:
from pydatalab.blocks.base import DataBlock

from pydatalab.blocks.common import CommentBlock, MediaBlock, NotSupportedBlock

BLOCKS: Sequence[Type["DataBlock"]] = (
CommentBlock,
MediaBlock,
XRDBlock,
Expand All @@ -31,11 +27,9 @@
EISBlock,
)

BLOCK_TYPES: Dict[str, Type[DataBlock]] = {block.blocktype: block for block in BLOCKS}
BLOCK_TYPES["test"] = DataBlock
BLOCK_TYPES: Dict[str, Type["DataBlock"]] = {block.blocktype: block for block in BLOCKS}

__all__ = (
"DataBlock",
"CommentBlock",
"MediaBlock",
"XRDBlock",
Expand Down
8 changes: 4 additions & 4 deletions pydatalab/pydatalab/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pydatalab.models import File
from pydatalab.models.utils import PyObjectId
from pydatalab.mongo import flask_mongo
from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions

FILE_DIRECTORY = CONFIG.FILE_DIRECTORY
DIRECTORIES_DICT = {fs.name: fs for fs in CONFIG.REMOTE_FILESYSTEMS}
Expand Down Expand Up @@ -302,7 +302,7 @@ def save_uploaded_file(
last_modified should be an isodate format. if last_modified is None, the current time will be inserted
"""

from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions

sample_collection = flask_mongo.db.items
file_collection = flask_mongo.db.files
Expand Down Expand Up @@ -388,7 +388,7 @@ def save_uploaded_file(


def add_file_from_remote_directory(file_entry, item_id, block_ids=None):
from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions

file_collection = flask_mongo.db.files
sample_collection = flask_mongo.db.items
Expand Down Expand Up @@ -504,7 +504,7 @@ def remove_file_from_sample(item_id: Union[str, ObjectId], file_id: Union[str, O
file_id: The database ID of the file to remove from the item.
"""
from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions

item_id, file_id = ObjectId(item_id), ObjectId(file_id)
sample_collection = flask_mongo.db.items
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions pydatalab/pydatalab/routes/v0_1/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from flask import jsonify, request

from pydatalab.blocks import BLOCK_TYPES, DataBlock
from pydatalab.blocks import BLOCK_TYPES
from pydatalab.blocks.base import DataBlock
from pydatalab.logger import LOGGER
from pydatalab.mongo import flask_mongo
from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions


def add_data_block():
Expand Down
2 changes: 1 addition & 1 deletion pydatalab/pydatalab/routes/v0_1/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydatalab.logger import logged_route
from pydatalab.models.collections import Collection
from pydatalab.mongo import flask_mongo
from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions
from pydatalab.routes.v0_1.items import creators_lookup, get_samples_summary

collection = Blueprint("collections", __name__)
Expand Down
2 changes: 1 addition & 1 deletion pydatalab/pydatalab/routes/v0_1/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pydatalab.mongo
from pydatalab import file_utils
from pydatalab.config import CONFIG
from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions


def get_file(file_id: str, filename: str):
Expand Down
2 changes: 1 addition & 1 deletion pydatalab/pydatalab/routes/v0_1/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from flask import jsonify, request

from pydatalab.mongo import flask_mongo
from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions


def get_graph_cy_format(item_id: Optional[str] = None, collection_id: Optional[str] = None):
Expand Down
2 changes: 1 addition & 1 deletion pydatalab/pydatalab/routes/v0_1/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pydatalab.models.relationships import RelationshipType
from pydatalab.models.utils import generate_unique_refcode
from pydatalab.mongo import flask_mongo
from pydatalab.routes.utils import get_default_permissions
from pydatalab.permissions import get_default_permissions


def reserialize_blocks(display_order: List[str], blocks_obj: Dict[str, Dict]) -> Dict[str, Dict]:
Expand Down

0 comments on commit b756bb3

Please sign in to comment.