Skip to content

Commit

Permalink
Merge pull request #1105 from DSD-DBS/add-user-profile
Browse files Browse the repository at this point in the history
feat: Add user profile page
  • Loading branch information
MoritzWeber0 authored Dec 11, 2023
2 parents 5e6c6de + c671633 commit 1d4175f
Show file tree
Hide file tree
Showing 34 changed files with 581 additions and 225 deletions.
2 changes: 1 addition & 1 deletion backend/capellacollab/core/authentication/jwt_bearer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from jose import jwt

import capellacollab.users.crud as users_crud
import capellacollab.users.events.crud as events_crud
from capellacollab.config import config
from capellacollab.core import database
from capellacollab.events import crud as events_crud

from . import get_authentication_entrypoint

Expand Down
2 changes: 1 addition & 1 deletion backend/capellacollab/core/database/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from capellacollab.config import config
from capellacollab.core import database
from capellacollab.events import crud as events_crud
from capellacollab.projects import crud as projects_crud
from capellacollab.projects import models as project_models
from capellacollab.projects.toolmodels import crud as toolmodels_crud
Expand All @@ -39,7 +40,6 @@
from capellacollab.tools.integrations import models as integrations_models
from capellacollab.users import crud as users_crud
from capellacollab.users import models as users_models
from capellacollab.users.events import crud as events_crud

LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion backend/capellacollab/core/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# pylint: disable=unused-import
# These import statements of the models are required and should not be removed! (SQLAlchemy will not load the models otherwise)

import capellacollab.events.models
import capellacollab.notices.models
import capellacollab.projects.models
import capellacollab.projects.toolmodels.backups.models
Expand All @@ -19,6 +20,5 @@
import capellacollab.settings.modelsources.t4c.models
import capellacollab.tools.integrations.models
import capellacollab.tools.models
import capellacollab.users.events.models
import capellacollab.users.models
import capellacollab.users.tokens
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from capellacollab.projects import models as projects_models
from capellacollab.users import models as users_models
from capellacollab.users.events import models

from . import models


def create_event(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ class HistoryEvent(BaseHistoryEvent):
id: int


class UserHistory(users_models.User):
created: datetime.datetime | None = None
last_login: datetime.datetime | None = None
events: list[HistoryEvent] | None = None

_validate_created = pydantic.field_serializer("created")(
core_pydantic.datetime_serializer
)
_validate_last_login = pydantic.field_serializer("last_login")(
core_pydantic.datetime_serializer
)


class DatabaseUserHistoryEvent(database.Base):
__tablename__ = "user_history_events"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@

from capellacollab.core import database
from capellacollab.core.authentication import injectables as auth_injectables
from capellacollab.users import injectables as users_injectables
from capellacollab.users import models as users_model
from capellacollab.users import models as users_models

from . import crud, models

router = fastapi.APIRouter(
dependencies=[
fastapi.Depends(
auth_injectables.RoleVerification(
required_role=users_model.Role.ADMIN
required_role=users_models.Role.USER
)
)
]
)


@router.get("/history/events", response_model=list[models.HistoryEvent])
@router.get(
"",
response_model=list[models.HistoryEvent],
dependencies=[
fastapi.Depends(
auth_injectables.RoleVerification(
required_role=users_models.Role.ADMIN
)
)
],
)
def get_events(
db: orm.Session = fastapi.Depends(database.get_db),
) -> abc.Sequence[models.DatabaseUserHistoryEvent]:
return crud.get_events(db)


@router.get("/{user_id}/history", response_model=models.UserHistory)
def get_user_history(
user: users_model.DatabaseUser = fastapi.Depends(
users_injectables.get_existing_user
),
) -> users_model.DatabaseUser:
return user
10 changes: 5 additions & 5 deletions backend/capellacollab/projects/events/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import sqlalchemy as sa
from sqlalchemy import orm

from capellacollab.events import models as events_models
from capellacollab.projects import models as projects_models
from capellacollab.users.events import models as users_events_models


def get_events_per_project_paginated(
db: orm.Session, project: projects_models.DatabaseProject
) -> fastapi_pagination.Page[users_events_models.DatabaseUserHistoryEvent]:
) -> fastapi_pagination.Page[events_models.DatabaseUserHistoryEvent]:
return fastapi_pagination.ext.sqlalchemy.paginate(
db,
sa.select(users_events_models.DatabaseUserHistoryEvent)
.where(users_events_models.DatabaseUserHistoryEvent.project == project)
.order_by(users_events_models.DatabaseUserHistoryEvent.id.desc()),
sa.select(events_models.DatabaseUserHistoryEvent)
.where(events_models.DatabaseUserHistoryEvent.project == project)
.order_by(events_models.DatabaseUserHistoryEvent.id.desc()),
)
6 changes: 3 additions & 3 deletions backend/capellacollab/projects/events/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

from capellacollab.core import database
from capellacollab.core.authentication import injectables as auth_injectables
from capellacollab.events import models as events_models
from capellacollab.projects import injectables as projects_injectables
from capellacollab.projects import models as projects_models
from capellacollab.projects.users import models as projects_users_models
from capellacollab.users.events import models as users_events_models

from . import crud

Expand All @@ -27,14 +27,14 @@

@router.get(
"",
response_model=fastapi_pagination.Page[users_events_models.HistoryEvent],
response_model=fastapi_pagination.Page[events_models.HistoryEvent],
)
def get_events(
db: orm.Session = fastapi.Depends(database.get_db),
project: projects_models.DatabaseProject = fastapi.Depends(
projects_injectables.get_existing_project
),
) -> fastapi_pagination.Page[users_events_models.DatabaseUserHistoryEvent]:
) -> fastapi_pagination.Page[events_models.DatabaseUserHistoryEvent]:
return crud.get_events_per_project_paginated(db, project)


Expand Down
2 changes: 1 addition & 1 deletion backend/capellacollab/projects/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from capellacollab.core import database
from capellacollab.core import logging as core_logging
from capellacollab.core.authentication import injectables as auth_injectables
from capellacollab.events import crud as events_crud
from capellacollab.projects import injectables as projects_injectables
from capellacollab.projects.events import routes as projects_events_routes
from capellacollab.projects.toolmodels import routes as toolmodels_routes
Expand All @@ -24,7 +25,6 @@
from capellacollab.sessions import routes as session_routes
from capellacollab.users import injectables as users_injectables
from capellacollab.users import models as users_models
from capellacollab.users.events import crud as events_crud

from . import crud, models

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from capellacollab.settings.modelsources.t4c.repositories import (
injectables as settings_t4c_repositories_injectables,
)
from capellacollab.users import models as users_model
from capellacollab.users import models as users_models

from . import crud, injectables, models

Expand Down Expand Up @@ -67,7 +67,7 @@ def get_t4c_model(
dependencies=[
fastapi.Depends(
auth_injectables.RoleVerification(
required_role=users_model.Role.ADMIN
required_role=users_models.Role.ADMIN
)
)
],
Expand Down Expand Up @@ -102,7 +102,7 @@ def create_t4c_model(
dependencies=[
fastapi.Depends(
auth_injectables.RoleVerification(
required_role=users_model.Role.ADMIN
required_role=users_models.Role.ADMIN
)
)
],
Expand Down
4 changes: 2 additions & 2 deletions backend/capellacollab/projects/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

from capellacollab.core import database
from capellacollab.core.authentication import injectables as auth_injectables
from capellacollab.events import crud as events_crud
from capellacollab.events import models as events_models
from capellacollab.projects import injectables as projects_injectables
from capellacollab.projects import models as projects_models
from capellacollab.users import crud as users_crud
from capellacollab.users import exceptions as users_exceptions
from capellacollab.users import injectables as users_injectables
from capellacollab.users import models as users_models
from capellacollab.users.events import crud as events_crud
from capellacollab.users.events import models as events_models

from . import crud, injectables, models, util

Expand Down
4 changes: 2 additions & 2 deletions backend/capellacollab/projects/users/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from sqlalchemy import orm

from capellacollab.events import crud as events_crud
from capellacollab.events import models as events_models
from capellacollab.projects import models as projects_models
from capellacollab.users import models as users_models
from capellacollab.users.events import crud as events_crud
from capellacollab.users.events import models as events_models

from . import models

Expand Down
7 changes: 7 additions & 0 deletions backend/capellacollab/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from capellacollab.core import authentication
from capellacollab.core import metadata as core_metadata
from capellacollab.core.authentication import responses as auth_responses
from capellacollab.events import routes as events_router
from capellacollab.health import routes as health_routes
from capellacollab.notices import routes as notices_routes
from capellacollab.projects import routes as projects_routes
Expand Down Expand Up @@ -52,6 +53,12 @@
responses=auth_responses.AUTHENTICATION_RESPONSES,
tags=["Users"],
)
router.include_router(
events_router.router,
prefix="/events",
responses=auth_responses.AUTHENTICATION_RESPONSES,
tags=["Events"],
)
router.include_router(
notices_routes.router, prefix="/notices", tags=["Notices"]
)
Expand Down
4 changes: 2 additions & 2 deletions backend/capellacollab/tools/integrations/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from capellacollab.core import database
from capellacollab.core.authentication import injectables as auth_injectables
from capellacollab.users import models as users_model
from capellacollab.users import models as users_models

from .. import injectables as tools_injectables
from .. import models as tools_models
Expand All @@ -16,7 +16,7 @@
dependencies=[
fastapi.Depends(
auth_injectables.RoleVerification(
required_role=users_model.Role.ADMIN
required_role=users_models.Role.ADMIN
)
)
]
Expand Down
12 changes: 11 additions & 1 deletion backend/capellacollab/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from sqlalchemy import orm

from capellacollab.core import database
from capellacollab.core import pydantic as core_pydantic

if t.TYPE_CHECKING:
from capellacollab.events.models import DatabaseUserHistoryEvent
from capellacollab.projects.users.models import ProjectUserAssociation
from capellacollab.sessions.models import DatabaseSession
from capellacollab.users.events.models import DatabaseUserHistoryEvent
from capellacollab.users.tokens.models import DatabaseUserToken


Expand All @@ -33,6 +34,15 @@ class BaseUser(pydantic.BaseModel):

class User(BaseUser):
id: int
created: datetime.datetime | None = None
last_login: datetime.datetime | None = None

_validate_created = pydantic.field_serializer("created")(
core_pydantic.datetime_serializer
)
_validate_last_login = pydantic.field_serializer("last_login")(
core_pydantic.datetime_serializer
)


class PatchUserRoleRequest(pydantic.BaseModel):
Expand Down
Loading

0 comments on commit 1d4175f

Please sign in to comment.