def test_merging_deletion_to_modification_or_creation(fake_datetime, tag_factory, user_factory, initial_operation): tag = tag_factory(names=['dummy'], category_name='dummy') user = user_factory() db.session.add_all([tag, user]) db.session.flush() with fake_datetime('13:00:00'): initial_operation(tag, user) tag.names = [db.TagName('changed')] with fake_datetime('14:00:00'): snapshots.save_entity_modification(tag, user) tag.names = [db.TagName('changed again')] with fake_datetime('14:00:01'): snapshots.save_entity_deletion(tag, user) assert db.session.query(db.Snapshot).count() == 2 results = db.session \ .query(db.Snapshot) \ .order_by(db.Snapshot.snapshot_id.asc()) \ .all() assert results[1].operation == db.Snapshot.OPERATION_DELETED assert results[1].data == { 'names': ['changed again'], 'category': 'dummy', 'suggestions': [], 'implications': [], }
def test_merging_deletion_to_modification_or_creation( fake_datetime, tag_factory, user_factory, initial_operation): tag = tag_factory(names=['dummy'], category_name='dummy') user = user_factory() db.session.add_all([tag, user]) db.session.flush() with fake_datetime('13:00:00'): initial_operation(tag, user) tag.names = [db.TagName('changed')] with fake_datetime('14:00:00'): snapshots.save_entity_modification(tag, user) tag.names = [db.TagName('changed again')] with fake_datetime('14:00:01'): snapshots.save_entity_deletion(tag, user) assert db.session.query(db.Snapshot).count() == 2 results = db.session \ .query(db.Snapshot) \ .order_by(db.Snapshot.snapshot_id.asc()) \ .all() assert results[1].operation == db.Snapshot.OPERATION_DELETED assert results[1].data == { 'names': ['changed again'], 'category': 'dummy', 'suggestions': [], 'implications': [], }
def delete(self, ctx, post_id): auth.verify_privilege(ctx.user, 'posts:delete') post = posts.get_post_by_id(post_id) snapshots.save_entity_deletion(post, ctx.user) ctx.session.delete(post) ctx.session.commit() tags.export_to_json() return {}
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) ctx.session.commit() tags.export_to_json() return {}
def post(self, ctx): source_tag_name = ctx.get_param_as_string('remove', required=True) or '' target_tag_name = ctx.get_param_as_string('mergeTo', required=True) or '' source_tag = tags.get_tag_by_name(source_tag_name) target_tag = tags.get_tag_by_name(target_tag_name) if source_tag.tag_id == target_tag.tag_id: raise tags.InvalidTagRelationError('Cannot merge tag with itself.') auth.verify_privilege(ctx.user, 'tags:merge') snapshots.save_entity_deletion(source_tag, ctx.user) tags.merge_tags(source_tag, target_tag) ctx.session.commit() tags.export_to_json() return tags.serialize_tag_with_details(target_tag)
def test_merging_deletion_all_the_way_deletes_all_snapshots( fake_datetime, tag_factory, user_factory, expected_operation): tag = tag_factory(names=['dummy']) user = user_factory() db.session.add_all([tag, user]) db.session.flush() with fake_datetime('13:00:00'): snapshots.save_entity_creation(tag, user) tag.names = [db.TagName('changed')] with fake_datetime('13:00:01'): snapshots.save_entity_modification(tag, user) tag.names = [db.TagName('changed again')] with fake_datetime('13:00:02'): snapshots.save_entity_deletion(tag, user) assert db.session.query(db.Snapshot).count() == 0
def delete(self, ctx, category_name): category = tag_categories.get_category_by_name(category_name) auth.verify_privilege(ctx.user, 'tag_categories:delete') if len(tag_categories.get_all_category_names()) == 1: raise tag_categories.TagCategoryIsInUseError( 'Cannot delete the default category.') if category.tag_count > 0: raise tag_categories.TagCategoryIsInUseError( 'Tag category has some usages and cannot be deleted. ' + 'Please remove this category from relevant tags first..') snapshots.save_entity_deletion(category, ctx.user) ctx.session.delete(category) ctx.session.commit() tags.export_to_json() return {}