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 3, 2024
1 parent 5436a1d commit 3095dbe
Show file tree
Hide file tree
Showing 24 changed files with 971 additions and 750 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
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.

Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,47 @@
Learn how to use the diagram cache with capellambse!
</mat-panel-title>
</mat-expansion-panel-header>
<div class="mt-2">
You can also access the diagrams via our Python library
<i>capellambse</i>. Follow the installation instructions on
<a
target="_blank"
rel="noopener"
class="text-url"
href="https://github.com/DSD-DBS/py-capellambse#installation"
>Github<span class="align-middle"
><mat-icon class="scale-75">open_in_new</mat-icon></span
<div class="px-3 pb-3">
<div>
You can also access the diagrams via our Python library
<i>capellambse</i>. Follow the installation instructions on
<a
target="_blank"
rel="noopener"
class="text-url"
href="https://github.com/DSD-DBS/py-capellambse#installation"
>Github<span class="align-middle"
><mat-icon class="scale-75">open_in_new</mat-icon></span
>
</a>
and then use the code snippet. To authenticate, you have to insert a
personal access token. The token has the same scope as your user. Be
careful with it. You can revoke the token in the settings.
</div>
<pre><code
class="language-python my-2 rounded-md border shadow"
[innerHTML]="this.codeBlockContent | highlight: 'python'"
></code></pre>
<div class="flex flex-wrap gap-2">
<button
[cdkCopyToClipboard]="this.codeBlockContent"
matTooltip="Copy codeblock to clipboard"
color="bg-transparent"
mat-raised-button
(click)="showClipboardMessage()"
>
</a>
and then use the code snippet. To authenticate, you have to insert a
personal access token. The token has the same scope as your user. Be careful
with it. You can revoke the token in the settings.
</div>
<pre><code
class="language-python my-2 rounded-md border shadow"
[innerHTML]="this.codeBlockContent | highlight: 'python'"
></code></pre>
<div class="flex flex-wrap gap-2">
<button
[cdkCopyToClipboard]="this.codeBlockContent"
matTooltip="Copy codeblock to clipboard"
color="bg-transparent"
mat-raised-button
(click)="showClipboardMessage()"
>
<mat-icon class="!m-0">content_copy</mat-icon>
</button>
<button
class="mt-auto self-end text-white"
(click)="insertToken()"
[disabled]="passwordValue"
matTooltip="Insert new personal access token for your user"
color="primary"
mat-raised-button
>
Insert token
</button>
<mat-icon class="!m-0">content_copy</mat-icon>
</button>
<button
class="mt-auto self-end text-white"
(click)="insertToken()"
[disabled]="passwordValue"
matTooltip="Insert new personal access token for your user"
color="primary"
mat-raised-button
>
Insert token
</button>
</div>
</div>
</mat-expansion-panel>
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 3095dbe

Please sign in to comment.