Exemple #1
0
    def post(self, ctx):
        auth.verify_privilege(ctx.user, 'posts:create')
        content = ctx.get_file('content', required=True)
        tag_names = ctx.get_param_as_list('tags', required=True)
        safety = ctx.get_param_as_string('safety', required=True)
        source = ctx.get_param_as_string('source',
                                         required=False,
                                         default=None)
        if ctx.has_param('contentUrl') and not source:
            source = ctx.get_param_as_string('contentUrl')
        relations = ctx.get_param_as_list('relations', required=False) or []
        notes = ctx.get_param_as_list('notes', required=False) or []
        flags = ctx.get_param_as_list('flags', required=False) or []

        post = posts.create_post(content, tag_names, ctx.user)
        posts.update_post_safety(post, safety)
        posts.update_post_source(post, source)
        posts.update_post_relations(post, relations)
        posts.update_post_notes(post, notes)
        posts.update_post_flags(post, flags)
        if ctx.has_file('thumbnail'):
            posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
        ctx.session.add(post)
        snapshots.save_entity_creation(post, ctx.user)
        ctx.session.commit()
        tags.export_to_json()
        return posts.serialize_post_with_details(post, ctx.user)
Exemple #2
0
def create_post(ctx, _params=None):
    anonymous = ctx.get_param_as_bool('anonymous', default=False)
    if anonymous:
        auth.verify_privilege(ctx.user, 'posts:create:anonymous')
    else:
        auth.verify_privilege(ctx.user, 'posts:create:identified')
    content = ctx.get_file('content', required=True)
    tag_names = ctx.get_param_as_list('tags', required=False, default=[])
    safety = ctx.get_param_as_string('safety', required=True)
    source = ctx.get_param_as_string('source', required=False, default=None)
    if ctx.has_param('contentUrl') and not source:
        source = ctx.get_param_as_string('contentUrl')
    relations = ctx.get_param_as_list('relations', required=False) or []
    notes = ctx.get_param_as_list('notes', required=False) or []
    flags = ctx.get_param_as_list('flags', required=False) or []

    post, new_tags = posts.create_post(
        content, tag_names, None if anonymous else ctx.user)
    if len(new_tags):
        auth.verify_privilege(ctx.user, 'tags:create')
    posts.update_post_safety(post, safety)
    posts.update_post_source(post, source)
    posts.update_post_relations(post, relations)
    posts.update_post_notes(post, notes)
    posts.update_post_flags(post, flags)
    if ctx.has_file('thumbnail'):
        posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
    ctx.session.add(post)
    ctx.session.flush()
    snapshots.create(post, None if anonymous else ctx.user)
    for tag in new_tags:
        snapshots.create(tag, None if anonymous else ctx.user)
    ctx.session.commit()
    tags.export_to_json()
    return _serialize_post(ctx, post)
Exemple #3
0
def create_post(ctx: rest.Context,
                _params: Dict[str, str] = {}) -> rest.Response:
    anonymous = ctx.get_param_as_bool('anonymous', default=False)
    if anonymous:
        auth.verify_privilege(ctx.user, 'posts:create:anonymous')
    else:
        auth.verify_privilege(ctx.user, 'posts:create:identified')
    content = ctx.get_file('content')
    tag_names = ctx.get_param_as_string_list('tags', default=[])
    safety = ctx.get_param_as_string('safety')
    source = ctx.get_param_as_string('source', default='')
    if ctx.has_param('contentUrl') and not source:
        source = ctx.get_param_as_string('contentUrl', default='')
    relations = ctx.get_param_as_int_list('relations', default=[])
    notes = ctx.get_param_as_list('notes', default=[])
    flags = ctx.get_param_as_string_list('flags', default=[])

    post, new_tags = posts.create_post(content, tag_names,
                                       None if anonymous else ctx.user)
    if len(new_tags):
        auth.verify_privilege(ctx.user, 'tags:create')
    posts.update_post_safety(post, safety)
    posts.update_post_source(post, source)
    posts.update_post_relations(post, relations)
    posts.update_post_notes(post, notes)
    posts.update_post_flags(post, flags)
    if ctx.has_file('thumbnail'):
        posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
    ctx.session.add(post)
    ctx.session.flush()
    snapshots.create(post, None if anonymous else ctx.user)
    for tag in new_tags:
        snapshots.create(tag, None if anonymous else ctx.user)
    ctx.session.commit()
    return _serialize_post(ctx, post)
Exemple #4
0
    def post(self, ctx):
        auth.verify_privilege(ctx.user, 'posts:create')
        content = ctx.get_file('content', required=True)
        tag_names = ctx.get_param_as_list('tags', required=True)
        safety = ctx.get_param_as_string('safety', required=True)
        source = ctx.get_param_as_string('source', required=False, default=None)
        if ctx.has_param('contentUrl') and not source:
            source = ctx.get_param_as_string('contentUrl')
        relations = ctx.get_param_as_list('relations', required=False) or []
        notes = ctx.get_param_as_list('notes', required=False) or []
        flags = ctx.get_param_as_list('flags', required=False) or []

        post = posts.create_post(content, tag_names, ctx.user)
        posts.update_post_safety(post, safety)
        posts.update_post_source(post, source)
        posts.update_post_relations(post, relations)
        posts.update_post_notes(post, notes)
        posts.update_post_flags(post, flags)
        if ctx.has_file('thumbnail'):
            posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
        ctx.session.add(post)
        snapshots.save_entity_creation(post, ctx.user)
        ctx.session.commit()
        tags.export_to_json()
        return posts.serialize_post_with_details(post, ctx.user)
Exemple #5
0
def test_create_post(user_factory, fake_datetime):
    with unittest.mock.patch('szurubooru.func.posts.update_post_content'), \
        unittest.mock.patch('szurubooru.func.posts.update_post_tags'), \
        fake_datetime('1997-01-01'):
        auth_user = user_factory()
        post = posts.create_post('content', ['tag'], auth_user)
        assert post.creation_time == datetime.datetime(1997, 1, 1)
        assert post.last_edit_time is None
        posts.update_post_tags.assert_called_once_with(post, ['tag'])
        posts.update_post_content.assert_called_once_with(post, 'content')
Exemple #6
0
def test_create_post(user_factory, fake_datetime):
    with patch("szurubooru.func.posts.update_post_content"), patch(
            "szurubooru.func.posts.update_post_tags"), fake_datetime(
                "1997-01-01"):
        auth_user = user_factory()
        post, _new_tags = posts.create_post("content", ["tag"], auth_user)
        assert post.creation_time == datetime(1997, 1, 1)
        assert post.last_edit_time is None
        posts.update_post_tags.assert_called_once_with(post, ["tag"])
        posts.update_post_content.assert_called_once_with(post, "content")
Exemple #7
0
def test_create_post(user_factory, fake_datetime):
    with patch('szurubooru.func.posts.update_post_content'), \
            patch('szurubooru.func.posts.update_post_tags'), \
            fake_datetime('1997-01-01'):
        auth_user = user_factory()
        post, _new_tags = posts.create_post('content', ['tag'], auth_user)
        assert post.creation_time == datetime(1997, 1, 1)
        assert post.last_edit_time is None
        posts.update_post_tags.assert_called_once_with(post, ['tag'])
        posts.update_post_content.assert_called_once_with(post, 'content')
Exemple #8
0
def create_post(ctx: rest.Context,
                _params: Dict[str, str] = {}) -> rest.Response:
    anonymous = ctx.get_param_as_bool("anonymous", default=False)
    if anonymous:
        auth.verify_privilege(ctx.user, "posts:create:anonymous")
    else:
        auth.verify_privilege(ctx.user, "posts:create:identified")
    content = ctx.get_file(
        "content",
        use_video_downloader=auth.has_privilege(ctx.user,
                                                "uploads:use_downloader"),
    )
    tag_names = ctx.get_param_as_string_list("tags", default=[])
    safety = ctx.get_param_as_string("safety")
    source = ctx.get_param_as_string("source", default="")
    if ctx.has_param("contentUrl") and not source:
        source = ctx.get_param_as_string("contentUrl", default="")
    relations = ctx.get_param_as_int_list("relations", default=[])
    notes = ctx.get_param_as_list("notes", default=[])
    flags = ctx.get_param_as_string_list(
        "flags", default=posts.get_default_flags(content))

    post, new_tags = posts.create_post(content, tag_names,
                                       None if anonymous else ctx.user)
    if len(new_tags):
        auth.verify_privilege(ctx.user, "tags:create")
    posts.update_post_safety(post, safety)
    posts.update_post_source(post, source)
    posts.update_post_relations(post, relations)
    posts.update_post_notes(post, notes)
    posts.update_post_flags(post, flags)
    if ctx.has_file("thumbnail"):
        posts.update_post_thumbnail(post, ctx.get_file("thumbnail"))
    ctx.session.add(post)
    ctx.session.flush()
    create_snapshots_for_post(post, new_tags, None if anonymous else ctx.user)
    alternate_format_posts = posts.generate_alternate_formats(post, content)
    for alternate_post, alternate_post_new_tags in alternate_format_posts:
        create_snapshots_for_post(
            alternate_post,
            alternate_post_new_tags,
            None if anonymous else ctx.user,
        )
    ctx.session.commit()
    return _serialize_post(ctx, post)
Exemple #9
0
def create_post(
        ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
    anonymous = ctx.get_param_as_bool('anonymous', default=False)
    if anonymous:
        auth.verify_privilege(ctx.user, 'posts:create:anonymous')
    else:
        auth.verify_privilege(ctx.user, 'posts:create:identified')
    content = ctx.get_file('content')
    tag_names = ctx.get_param_as_string_list('tags', default=[])
    safety = ctx.get_param_as_string('safety')
    source = ctx.get_param_as_string('source', default='')
    if ctx.has_param('contentUrl') and not source:
        source = ctx.get_param_as_string('contentUrl', default='')
    relations = ctx.get_param_as_int_list('relations', default=[])
    notes = ctx.get_param_as_list('notes', default=[])
    flags = ctx.get_param_as_string_list('flags', default=[])

    post, new_tags = posts.create_post(
        content, tag_names, None if anonymous else ctx.user)
    if len(new_tags):
        auth.verify_privilege(ctx.user, 'tags:create')
    posts.update_post_safety(post, safety)
    posts.update_post_source(post, source)
    posts.update_post_relations(post, relations)
    posts.update_post_notes(post, notes)
    posts.update_post_flags(post, flags)
    posts.test_sound(post, content)
    if ctx.has_file('thumbnail'):
        posts.update_post_thumbnail(post, ctx.get_file('thumbnail'))
    ctx.session.add(post)
    ctx.session.flush()
    create_snapshots_for_post(post, new_tags, None if anonymous else ctx.user)
    alternate_format_posts = posts.generate_alternate_formats(post, content)
    for alternate_post, alternate_post_new_tags in alternate_format_posts:
        create_snapshots_for_post(
            alternate_post,
            alternate_post_new_tags,
            None if anonymous else ctx.user)
    ctx.session.commit()
    return _serialize_post(ctx, post)