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 8, 2024
1 parent c72825a commit 4c8b767
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 63 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
58 changes: 39 additions & 19 deletions amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ msgstr ""
msgid "There is one error:"
msgstr ""

#: amt/site/templates/layouts/base.html.j2:1
#: amt/site/templates/layouts/base.html.j2:11
msgid "Algorithmic Management Toolkit (AMT)"
msgstr ""

Expand Down Expand Up @@ -323,10 +323,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 @@ -502,28 +502,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 @@ -687,14 +715,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.
58 changes: 39 additions & 19 deletions amt/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ msgstr ""
msgid "There is one error:"
msgstr ""

#: amt/site/templates/layouts/base.html.j2:1
#: amt/site/templates/layouts/base.html.j2:11
msgid "Algorithmic Management Toolkit (AMT)"
msgstr ""

Expand Down 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 @@ -503,28 +503,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 @@ -688,14 +716,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.
60 changes: 41 additions & 19 deletions amt/locale/nl_NL/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ msgstr "Er zijn enkele fouten"
msgid "There is one error:"
msgstr "Er is één fout:"

#: amt/site/templates/layouts/base.html.j2:1
#: amt/site/templates/layouts/base.html.j2:11
msgid "Algorithmic Management Toolkit (AMT)"
msgstr "Algoritme Management Toolkit (AMT)"

Expand Down Expand Up @@ -332,10 +332,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 @@ -527,28 +527,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 @@ -719,14 +749,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
Loading

0 comments on commit 4c8b767

Please sign in to comment.