Esempio n. 1
0
    def get(self, cr_id):
        """
        Get dataset from metax and strip it from having sensitive information

        :param cr_id: id to use to fetch the record from metax
        :return:
        """
        is_authd = authentication.is_authenticated()
        cr = cr_service.get_catalog_record(cr_id, True, True)
        if not cr:
            abort(400, message="Unable to get catalog record from Metax")

        # Sort data items
        sort_array_of_obj_by_key(
            cr.get('research_dataset', {}).get('remote_resources', []),
            'title')
        sort_array_of_obj_by_key(
            cr.get('research_dataset', {}).get('directories', []), 'details',
            'directory_name')
        sort_array_of_obj_by_key(
            cr.get('research_dataset', {}).get('files', []), 'details',
            'file_name')

        ret_obj = {
            'catalog_record':
            authorization.strip_information_from_catalog_record(cr, is_authd),
            'email_info':
            get_email_info(cr)
        }
        if cr_service.is_rems_catalog_record(cr):
            ret_obj[
                'has_permit'] = authorization.user_has_rems_permission_for_catalog_record(
                    cr_id, authentication.get_user_id(), is_authd)

        return ret_obj, 200
Esempio n. 2
0
def _render_index_template(saml_errors=[], slo_success=False):
    is_auth = is_authenticated()
    if is_auth:
        saml_attributes = session['samlUserdata'].items()
        log.debug("SAML attributes: {0}".format(saml_attributes))

    return render_template('index.html')
Esempio n. 3
0
    def get(self, cr_id):
        """
        Get files and directory objects for frontend.

        :param cr_id:
        :return:
        """
        args = self.parser.parse_args()
        dir_id = args['dir_id']
        file_fields = args.get('file_fields', None)
        directory_fields = args.get('directory_fields', None)

        cr = cr_service.get_catalog_record(cr_id, False, False)
        dir_api_obj = cr_service.get_directory_data_for_catalog_record(
            cr_id, dir_id, file_fields, directory_fields)

        if cr and dir_api_obj:
            # Sort the items
            sort_array_of_obj_by_key(dir_api_obj.get('directories', []),
                                     'directory_name')
            sort_array_of_obj_by_key(dir_api_obj.get('files', []), 'file_name')

            # Limit the amount of items to be sent to the frontend
            if 'directories' in dir_api_obj:
                dir_api_obj['directories'] = slice_array_on_limit(
                    dir_api_obj['directories'], TOTAL_ITEM_LIMIT)
            if 'files' in dir_api_obj:
                dir_api_obj['files'] = slice_array_on_limit(
                    dir_api_obj['files'], TOTAL_ITEM_LIMIT)

            # Strip the items of sensitive data
            authorization.strip_dir_api_object(
                dir_api_obj, authentication.is_authenticated(), cr)
            return dir_api_obj, 200
        return '', 404
    def get(self, dir_id):
        """
        Get files and directory objects for frontend.

        :param dir_id:
        :return:
        """
        dir_obj = qvain_light_service.get_directory(dir_id)

        # Return data only if authenticated
        if dir_obj and authentication.is_authenticated():
            # Sort the items
            sort_array_of_obj_by_key(dir_obj.get('directories', []),
                                     'directory_name')
            sort_array_of_obj_by_key(dir_obj.get('files', []), 'file_name')

            # Limit the amount of items to be sent to the frontend
            if 'directories' in dir_obj:
                dir_obj['directories'] = slice_array_on_limit(
                    dir_obj['directories'], TOTAL_ITEM_LIMIT)
            if 'files' in dir_obj:
                dir_obj['files'] = slice_array_on_limit(
                    dir_obj['files'], TOTAL_ITEM_LIMIT)

            return dir_obj, 200
        return '', 404
Esempio n. 5
0
    def delete(self):
        """
        Delete Flask session, used by frontend.

        :return:
        """
        authentication.reset_flask_session_on_logout()
        return not authentication.is_authenticated(), 200
Esempio n. 6
0
    def get(self):
        """
        Renew Flask session, used by frontend.

        :return:
        """
        if authentication.is_authenticated():
            session.modified = True
            return '', 200
        return '', 401
Esempio n. 7
0
    def get(self):
        """
        Get (logged-in) user info.

        :return:
        """
        user_info = {'is_authenticated': authentication.is_authenticated()}
        dn = authentication.get_user_display_name()
        if dn is not None:
            user_info['user_display_name'] = dn
        return user_info, 200
    def patch(self, cr_id):
        """
        Updete existing detaset.

        Arguments:
            cr_id {string} -- The identifier of the dataset.

        Returns:
            object -- The response from metax or if error an error message.

        """
        is_authd = authentication.is_authenticated()
        if not is_authd:
            return 'Not logged in', 400
        try:
            data, error = self.validationSchema.loads(request.data)
        except ValidationError as err:
            log.warning("INVALID FORM DATA: {0}".format(err.messages))
            return err.messages, 400
        try:
            metadata_provider_org = session["samlUserdata"][
                "urn:oid:1.3.6.1.4.1.25178.1.2.9"]
            metadata_provider_user = session["samlUserdata"][
                "urn:oid:1.3.6.1.4.1.8057.2.80.26"]
        except KeyError as err:
            log.warning(
                "The Metadata provider is not specified: \n{0}".format(err))
            return "The Metadata provider is not specified", 400
        if all([
                "remote_resources" in data, "files" not in data, "directorys"
                not in data
        ]):
            data_catalog = "urn:nbn:fi:att:data-catalog-att"
        elif all([
                "remote_resources" not in data, "files" in data
                or "directorys" in data
        ]):
            data_catalog = "urn:nbn:fi:att:data-catalog-ida"
        else:
            # If the user whants to add a dataset without data, the data_catalog is set to att.
            data_catalog = "urn:nbn:fi:att:data-catalog-att"
        metax_redy_data = data_to_metax(data, metadata_provider_org,
                                        metadata_provider_user, data_catalog)
        metax_response = update_dataset(metax_redy_data)
        return metax_response, 200
    def post(self):
        """
        Create a dataset to Metax with the form data from the frontend.

        Returns:
            object -- The response from metax or if error an error message.

        """
        is_authd = authentication.is_authenticated()
        if not is_authd:
            return 'Not logged in'
        try:
            data = self.validationSchema.loads(request.data)
        except ValidationError as err:
            log.warning("INVALID FORM DATA: {0}".format(err.messages))
            return err.messages
        try:
            metadata_provider_org = session["samlUserdata"][
                "urn:oid:1.3.6.1.4.1.25178.1.2.9"][0]
            metadata_provider_user = session["samlUserdata"][
                "urn:oid:1.3.6.1.4.1.16161.4.0.53"][0]
        except KeyError as err:
            log.warning(
                "The Metadata provider is not specified: \n{0}".format(err))
            return "The Metadata provider is not specified"

        if all([
                "remote_resources" in data, "files" not in data, "directorys"
                not in data
        ]):
            data_catalog = "urn:nbn:fi:att:data-catalog-att"
        elif all([
                "remote_resources" not in data, "files" in data
                or "directorys" in data
        ]):
            data_catalog = "urn:nbn:fi:att:data-catalog-ida"
        else:
            # If the user whants to add a dataset without data, the data_catalog is set to att.
            data_catalog = "urn:nbn:fi:att:data-catalog-att"
        metax_redy_data = data_to_metax(data, metadata_provider_org,
                                        metadata_provider_user, data_catalog)
        metax_response = create_dataset(metax_redy_data)
        return metax_response
Esempio n. 10
0
    def get(self):
        """
        Get (logged-in) user info.

        :return:
        """
        user_info = {
            'is_authenticated': authentication.is_authenticated(),
            'is_authenticated_CSC_user':
            authentication.is_authenticated_CSC_user()
        }
        dn = authentication.get_user_display_name()
        csc_user = authentication.get_user_csc_name()
        groups = authentication.get_user_ida_groups()
        user_info['user_ida_groups'] = groups
        if dn is not None:
            user_info['user_display_name'] = dn
        if csc_user is not None:
            user_info['user_csc_name'] = csc_user
        return user_info, 200
Esempio n. 11
0
    def get(self):
        """
        Download data REST endpoint for frontend.

        :return:
        """
        # Check request query parameters are present
        args = self.parser.parse_args()
        cr_id = args['cr_id']

        cr = cr_service.get_catalog_record(cr_id, False, False)
        if not cr:
            abort(400, message="Unable to get catalog record")

        if authorization.user_is_allowed_to_download_from_ida(
                cr, authentication.is_authenticated()):
            file_ids = args['file_id'] or []
            dir_ids = args['dir_id'] or []
            return download_data(cr_id, file_ids, dir_ids)
        else:
            abort(403, message="Not authorized")
    def get(self, user_id):
        """
        Get files and directory objects for frontend.

        :param dir_id:
        :return:
        """
        args = self.parser.parse_args()
        limit = args.get('limit', None)
        offset = args.get('offset', None)

        result = qvain_light_service.get_datasets_for_user(
            user_id, limit, offset)

        # Return data only if authenticated
        if result and authentication.is_authenticated():

            # Limit the amount of items to be sent to the frontend
            if 'results' in result:
                result['results'] = slice_array_on_limit(
                    result['results'], TOTAL_ITEM_LIMIT)

            return result, 200
        return '', 404