Skip to content

Projects implementation cleanup #1222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
303 changes: 171 additions & 132 deletions backend/app/deps/authorization_deps.py

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import logging

import uvicorn
from beanie import init_beanie
from fastapi import APIRouter, Depends, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from motor.motor_asyncio import AsyncIOMotorClient
from pydantic import BaseConfig

from app.config import settings
from app.keycloak_auth import get_current_username
from app.models.authorization import AuthorizationDB
Expand All @@ -26,6 +32,7 @@
MetadataDefinitionDB,
MetadataFreezeDB,
)
from app.models.projects import ProjectDB
from app.models.thumbnails import ThumbnailDB, ThumbnailDBViewList, ThumbnailFreezeDB
from app.models.tokens import TokenDB
from app.models.users import ListenerAPIKeyDB, UserAPIKeyDB, UserDB
Expand All @@ -48,6 +55,7 @@
files,
folders,
groups,
projects,
jobs,
keycloak,
licenses,
Expand All @@ -67,25 +75,19 @@
users,
visualization,
)

# setup loggers
# logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
from app.search.config import indexSettings
from app.search.connect import connect_elasticsearch, create_index
from beanie import init_beanie
from fastapi import APIRouter, Depends, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from motor.motor_asyncio import AsyncIOMotorClient
from pydantic import BaseConfig

logger = logging.getLogger(__name__)

app = FastAPI(
title=settings.APP_NAME,
openapi_url=f"{settings.API_V2_STR}/openapi.json",
description="A cloud native data management framework to support any research domain. Clowder was "
"developed to help researchers and scientists in data intensive domains manage raw data, complex "
"metadata, and automatic data pipelines. ",
"developed to help researchers and scientists in data intensive domains manage raw data, complex "
"metadata, and automatic data pipelines. ",
version="2.0.0-beta.2",
contact={"name": "Clowder", "url": "https://clowderframework.org/"},
license_info={
Expand Down Expand Up @@ -228,6 +230,11 @@
tags=["groups"],
dependencies=[Depends(get_current_username)],
)
api_router.include_router(
projects.router,
prefix="/projects",
tags=["projects"],
)
api_router.include_router(
visualization.router,
prefix="/visualizations",
Expand Down Expand Up @@ -303,6 +310,7 @@ async def startup_beanie():
UserAPIKeyDB,
ListenerAPIKeyDB,
GroupDB,
ProjectDB,
TokenDB,
ErrorDB,
VisualizationConfigDB,
Expand Down
17 changes: 15 additions & 2 deletions backend/app/models/groups.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
from enum import Enum
from typing import List, Optional

from beanie import Document, PydanticObjectId
from pydantic import BaseModel

from app.models.authorization import Provenance
from app.models.users import UserOut
from beanie import Document
from pydantic import BaseModel


class Member(BaseModel):
user: UserOut
editor: bool = False


class GroupType(str, Enum):
"""Certain group types will be hidden from common lists. For example, 'project' type groups are associated with
specific projects and used to track their membership; those groups are managed using the project interface, not
the groups interface."""

STANDARD = "standard"
PROJECT = "project"


class GroupBase(BaseModel):
name: str
description: Optional[str]
users: List[Member] = []
type: GroupType = GroupType.STANDARD
project_id: Optional[PydanticObjectId] = None


class GroupIn(GroupBase):
Expand Down
46 changes: 46 additions & 0 deletions backend/app/models/projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from datetime import datetime
from typing import List, Optional

from beanie import Document, PydanticObjectId
from pydantic import BaseModel, Field

from app.models.groups import GroupOut
from app.models.users import UserOut


class ProjectMember(BaseModel):
group: GroupOut
editor: bool = False


class ProjectBase(BaseModel):
"""Projects handle their membership and permissions with a group that is created with the project.
Members who are added to the project are added to this group. Other groups can also be added to the
project, but this one is a special one tied to the project - it cannot be deleted unless the project
is deleted (which deletes the associated group).

"""
name: str
description: Optional[str] = None
# Individual users are added to one of the project's hidden groups (viewers or editors)
viewers_group_id: Optional[PydanticObjectId] = None
editors_group_id: Optional[PydanticObjectId] = None
groups: List[ProjectMember] = []
dataset_ids: List[PydanticObjectId] = []


class ProjectDB(Document, ProjectBase):
creator: UserOut
created: datetime = Field(default_factory=datetime.utcnow)

class Settings:
name = "projects"


class ProjectIn(ProjectBase):
pass


class ProjectOut(ProjectDB):
class Config:
fields = {"id": "id"}
Loading
Loading