コード例 #1
0
ファイル: tag_api.py プロジェクト: stopsquarks/quarkman
def update_tag(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    tag = _get_tag(params)
    versions.verify_version(tag, ctx)
    versions.bump_version(tag)
    if ctx.has_param("names"):
        auth.verify_privilege(ctx.user, "tags:edit:names")
        tags.update_tag_names(tag, ctx.get_param_as_string_list("names"))
    if ctx.has_param("category"):
        auth.verify_privilege(ctx.user, "tags:edit:category")
        tags.update_tag_category_name(tag, ctx.get_param_as_string("category"))
    if ctx.has_param("description"):
        auth.verify_privilege(ctx.user, "tags:edit:description")
        tags.update_tag_description(tag,
                                    ctx.get_param_as_string("description"))
    if ctx.has_param("suggestions"):
        auth.verify_privilege(ctx.user, "tags:edit:suggestions")
        suggestions = ctx.get_param_as_string_list("suggestions")
        _create_if_needed(suggestions, ctx.user)
        tags.update_tag_suggestions(tag, suggestions)
    if ctx.has_param("implications"):
        auth.verify_privilege(ctx.user, "tags:edit:implications")
        implications = ctx.get_param_as_string_list("implications")
        _create_if_needed(implications, ctx.user)
        tags.update_tag_implications(tag, implications)
    tag.last_edit_time = datetime.utcnow()
    ctx.session.flush()
    snapshots.modify(tag, ctx.user)
    ctx.session.commit()
    return _serialize(ctx, tag)
コード例 #2
0
def update_tag(ctx, params):
    tag = tags.get_tag_by_name(params['tag_name'])
    versions.verify_version(tag, ctx)
    versions.bump_version(tag)
    if ctx.has_param('names'):
        auth.verify_privilege(ctx.user, 'tags:edit:names')
        tags.update_tag_names(tag, ctx.get_param_as_list('names'))
    if ctx.has_param('category'):
        auth.verify_privilege(ctx.user, 'tags:edit:category')
        tags.update_tag_category_name(
            tag, ctx.get_param_as_string('category'))
    if ctx.has_param('description'):
        auth.verify_privilege(ctx.user, 'tags:edit:description')
        tags.update_tag_description(
            tag, ctx.get_param_as_string('description', default=None))
    if ctx.has_param('suggestions'):
        auth.verify_privilege(ctx.user, 'tags:edit:suggestions')
        suggestions = ctx.get_param_as_list('suggestions')
        _create_if_needed(suggestions, ctx.user)
        tags.update_tag_suggestions(tag, suggestions)
    if ctx.has_param('implications'):
        auth.verify_privilege(ctx.user, 'tags:edit:implications')
        implications = ctx.get_param_as_list('implications')
        _create_if_needed(implications, ctx.user)
        tags.update_tag_implications(tag, implications)
    tag.last_edit_time = datetime.datetime.utcnow()
    ctx.session.flush()
    snapshots.modify(tag, ctx.user)
    ctx.session.commit()
    tags.export_to_json()
    return _serialize(ctx, tag)
コード例 #3
0
ファイル: tag_api.py プロジェクト: rr-/szurubooru
def update_tag(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    tag = _get_tag(params)
    versions.verify_version(tag, ctx)
    versions.bump_version(tag)
    if ctx.has_param('names'):
        auth.verify_privilege(ctx.user, 'tags:edit:names')
        tags.update_tag_names(tag, ctx.get_param_as_string_list('names'))
    if ctx.has_param('category'):
        auth.verify_privilege(ctx.user, 'tags:edit:category')
        tags.update_tag_category_name(
            tag, ctx.get_param_as_string('category'))
    if ctx.has_param('description'):
        auth.verify_privilege(ctx.user, 'tags:edit:description')
        tags.update_tag_description(
            tag, ctx.get_param_as_string('description'))
    if ctx.has_param('suggestions'):
        auth.verify_privilege(ctx.user, 'tags:edit:suggestions')
        suggestions = ctx.get_param_as_string_list('suggestions')
        _create_if_needed(suggestions, ctx.user)
        tags.update_tag_suggestions(tag, suggestions)
    if ctx.has_param('implications'):
        auth.verify_privilege(ctx.user, 'tags:edit:implications')
        implications = ctx.get_param_as_string_list('implications')
        _create_if_needed(implications, ctx.user)
        tags.update_tag_implications(tag, implications)
    tag.last_edit_time = datetime.utcnow()
    ctx.session.flush()
    snapshots.modify(tag, ctx.user)
    ctx.session.commit()
    return _serialize(ctx, tag)
コード例 #4
0
def test_update_tag_names_reusing_own_name(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-zA-Z]*$'})
    for name in list('aA'):
        tag = tag_factory(names=['a'])
        db.session.add(tag)
        db.session.flush()
        tags.update_tag_names(tag, [name])
        assert [tag_name.name for tag_name in tag.names] == [name]
        db.session.rollback()
コード例 #5
0
def test_update_tag_names_reusing_own_name(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-zA-Z]*$'})
    for name in list('aA'):
        tag = tag_factory(names=['a'])
        db.session.add(tag)
        db.session.flush()
        tags.update_tag_names(tag, [name])
        assert [tag_name.name for tag_name in tag.names] == [name]
        db.session.rollback()
コード例 #6
0
ファイル: test_tags.py プロジェクト: stopsquarks/quarkman
def test_update_tag_names_changing_primary_name(config_injector, tag_factory):
    config_injector({"tag_name_regex": "^[a-zA-Z]*$"})
    tag = tag_factory(names=["a", "b"])
    db.session.add(tag)
    db.session.flush()
    tags.update_tag_names(tag, ["b", "a"])
    db.session.flush()
    db.session.refresh(tag)
    assert [tag_name.name for tag_name in tag.names] == ["b", "a"]
    db.session.rollback()
コード例 #7
0
def test_update_tag_names_changing_primary_name(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-zA-Z]*$'})
    tag = tag_factory(names=['a', 'b'])
    db.session.add(tag)
    db.session.flush()
    tags.update_tag_names(tag, ['b', 'a'])
    db.session.flush()
    db.session.refresh(tag)
    assert [tag_name.name for tag_name in tag.names] == ['b', 'a']
    db.session.rollback()
コード例 #8
0
def test_update_tag_names_changing_primary_name(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-zA-Z]*$'})
    tag = tag_factory(names=['a', 'b'])
    db.session.add(tag)
    db.session.flush()
    tags.update_tag_names(tag, ['b', 'a'])
    db.session.flush()
    db.session.refresh(tag)
    assert [tag_name.name for tag_name in tag.names] == ['b', 'a']
    db.session.rollback()
コード例 #9
0
def test_update_tag_names_trying_to_use_taken_name(
        config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-zA-Z]*$'})
    existing_tag = tag_factory(names=['a'])
    db.session.add(existing_tag)
    tag = tag_factory()
    db.session.add(tag)
    db.session.flush()
    with pytest.raises(tags.TagAlreadyExistsError):
        tags.update_tag_names(tag, ['a'])
    with pytest.raises(tags.TagAlreadyExistsError):
        tags.update_tag_names(tag, ['A'])
コード例 #10
0
def test_update_tag_names_trying_to_use_taken_name(
        config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-zA-Z]*$'})
    existing_tag = tag_factory(names=['a'])
    db.session.add(existing_tag)
    tag = tag_factory()
    db.session.add(tag)
    db.session.flush()
    with pytest.raises(tags.TagAlreadyExistsError):
        tags.update_tag_names(tag, ['a'])
    with pytest.raises(tags.TagAlreadyExistsError):
        tags.update_tag_names(tag, ['A'])
コード例 #11
0
ファイル: tag_api.py プロジェクト: hnamquoc/szurubooru
 def put(self, ctx, tag_name):
     tag = tags.get_tag_by_name(tag_name)
     if ctx.has_param('names'):
         auth.verify_privilege(ctx.user, 'tags:edit:names')
         tags.update_tag_names(tag, ctx.get_param_as_list('names'))
     if ctx.has_param('category'):
         auth.verify_privilege(ctx.user, 'tags:edit:category')
         tags.update_tag_category_name(
             tag, ctx.get_param_as_string('category'))
     if ctx.has_param('suggestions'):
         auth.verify_privilege(ctx.user, 'tags:edit:suggestions')
         tags.update_tag_suggestions(
             tag, ctx.get_param_as_list('suggestions'))
     if ctx.has_param('implications'):
         auth.verify_privilege(ctx.user, 'tags:edit:implications')
         tags.update_tag_implications(
             tag, ctx.get_param_as_list('implications'))
     tag.last_edit_time = datetime.datetime.now()
     ctx.session.flush()
     snapshots.save_entity_modification(tag, ctx.user)
     ctx.session.commit()
     tags.export_to_json()
     return tags.serialize_tag_with_details(tag)
コード例 #12
0
 def put(self, ctx, tag_name):
     tag = tags.get_tag_by_name(tag_name)
     if ctx.has_param('names'):
         auth.verify_privilege(ctx.user, 'tags:edit:names')
         tags.update_tag_names(tag, ctx.get_param_as_list('names'))
     if ctx.has_param('category'):
         auth.verify_privilege(ctx.user, 'tags:edit:category')
         tags.update_tag_category_name(tag,
                                       ctx.get_param_as_string('category'))
     if ctx.has_param('suggestions'):
         auth.verify_privilege(ctx.user, 'tags:edit:suggestions')
         tags.update_tag_suggestions(tag,
                                     ctx.get_param_as_list('suggestions'))
     if ctx.has_param('implications'):
         auth.verify_privilege(ctx.user, 'tags:edit:implications')
         tags.update_tag_implications(tag,
                                      ctx.get_param_as_list('implications'))
     tag.last_edit_time = datetime.datetime.now()
     ctx.session.flush()
     snapshots.save_entity_modification(tag, ctx.user)
     ctx.session.commit()
     tags.export_to_json()
     return tags.serialize_tag_with_details(tag)
コード例 #13
0
ファイル: test_tags.py プロジェクト: stopsquarks/quarkman
def test_update_tag_names_with_invalid_name(config_injector, tag_factory):
    config_injector({"tag_name_regex": "^[a-z]*$"})
    tag = tag_factory()
    with pytest.raises(tags.InvalidTagNameError):
        tags.update_tag_names(tag, ["0"])
コード例 #14
0
def test_update_tag_names_to_empty(tag_factory):
    tag = tag_factory()
    with pytest.raises(tags.InvalidTagNameError):
        tags.update_tag_names(tag, [])
コード例 #15
0
def test_update_tag_names_with_duplicate_names(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-z]*$'})
    tag = tag_factory()
    tags.update_tag_names(tag, ['a', 'A'])
    assert [tag_name.name for tag_name in tag.names] == ['a']
コード例 #16
0
def test_update_tag_names_with_too_long_string(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-z]*$'})
    tag = tag_factory()
    with pytest.raises(tags.InvalidTagNameError):
        tags.update_tag_names(tag, ['a' * 300])
コード例 #17
0
def test_update_tag_names_with_invalid_name(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-z]*$'})
    tag = tag_factory()
    with pytest.raises(tags.InvalidTagNameError):
        tags.update_tag_names(tag, ['0'])
コード例 #18
0
def test_update_tag_names_to_empty(tag_factory):
    tag = tag_factory()
    with pytest.raises(tags.InvalidTagNameError):
        tags.update_tag_names(tag, [])
コード例 #19
0
ファイル: test_tags.py プロジェクト: stopsquarks/quarkman
def test_update_tag_names_with_duplicate_names(config_injector, tag_factory):
    config_injector({"tag_name_regex": "^[a-z]*$"})
    tag = tag_factory()
    tags.update_tag_names(tag, ["a", "A"])
    assert [tag_name.name for tag_name in tag.names] == ["a"]
コード例 #20
0
def test_update_tag_names_with_invalid_name(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-z]*$'})
    tag = tag_factory()
    with pytest.raises(tags.InvalidTagNameError):
        tags.update_tag_names(tag, ['0'])
コード例 #21
0
def test_update_tag_names_with_duplicate_names(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-z]*$'})
    tag = tag_factory()
    tags.update_tag_names(tag, ['a', 'A'])
    assert [tag_name.name for tag_name in tag.names] == ['a']
コード例 #22
0
def test_update_tag_names_with_too_long_string(config_injector, tag_factory):
    config_injector({'tag_name_regex': '^[a-z]*$'})
    tag = tag_factory()
    with pytest.raises(tags.InvalidTagNameError):
        tags.update_tag_names(tag, ['a' * 300])