Commit 017e24a8 authored by robert.vincze's avatar robert.vincze
Browse files

TVB-2584: Changed structure of inheritance adding SecuredRestResource

parent adb0b38a
......@@ -35,12 +35,12 @@ from tvb.core.neocom.h5 import h5_file_for_index
from tvb.core.services.flow_service import FlowService
from tvb.interfaces.rest.commons.dtos import AlgorithmDto
from tvb.interfaces.rest.commons.exceptions import InvalidIdentifierException
from tvb.interfaces.rest.server.resources.rest_resource import RestResource
from tvb.interfaces.rest.server.resources.rest_resource import SecuredRestResource
INVALID_DATATYPE_GID_MESSAGE = 'No datatype found for GID: {}'
class RetrieveDatatypeResource(RestResource):
class RetrieveDatatypeResource(SecuredRestResource):
@staticmethod
def get(datatype_gid):
......@@ -56,7 +56,7 @@ class RetrieveDatatypeResource(RestResource):
return flask.send_file(h5_file.path, as_attachment=True, attachment_filename=file_name)
class GetOperationsForDatatypeResource(RestResource):
class GetOperationsForDatatypeResource(SecuredRestResource):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......
......@@ -40,16 +40,14 @@ from tvb.core.services.project_service import ProjectService
from tvb.core.services.user_service import UserService
from tvb.interfaces.rest.commons.dtos import DataTypeDto
from tvb.interfaces.rest.commons.exceptions import InvalidIdentifierException, ServiceException
from tvb.interfaces.rest.server.decorators.rest_decorators import rest_jsonify, token_required
from tvb.interfaces.rest.server.resources.project.project_resource import INVALID_PROJECT_GID_MESSAGE
from tvb.interfaces.rest.server.resources.rest_resource import RestResource
from tvb.interfaces.rest.server.resources.rest_resource import SecuredRestResource
from tvb.interfaces.rest.server.resources.util import save_temporary_file
INVALID_OPERATION_GID_MESSAGE = "No operation found for GID: %s"
class GetOperationStatusResource(RestResource):
method_decorators = [rest_jsonify, token_required]
class GetOperationStatusResource(SecuredRestResource):
def get(self, operation_gid):
"""
......@@ -62,8 +60,7 @@ class GetOperationStatusResource(RestResource):
return operation.status
class GetOperationResultsResource(RestResource):
method_decorators = [rest_jsonify, token_required]
class GetOperationResultsResource(SecuredRestResource):
@staticmethod
def get(operation_gid):
......@@ -82,8 +79,7 @@ class GetOperationResultsResource(RestResource):
return [DataTypeDto(datatype) for datatype in data_types]
class LaunchOperationResource(RestResource):
method_decorators = [rest_jsonify, token_required]
class LaunchOperationResource(SecuredRestResource):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......
......@@ -33,14 +33,12 @@ from tvb.core.services.project_service import ProjectService
from tvb.interfaces.rest.commons import Strings
from tvb.interfaces.rest.commons.dtos import OperationDto, DataTypeDto
from tvb.interfaces.rest.commons.exceptions import InvalidIdentifierException, InvalidInputException
from tvb.interfaces.rest.server.decorators.rest_decorators import rest_jsonify, token_required
from tvb.interfaces.rest.server.resources.rest_resource import RestResource
from tvb.interfaces.rest.server.resources.rest_resource import SecuredRestResource
INVALID_PROJECT_GID_MESSAGE = 'No project found for GID: %s'
class GetDataInProjectResource(RestResource):
method_decorators = [rest_jsonify, token_required]
class GetDataInProjectResource(SecuredRestResource):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......@@ -59,8 +57,7 @@ class GetDataInProjectResource(RestResource):
return [DataTypeDto(datatype) for datatype in datatypes]
class GetOperationsInProjectResource(RestResource):
method_decorators = [rest_jsonify, token_required]
class GetOperationsInProjectResource(SecuredRestResource):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......
......@@ -31,6 +31,7 @@ import flask
from flask_restplus import Resource
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.interfaces.rest.commons.exceptions import BadRequestException
from tvb.interfaces.rest.server.decorators.rest_decorators import rest_jsonify, token_required
class RestResource(Resource):
......@@ -44,3 +45,7 @@ class RestResource(Resource):
raise BadRequestException('Only %s files are allowed!' % file_extension)
return file
class SecuredRestResource(RestResource):
method_decorators = [rest_jsonify, token_required]
......@@ -38,15 +38,13 @@ from tvb.core.services.flow_service import FlowService
from tvb.core.services.project_service import ProjectService
from tvb.core.services.simulator_service import SimulatorService
from tvb.interfaces.rest.commons.exceptions import InvalidIdentifierException, InvalidInputException, ServiceException
from tvb.interfaces.rest.server.decorators.rest_decorators import rest_jsonify, token_required
from tvb.interfaces.rest.server.resources.project.project_resource import INVALID_PROJECT_GID_MESSAGE
from tvb.interfaces.rest.server.resources.rest_resource import RestResource
from tvb.interfaces.rest.server.resources.rest_resource import SecuredRestResource
from tvb.interfaces.rest.server.resources.util import save_temporary_file
from tvb.simulator.simulator import Simulator
class FireSimulationResource(RestResource):
method_decorators = [rest_jsonify, token_required]
class FireSimulationResource(SecuredRestResource):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......
......@@ -31,8 +31,7 @@ from tvb.core.services.project_service import ProjectService
from tvb.core.services.user_service import UserService
from tvb.interfaces.rest.commons.dtos import UserDto, ProjectDto
from tvb.interfaces.rest.commons.exceptions import InvalidIdentifierException
from tvb.interfaces.rest.server.decorators.rest_decorators import token_required, rest_jsonify
from tvb.interfaces.rest.server.resources.rest_resource import RestResource
from tvb.interfaces.rest.server.resources.rest_resource import RestResource, SecuredRestResource
from flask import make_response, jsonify, request
import jwt
import datetime
......@@ -65,8 +64,7 @@ class AuthenticateResource(RestResource):
return make_response('Could not verify', 401, {'WWWW-Authenticate': 'Basic realm="Incorrect password!"'})
class GetUsersResource(RestResource):
method_decorators = [rest_jsonify, token_required]
class GetUsersResource(SecuredRestResource):
def get(self):
"""
......@@ -76,8 +74,7 @@ class GetUsersResource(RestResource):
return [UserDto(user) for user in users]
class GetProjectsListResource(RestResource):
method_decorators = [rest_jsonify, token_required]
class GetProjectsListResource(SecuredRestResource):
def get(self, username):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment