server/tags: allow deleting used tags

This commit is contained in:
rr- 2016-07-29 12:44:21 +02:00
parent f63851e2cf
commit f40e41ae8b
3 changed files with 8 additions and 12 deletions

1
API.md
View file

@ -486,7 +486,6 @@ data.
- **Errors**
- the tag does not exist
- the tag is used by some posts
- privileges are too low
- **Description**

View file

@ -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)

View file

@ -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
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):