Skip to content

Commit

Permalink
Add project soft delete
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed Nov 11, 2024
1 parent 0bbb4af commit c43ba36
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 60 deletions.
10 changes: 10 additions & 0 deletions amt/api/routes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,16 @@ def find_requirement_tasks_by_measure_urn(system_card: SystemCard, measure_urn:
return requirement_tasks


@router.delete("/{project_id}")
async def delete_project(
request: Request,
project_id: int,
projects_service: Annotated[ProjectsService, Depends(ProjectsService)],
) -> HTMLResponse:
await projects_service.delete(project_id)
return templates.Redirect(request, "/algorithm-systems/")


@router.get("/{project_id}/measure/{measure_urn}")
async def get_measure(
request: Request,
Expand Down
56 changes: 38 additions & 18 deletions amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ msgid "Reviewing"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:32
#: amt/site/templates/projects/details_base.html.j2:29
#: amt/site/templates/projects/details_base.html.j2:55
#: amt/site/templates/projects/details_base.html.j2:84
#: amt/site/templates/projects/details_base.html.j2:107
#: amt/site/templates/projects/details_base.html.j2:74
#: amt/site/templates/projects/details_base.html.j2:100
#: amt/site/templates/projects/details_base.html.j2:129
#: amt/site/templates/projects/details_base.html.j2:152
msgid "Done"
msgstr ""

Expand Down Expand Up @@ -499,28 +499,56 @@ msgstr ""
msgid "Select group by"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:19
msgid "Delete algoritmic system"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:26
msgid "Are you sure you want to delete your algoritmic system "
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:30
msgid ""
"Data will be stored for at least 45 days before permanent\n"
" deletion."
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:39
#: amt/site/templates/projects/new.html.j2:132
msgid "Yes"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:44
#: amt/site/templates/projects/new.html.j2:142
msgid "No"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:57
msgid "Delete algorithm system"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:71
msgid "Does the algorithm meet the requirements?"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:51
#: amt/site/templates/projects/details_base.html.j2:105
#: amt/site/templates/projects/details_base.html.j2:96
#: amt/site/templates/projects/details_base.html.j2:150
msgid "To do"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:53
#: amt/site/templates/projects/details_base.html.j2:98
msgid "In progress"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:70
#: amt/site/templates/projects/details_base.html.j2:115
msgid "Go to all requirements"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:81
#: amt/site/templates/projects/details_base.html.j2:126
msgid "Which instruments are executed?"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:122
#: amt/site/templates/projects/details_base.html.j2:167
msgid "Go to all instruments"
msgstr ""

Expand Down Expand Up @@ -684,14 +712,6 @@ msgstr ""
msgid "Find your AI Act profile"
msgstr ""

#: amt/site/templates/projects/new.html.j2:132
msgid "Yes"
msgstr ""

#: amt/site/templates/projects/new.html.j2:142
msgid "No"
msgstr ""

#: amt/site/templates/projects/new.html.j2:151
msgid ""
"Overview of instruments for the responsible development, deployment, "
Expand Down
Binary file modified amt/locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
56 changes: 38 additions & 18 deletions amt/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ msgid "Reviewing"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:32
#: amt/site/templates/projects/details_base.html.j2:29
#: amt/site/templates/projects/details_base.html.j2:55
#: amt/site/templates/projects/details_base.html.j2:84
#: amt/site/templates/projects/details_base.html.j2:107
#: amt/site/templates/projects/details_base.html.j2:74
#: amt/site/templates/projects/details_base.html.j2:100
#: amt/site/templates/projects/details_base.html.j2:129
#: amt/site/templates/projects/details_base.html.j2:152
msgid "Done"
msgstr ""

Expand Down Expand Up @@ -500,28 +500,56 @@ msgstr ""
msgid "Select group by"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:19
msgid "Delete algoritmic system"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:26
msgid "Are you sure you want to delete your algoritmic system "
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:30
msgid ""
"Data will be stored for at least 45 days before permanent\n"
" deletion."
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:39
#: amt/site/templates/projects/new.html.j2:132
msgid "Yes"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:44
#: amt/site/templates/projects/new.html.j2:142
msgid "No"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:57
msgid "Delete algorithm system"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:71
msgid "Does the algorithm meet the requirements?"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:51
#: amt/site/templates/projects/details_base.html.j2:105
#: amt/site/templates/projects/details_base.html.j2:96
#: amt/site/templates/projects/details_base.html.j2:150
msgid "To do"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:53
#: amt/site/templates/projects/details_base.html.j2:98
msgid "In progress"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:70
#: amt/site/templates/projects/details_base.html.j2:115
msgid "Go to all requirements"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:81
#: amt/site/templates/projects/details_base.html.j2:126
msgid "Which instruments are executed?"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:122
#: amt/site/templates/projects/details_base.html.j2:167
msgid "Go to all instruments"
msgstr ""

Expand Down Expand Up @@ -685,14 +713,6 @@ msgstr ""
msgid "Find your AI Act profile"
msgstr ""

#: amt/site/templates/projects/new.html.j2:132
msgid "Yes"
msgstr ""

#: amt/site/templates/projects/new.html.j2:142
msgid "No"
msgstr ""

#: amt/site/templates/projects/new.html.j2:151
msgid ""
"Overview of instruments for the responsible development, deployment, "
Expand Down
Binary file modified amt/locale/nl_NL/LC_MESSAGES/messages.mo
Binary file not shown.
58 changes: 40 additions & 18 deletions amt/locale/nl_NL/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ msgid "Reviewing"
msgstr "Beoordelen"

#: amt/site/templates/macros/tasks.html.j2:32
#: amt/site/templates/projects/details_base.html.j2:29
#: amt/site/templates/projects/details_base.html.j2:55
#: amt/site/templates/projects/details_base.html.j2:84
#: amt/site/templates/projects/details_base.html.j2:107
#: amt/site/templates/projects/details_base.html.j2:74
#: amt/site/templates/projects/details_base.html.j2:100
#: amt/site/templates/projects/details_base.html.j2:129
#: amt/site/templates/projects/details_base.html.j2:152
msgid "Done"
msgstr "Afgerond"

Expand Down Expand Up @@ -524,28 +524,58 @@ msgstr "Groeperen op"
msgid "Select group by"
msgstr "Selecteer groepering"

#: amt/site/templates/projects/details_base.html.j2:19
msgid "Delete algoritmic system"
msgstr "Verwijder Algoritmesysteem"

#: amt/site/templates/projects/details_base.html.j2:26
msgid "Are you sure you want to delete your algoritmic system "
msgstr "Weet u zeker dat u uw algoritmische systeem wilt verwijderen "

#: amt/site/templates/projects/details_base.html.j2:30
msgid ""
"Data will be stored for at least 45 days before permanent\n"
" deletion."
msgstr ""
"gegevens worden minimaal 45 dagen bewaard voordat ze definitief worden\n"
" verwijderd."

#: amt/site/templates/projects/details_base.html.j2:39
#: amt/site/templates/projects/new.html.j2:132
msgid "Yes"
msgstr "Ja"

#: amt/site/templates/projects/details_base.html.j2:44
#: amt/site/templates/projects/new.html.j2:142
msgid "No"
msgstr "Nee"

#: amt/site/templates/projects/details_base.html.j2:57
msgid "Delete algorithm system"
msgstr "Verwijder Algoritmesysteem"

#: amt/site/templates/projects/details_base.html.j2:71
msgid "Does the algorithm meet the requirements?"
msgstr "Voldoet het algoritme aan de vereisten?"

#: amt/site/templates/projects/details_base.html.j2:51
#: amt/site/templates/projects/details_base.html.j2:105
#: amt/site/templates/projects/details_base.html.j2:96
#: amt/site/templates/projects/details_base.html.j2:150
msgid "To do"
msgstr "Te doen"

#: amt/site/templates/projects/details_base.html.j2:53
#: amt/site/templates/projects/details_base.html.j2:98
msgid "In progress"
msgstr "Onderhanden"

#: amt/site/templates/projects/details_base.html.j2:70
#: amt/site/templates/projects/details_base.html.j2:115
msgid "Go to all requirements"
msgstr "Ga naar alle Vereisten"

#: amt/site/templates/projects/details_base.html.j2:81
#: amt/site/templates/projects/details_base.html.j2:126
msgid "Which instruments are executed?"
msgstr "Welke instrumenten zijn uitgevoerd?"

#: amt/site/templates/projects/details_base.html.j2:122
#: amt/site/templates/projects/details_base.html.j2:167
msgid "Go to all instruments"
msgstr "Ga naar all instrumenten"

Expand Down Expand Up @@ -716,14 +746,6 @@ msgstr ""
msgid "Find your AI Act profile"
msgstr "Vind uw AI Act profiel"

#: amt/site/templates/projects/new.html.j2:132
msgid "Yes"
msgstr "Ja"

#: amt/site/templates/projects/new.html.j2:142
msgid "No"
msgstr "Nee"

#: amt/site/templates/projects/new.html.j2:151
msgid ""
"Overview of instruments for the responsible development, deployment, "
Expand Down
27 changes: 27 additions & 0 deletions amt/migrations/versions/6581a03aabec_add_deleted_at_to_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""add deleted_at to project
Revision ID: 6581a03aabec
Revises: 7f20f8562007
Create Date: 2024-11-01 10:29:58.930558
"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import sqlite

# revision identifiers, used by Alembic.
revision: str = "6581a03aabec"
down_revision: str | None = "7f20f8562007"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
op.add_column("project", sa.Column("deleted_at", sa.DateTime(), nullable=True))


def downgrade() -> None:
op.drop_column("project", "deleted_at")
1 change: 1 addition & 0 deletions amt/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Project(Base):
lifecycle: Mapped[Lifecycles | None] = mapped_column(ENUM(Lifecycles, name="lifecycle"), nullable=True)
system_card_json: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict)
last_edited: Mapped[datetime] = mapped_column(server_default=func.now(), onupdate=func.now(), nullable=False)
deleted_at: Mapped[datetime | None] = mapped_column(server_default=None, nullable=True)

def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401
system_card: SystemCard | None = kwargs.pop("system_card", None)
Expand Down
5 changes: 3 additions & 2 deletions amt/repositories/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, session: Annotated[AsyncSession, Depends(get_session)]) -> No
self.session = session

async def find_all(self) -> Sequence[Project]:
result = await self.session.execute(select(Project))
result = await self.session.execute(select(Project).where(Project.deleted_at.is_(None)))
return result.scalars().all()

async def delete(self, project: Project) -> None:
Expand Down Expand Up @@ -66,7 +66,7 @@ async def save(self, project: Project) -> Project:

async def find_by_id(self, project_id: int) -> Project:
try:
statement = select(Project).where(Project.id == project_id)
statement = select(Project).where(Project.id == project_id).where(Project.deleted_at.is_(None))
result = await self.session.execute(statement)
return result.scalars().one()
except NoResultFound as e:
Expand Down Expand Up @@ -103,6 +103,7 @@ async def paginate( # noqa
statement = statement.order_by(Project.last_edited.desc())
else:
statement = statement.order_by(func.lower(Project.name))
statement = statement.filter(Project.deleted_at.is_(None))
statement = statement.offset(skip).limit(limit)
db_result = await self.session.execute(statement)
result = list(db_result.scalars())
Expand Down
9 changes: 9 additions & 0 deletions amt/services/projects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from datetime import datetime
from functools import lru_cache
from os import listdir
from os.path import isfile, join
Expand Down Expand Up @@ -36,6 +37,14 @@ def __init__(

async def get(self, project_id: int) -> Project:
project = await self.repository.find_by_id(project_id)
if project.deleted_at:
raise AMTNotFound()
return project

async def delete(self, project_id: int) -> Project:
project = await self.repository.find_by_id(project_id)
project.deleted_at = datetime.now(tz=None) # noqa: DTZ005
project = await self.repository.save(project)
return project

async def create(self, project_new: ProjectNew) -> Project:
Expand Down
5 changes: 5 additions & 0 deletions amt/site/static/scss/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,8 @@ main {
color: var(--rvo-form-feedback-error-color);
font-weight: var(--rvo-form-feedback-error-font-weight);
}

.amt-flex-container {
display: flex;
justify-content: space-between;
}
Loading

0 comments on commit c43ba36

Please sign in to comment.