-
Notifications
You must be signed in to change notification settings - Fork 61
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
35 changed files
with
692 additions
and
41 deletions.
There are no files selected for viewing
Binary file not shown.
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,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from taiga.base.django import apps | ||
|
||
|
||
class AttachmentConfig(apps.AppConfig): | ||
name = "taiga.attachments" | ||
label = "attachments" | ||
verbose_name = "Attachments" | ||
|
||
def ready(self) -> None: | ||
from taiga.attachments.signals import mark_attachment_file_to_delete | ||
from taiga.base.db.models import signals | ||
|
||
signals.post_delete.connect( | ||
mark_attachment_file_to_delete, | ||
sender="attachments.Attachment", | ||
dispatch_uid="mark_attachment_file_to_delete", | ||
) |
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,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from typing import Any | ||
|
||
from taiga.attachments.models import Attachment | ||
from taiga.base.db.models import Model | ||
from taiga.commons.storage import repositories as storage_repositories | ||
|
||
|
||
def mark_attachment_file_to_delete(sender: Model, instance: Attachment, **kwargs: Any) -> None: | ||
""" | ||
Mark the store object (with the file) of the attachment as deleted. | ||
""" | ||
storage_repositories.mark_storaged_object_as_deleted(storaged_object=instance.file) |
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,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from django.apps import AppConfig # noqa |
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,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC |
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,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from taiga.base.db import admin | ||
from taiga.commons.storage.models import StoragedObject | ||
|
||
|
||
@admin.register(StoragedObject) | ||
class StoragedObjectAdmin(admin.ModelAdmin[StoragedObject]): | ||
list_display = ( | ||
"file", | ||
"created_at", | ||
"deleted_at", | ||
) | ||
readonly_fields = ( | ||
"created_at", | ||
"deleted_at", | ||
) | ||
search_fields = ("file",) | ||
list_filter = ("created_at", "deleted_at") | ||
ordering = ("-created_at",) |
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,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# Copyright (c) 2023-present Kaleidos INC | ||
|
||
from datetime import timedelta | ||
|
||
import typer | ||
from taiga.base.utils import pprint | ||
from taiga.base.utils.concurrency import run_async_as_sync | ||
from taiga.base.utils.datetime import aware_utcnow | ||
from taiga.commons.storage import services as storage_services | ||
from taiga.conf import settings | ||
|
||
cli = typer.Typer( | ||
name="Taiga Storage commands", | ||
help="Manage the starege system of Taiga.", | ||
add_completion=True, | ||
) | ||
|
||
|
||
@cli.command(help="Clean deleted storaged object. Remove entries from DB and files from storage") | ||
def clean_storaged_objects( | ||
days_to_store_deleted_storaged_object: int = typer.Option( | ||
settings.STORAGE.DAYS_TO_STORE_DELETED_STORAGED_OBJECTS, | ||
"--days", | ||
"-d", | ||
help="Number of days to store deleted storaged objects", | ||
), | ||
) -> None: | ||
total_deleted = run_async_as_sync( | ||
storage_services.clean_deleted_storaged_objects( | ||
before=aware_utcnow() - timedelta(days=days_to_store_deleted_storaged_object) | ||
) | ||
) | ||
|
||
color = "red" if total_deleted else "white" | ||
pprint.print(f"Deleted [bold][{color}]{total_deleted}[/{color}][/bold] storaged objects.") |
Oops, something went wrong.