Пример #1
0
from flask import Blueprint
from flask_restx import Resource
from flask_security import roles_accepted

from app.extensions import api as root_api
from app.services.task import TaskService
from app.utils.decorators import token_required

blueprint = Blueprint('tasks', __name__, url_prefix='/api/tasks')
api = root_api.namespace('tasks', description='Tasks endpoints')


class TaskResource(Resource):
    task_service = TaskService()


@api.route('/status/<string:task_id>')
class TaskStatusResource(TaskResource):
    @api.doc(responses={
        401: 'Unauthorized',
        403: 'Forbidden',
        404: 'Not found',
        422: 'Unprocessable Entity'
    },
             security='auth_token')
    @token_required
    @roles_accepted('admin', 'team_leader', 'worker')
    def get(self, task_id: str):
        return self.task_service.check_task_status(task_id), 200
from flask import jsonify
from datetime import datetime
from app.extensions import api
from flask_restplus_patched import Resource
from app.libs.schema import common_schema

ns = api.namespace("healthCheck")


@ns.route("/")
class HealthCheckList(Resource):
    @ns.parameters(common_schema.HealthCheckParams())
    def get(self, args, **kwargs):
        data = {
            'status': "OK",
            'date': datetime.now(),
            'version': "0.0.3-redis-cache"
        }
        return jsonify(data)
from flask import current_app
from datetime import datetime
from werkzeug.exceptions import NotFound
from app.libs.schema import hr_schema
from flask_restplus_patched import Resource
from app.extensions import api
from app.libs.common.logger import TraceException
from app.libs.common.custom_exception import CustomControllerException, ERROR_MESSAGE
from app.libs.common import redis_lib
from app.database_connect import department_model

ns = api.namespace("hrApi")


@ns.route("/departments")
class DepartmentAPI(Resource):
    @ns.parameters(hr_schema.DepartmentGetAllParams())
    def get(self, args):
        """
        get all departments by cache or none
        :param args:
        :return:
        """
        try:
            is_reload_cache = args.get('isReloadCache', False)
            result = dict()
            is_get_new_data = False
            key_cache = current_app.config.get("CACHE_DEPARTMENT_KEY")

            if is_reload_cache:
                lst_departments = self.get_value_from_database()
Пример #4
0
from flask import Blueprint, request
from flask_security import roles_required

from app.extensions import api as root_api
from app.serializers import RoleSerializer
from app.swagger import (role_input_sw_model, role_sw_model,
                         search_input_sw_model, role_search_output_sw_model)
from app.utils.decorators import token_required
from .base import BaseResource
from ..services.role import RoleService

_API_DESCRIPTION = 'Users with role admin can manage these endpoints.'
blueprint = Blueprint('roles', __name__)
api = root_api.namespace('roles', description=_API_DESCRIPTION)


class RoleBaseResource(BaseResource):
    role_service = RoleService()
    role_serializer = RoleSerializer()


@api.route('')
class NewRoleResource(RoleBaseResource):
    @api.doc(responses={
        401: 'Unauthorized',
        403: 'Forbidden',
        422: 'Unprocessable Entity'
    },
             security='auth_token')
    @api.expect(role_input_sw_model)
    @api.marshal_with(role_sw_model, envelope='data', code=201)
Пример #5
0
from flask_security import roles_accepted
from werkzeug.datastructures import FileStorage as WerkzeugFileStorage

from app.blueprints.base import BaseResource
from app.extensions import api as root_api
from app.serializers import DocumentSerializer
from app.services.document import DocumentService
from app.swagger import (document_sw_model, document_search_output_sw_model,
                         search_input_sw_model)
from app.utils import get_request_file
from app.utils.decorators import token_required

_API_DESCRIPTION = ('Users with role admin, team_leader or worker can '
                    'manage these endpoints.')
blueprint = Blueprint('documents', __name__)
api = root_api.namespace('documents', description=_API_DESCRIPTION)


class DocumentBaseResource(BaseResource):
    doc_service = DocumentService()
    doc_serializer = DocumentSerializer(exclude=('internal_filename', ))


@api.route('')
class NewDocumentResource(DocumentBaseResource):
    parser = api.parser()
    parser.add_argument('Content-Type',
                        type=str,
                        location='headers',
                        required=True,
                        choices=('multipart/form-data', ))
Пример #6
0
from flask import jsonify, request, current_app
from datetime import datetime
from app.extensions import api
from flask_restplus_patched import Resource
from app.libs.schema import common_schema
from app.task import celery

ns = api.namespace("task")


@ns.route('/registerTask/<taskName>/<countDown>')
class RegisterTaskByNameAPI(Resource):
    @ns.parameters(common_schema.BlankParams(), locations=('json', ))
    def post(self, args, **kwargs):
        """
        send a request to register background task

        :param args:
        :param kwargs:
        :return:
        """
        data = request.json
        task_name = kwargs.get("taskName", "")
        count_down = kwargs.get("countDown", 0)
        data_string = "Receive data to register task {} from {} content {}".\
            format(task_name, request.remote_addr, str(data))
        current_app.logger.info(data_string)
        if data:
            celery.send_task(task_name, args=[data], countdown=int(count_down))
        else:
            celery.send_task(task_name, args=[], countdown=int(count_down))
Пример #7
0
from flask import Blueprint, request
from flask_restx import Resource

from app.extensions import api as root_api
from app.services.auth import AuthService
from app.swagger import (auth_login_sw_model, auth_token_sw_model,
                         auth_user_reset_password_sw_model,
                         auth_user_reset_password_token_sw_model)
from app.utils.decorators import token_required

blueprint = Blueprint('auth', __name__)
api = root_api.namespace('auth', description='Authentication endpoints')


class AuthBaseResource(Resource):
    auth_service = AuthService()


@api.route('/login')
class AuthUserLoginResource(AuthBaseResource):
    @api.doc(
        responses={
            401: 'Unauthorized',
            403: 'Forbidden',
            404: 'Not found',
            422: 'Unprocessable Entity'
        })
    @api.expect(auth_login_sw_model)
    @api.marshal_with(auth_token_sw_model)
    def post(self) -> tuple:
        token = self.auth_service.login_user(**request.get_json())