def test_merge(tag_factory, user_factory): source_tag = tag_factory(names=['source']) target_tag = tag_factory(names=['target']) db.session.add_all([source_tag, target_tag]) db.session.flush() snapshots.merge(source_tag, target_tag, user_factory()) db.session.flush() result = db.session.query(model.Snapshot).one() assert result.operation == model.Snapshot.OPERATION_MERGED assert result.data == ['tag', 'target']
def test_merge(tag_factory, user_factory): source_tag = tag_factory(names=["source"]) target_tag = tag_factory(names=["target"]) db.session.add_all([source_tag, target_tag]) db.session.flush() with patch("szurubooru.func.snapshots._post_to_webhooks"): snapshots.merge(source_tag, target_tag, user_factory()) db.session.flush() result = db.session.query(model.Snapshot).one() assert result.operation == model.Snapshot.OPERATION_MERGED assert result.data == ["tag", "target"]
def merge_tags(ctx, _params=None): 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) versions.verify_version(source_tag, ctx, 'removeVersion') versions.verify_version(target_tag, ctx, 'mergeToVersion') versions.bump_version(target_tag) auth.verify_privilege(ctx.user, 'tags:merge') tags.merge_tags(source_tag, target_tag) snapshots.merge(source_tag, target_tag, ctx.user) ctx.session.commit() tags.export_to_json() return _serialize(ctx, target_tag)
def merge_pools(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: source_pool_id = ctx.get_param_as_string("remove") target_pool_id = ctx.get_param_as_string("mergeTo") source_pool = pools.get_pool_by_id(source_pool_id) target_pool = pools.get_pool_by_id(target_pool_id) versions.verify_version(source_pool, ctx, "removeVersion") versions.verify_version(target_pool, ctx, "mergeToVersion") versions.bump_version(target_pool) auth.verify_privilege(ctx.user, "pools:merge") pools.merge_pools(source_pool, target_pool) snapshots.merge(source_pool, target_pool, ctx.user) ctx.session.commit() return _serialize(ctx, target_pool)
def merge_tags( ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: source_tag_name = ctx.get_param_as_string('remove') target_tag_name = ctx.get_param_as_string('mergeTo') source_tag = tags.get_tag_by_name(source_tag_name) target_tag = tags.get_tag_by_name(target_tag_name) versions.verify_version(source_tag, ctx, 'removeVersion') versions.verify_version(target_tag, ctx, 'mergeToVersion') versions.bump_version(target_tag) auth.verify_privilege(ctx.user, 'tags:merge') tags.merge_tags(source_tag, target_tag) snapshots.merge(source_tag, target_tag, ctx.user) ctx.session.commit() return _serialize(ctx, target_tag)
def merge_tags(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: source_tag_name = ctx.get_param_as_string("remove") target_tag_name = ctx.get_param_as_string("mergeTo") source_tag = tags.get_tag_by_name(source_tag_name) target_tag = tags.get_tag_by_name(target_tag_name) versions.verify_version(source_tag, ctx, "removeVersion") versions.verify_version(target_tag, ctx, "mergeToVersion") versions.bump_version(target_tag) auth.verify_privilege(ctx.user, "tags:merge") tags.merge_tags(source_tag, target_tag) snapshots.merge(source_tag, target_tag, ctx.user) ctx.session.commit() return _serialize(ctx, target_tag)
def merge_posts(ctx, _params=None): source_post_id = ctx.get_param_as_string('remove', required=True) or '' target_post_id = ctx.get_param_as_string('mergeTo', required=True) or '' replace_content = ctx.get_param_as_bool('replaceContent') source_post = posts.get_post_by_id(source_post_id) target_post = posts.get_post_by_id(target_post_id) versions.verify_version(source_post, ctx, 'removeVersion') versions.verify_version(target_post, ctx, 'mergeToVersion') versions.bump_version(target_post) auth.verify_privilege(ctx.user, 'posts:merge') posts.merge_posts(source_post, target_post, replace_content) snapshots.merge(source_post, target_post, ctx.user) ctx.session.commit() return _serialize_post(ctx, target_post)
def merge_posts(ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: source_post_id = ctx.get_param_as_int('remove') target_post_id = ctx.get_param_as_int('mergeTo') source_post = posts.get_post_by_id(source_post_id) target_post = posts.get_post_by_id(target_post_id) replace_content = ctx.get_param_as_bool('replaceContent') versions.verify_version(source_post, ctx, 'removeVersion') versions.verify_version(target_post, ctx, 'mergeToVersion') versions.bump_version(target_post) auth.verify_privilege(ctx.user, 'posts:merge') posts.merge_posts(source_post, target_post, replace_content) snapshots.merge(source_post, target_post, ctx.user) ctx.session.commit() return _serialize_post(ctx, target_post)
def merge_posts( ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response: source_post_id = ctx.get_param_as_int('remove') target_post_id = ctx.get_param_as_int('mergeTo') source_post = posts.get_post_by_id(source_post_id) target_post = posts.get_post_by_id(target_post_id) replace_content = ctx.get_param_as_bool('replaceContent') versions.verify_version(source_post, ctx, 'removeVersion') versions.verify_version(target_post, ctx, 'mergeToVersion') versions.bump_version(target_post) auth.verify_privilege(ctx.user, 'posts:merge') posts.merge_posts(source_post, target_post, replace_content) snapshots.merge(source_post, target_post, ctx.user) ctx.session.commit() return _serialize_post(ctx, target_post)