From f40e41ae8beeaef893cb8ed441c66a35c9ce3e2b Mon Sep 17 00:00:00 2001 From: rr- Date: Fri, 29 Jul 2016 12:44:21 +0200 Subject: [PATCH] server/tags: allow deleting used tags --- API.md | 1 - server/szurubooru/api/tag_api.py | 4 ---- server/szurubooru/tests/api/test_tag_deleting.py | 15 ++++++++------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/API.md b/API.md index e5b8571..cb827dd 100644 --- a/API.md +++ b/API.md @@ -486,7 +486,6 @@ data. - **Errors** - the tag does not exist - - the tag is used by some posts - privileges are too low - **Description** diff --git a/server/szurubooru/api/tag_api.py b/server/szurubooru/api/tag_api.py index 72e29ff..c532266 100644 --- a/server/szurubooru/api/tag_api.py +++ b/server/szurubooru/api/tag_api.py @@ -90,10 +90,6 @@ class TagDetailApi(BaseApi): def delete(self, ctx, tag_name): tag = tags.get_tag_by_name(tag_name) - if tag.post_count > 0: - raise tags.TagIsInUseError( - 'Tag has some usages and cannot be deleted. ' + - 'Please untag relevant posts first.') auth.verify_privilege(ctx.user, 'tags:delete') snapshots.save_entity_deletion(tag, ctx.user) tags.delete(tag) diff --git a/server/szurubooru/tests/api/test_tag_deleting.py b/server/szurubooru/tests/api/test_tag_deleting.py index 634962f..bb7cd49 100644 --- a/server/szurubooru/tests/api/test_tag_deleting.py +++ b/server/szurubooru/tests/api/test_tag_deleting.py @@ -31,18 +31,19 @@ def test_deleting(test_ctx): assert db.session.query(db.Tag).count() == 0 assert os.path.exists(os.path.join(config.config['data_dir'], 'tags.json')) -def test_trying_to_delete_used(test_ctx, post_factory): +def test_deleting_used(test_ctx, post_factory): tag = test_ctx.tag_factory(names=['tag']) post = post_factory() post.tags.append(tag) db.session.add_all([tag, post]) db.session.commit() - with pytest.raises(tags.TagIsInUseError): - test_ctx.api.delete( - test_ctx.context_factory( - user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), - 'tag') - assert db.session.query(db.Tag).count() == 1 + test_ctx.api.delete( + test_ctx.context_factory( + user=test_ctx.user_factory(rank=db.User.RANK_REGULAR)), + 'tag') + db.session.refresh(post) + assert db.session.query(db.Tag).count() == 0 + assert post.tags == [] def test_trying_to_delete_non_existing(test_ctx): with pytest.raises(tags.TagNotFoundError):