Example #1
0
 def put(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:score')
     post = posts.get_post_by_id(post_id)
     score = ctx.get_param_as_int('score', required=True)
     scores.set_score(post, ctx.user, score)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #2
0
 def put(self, ctx, post_id):
     post = posts.get_post_by_id(post_id)
     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')
         posts.update_post_tags(post, ctx.get_param_as_list('tags'))
     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_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_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.datetime.now()
     ctx.session.flush()
     snapshots.save_entity_modification(post, ctx.user)
     ctx.session.commit()
     tags.export_to_json()
     return posts.serialize_post_with_details(post, ctx.user)
Example #3
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)
Example #4
0
 def put(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:score')
     post = posts.get_post_by_id(post_id)
     score = ctx.get_param_as_int('score', required=True)
     scores.set_score(post, ctx.user, score)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #5
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)
Example #6
0
def test_serialize_post_with_details(post_factory, comment_factory,
                                     user_factory):
    with unittest.mock.patch('szurubooru.func.comments.serialize_comment'), \
        unittest.mock.patch('szurubooru.func.snapshots.get_serialized_history'), \
        unittest.mock.patch('szurubooru.func.posts.serialize_post'):
        comments.serialize_comment.side_effect \
            = lambda comment, auth_user: comment.user.name
        posts.serialize_post.side_effect \
            = lambda post, auth_user: post.post_id
        snapshots.get_serialized_history.return_value = 'snapshot history'

        auth_user = user_factory(name='auth user')
        post = post_factory()
        post.comments = [
            comment_factory(user=user_factory(name='commenter1')),
            comment_factory(user=user_factory(name='commenter2')),
        ]
        db.session.add(post)
        db.session.flush()

        result = posts.serialize_post_with_details(post, auth_user)

    assert result == {
        'post': post.post_id,
        'snapshots': 'snapshot history',
        'comments': ['commenter1', 'commenter2'],
    }
Example #7
0
 def post(self, ctx):
     auth.verify_privilege(ctx.user, 'posts:feature')
     post_id = ctx.get_param_as_int('id', required=True)
     post = posts.get_post_by_id(post_id)
     featured_post = posts.try_get_featured_post()
     if featured_post and featured_post.post_id == post.post_id:
         raise posts.PostAlreadyFeaturedError(
             'Post %r is already featured.' % post_id)
     posts.feature_post(post, ctx.user)
     if featured_post:
         snapshots.save_entity_modification(featured_post, ctx.user)
     snapshots.save_entity_modification(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #8
0
 def post(self, ctx):
     auth.verify_privilege(ctx.user, 'posts:feature')
     post_id = ctx.get_param_as_int('id', required=True)
     post = posts.get_post_by_id(post_id)
     featured_post = posts.try_get_featured_post()
     if featured_post and featured_post.post_id == post.post_id:
         raise posts.PostAlreadyFeaturedError(
             'Post %r is already featured.' % post_id)
     posts.feature_post(post, ctx.user)
     if featured_post:
         snapshots.save_entity_modification(featured_post, ctx.user)
     snapshots.save_entity_modification(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #9
0
 def put(self, ctx, post_id):
     post = posts.get_post_by_id(post_id)
     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')
         posts.update_post_tags(post, ctx.get_param_as_list('tags'))
     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_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_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.datetime.now()
     ctx.session.flush()
     snapshots.save_entity_modification(post, ctx.user)
     ctx.session.commit()
     tags.export_to_json()
     return posts.serialize_post_with_details(post, ctx.user)
Example #10
0
 def get(self, ctx):
     post = posts.try_get_featured_post()
     return posts.serialize_post_with_details(post, ctx.user)
Example #11
0
 def delete(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:score')
     post = posts.get_post_by_id(post_id)
     scores.delete_score(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #12
0
 def get(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:view')
     post = posts.get_post_by_id(post_id)
     return posts.serialize_post_with_details(post, ctx.user)
Example #13
0
 def delete(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:favorite')
     post = posts.get_post_by_id(post_id)
     favorites.unset_favorite(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #14
0
 def delete(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:score')
     post = posts.get_post_by_id(post_id)
     scores.delete_score(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #15
0
 def delete(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:favorite')
     post = posts.get_post_by_id(post_id)
     favorites.unset_favorite(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #16
0
 def get(self, ctx):
     post = posts.try_get_featured_post()
     return posts.serialize_post_with_details(post, ctx.user)
Example #17
0
 def get(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:view')
     post = posts.get_post_by_id(post_id)
     return posts.serialize_post_with_details(post, ctx.user)