Skip to content

Commit

Permalink
feat: Group sessions by projects
Browse files Browse the repository at this point in the history
Show the project for read-only and provisioned sessions in the
Active Sessions overview.
  • Loading branch information
MoritzWeber0 committed Dec 2, 2024
1 parent f4b33e5 commit ba504d5
Show file tree
Hide file tree
Showing 23 changed files with 820 additions and 700 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

"""Add project scope to session table
Revision ID: 4cf566b4f986
Revises: 2f8449c217fa
Create Date: 2024-12-02 14:40:15.815359
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "4cf566b4f986"
down_revision = "2f8449c217fa"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
"sessions", sa.Column("project_id", sa.Integer(), nullable=True)
)
op.create_foreign_key(None, "sessions", "projects", ["project_id"], ["id"])
15 changes: 15 additions & 0 deletions backend/capellacollab/sessions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from capellacollab.core import database
from capellacollab.core import models as core_models
from capellacollab.core import pydantic as core_pydantic
from capellacollab.projects import models as projects_models
from capellacollab.sessions import models2 as sessions_models2
from capellacollab.sessions import operators
from capellacollab.tools import models as tools_models
Expand All @@ -24,6 +25,7 @@
from . import injection

if t.TYPE_CHECKING:
from capellacollab.projects.models import DatabaseProject
from capellacollab.projects.toolmodels.provisioning.models import (
DatabaseModelProvisioning,
)
Expand Down Expand Up @@ -131,6 +133,10 @@ class Session(core_pydantic.BaseModel):

shared_with: list[SessionSharing] = pydantic.Field(default=[])

project: projects_models.SimpleProject | None = pydantic.Field(
default=None
)

_validate_created_at = pydantic.field_serializer("created_at")(
core_pydantic.datetime_serializer
)
Expand Down Expand Up @@ -217,6 +223,15 @@ class DatabaseSession(database.Base):
)
)

project_id: orm.Mapped[int | None] = orm.mapped_column(
sa.ForeignKey("projects.id"),
init=False,
)
project: orm.Mapped[DatabaseProject | None] = orm.relationship(
foreign_keys=[project_id],
default=None,
)

environment: orm.Mapped[dict[str, str]] = orm.mapped_column(
nullable=False, default_factory=dict
)
Expand Down
1 change: 1 addition & 0 deletions backend/capellacollab/sessions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ async def request_session(
},
created_at=session["created_at"],
connection_method_id=connection_method.id,
project=project_scope,
),
)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/src/app/openapi/model/session.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 14 additions & 28 deletions frontend/src/app/sessions/service/session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { Injectable } from '@angular/core';
import { Observable, tap } from 'rxjs';
import {
Session,
SessionProvisioningRequest,
SessionsService,
SessionConnectionInformation,
FileTree,
SessionPreparationState,
SessionState,
PostSessionRequest,
} from 'src/app/openapi';
import { SessionHistoryService } from 'src/app/sessions/user-sessions-wrapper/create-sessions/create-session-history/session-history.service';

Expand All @@ -32,33 +32,19 @@ export class SessionService {
private sessionsService: SessionsService,
) {}

createSession(
toolId: number,
versionId: number,
connectionMethodId: string,
session_type: 'persistent' | 'readonly',
models: SessionProvisioningRequest[],
): Observable<Session> {
return this.sessionsService
.requestSession({
tool_id: toolId,
version_id: versionId,
connection_method_id: connectionMethodId,
session_type: session_type,
provisioning: models,
})
.pipe(
tap((session) => {
if (isPersistentSession(session)) {
this.sessionHistoryService.addSessionRequestToHistory({
toolId,
versionId,
connectionMethodId,
lastRequested: new Date(),
});
}
}),
);
createSession(request: PostSessionRequest): Observable<Session> {
return this.sessionsService.requestSession(request).pipe(
tap((session) => {
if (isPersistentSession(session)) {
this.sessionHistoryService.addSessionRequestToHistory({
toolId: request.tool_id,
versionId: request.version_id,
connectionMethodId: session.connection_method_id,
lastRequested: new Date(),
});
}
}),
);
}

setConnectionInformation(connectionInfo: SessionConnectionInformation): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
SessionState,
} from 'src/app/openapi';
import {
createPersistentSessionWithState,
mockPersistentSession,
mockReadonlySession,
} from 'src/storybook/session';
Expand Down Expand Up @@ -57,10 +56,9 @@ const sessions = [
mockPersistentSession,
{ ...mockReadonlySession, id: 'vjmczglcgeltbfcronujtelwx' },
{
...createPersistentSessionWithState(
SessionPreparationState.Failed,
SessionState.Pending,
),
...mockPersistentSession,
preparation_state: SessionPreparationState.Failed,
state: SessionState.Pending,
owner: {
...mockUser,
name: 'anotherUser',
Expand Down

This file was deleted.

Loading

0 comments on commit ba504d5

Please sign in to comment.