def edit_verdict(verdict_id): check_has_role(current_user, 'EDITOR') verdict = load_or_404(Verdict, verdict_id) verdict.modify(request.json) ApiHandler.save(verdict) return jsonify(as_dict(verdict, includes=VERDICT_INCLUDES)), 201
def create_verdict_reviewer(): check_has_role(current_user, 'EDITOR') verdict_reviewer = VerdictReviewer() verdict_reviewer.modify(request.json) ApiHandler.save(verdict_reviewer) return jsonify(as_dict(verdict_reviewer)), 201
def create_verdict(): check_has_role(current_user, 'EDITOR') verdict = Verdict() verdict.modify(request.json) verdict.user = current_user ApiHandler.save(verdict) return jsonify(as_dict(verdict, includes=VERDICT_INCLUDES)), 201
def delete_role(role_id): check_has_role(current_user, 'ADMIN') role = load_or_404(Role, role_id) ApiHandler.delete(role) db.session.commit() return jsonify({"id": role_id}), 201
def soft_delete_article(article_id): check_has_role(current_user, 'editor') article = load_or_404(Article, article_id) article.soft_delete() ApiHandler.save(article) return jsonify(as_dict(article)), 201
def modify_article(article_id): check_has_role(current_user, 'editor') article = load_or_404(Article, article_id) article.modify(request.json) ApiHandler.save(article) return jsonify(as_dict(article, includes=ARTICLE_INCLUDES)), 201
def soft_delete_content(content_id): check_has_role(current_user, 'EDITOR') content = load_or_404(Content, content_id) content.soft_delete() ApiHandler.save(content) return jsonify(as_dict(content)), 201
def modify_content(content_id): check_has_role(current_user, 'EDITOR') content = load_or_404(Content, content_id) content.modify(request.json) ApiHandler.save(content) return jsonify(as_dict(content, includes=CONTENT_INCLUDES)), 201
def post_role(): check_has_role(current_user, 'ADMIN') user = load_or_404(User, request.json['userId']) role = Role() role.type = request.json['type'] role.user = user ApiHandler.save(role) return jsonify(as_dict(role)), 200
def modify_review(review_id): check_has_role(current_user, 'REVIEWER') review = load_or_404(Review, review_id) review.modify(request.json) ApiHandler.save(review) save_tags(review, request.json.get('tagIds', [])) return jsonify(as_dict(review, includes=REVIEW_INCLUDES)), 201
def create_review(): check_has_role(current_user, 'REVIEWER') review = Review() review.modify(request.json) review.user = current_user ApiHandler.save(review) save_tags(review, request.json.get('tagIds', [])) return jsonify(as_dict(review, includes=REVIEW_INCLUDES)), 201
def create_image_from_files(): check_has_role(current_user, 'REVIEWER') thumb = check_and_read_files_thumb(request.files) image = Image() image_dict = {'name': request.files['thumb'].filename} image.modify(image_dict) ApiHandler.save(image) save_thumb(image, thumb, 0) return jsonify(as_dict(image)), 201
def create_content(): check_has_role(current_user, 'EDITOR') content = content_from_url(request.json['url']) content.modify(**request.json) check_content_is_not_yet_saved(content) ApiHandler.save(content) # TODO: put it in a celery pipe subprocess.Popen( 'PYTHONPATH="." python scripts/manager.py screenshotmachine' + ' --url ' + str(content.url) + ' --id ' + str(content.id), shell=True, cwd=API_ROOT_PATH) return jsonify(as_dict(content, includes=CONTENT_INCLUDES)), 201
def get_reviews(): check_has_role(current_user, 'EDITOR') query = Review.query content_id = request.args.get('contentId') if content_id is not None: query = query.filter_by(contentId=dehumanize(content_id)) keywords = request.args.get('keywords') if keywords is not None: query = get_reviews_join_query(query) query = get_reviews_query_with_keywords(query, keywords) return listify(Review, includes=REVIEW_INCLUDES, query=query, page=request.args.get('page', 1), paginate=10)
def get_users(): check_has_role(current_user, 'ADMIN') query = User.query roles = request.args.get('roles') if roles is not None: query = keep_users_with_roles(query, roles.split(',')) keywords = request.args.get('keywords') if keywords is not None: query = get_users_join_query(query) query = get_users_query_with_keywords(query, keywords) return listify(User, includes=USER_INCLUDES, page=request.args.get('page'), paginate=10, query=query, with_total_data_count=True)
def create_article(): check_has_role(current_user, 'editor') content = dict(resolve_with_url(request.json['url']), **request.json) check_article_is_not_yet_saved(content) article = Article(**content) ApiHandler.save(article) # TODO: put it in a celery pipe p = subprocess.Popen( 'PYTHONPATH="." python scripts/manager.py screenshotmachine' + ' --url ' + str(article.url) + ' --id ' + str(article.id), shell=True, cwd=API_ROOT_PATH) return jsonify(as_dict(article, includes=ARTICLE_INCLUDES)), 201
def get_user(user_id): check_has_role(current_user, 'ADMIN') user = load_or_404(User, user_id) return jsonify(as_dict(user, includes=USER_INCLUDES)), 200
def list_roles(): check_has_role(current_user, 'ADMIN') role_types = [as_dict(role_type) for role_type in RoleType] return jsonify(role_types), 200