Exemple #1
0
"""

__license__ = "LGPLv3+"

from flask import request, current_app
from flask_restx._http import HTTPStatus

from flask_restx_patched import Resource

from app.extensions.api import api_v1, Namespace
from app.extensions.auth import token_required, authorization_required
from app.extensions.user_office_link import user_office_link

api = Namespace("User office",
                description="User office related namespace",
                path="/user_office")
api_v1.add_namespace(api)


@api.route("/sync_all", endpoint="user_office_sync_all")
@api.doc(security="apikey")
class SyncAll(Resource):
    """Sync with user office"""
    @token_required
    @authorization_required
    def post(self):
        """Sync with user office"""

        api.logger.info("Sync with uer office")
        user_office_link.sync_with_user_office()
Exemple #2
0
from ispyb_ssx.schemas import loaded_sample as loaded_sample_schemas
from ispyb_ssx.schemas import crystal_slurry as crystal_slurry_schemas
from ispyb_ssx.schemas import (
    crystal_size_distribution as crystal_size_distribution_schemas, )
from ispyb_ssx.schemas import sample_stock as sample_stock_schemas
from ispyb_ssx.schemas import sample_delivery_device as sample_delivery_device_schemas
from ispyb_ssx.modules import loaded_sample

from ispyb_service_connector import get_ispyb_resource

__license__ = "LGPLv3+"

log = logging.getLogger(__name__)
api = Namespace("Samples",
                description="Samples related namespace",
                path="/samples")
api_v1.add_namespace(api)


@api.route("", endpoint="loaded_samples")
@api.doc(security="apikey")
class LoadedSample(Resource):
    """Loaded sample resource"""

    # @token_required
    def get(self):
        """Returns all loaded samples"""
        # app.logger.info("Return all data collections")
        return loaded_sample.get_loaded_samples(request)
from flask_login import current_user
from flask_restplus_patched import Resource
from flask_restplus_patched._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace, abort
from app.extensions.api.parameters import PaginationParameters
from app.modules.users import permissions
from app.modules.users.models import User

from . import parameters, schemas
from .models import Team, TeamMember

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('teams', description="Teams")  # pylint: disable=invalid-name


@api.route('/')
@api.login_required(oauth_scopes=['teams:read'])
class Teams(Resource):
    """
    Manipulations with teams.
    """
    @api.parameters(PaginationParameters())
    @api.response(schemas.BaseTeamSchema(many=True))
    def get(self, args):
        """
        List of teams.

        Returns a list of teams starting from ``offset`` limited by ``limit``
Exemple #4
0
#  GNU Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with py-ispyb. If not, see <http://www.gnu.org/licenses/>.

from flask import request, make_response

from flask_restx_patched import Resource

from app.extensions.api import api_v1, Namespace
from app.extensions import auth_provider

__license__ = "LGPLv3+"

api = Namespace("Authentication",
                description="authentication namespace",
                path="/auth")
api_v1.add_namespace(api)


@api.route("/login")
class Login(Resource):
    """Login resource"""
    def get(self):
        authorization = request.authorization

        if (not authorization or not authorization.username
                or not authorization.password):
            if not request.headers.get("username") or not request.headers.get(
                    "password"):
                return make_response(
Exemple #5
0
import logging

from flask_login import current_user  # NOQA
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace
from app.extensions.api.parameters import PaginationParameters
from app.modules.users import permissions

from . import parameters, schemas
from .models import Collaboration

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('collaborations', description='Collaborations')  # pylint: disable=invalid-name


@api.route('/')
@api.login_required(oauth_scopes=['collaborations:read'])
class Collaborations(Resource):
    """
    Manipulations with Collaborations.
    """
    @api.parameters(PaginationParameters())
    @api.response(schemas.BaseCollaborationSchema(many=True))
    def get(self, args):
        """
        List of Collaboration.

        Returns a list of Collaboration starting from ``offset`` limited by ``limit``
Exemple #6
0
from flask_login import current_user
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace
from app.extensions.api.parameters import PaginationParameters
from app.modules.users import permissions
from app.modules.users.permissions.types import AccessOperation

from . import parameters, schemas
from .models import Submission
import os

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('submissions', description='Submissions')  # pylint: disable=invalid-name


@api.route('/')
@api.login_required(oauth_scopes=['submissions:read'])
class Submissions(Resource):
    """
    Manipulations with Submissions.
    """
    @api.permission_required(
        permissions.ModuleAccessPermission,
        kwargs_on_request=lambda kwargs: {
            'module': Submission,
            'action': AccessOperation.READ,
        },
    )
Exemple #7
0
import logging

from flask import current_app, request
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus
from app.extensions.api import Namespace
from app.extensions.api import abort

from app.modules.users.models import User

from werkzeug.exceptions import BadRequest

import json

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
edm_configuration = Namespace('configuration',
                              description='(EDM) Configuration')  # pylint: disable=invalid-name
edm_configurationDefinition = Namespace(
    'configurationDefinition', description='(EDM) Configuration Definition')  # pylint: disable=invalid-name


@edm_configuration.route('/')
@edm_configuration.login_required(oauth_scopes=['configuration:read'])
class EDMConfigurationTargets(Resource):
    """
    Manipulations with Configuration.
    """
    def get(self):
        """
        List the possible EDM passthrough targets.
        """
        current_app.edm.ensure_initialed()
Exemple #8
0
"""

__license__ = "LGPLv3+"

from flask import request, current_app
from flask_restx._http import HTTPStatus

from flask_restx_patched import Resource

from app.extensions.api import api_v1, Namespace
from app.extensions.auth import token_required, authorization_required
from ispyb_core.schemas import proposal as proposal_schemas
from ispyb_core.modules import proposal

api = Namespace("Proposals",
                description="Proposal related namespace",
                path="/proposals")
api_v1.add_namespace(api)


@api.route("", endpoint="proposals")
@api.doc(security="apikey")
class Proposals(Resource):
    """Allows to get all proposals"""
    @token_required
    @authorization_required
    def get(self):
        """Returns proposals based on query parameters"""

        api.logger.info("Get all proposals")
        return proposal.get_proposals(request)
Exemple #9
0
from app.extensions.api import api_v1, Namespace
from app.extensions.auth import token_required, authorization_required

from ispyb_core.schemas import auto_proc as auto_proc_schemas
from ispyb_core.schemas import auto_proc_program as auto_proc_program_schemas
from ispyb_core.schemas import (
    auto_proc_program_attachment as auto_proc_program_attachment_schemas, )
from ispyb_core.schemas import (
    auto_proc_program_message as auto_proc_program_message_schemas, )
from ispyb_core.schemas import auto_proc_status as auto_proc_status_schemas
from ispyb_core.modules import auto_proc

__license__ = "LGPLv3+"

api = Namespace("Auto processing",
                description="Auto processing related namespace",
                path="/autoproc")

api_v1.add_namespace(api)


@api.route("", endpoint="auto_procs")
@api.doc(security="apikey")
class AutoProcs(Resource):
    """Allows to get all auto proc entries"""
    @token_required
    @authorization_required
    def get(self):
        """Returns auto proc entries"""
        return auto_proc.get_auto_procs(request)
Exemple #10
0
from app.extensions.api import Namespace, abort
from app.modules.users import permissions
from app.extensions.api.parameters import PaginationParameters

from app.modules.auth.models import Code

from .models import Asset

from . import schemas

from PIL import Image
import os


log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('assets', description='Assets')  # pylint: disable=invalid-name


def process_file_upload(square=False):
    FINAL_EXT = '.jpg'

    asset_path = current_app.config.get('ASSET_DATABASE_PATH', None)
    assert asset_path is not None
    assert os.path.exists(asset_path)

    allowed_extensions = current_app.config.get('ASSET_ALLOWED_EXTS', [])

    upload_file = request.files.get('file', None)
    if upload_file is None:
        abort(code=HTTPStatus.CONFLICT, message='The file was not uploaded as expected')
Exemple #11
0
import logging

from flask_login import current_user  # NOQA
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace
from app.extensions.api.parameters import PaginationParameters
from app.modules.users import permissions

from . import parameters, schemas
from .models import Notification

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('notifications', description='Notifications')  # pylint: disable=invalid-name


@api.route('/')
@api.login_required(oauth_scopes=['notifications:read'])
class Notifications(Resource):
    """
    Manipulations with Notifications.
    """
    @api.parameters(PaginationParameters())
    @api.response(schemas.BaseNotificationSchema(many=True))
    def get(self, args):
        """
        List of Notification.

        Returns a list of Notification starting from ``offset`` limited by ``limit``
Exemple #12
0
from flask import request
from flask_restx._http import HTTPStatus
from flask_restx_patched import Resource
from app.extensions.auth import token_required, authorization_required
from app.extensions.api import api_v1, Namespace
from ispyb_core.modules import shipping
from ispyb_core.schemas import shipping as shipping_schemas

import logging

__license__ = "LGPLv3+"

log = logging.getLogger(__name__)
api = Namespace("Shipments",
                description="Shipment related namespace",
                path="/shipments")
api_v1.add_namespace(api)


@api.route("", endpoint="shipments")
@api.doc(security="apikey")
class Shipments(Resource):
    """Allows to get all shipments"""
    @token_required
    @authorization_required
    def get(self):
        """Returns list of shipments"""
        return shipping.get_shipments(request), HTTPStatus.OK

    @api.expect(shipping_schemas.f_schema)
import logging

from flask_login import current_user
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace, abort
from app.modules.users import permissions

from ..related_jira_util.commands import find_related_tickets

from . import parameters, schemas

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('related-jira-finder', description="Related JIRA Finder")  # pylint: disable=invalid-name


@api.route('/')
class RelatedJira(Resource):
    """
    Use related jira form helpers.
    """
    @api.parameters(parameters.RelatedJiraParameters())
    def get(self, args):
        """
        Get Related JIRA.

        This endpoint must be used in order to get a server reCAPTCHA public key which
        must be used to receive a reCAPTCHA secret key for POST /users/ form.
        """
Exemple #14
0
import logging

from flask_login import current_user
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus
from app.extensions.api import abort

from app.extensions.api import Namespace

from . import permissions, schemas, parameters
from .models import db, User


log = logging.getLogger(__name__)
api = Namespace('users', description='Users')


@api.route('/')
class Users(Resource):
    """
    Manipulations with users.
    """

    @api.login_required(oauth_scopes=['users:read'])
    @api.permission_required(permissions.StaffRolePermission())
    @api.response(schemas.BaseUserSchema(many=True))
    @api.paginate(parameters.ListUserParameters())
    def get(self, args):
        """
        List of users.
Exemple #15
0
import importlib

from flask import current_app
from flask_restx_patched import Resource, HTTPStatus

from app.extensions.api import api_v1, Namespace

# from app.extensions.auth import token_required

from ispyb_core import schemas

__license__ = "LGPLv3+"

api = Namespace("Schemas",
                description="Schemas related namespace",
                path="/schemas")
api_v1.add_namespace(api)


@api.route("/available_names", endpoint="available_schemas_names")
class SchemasList(Resource):

    # @token_required
    def get(self):
        """Returns list of available schemas

        Returns:
            list: list of names
        """
        current_app.logger.info("Get all schemas")
Exemple #16
0
from flask import request
from flask_restx_patched import Resource, HTTPStatus

from app.extensions.api import api_v1, Namespace
from app.extensions.auth import token_required, authorization_required

from ispyb_core.schemas import container as container_schemas
from ispyb_core.modules import container


__license__ = "LGPLv3+"


api = Namespace(
    "Containers", description="Container related namespace", path="/containers"
)
api_v1.add_namespace(api)


@api.route("", endpoint="containers")
@api.doc(security="apikey")
class Containers(Resource):
    """Containers resource"""

    @token_required
    @authorization_required
    def get(self):
        """Returns all container items"""
        return container.get_containers(request)
Exemple #17
0
from datetime import datetime

from flask import request
from flask_restx_patched import Resource, HTTPStatus, abort

from app.extensions.api import api_v1, Namespace
from app.extensions.auth import token_required, authorization_required

from ispyb_core.schemas import session as session_schemas
from ispyb_core.modules import session

__license__ = "LGPLv3+"

log = logging.getLogger(__name__)
api = Namespace("Sessions",
                description="Session related namespace",
                path="/sessions")
api_v1.add_namespace(api)


@api.route("", endpoint="sessions")
@api.doc(security="apikey")
class Sessions(Resource):
    """Allows to get all sessions and insert a new one"""
    @token_required
    @authorization_required
    def get(self):
        """Returns list of sessions"""
        return session.get_sessions(request)

    @api.expect(session_schemas.f_schema)
Exemple #18
0
along with py-ispyb. If not, see <http://www.gnu.org/licenses/>.
"""

from flask import request
from flask_restx_patched import Resource, HTTPStatus

from app.extensions.api import api_v1, Namespace
from app.extensions.auth import token_required, authorization_required

from ispyb_core.schemas import dewar as dewar_schemas
from ispyb_core.modules import dewar

__license__ = "LGPLv3+"

api = Namespace("Dewars",
                description="Dewar related namespace",
                path="/dewars")
api_v1.add_namespace(api)


@api.route("", endpoint="dewars")
@api.doc(security="apikey")
class Dewars(Resource):
    """Dewars resource"""
    @token_required
    @authorization_required
    def get(self):
        """Returns all dewars items"""
        return dewar.get_dewars(request)

    @token_required
Exemple #19
0
import logging

from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace
from app.extensions.api.parameters import PaginationParameters
from app.modules.users import permissions

from . import parameters, schemas
from .models import Sighting

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('sightings', description='Sightings')  # pylint: disable=invalid-name


@api.route('/')
@api.login_required(oauth_scopes=['sightings:read'])
class Sightings(Resource):
    """
    Manipulations with Sightings.
    """
    @api.parameters(PaginationParameters())
    @api.response(schemas.BaseSightingSchema(many=True))
    def get(self, args):
        """
        List of Sighting.

        Returns a list of Sighting starting from ``offset`` limited by ``limit``
"""

import logging

from flask_login import current_user
from flask_restplus_patched import Resource
from flask_restplus_patched._http import HTTPStatus

from app.extensions.api import Namespace
from app.extensions.api.parameters import PaginationParameters

from . import permissions, schemas, parameters
from .models import db, User

log = logging.getLogger(__name__)
api = Namespace('users', description="Users")


@api.route('/')
class Users(Resource):
    """
    Manipulations with users.
    """
    @api.login_required(oauth_scopes=['users:read'])
    @api.permission_required(permissions.AdminRolePermission())
    @api.parameters(PaginationParameters())
    @api.response(schemas.BaseUserSchema(many=True))
    def get(self, args):
        """
        List of users.
Exemple #21
0
import logging
import io

from flask import request, jsonify, make_response, Response
from flask_restplus_patched import Resource
from app.extensions.api import Namespace, abort

from app.library import jwt
from mind.manager import img_store_manager

import numpy as np
from PIL import Image

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('image', description="Image")  # pylint: disable=invalid-name


@api.route("/upload")
class ImgUpload(Resource):
    @jwt.required
    def post(self):
        try:
            file = request.files['image']
            img_bytes = file.read()
            image_pil = Image.open(io.BytesIO(img_bytes))
            uid = img_store_manager.save_image(image_pil)
        except Exception as e:
            res = {"message": str(e), "image_name": ""}
            scode = 500
        else:
            res = {"message": "upload success.", "image_name": uid}
Exemple #22
0
from flask_login import current_user  # NOQA
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace
from app.extensions.api.parameters import PaginationParameters
from app.modules.users import permissions


from . import parameters, schemas
from .models import Encounter


log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('encounters', description='Encounters')  # pylint: disable=invalid-name


@api.route('/')
@api.login_required(oauth_scopes=['encounters:read'])
class Encounters(Resource):
    """
    Manipulations with Encounters.
    """

    @api.parameters(PaginationParameters())
    @api.response(schemas.BaseEncounterSchema(many=True))
    def get(self, args):
        """
        List of Encounter.
from flask import request

from flask_restx_patched import Resource, HTTPStatus

from app.extensions.api import api_v1, Namespace
from app.extensions.auth import token_required, authorization_required

from ispyb_core.schemas import data_collection as data_collection_schemas
from ispyb_core.modules import data_collection

__license__ = "LGPLv3+"

api = Namespace(
    "Data collections",
    description="Data collection related namespace",
    path="/data_collections",
)
api_v1.add_namespace(api)


@api.route("")
@api.doc(security="apikey")
class DataColletions(Resource):
    """Allows to get all data_collections"""

    # @api.marshal_list_with(data_collection_schemas.data_collection_f_schema, skip_none=True, code=HTTPStatus.OK)
    # TODO Define model with JSON Schema
    @token_required
    @authorization_required
    def get(self):
Exemple #24
0
"""

import logging
import glob
import os

from flask import current_app
from flask_login import current_user  # NOQA
from flask_restplus_patched import Resource

from app.extensions.api import Namespace

import datetime

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('frontends', description='Frontends')  # pylint: disable=invalid-name

DATETIME_FMTSTR = '%Y%m%d-%H%M%S'


def parse_frontend_versions():
    static_root = current_app.config.get('STATIC_ROOT')
    frontend_dist_list = glob.glob(os.path.join(static_root, 'dist-*/'))
    frontend_dist_latest = glob.glob(os.path.join(static_root, 'dist-latest/'))

    assert len(frontend_dist_latest) == 1
    frontend_dist_latest = frontend_dist_latest[0]
    assert frontend_dist_latest in frontend_dist_list
    frontend_dist_list.remove(frontend_dist_latest)

    frontend_link_latest = os.path.realpath(frontend_dist_latest)
Exemple #25
0
--------------------------
"""

import logging

from flask_login import current_user
from flask_restplus_patched import Resource
from werkzeug import security

from app.extensions.api import Namespace, http_exceptions

from . import schemas, parameters
from .models import db, OAuth2Client

log = logging.getLogger(__name__)
api = Namespace('auth', description="Authentication")


@api.route('/oauth2_clients/')
@api.login_required(oauth_scopes=['auth:read'])
class OAuth2Clients(Resource):
    """
    Manipulations with OAuth2 clients.
    """
    @api.parameters(parameters.ListOAuth2ClientsParameters())
    @api.response(schemas.BaseOAuth2ClientSchema(many=True))
    def get(self, args):
        """
        List of OAuth2 Clients.

        Returns a list of OAuth2 Clients starting from ``offset`` limited by
Exemple #26
0
RESTful API Passthroughs resources
--------------------------
"""

import logging

from flask import current_app, request
from flask_restplus_patched import Resource
from app.extensions.api import Namespace

from werkzeug.exceptions import BadRequest

import json

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
edm_pass = Namespace('passthroughs/edm', description='EDM Passthroughs')  # pylint: disable=invalid-name
acm_pass = Namespace('passthroughs/acm', description='ACM Passthroughs')  # pylint: disable=invalid-name


@edm_pass.route('/')
@edm_pass.login_required(oauth_scopes=['passthroughs:read'])
class EDMPassthroughTargets(Resource):
    """
    Manipulations with Passthroughs.
    """
    def get(self):
        """
        List the possible EDM passthrough targets.
        """
        current_app.edm.ensure_initialed()
        targets = list(current_app.edm.targets)
Exemple #27
0
import logging

from flask_login import current_user  # NOQA
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace
from app.extensions.api.parameters import PaginationParameters
from app.modules.users import permissions

from . import parameters, schemas
from .models import Organization

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('organizations', description='Organizations')  # pylint: disable=invalid-name


@api.route('/')
@api.login_required(oauth_scopes=['organizations:read'])
class Organizations(Resource):
    """
    Manipulations with Organizations.
    """
    @api.parameters(PaginationParameters())
    @api.response(schemas.BaseOrganizationSchema(many=True))
    def get(self, args):
        """
        List of Organization.

        Returns a list of Organization starting from ``offset`` limited by ``limit``
Exemple #28
0
import logging

from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus
from flask_login import current_user  # NOQA

from app.extensions import db
from app.extensions.api import Namespace
from app.extensions.api.parameters import PaginationParameters
from app.modules.users import permissions
from app.modules.users.permissions.types import AccessOperation
from . import parameters, schemas
from .models import Project

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('projects', description='Projects')  # pylint: disable=invalid-name


@api.route('/')
@api.login_required(oauth_scopes=['projects:read'])
class Projects(Resource):
    """
    Manipulations with Projects.
    """
    @api.permission_required(
        permissions.ModuleAccessPermission,
        kwargs_on_request=lambda kwargs: {
            'module': Project,
            'action': AccessOperation.READ,
        },
    )
import logging

from flask_login import current_user
from flask_restplus_patched import Resource
from flask_restplus._http import HTTPStatus

from app.extensions import db
from app.extensions.api import Namespace, abort
from app.extensions.api.parameters import PaginationParameters

from . import parameters, schemas
from .models import Payment

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('payments', description="Payments")  # pylint: disable=invalid-name


@api.route('/')
class Payments(Resource):
    """
    Manipulations with Payments.
    """
    @api.parameters(PaginationParameters())
    @api.response(schemas.BasePaymentSchema(many=True))
    def get(self, args):
        """
        List of Payment.

        Returns a list of Payment starting from ``offset`` limited by ``limit``
        parameter.
from . import parameters, schemas
from .models import CharacterAnalysis as CA_Model
from .models import AnalysisReport as AR_Model
from .models import MindMatch as MCM_Model
from .models import MindSpecMatch as MSM_Model

from .models import AI_USER_INFOModel as User_Model

from mind.manager import img_store_manager
from cv.align import get_points, warpImage
from cv.utils import *
from mock import object as mock_obj

log = logging.getLogger(__name__)  # pylint: disable=invalid-name
api = Namespace('analysis', description="analysis")  # pylint: disable=invalid-name

# bussmodel = api.model('BussModel', {
#     'source_id': fields.Integer(required=True, description='The task unique identifier'),
#     'request_type': fields.String(required=True, description='The task details'),
#     'image': fields.String(required=True, description='The task details'),
#     'sub_type': fields.String(required=True, description='The task details'),
#     'content_id': fields.String(required=True, description='The task details'),
#     'content_type': fields.String(required=True, description='The task details'),
#     'content_text': fields.String(required=True, description='The task details'),
# })

login_dict = {}

Fields_mapping = {
    10: {