Exemplo n.º 1
0
def edit_post(url):
    optional_data = {
        'title': {
            'type': 'string',
            'min_length': 5,
            'max_length': 64
        },
        'category': {
            'type': 'string',
            'max_length': 20
        },
        'banner': {
            'type': 'string'
        },
        'content': {
            'type': 'string',
            'min_length': 50
        }
    }
    PostsController.get_one(url)
    data = CheckBody.call(request, optional_data=optional_data)
    CheckPermissions.call(request, permissions=['POST_WRITE'])
    PostsController.update_one(url=url,
                               params=data['optional'],
                               optional_data=optional_data)
    return responses.no_content()
Exemplo n.º 2
0
def get_all_comments():
    CheckPermissions.call(request, ['USER_WRITE'])

    comments = CommentsController.fetch_all()
    comments, pages = paginate(request, comments)
    comments = CommentsController.multi_fill_information(comments)
    return responses.success(comments, pages=pages)
Exemplo n.º 3
0
def create_post():
    required_data = {
        'title': {
            'type': 'string',
            'min_length': 5,
            'max_length': 64
        },
        'category': {
            'type': 'string',
            'max_length': 20
        },
        'content': {
            'type': 'string',
            'min_length': 50
        },
        'banner': {
            'type': 'string'
        }
    }
    data = CheckBody.call(request, required_data=required_data)
    CheckPermissions.call(request, permissions=['POST_WRITE'])
    author = UsersController.get_one_by_token(
        request.headers.get('Authorization'))
    data['author_username'] = author['username']
    PostsController.create_one(data)
    return responses.created()
Exemplo n.º 4
0
def create_blog_post():
    required_data = {
        'title': {
            'type': 'string',
            'min_length': 5,
            'max_length': 64
        },
        'type': {
            'type': 'string'
        },
        'category': {
            'type': 'string'
        },
        'description': {
            'type': 'string',
            'min_length': 10,
            'max_length': 250
        },
        'labels': {
            'type': 'list<string>'
        },
        'banner': {
            'type': 'string'
        },
        'content': {
            'type': 'string',
            'min_length': 20
        }
    }
    optional_data = {'locale': {'type': 'string', 'default': 'fr'}}
    data = CheckBody.call(request,
                          required_data=required_data,
                          optional_data=optional_data)
    CheckPermissions.call(request, permissions=['BLOG_WRITE'])
    author = UsersController.get_one_by_token(
        request.headers.get('Authorization'))
    data['author_username'] = author['username']
    BlogPostsController.create_one(params=data, optional_data=optional_data)
    return responses.created()
Exemplo n.º 5
0
def edit_blog_post(url):
    optional_data = {
        'title': {
            'type': 'string',
            'min_length': 5,
            'max_length': 64
        },
        'type': {
            'type': 'string'
        },
        'category': {
            'type': 'string'
        },
        'description': {
            'type': 'string',
            'min_length': 10,
            'max_length': 250
        },
        'labels': {
            'type': 'list<string>'
        },
        'banner': {
            'type': 'string'
        },
        'content': {
            'type': 'string',
            'min_length': 20
        }
    }
    post = BlogPostsController.get_one(url)
    data = CheckBody.call(request, optional_data=optional_data)
    CheckPermissions.call(request, permissions=['BLOG_WRITE'])
    BlogPostsController.update_one(url=url,
                                   params=data['optional'],
                                   optional_data=optional_data)
    return responses.no_content()
Exemplo n.º 6
0
def delete_blog_post(url):
    post = BlogPostsController.get_one(url)
    CheckPermissions.call(request, permissions=['BLOG_WRITE'])
    BlogPostsController.delete_one(url)
    return responses.no_content()
Exemplo n.º 7
0
def delete_comment(post, comment):
    CheckPermissions.call(request, ['USER_WRITE'])
    CommentsController.delete_one(comment)
    return responses.no_content()
Exemplo n.º 8
0
def get_user_permissions(username):
    CheckPermissions.call(request, ['USER_WRITE'])
    return responses.success(UsersController.get_user_permissions(username))
Exemplo n.º 9
0
def get_all_users():
    CheckPermissions.call(request, ['USER_WRITE'])
    return responses.success(UsersController.get_all())
Exemplo n.º 10
0
def update_permissions(username):
    required_data = {'permissions': {'type': 'list'}}
    CheckPermissions.call(request, permissions=['USER_WRITE'])
    request_data = request.json
    UsersController.update_permissions(username, request_data['permissions'])
    return responses.no_content()
Exemplo n.º 11
0
def delete_post(url):
    CheckPermissions.call(request, permissions=['POST_WRITE'])
    PostsController.delete_one(url)
    return responses.no_content()