-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
1,439 additions
and
804 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
backend/capellacollab/alembic/versions/ca9ce61491a7_make_announcements_dismissible.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""Make announcements dismissible | ||
Revision ID: ca9ce61491a7 | ||
Revises: 8731ac0b284e | ||
Create Date: 2025-02-07 19:42:01.723097 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ca9ce61491a7" | ||
down_revision = "8731ac0b284e" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.rename_table("notices", "announcements") | ||
|
||
op.add_column( | ||
"announcements", sa.Column("dismissible", sa.Boolean(), nullable=True) | ||
) | ||
op.execute("UPDATE announcements SET dismissible = false") | ||
op.alter_column("announcements", "dismissible", nullable=False) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
from collections import abc | ||
|
||
import sqlalchemy as sa | ||
from sqlalchemy import orm | ||
|
||
from capellacollab.announcements import models | ||
|
||
|
||
def get_announcements( | ||
db: orm.Session, | ||
) -> abc.Sequence[models.DatabaseAnnouncement]: | ||
return db.execute(sa.select(models.DatabaseAnnouncement)).scalars().all() | ||
|
||
|
||
def get_announcement_by_id( | ||
db: orm.Session, announcement_id: int | ||
) -> models.DatabaseAnnouncement | None: | ||
return db.execute( | ||
sa.select(models.DatabaseAnnouncement).where( | ||
models.DatabaseAnnouncement.id == announcement_id | ||
) | ||
).scalar_one_or_none() | ||
|
||
|
||
def create_announcement( | ||
db: orm.Session, body: models.CreateAnnouncementRequest | ||
) -> models.DatabaseAnnouncement: | ||
announcement = models.DatabaseAnnouncement(**body.model_dump()) | ||
db.add(announcement) | ||
db.commit() | ||
return announcement | ||
|
||
|
||
def update_announcement( | ||
db: orm.Session, | ||
announcement: models.DatabaseAnnouncement, | ||
body: models.CreateAnnouncementRequest, | ||
) -> models.DatabaseAnnouncement: | ||
for field, value in body.model_dump().items(): | ||
setattr(announcement, field, value) | ||
db.commit() | ||
return announcement | ||
|
||
|
||
def delete_announcement( | ||
db: orm.Session, announcement: models.DatabaseAnnouncement | ||
) -> None: | ||
db.delete(announcement) | ||
db.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import fastapi | ||
from sqlalchemy import orm | ||
|
||
from capellacollab.announcements import crud, models | ||
from capellacollab.core import database | ||
|
||
from . import exceptions | ||
|
||
|
||
def get_existing_announcement( | ||
announcement_id: int, | ||
db: orm.Session = fastapi.Depends(database.get_db), | ||
) -> models.DatabaseAnnouncement: | ||
if announcement := crud.get_announcement_by_id(db, announcement_id): | ||
return announcement | ||
|
||
raise exceptions.AnnouncementNotFoundError(announcement_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import fastapi | ||
from sqlalchemy import orm | ||
|
||
from capellacollab.core import database | ||
from capellacollab.permissions import injectables as permissions_injectables | ||
from capellacollab.permissions import models as permissions_models | ||
|
||
from . import crud, injectables, models | ||
|
||
router = fastapi.APIRouter() | ||
|
||
|
||
@router.get( | ||
"", | ||
response_model=list[models.AnnouncementResponse], | ||
) | ||
def get_announcements(db: orm.Session = fastapi.Depends(database.get_db)): | ||
return crud.get_announcements(db) | ||
|
||
|
||
@router.get("/{announcement_id}") | ||
def get_announcement_by_id( | ||
announcement: models.DatabaseAnnouncement = fastapi.Depends( | ||
injectables.get_existing_announcement | ||
), | ||
): | ||
return announcement | ||
|
||
|
||
@router.post( | ||
"", | ||
dependencies=[ | ||
fastapi.Depends( | ||
permissions_injectables.PermissionValidation( | ||
required_scope=permissions_models.GlobalScopes( | ||
admin=permissions_models.AdminScopes( | ||
announcements={permissions_models.UserTokenVerb.CREATE} | ||
) | ||
) | ||
), | ||
) | ||
], | ||
) | ||
def create_announcement( | ||
post_announcement: models.CreateAnnouncementRequest, | ||
db: orm.Session = fastapi.Depends(database.get_db), | ||
): | ||
return crud.create_announcement(db, post_announcement) | ||
|
||
|
||
@router.patch( | ||
"/{announcement_id}", | ||
dependencies=[ | ||
fastapi.Depends( | ||
permissions_injectables.PermissionValidation( | ||
required_scope=permissions_models.GlobalScopes( | ||
admin=permissions_models.AdminScopes( | ||
announcements={permissions_models.UserTokenVerb.UPDATE} | ||
) | ||
) | ||
), | ||
) | ||
], | ||
) | ||
def update_announcement( | ||
post_announcement: models.CreateAnnouncementRequest, | ||
announcement: models.DatabaseAnnouncement = fastapi.Depends( | ||
injectables.get_existing_announcement | ||
), | ||
db: orm.Session = fastapi.Depends(database.get_db), | ||
): | ||
return crud.update_announcement(db, announcement, post_announcement) | ||
|
||
|
||
@router.delete( | ||
"/{announcement_id}", | ||
status_code=204, | ||
dependencies=[ | ||
fastapi.Depends( | ||
permissions_injectables.PermissionValidation( | ||
required_scope=permissions_models.GlobalScopes( | ||
admin=permissions_models.AdminScopes( | ||
announcements={permissions_models.UserTokenVerb.DELETE} | ||
) | ||
) | ||
), | ||
) | ||
], | ||
) | ||
def delete_announcement( | ||
announcement: models.DatabaseAnnouncement = fastapi.Depends( | ||
injectables.get_existing_announcement | ||
), | ||
db: orm.Session = fastapi.Depends(database.get_db), | ||
): | ||
crud.delete_announcement(db, announcement) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.