Delete thumbnails and post source immediately on post delete
This commit is contained in:
parent
a1fbeb91a0
commit
0815c99740
5 changed files with 34 additions and 10 deletions
|
@ -399,7 +399,9 @@ def _after_post_update(
|
||||||
def _before_post_delete(
|
def _before_post_delete(
|
||||||
_mapper: Any, _connection: Any, post: model.Post) -> None:
|
_mapper: Any, _connection: Any, post: model.Post) -> None:
|
||||||
if post.post_id:
|
if post.post_id:
|
||||||
image_hash.delete_image(post.post_id)
|
image_hash.delete_image(str(post.post_id))
|
||||||
|
files.delete(get_post_content_path(post))
|
||||||
|
files.delete(get_post_thumbnail_path(post))
|
||||||
|
|
||||||
|
|
||||||
def _sync_post_content(post: model.Post) -> None:
|
def _sync_post_content(post: model.Post) -> None:
|
||||||
|
@ -686,12 +688,14 @@ def merge_posts(
|
||||||
merge_favorites(source_post.post_id, target_post.post_id)
|
merge_favorites(source_post.post_id, target_post.post_id)
|
||||||
merge_relations(source_post.post_id, target_post.post_id)
|
merge_relations(source_post.post_id, target_post.post_id)
|
||||||
|
|
||||||
delete(source_post)
|
content = None
|
||||||
|
|
||||||
db.session.flush()
|
|
||||||
|
|
||||||
if replace_content:
|
if replace_content:
|
||||||
content = files.get(get_post_content_path(source_post))
|
content = files.get(get_post_content_path(source_post))
|
||||||
|
|
||||||
|
delete(source_post)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
|
if content is not None:
|
||||||
update_post_content(target_post, content)
|
update_post_content(target_post, content)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from szurubooru import api, db, model, errors
|
from szurubooru import api, db, model, errors
|
||||||
from szurubooru.func import posts, tags, snapshots
|
from szurubooru.func import posts, snapshots
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def inject_config(config_injector):
|
def inject_config(config_injector):
|
||||||
config_injector({'privileges': {'posts:delete': model.User.RANK_REGULAR}})
|
config_injector({'secret': 'secret', 'data_dir': '', 'privileges': {'posts:delete': model.User.RANK_REGULAR}})
|
||||||
|
|
||||||
|
|
||||||
def test_deleting(user_factory, post_factory, context_factory):
|
def test_deleting(user_factory, post_factory, context_factory):
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import os
|
|
||||||
from unittest.mock import patch
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from szurubooru import db, model
|
from szurubooru import db, model
|
||||||
from szurubooru.func import (
|
from szurubooru.func import (
|
||||||
posts, users, comments, tags, images, files, util, image_hash)
|
posts, users, comments, tags, images, files, util, image_hash)
|
||||||
|
@ -936,6 +938,6 @@ def test_merge_posts_replaces_content(
|
||||||
assert posts.try_get_post_by_id(source_post.post_id) is None
|
assert posts.try_get_post_by_id(source_post.post_id) is None
|
||||||
post = posts.get_post_by_id(target_post.post_id)
|
post = posts.get_post_by_id(target_post.post_id)
|
||||||
assert post is not None
|
assert post is not None
|
||||||
assert os.path.exists(source_path)
|
assert not os.path.exists(source_path)
|
||||||
assert os.path.exists(target_path1)
|
assert os.path.exists(target_path1)
|
||||||
assert not os.path.exists(target_path2)
|
assert not os.path.exists(target_path2)
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from szurubooru import db, model
|
from szurubooru import db, model
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def inject_config(config_injector):
|
||||||
|
config_injector({'secret': 'secret', 'data_dir': ''})
|
||||||
|
|
||||||
|
|
||||||
def test_saving_post(post_factory, user_factory, tag_factory):
|
def test_saving_post(post_factory, user_factory, tag_factory):
|
||||||
user = user_factory()
|
user = user_factory()
|
||||||
tag1 = tag_factory()
|
tag1 = tag_factory()
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from szurubooru import db, model
|
from szurubooru import db, model
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def inject_config(config_injector):
|
||||||
|
config_injector({'secret': 'secret', 'data_dir': ''})
|
||||||
|
|
||||||
|
|
||||||
def test_saving_tag(tag_factory):
|
def test_saving_tag(tag_factory):
|
||||||
sug1 = tag_factory(names=['sug1'])
|
sug1 = tag_factory(names=['sug1'])
|
||||||
sug2 = tag_factory(names=['sug2'])
|
sug2 = tag_factory(names=['sug2'])
|
||||||
|
|
Loading…
Reference in a new issue