server/tags: allow deleting used tags
This commit is contained in:
parent
f63851e2cf
commit
f40e41ae8b
1
API.md
1
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**
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue