-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from MerginMaps/delete_project_by_id
Delete project by id
- Loading branch information
Showing
12 changed files
with
182 additions
and
21 deletions.
There are no files selected for viewing
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 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 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 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,67 @@ | ||
openapi: 3.0.0 | ||
info: | ||
description: Mergin API to synchronize your GIS data. | ||
version: "0.6" | ||
title: Mergin API | ||
servers: | ||
- url: /v2 | ||
tags: | ||
- name: project | ||
description: Mergin project | ||
paths: | ||
/project/{id}: | ||
delete: | ||
tags: | ||
- project | ||
summary: Delete project immediately | ||
operationId: delete_project_now | ||
parameters: | ||
- $ref: "#/components/parameters/ProjectId" | ||
responses: | ||
"204": | ||
$ref: "#/components/responses/NoContent" | ||
"400": | ||
$ref: "#/components/responses/BadRequest" | ||
"403": | ||
$ref: "#/components/responses/Unauthorized" | ||
"404": | ||
$ref: "#/components/responses/NotFound" | ||
x-openapi-router-controller: mergin.sync.public_api_v2_controller | ||
/project/{id}/scheduleDelete: | ||
delete: | ||
tags: | ||
- project | ||
summary: Schedule project to delete | ||
operationId: schedule_delete_project | ||
parameters: | ||
- $ref: "#/components/parameters/ProjectId" | ||
responses: | ||
"204": | ||
$ref: "#/components/responses/NoContent" | ||
"400": | ||
$ref: "#/components/responses/BadRequest" | ||
"403": | ||
$ref: "#/components/responses/Unauthorized" | ||
"404": | ||
$ref: "#/components/responses/NotFound" | ||
x-openapi-router-controller: mergin.sync.public_api_v2_controller | ||
components: | ||
responses: | ||
NoContent: | ||
description: No content | ||
BadRequest: | ||
description: Invalid request. | ||
Unauthorized: | ||
description: Authentication information is missing or invalid | ||
NotFound: | ||
description: Not found | ||
parameters: | ||
ProjectId: | ||
name: id | ||
in: path | ||
description: UUID of the project | ||
required: true | ||
schema: | ||
type: string | ||
format: uuid | ||
pattern: \b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b |
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,45 @@ | ||
# Copyright (C) Lutra Consulting Limited | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial | ||
|
||
from datetime import datetime | ||
|
||
from connexion import NoContent | ||
from flask import abort | ||
from flask_login import current_user | ||
|
||
from mergin import db | ||
from mergin.auth import auth_required | ||
from mergin.sync.models import Project | ||
from mergin.sync.permissions import ProjectPermissions, require_project_by_uuid | ||
|
||
|
||
@auth_required | ||
def schedule_delete_project(id_): | ||
"""Schedule deletion of the project. | ||
Celery job `mergin.sync.tasks.remove_projects_backups` does the | ||
rest. | ||
:param id_: Project id | ||
:type id_: str | ||
""" | ||
project = require_project_by_uuid(id_, ProjectPermissions.Delete) | ||
project.removed_at = datetime.utcnow() | ||
project.removed_by = current_user.username | ||
db.session.commit() | ||
|
||
return NoContent, 204 | ||
|
||
|
||
@auth_required | ||
def delete_project_now(id_): | ||
"""Delete the project immediately. | ||
:param id_: Project id | ||
:type id_: str | ||
""" | ||
project = require_project_by_uuid(id_, ProjectPermissions.Delete, scheduled=True) | ||
db.session.delete(project) | ||
db.session.commit() | ||
|
||
return NoContent, 204 |
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 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,39 @@ | ||
# Copyright (C) Lutra Consulting Limited | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial | ||
|
||
from mergin.sync.models import Project | ||
from tests import test_project, test_workspace_id | ||
|
||
|
||
def test_schedule_delete_project(client): | ||
project = Project.query.filter_by( | ||
workspace_id=test_workspace_id, name=test_project | ||
).first() | ||
response = client.delete(f"v2/project/{project.id}/scheduleDelete") | ||
assert response.status_code == 204 | ||
updated = Project.query.get(project.id) | ||
assert updated.removed_at and updated.removed_by | ||
response = client.delete(f"v2/project/{project.id}/scheduleDelete") | ||
assert response.status_code == 404 | ||
|
||
|
||
def test_delete_project_now(client): | ||
project = Project.query.filter_by( | ||
workspace_id=test_workspace_id, name=test_project | ||
).first() | ||
response = client.delete(f"v2/project/{project.id}") | ||
assert response.status_code == 204 | ||
assert not Project.query.get(project.id) | ||
response = client.delete(f"v2/project/{project.id}") | ||
assert response.status_code == 404 | ||
|
||
|
||
def test_delete_after_schedule(client): | ||
project = Project.query.filter_by( | ||
workspace_id=test_workspace_id, name=test_project | ||
).first() | ||
response = client.delete(f"v2/project/{project.id}/scheduleDelete") | ||
assert response.status_code == 204 | ||
response = client.delete(f"v2/project/{project.id}") | ||
assert response.status_code == 204 |