Esempio n. 1
0
import json
from typing import Any

from flask import request
from flask_restplus import Resource
from jsonschema import validate, ValidationError, Draft4Validator
from jsonschema.exceptions import best_match

from medtagger.types import ScanID
from medtagger.api import api
from medtagger.api.exceptions import InvalidArgumentsException
from medtagger.api.scans import business, serializers
from medtagger.api.security import login_required, role_required, require_one_of_roles
from medtagger.api.scans.serializers import elements_schema

scans_ns = api.namespace('scans', 'Methods related with scans')


@scans_ns.route('')
class Scans(Resource):
    """Endpoint that can create new scan."""

    @staticmethod
    @login_required
    @role_required('doctor', 'admin')
    @scans_ns.expect(serializers.args__scans)
    @scans_ns.marshal_with(serializers.out__scans_paginated)
    @scans_ns.doc(security='token')
    @scans_ns.doc(description='Return list of available scans.')
    @scans_ns.doc(responses={200: 'Success'})
    def get() -> Any:
Esempio n. 2
0
"""Module responsible for definition of Datasets service available via HTTP REST API."""
from typing import Any

from flask import request
from flask_restplus import Resource

from medtagger.api import api
from medtagger.api.datasets import serializers, business
from medtagger.api.security import login_required, role_required

datasets_ns = api.namespace('datasets', 'Methods related with datasets')


@datasets_ns.route('')
class Datasets(Resource):
    """Endpoint that manages datasets."""
    @staticmethod
    @login_required
    @datasets_ns.marshal_with(serializers.out__dataset)
    @datasets_ns.doc(security='token')
    @datasets_ns.doc(description='Returns all available Datasets.')
    @datasets_ns.doc(responses={200: 'Success'})
    def get() -> Any:
        """Return all available datasets."""
        return business.get_available_datasets()

    @staticmethod
    @login_required
    @role_required('doctor', 'admin')
    @datasets_ns.expect(serializers.in__dataset)
    @datasets_ns.marshal_with(serializers.out__dataset)
Esempio n. 3
0
"""Module responsible for defining endpoints for users administration."""
from typing import Any

from flask import request
from flask_restplus import Resource

from medtagger.api import api
from medtagger.api.exceptions import AccessForbiddenException
from medtagger.api.users import serializers
from medtagger.api.users.business import get_all_users, set_user_role, set_user_info, set_user_settings
from medtagger.api.utils import get_current_user
from medtagger.api.security import login_required, role_required

users_ns = api.namespace('users', 'Users management')


@users_ns.route('')
class GetUsers(Resource):
    """Get all users endpoint."""
    @staticmethod
    @login_required
    @role_required('admin')
    @users_ns.marshal_with(serializers.users_list)
    @users_ns.doc(security='token')
    def get() -> Any:
        """Get all users endpoint."""
        users = get_all_users()
        return {'users': users}, 200


@users_ns.route('/<int:user_id>/role')
Esempio n. 4
0
"""Module responsible for definition of Auth service."""
from typing import Any

from flask import request
from flask_restplus import Resource

from medtagger.api import api
from medtagger.api.auth.business import create_user, sign_in_user
from medtagger.api.auth import serializers

auth_ns = api.namespace('auth', 'Auth methods')


@auth_ns.route('/register')
class Register(Resource):
    """Register user endpoint."""

    @staticmethod
    @api.expect(serializers.new_user)
    @api.doc(responses={201: 'User created', 400: 'Invalid arguments'})
    def post() -> Any:
        """Register the user."""
        user = request.json
        user_id = create_user(user['email'], user['password'], user['firstName'], user['lastName'])
        return {'id': user_id}, 201


@auth_ns.route('/sign-in')
class SignIn(Resource):
    """Sign in endpoint."""
Esempio n. 5
0
"""Module responsible for definition of Core service."""
from typing import Any

from flask_restplus import Resource

from medtagger.api import api
from medtagger.api.core import business, serializers
from medtagger.api.security import login_required, role_required

core_ns = api.namespace('core', 'Core methods')


@core_ns.route('/status')
class Status(Resource):
    """Status endpoint that checks if everything is all right."""
    @staticmethod
    @core_ns.marshal_with(serializers.out__status)
    @core_ns.doc(description='Checks if API is running properly.')
    @core_ns.doc(responses={200: 'Success'})
    def get() -> Any:
        """Return status of the API."""
        return business.success()


@core_ns.route('/check-authentication')
class CheckAuthentication(Resource):
    """Endpoint gives the possibility to check authorization mechanism."""
    @staticmethod
    @login_required
    @core_ns.marshal_with(serializers.out__status)
    @core_ns.doc(security='token')
Esempio n. 6
0
"""Module responsible for definition of Labels service available via HTTP REST API."""
from typing import Any

from flask import request
from flask_restplus import Resource

from medtagger.types import LabelID, ActionID
from medtagger.definitions import LabelVerificationStatus
from medtagger.api import api, InvalidArgumentsException, NotFoundException
from medtagger.api.labels import business, serializers
from medtagger.api.security import login_required, role_required

labels_ns = api.namespace('labels', 'Methods related with labels')


@labels_ns.route('/<string:label_id>')
@labels_ns.param('label_id', 'Label identifier')
class Label(Resource):
    """Endpoint that returns Label for the given Label ID."""
    @staticmethod
    @login_required
    @role_required('doctor', 'admin')
    @labels_ns.marshal_with(serializers.out__label)
    @labels_ns.doc(security='token')
    @labels_ns.doc(description='Returns Label with given Label ID.')
    @labels_ns.doc(responses={200: 'Success', 404: 'Could not find Label'})
    def get(label_id: LabelID) -> Any:
        """Return Label for the given Label ID."""
        return business.get_label(label_id)

Esempio n. 7
0
"""Module responsible for definition of Tasks service available via HTTP REST API."""
from typing import Any

from flask import request
from flask_restplus import Resource

from medtagger.api import api
from medtagger.api.tasks import business, serializers
from medtagger.api.security import login_required, role_required
from medtagger.database.models import LabelTag

tasks_ns = api.namespace('tasks', 'Methods related with tasks')


@tasks_ns.route('')
class Tasks(Resource):
    """Endpoint that manages tasks."""
    @staticmethod
    @login_required
    @tasks_ns.marshal_with(serializers.out__task)
    @tasks_ns.doc(security='token')
    @tasks_ns.doc(description='Return all available tasks.')
    @tasks_ns.doc(responses={200: 'Success'})
    def get() -> Any:
        """Return all available tasks."""
        return business.get_tasks()

    @staticmethod
    @login_required
    @role_required('admin')
    @tasks_ns.expect(serializers.in__task)