예제 #1
0
def update_user(ctx, params):
    user = users.get_user_by_name(params['user_name'])
    versions.verify_version(user, ctx)
    versions.bump_version(user)
    infix = 'self' if ctx.user.user_id == user.user_id else 'any'
    if ctx.has_param('name'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:name' % infix)
        users.update_user_name(user, ctx.get_param_as_string('name'))
    if ctx.has_param('password'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:pass' % infix)
        users.update_user_password(
            user, ctx.get_param_as_string('password'))
    if ctx.has_param('email'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:email' % infix)
        users.update_user_email(user, ctx.get_param_as_string('email'))
    if ctx.has_param('rank'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:rank' % infix)
        users.update_user_rank(
            user, ctx.get_param_as_string('rank'), ctx.user)
    if ctx.has_param('avatarStyle'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:avatar' % infix)
        users.update_user_avatar(
            user,
            ctx.get_param_as_string('avatarStyle'),
            ctx.get_file('avatar'))
    ctx.session.commit()
    return _serialize(ctx, user)
예제 #2
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)
예제 #3
0
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 update_user(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    user = users.get_user_by_name(params["user_name"])
    versions.verify_version(user, ctx)
    versions.bump_version(user)
    infix = "self" if ctx.user.user_id == user.user_id else "any"
    if ctx.has_param("name"):
        auth.verify_privilege(ctx.user, "users:edit:%s:name" % infix)
        users.update_user_name(user, ctx.get_param_as_string("name"))
    if ctx.has_param("password"):
        auth.verify_privilege(ctx.user, "users:edit:%s:pass" % infix)
        users.update_user_password(user, ctx.get_param_as_string("password"))
    if ctx.has_param("email"):
        auth.verify_privilege(ctx.user, "users:edit:%s:email" % infix)
        users.update_user_email(user, ctx.get_param_as_string("email"))
    if ctx.has_param("rank"):
        auth.verify_privilege(ctx.user, "users:edit:%s:rank" % infix)
        users.update_user_rank(user, ctx.get_param_as_string("rank"), ctx.user)
    if ctx.has_param("avatarStyle"):
        auth.verify_privilege(ctx.user, "users:edit:%s:avatar" % infix)
        users.update_user_avatar(
            user,
            ctx.get_param_as_string("avatarStyle"),
            ctx.get_file("avatar", default=b""),
        )
    ctx.session.commit()
    return _serialize(ctx, user)
예제 #5
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)
예제 #6
0
def update_comment(ctx, params):
    comment = comments.get_comment_by_id(params['comment_id'])
    versions.verify_version(comment, ctx)
    versions.bump_version(comment)
    infix = 'own' if ctx.user.user_id == comment.user_id else 'any'
    text = ctx.get_param_as_string('text', required=True)
    auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
    comments.update_comment_text(comment, text)
    comment.last_edit_time = datetime.datetime.utcnow()
    ctx.session.commit()
    return _serialize(ctx, comment)
예제 #7
0
def update_comment(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    comment = _get_comment(params)
    versions.verify_version(comment, ctx)
    versions.bump_version(comment)
    infix = 'own' if ctx.user.user_id == comment.user_id else 'any'
    text = ctx.get_param_as_string('text')
    auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
    comments.update_comment_text(comment, text)
    comment.last_edit_time = datetime.utcnow()
    ctx.session.commit()
    return _serialize(ctx, comment)
예제 #8
0
def update_comment(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    comment = _get_comment(params)
    versions.verify_version(comment, ctx)
    versions.bump_version(comment)
    infix = 'own' if ctx.user.user_id == comment.user_id else 'any'
    text = ctx.get_param_as_string('text')
    auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
    comments.update_comment_text(comment, text)
    comment.last_edit_time = datetime.utcnow()
    ctx.session.commit()
    return _serialize(ctx, comment)
예제 #9
0
def finish_password_reset(
        ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    good_token = auth.generate_authentication_token(user)
    token = ctx.get_param_as_string('token')
    if _hash(token) != _hash(good_token):
        raise errors.ValidationError('Invalid password reset token.')
    new_password = users.reset_user_password(user)
    versions.bump_version(user)
    ctx.session.commit()
    return {'password': new_password}
예제 #10
0
def finish_password_reset(ctx: rest.Context,
                          params: Dict[str, str]) -> rest.Response:
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    good_token = auth.generate_authentication_token(user)
    token = ctx.get_param_as_string('token')
    if _hash(token) != _hash(good_token):
        raise errors.ValidationError('Invalid password reset token.')
    new_password = users.reset_user_password(user)
    versions.bump_version(user)
    ctx.session.commit()
    return {'password': new_password}
예제 #11
0
def finish_password_reset(ctx, params):
    ''' Verify token from mail, generate a new password and return it. '''
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    good_token = auth.generate_authentication_token(user)
    token = ctx.get_param_as_string('token', required=True)
    if token != good_token:
        raise errors.ValidationError('Invalid password reset token.')
    new_password = users.reset_user_password(user)
    versions.bump_version(user)
    ctx.session.commit()
    return {'password': new_password}
예제 #12
0
파일: tag_api.py 프로젝트: rr-/szurubooru
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)
예제 #13
0
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)
예제 #14
0
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)
예제 #15
0
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)
예제 #16
0
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)
예제 #17
0
def update_post(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    post = _get_post(params)
    versions.verify_version(post, ctx)
    versions.bump_version(post)
    if ctx.has_file("content"):
        auth.verify_privilege(ctx.user, "posts:edit:content")
        posts.update_post_content(
            post,
            ctx.get_file(
                "content",
                use_video_downloader=auth.has_privilege(
                    ctx.user, "uploads:use_downloader"),
            ),
        )
    if ctx.has_param("tags"):
        auth.verify_privilege(ctx.user, "posts:edit:tags")
        new_tags = posts.update_post_tags(post,
                                          ctx.get_param_as_string_list("tags"))
        if len(new_tags):
            auth.verify_privilege(ctx.user, "tags:create")
            db.session.flush()
            for tag in new_tags:
                snapshots.create(tag, ctx.user)
    if ctx.has_param("safety"):
        auth.verify_privilege(ctx.user, "posts:edit:safety")
        posts.update_post_safety(post, ctx.get_param_as_string("safety"))
    if ctx.has_param("source"):
        auth.verify_privilege(ctx.user, "posts:edit:source")
        posts.update_post_source(post, ctx.get_param_as_string("source"))
    elif ctx.has_param("contentUrl"):
        posts.update_post_source(post, ctx.get_param_as_string("contentUrl"))
    if ctx.has_param("relations"):
        auth.verify_privilege(ctx.user, "posts:edit:relations")
        posts.update_post_relations(post,
                                    ctx.get_param_as_int_list("relations"))
    if ctx.has_param("notes"):
        auth.verify_privilege(ctx.user, "posts:edit:notes")
        posts.update_post_notes(post, ctx.get_param_as_list("notes"))
    if ctx.has_param("flags"):
        auth.verify_privilege(ctx.user, "posts:edit:flags")
        posts.update_post_flags(post, ctx.get_param_as_string_list("flags"))
    if ctx.has_file("thumbnail"):
        auth.verify_privilege(ctx.user, "posts:edit:thumbnail")
        posts.update_post_thumbnail(post, ctx.get_file("thumbnail"))
    post.last_edit_time = datetime.utcnow()
    ctx.session.flush()
    snapshots.modify(post, ctx.user)
    ctx.session.commit()
    return _serialize_post(ctx, post)
예제 #18
0
파일: post_api.py 프로젝트: rr-/szurubooru
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)
예제 #19
0
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)
예제 #20
0
def update_tag_category(ctx, params):
    category = tag_categories.get_category_by_name(
        params['category_name'], lock=True)
    versions.verify_version(category, ctx)
    versions.bump_version(category)
    if ctx.has_param('name'):
        auth.verify_privilege(ctx.user, 'tag_categories:edit:name')
        tag_categories.update_category_name(
            category, ctx.get_param_as_string('name'))
    if ctx.has_param('color'):
        auth.verify_privilege(ctx.user, 'tag_categories:edit:color')
        tag_categories.update_category_color(
            category, ctx.get_param_as_string('color'))
    ctx.session.flush()
    snapshots.modify(category, ctx.user)
    ctx.session.commit()
    tags.export_to_json()
    return _serialize(ctx, category)
예제 #21
0
def update_pool_category(ctx: rest.Context,
                         params: Dict[str, str]) -> rest.Response:
    category = pool_categories.get_category_by_name(params["category_name"],
                                                    lock=True)
    versions.verify_version(category, ctx)
    versions.bump_version(category)
    if ctx.has_param("name"):
        auth.verify_privilege(ctx.user, "pool_categories:edit:name")
        pool_categories.update_category_name(category,
                                             ctx.get_param_as_string("name"))
    if ctx.has_param("color"):
        auth.verify_privilege(ctx.user, "pool_categories:edit:color")
        pool_categories.update_category_color(category,
                                              ctx.get_param_as_string("color"))
    ctx.session.flush()
    snapshots.modify(category, ctx.user)
    ctx.session.commit()
    return _serialize(ctx, category)
예제 #22
0
def update_tag_category(
        ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    category = tag_categories.get_category_by_name(
        params['category_name'], lock=True)
    versions.verify_version(category, ctx)
    versions.bump_version(category)
    if ctx.has_param('name'):
        auth.verify_privilege(ctx.user, 'tag_categories:edit:name')
        tag_categories.update_category_name(
            category, ctx.get_param_as_string('name'))
    if ctx.has_param('color'):
        auth.verify_privilege(ctx.user, 'tag_categories:edit:color')
        tag_categories.update_category_color(
            category, ctx.get_param_as_string('color'))
    ctx.session.flush()
    snapshots.modify(category, ctx.user)
    ctx.session.commit()
    return _serialize(ctx, category)
예제 #23
0
def update_tag_category(
        ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    category = tag_categories.get_category_by_name(
        params['category_name'], lock=True)
    versions.verify_version(category, ctx)
    versions.bump_version(category)
    if ctx.has_param('name'):
        auth.verify_privilege(ctx.user, 'tag_categories:edit:name')
        tag_categories.update_category_name(
            category, ctx.get_param_as_string('name'))
    if ctx.has_param('color'):
        auth.verify_privilege(ctx.user, 'tag_categories:edit:color')
        tag_categories.update_category_color(
            category, ctx.get_param_as_string('color'))
    ctx.session.flush()
    snapshots.modify(category, ctx.user)
    ctx.session.commit()
    tags.export_to_json()
    return _serialize(ctx, category)
예제 #24
0
def update_post(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    post = _get_post(params)
    versions.verify_version(post, ctx)
    versions.bump_version(post)
    if ctx.has_file('content'):
        auth.verify_privilege(ctx.user, 'posts:edit:content')
        posts.update_post_content(post, ctx.get_file('content'))
    if ctx.has_param('tags'):
        auth.verify_privilege(ctx.user, 'posts:edit:tags')
        new_tags = posts.update_post_tags(
            post, ctx.get_param_as_string_list('tags'))
        if len(new_tags):
            auth.verify_privilege(ctx.user, 'tags:create')
            db.session.flush()
            for tag in new_tags:
                snapshots.create(tag, ctx.user)
    if ctx.has_param('safety'):
        auth.verify_privilege(ctx.user, 'posts:edit:safety')
        posts.update_post_safety(post, ctx.get_param_as_string('safety'))
    if ctx.has_param('source'):
        auth.verify_privilege(ctx.user, 'posts:edit:source')
        posts.update_post_source(post, ctx.get_param_as_string('source'))
    elif ctx.has_param('contentUrl'):
        posts.update_post_source(post, ctx.get_param_as_string('contentUrl'))
    if ctx.has_param('relations'):
        auth.verify_privilege(ctx.user, 'posts:edit:relations')
        posts.update_post_relations(
            post, ctx.get_param_as_int_list('relations'))
    if ctx.has_param('notes'):
        auth.verify_privilege(ctx.user, 'posts:edit:notes')
        posts.update_post_notes(post, ctx.get_param_as_list('notes'))
    if ctx.has_param('flags'):
        auth.verify_privilege(ctx.user, 'posts:edit:flags')
        posts.update_post_flags(post, ctx.get_param_as_string_list('flags'))
    if ctx.has_file('thumbnail'):
        auth.verify_privilege(ctx.user, 'posts:edit:thumbnail')
        posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
    post.last_edit_time = datetime.utcnow()
    ctx.session.flush()
    snapshots.modify(post, ctx.user)
    ctx.session.commit()
    tags.export_to_json()
    return _serialize_post(ctx, post)
예제 #25
0
파일: post_api.py 프로젝트: rr-/szurubooru
def update_post(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    post = _get_post(params)
    versions.verify_version(post, ctx)
    versions.bump_version(post)
    if ctx.has_file('content'):
        auth.verify_privilege(ctx.user, 'posts:edit:content')
        posts.update_post_content(post, ctx.get_file('content'))
    if ctx.has_param('tags'):
        auth.verify_privilege(ctx.user, 'posts:edit:tags')
        new_tags = posts.update_post_tags(
            post, ctx.get_param_as_string_list('tags'))
        if len(new_tags):
            auth.verify_privilege(ctx.user, 'tags:create')
            db.session.flush()
            for tag in new_tags:
                snapshots.create(tag, ctx.user)
    if ctx.has_param('safety'):
        auth.verify_privilege(ctx.user, 'posts:edit:safety')
        posts.update_post_safety(post, ctx.get_param_as_string('safety'))
    if ctx.has_param('source'):
        auth.verify_privilege(ctx.user, 'posts:edit:source')
        posts.update_post_source(post, ctx.get_param_as_string('source'))
    elif ctx.has_param('contentUrl'):
        posts.update_post_source(post, ctx.get_param_as_string('contentUrl'))
    if ctx.has_param('relations'):
        auth.verify_privilege(ctx.user, 'posts:edit:relations')
        posts.update_post_relations(
            post, ctx.get_param_as_int_list('relations'))
    if ctx.has_param('notes'):
        auth.verify_privilege(ctx.user, 'posts:edit:notes')
        posts.update_post_notes(post, ctx.get_param_as_list('notes'))
    if ctx.has_param('flags'):
        auth.verify_privilege(ctx.user, 'posts:edit:flags')
        posts.update_post_flags(post, ctx.get_param_as_string_list('flags'))
    if ctx.has_file('thumbnail'):
        auth.verify_privilege(ctx.user, 'posts:edit:thumbnail')
        posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
    post.last_edit_time = datetime.utcnow()
    ctx.session.flush()
    snapshots.modify(post, ctx.user)
    ctx.session.commit()
    return _serialize_post(ctx, post)
예제 #26
0
def update_user(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    user = users.get_user_by_name(params['user_name'])
    versions.verify_version(user, ctx)
    versions.bump_version(user)
    infix = 'self' if ctx.user.user_id == user.user_id else 'any'
    if ctx.has_param('name'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:name' % infix)
        users.update_user_name(user, ctx.get_param_as_string('name'))
    if ctx.has_param('password'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:pass' % infix)
        users.update_user_password(user, ctx.get_param_as_string('password'))
    if ctx.has_param('email'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:email' % infix)
        users.update_user_email(user, ctx.get_param_as_string('email'))
    if ctx.has_param('rank'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:rank' % infix)
        users.update_user_rank(user, ctx.get_param_as_string('rank'), ctx.user)
    if ctx.has_param('avatarStyle'):
        auth.verify_privilege(ctx.user, 'users:edit:%s:avatar' % infix)
        users.update_user_avatar(user, ctx.get_param_as_string('avatarStyle'),
                                 ctx.get_file('avatar', default=b''))
    ctx.session.commit()
    return _serialize(ctx, user)
예제 #27
0
def update_user_token(ctx: rest.Context,
                      params: Dict[str, str] = {}) -> rest.Response:
    user = users.get_user_by_name(params["user_name"])
    infix = "self" if ctx.user.user_id == user.user_id else "any"
    auth.verify_privilege(ctx.user, "user_tokens:edit:%s" % infix)
    user_token = user_tokens.get_by_user_and_token(user, params["user_token"])
    versions.verify_version(user_token, ctx)
    versions.bump_version(user_token)
    if ctx.has_param("enabled"):
        auth.verify_privilege(ctx.user, "user_tokens:edit:%s" % infix)
        user_tokens.update_user_token_enabled(user_token,
                                              ctx.get_param_as_bool("enabled"))
    if ctx.has_param("note"):
        auth.verify_privilege(ctx.user, "user_tokens:edit:%s" % infix)
        note = ctx.get_param_as_string("note")
        user_tokens.update_user_token_note(user_token, note)
    if ctx.has_param("expirationTime"):
        auth.verify_privilege(ctx.user, "user_tokens:edit:%s" % infix)
        expiration_time = ctx.get_param_as_string("expirationTime")
        user_tokens.update_user_token_expiration_time(user_token,
                                                      expiration_time)
    user_tokens.update_user_token_edit_time(user_token)
    ctx.session.commit()
    return _serialize(ctx, user_token)
예제 #28
0
def update_user_token(ctx: rest.Context,
                      params: Dict[str, str] = {}) -> rest.Response:
    user = users.get_user_by_name(params['user_name'])
    infix = 'self' if ctx.user.user_id == user.user_id else 'any'
    auth.verify_privilege(ctx.user, 'user_tokens:edit:%s' % infix)
    user_token = user_tokens.get_by_user_and_token(user, params['user_token'])
    versions.verify_version(user_token, ctx)
    versions.bump_version(user_token)
    if ctx.has_param('enabled'):
        auth.verify_privilege(ctx.user, 'user_tokens:edit:%s' % infix)
        user_tokens.update_user_token_enabled(user_token,
                                              ctx.get_param_as_bool('enabled'))
    if ctx.has_param('note'):
        auth.verify_privilege(ctx.user, 'user_tokens:edit:%s' % infix)
        note = ctx.get_param_as_string('note')
        user_tokens.update_user_token_note(user_token, note)
    if ctx.has_param('expirationTime'):
        auth.verify_privilege(ctx.user, 'user_tokens:edit:%s' % infix)
        expiration_time = ctx.get_param_as_string('expirationTime')
        user_tokens.update_user_token_expiration_time(user_token,
                                                      expiration_time)
    user_tokens.update_user_token_edit_time(user_token)
    ctx.session.commit()
    return _serialize(ctx, user_token)
예제 #29
0
def update_pool(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    pool = _get_pool(params)
    versions.verify_version(pool, ctx)
    versions.bump_version(pool)
    if ctx.has_param("names"):
        auth.verify_privilege(ctx.user, "pools:edit:names")
        pools.update_pool_names(pool, ctx.get_param_as_string_list("names"))
    if ctx.has_param("category"):
        auth.verify_privilege(ctx.user, "pools:edit:category")
        pools.update_pool_category_name(pool,
                                        ctx.get_param_as_string("category"))
    if ctx.has_param("description"):
        auth.verify_privilege(ctx.user, "pools:edit:description")
        pools.update_pool_description(pool,
                                      ctx.get_param_as_string("description"))
    if ctx.has_param("posts"):
        auth.verify_privilege(ctx.user, "pools:edit:posts")
        posts = ctx.get_param_as_int_list("posts")
        pools.update_pool_posts(pool, posts)
    pool.last_edit_time = datetime.utcnow()
    ctx.session.flush()
    snapshots.modify(pool, ctx.user)
    ctx.session.commit()
    return _serialize(ctx, pool)
예제 #30
0
def update_user_token(
        ctx: rest.Context, params: Dict[str, str] = {}) -> rest.Response:
    user = users.get_user_by_name(params['user_name'])
    infix = 'self' if ctx.user.user_id == user.user_id else 'any'
    auth.verify_privilege(ctx.user, 'user_tokens:edit:%s' % infix)
    user_token = user_tokens.get_by_user_and_token(user, params['user_token'])
    versions.verify_version(user_token, ctx)
    versions.bump_version(user_token)
    if ctx.has_param('enabled'):
        auth.verify_privilege(ctx.user, 'user_tokens:edit:%s' % infix)
        user_tokens.update_user_token_enabled(
            user_token, ctx.get_param_as_bool('enabled'))
    if ctx.has_param('note'):
        auth.verify_privilege(ctx.user, 'user_tokens:edit:%s' % infix)
        note = ctx.get_param_as_string('note')
        user_tokens.update_user_token_note(user_token, note)
    if ctx.has_param('expirationTime'):
        auth.verify_privilege(ctx.user, 'user_tokens:edit:%s' % infix)
        expiration_time = ctx.get_param_as_string('expirationTime')
        user_tokens.update_user_token_expiration_time(
            user_token, expiration_time)
    user_tokens.update_user_token_edit_time(user_token)
    ctx.session.commit()
    return _serialize(ctx, user_token)