Exemple #1
0
    def _get_study_and_check_access(self, study_id):
        """Checks if the current user has access to the study

        First tries to instantiate the study object. Then it checks if the
        current user has access to such study.

        Parameters
        ----------
        study_id : str or int
            The current study

        Returns
        -------
        The study object, the current user object and a boolean indicating if
        the user has full access to the study or only to public data

        Raises
        ------
        HTTPError
            If study_id does not correspond to any study in the system
        """
        user = self.current_user

        try:
            study = Study(_to_int(study_id))
        except (QiitaDBUnknownIDError, HTTPError):
            # Study not in database so fail nicely
            raise HTTPError(404, "Study %s does not exist" % study_id)
        else:
            check_access(user, study, raise_error=True)

        full_access = (user.level == 'admin' or
                       study.id in user.user_studies | user.shared_studies)

        return study, user, full_access
    def _get_sudy_and_check_access(self, study_id):
        """Checks if the current user has access to the study

        First tries to instantiate the study object. Then it checks if the
        current user has access to such study.

        Parameters
        ----------
        study_id : str or int
            The current study

        Returns
        -------
        The study object and the current user object

        Raises
        ------
        HTTPError
            If study_id does not correspond to any study in the system
        """
        user = User(self.current_user)

        try:
            study = Study(_to_int(study_id))
        except (QiitaDBUnknownIDError, HTTPError):
            # Study not in database so fail nicely
            raise HTTPError(404, "Study %s does not exist" % study_id)
        else:
            check_access(user, study, raise_error=True)

        return study, user
Exemple #3
0
    def _get_study_and_check_access(self, study_id):
        """Checks if the current user has access to the study

        First tries to instantiate the study object. Then it checks if the
        current user has access to such study.

        Parameters
        ----------
        study_id : str or int
            The current study

        Returns
        -------
        The study object and the current user object

        Raises
        ------
        HTTPError
            If study_id does not correspond to any study in the system
        """
        user = self.current_user

        try:
            study = Study(_to_int(study_id))
        except (QiitaDBUnknownIDError, HTTPError):
            # Study not in database so fail nicely
            raise HTTPError(404, "Study %s does not exist" % study_id)
        else:
            check_access(user, study, raise_error=True)

        return study, user
    def _get_study_and_check_access(self, study_id):
        """Checks if the current user has access to the study

        First tries to instantiate the study object. Then it checks if the
        current user has access to such study.

        Parameters
        ----------
        study_id : str or int
            The current study

        Returns
        -------
        The study object, the current user object and a boolean indicating if
        the user has full access to the study or only to public data

        Raises
        ------
        HTTPError
            If study_id does not correspond to any study in the system
        """
        user = self.current_user

        try:
            study = Study(_to_int(study_id))
        except (QiitaDBUnknownIDError, HTTPError):
            # Study not in database so fail nicely
            raise HTTPError(404, "Study %s does not exist" % study_id)
        else:
            check_access(user, study, raise_error=True)

        full_access = (user.level == 'admin'
                       or study in user.user_studies | user.shared_studies)

        return study, user, full_access
Exemple #5
0
    def _check_study_exists_and_user_access(self, study_id):
        try:
            study = Study(int(study_id))
        except QiitaDBUnknownIDError:
            # Study not in database so fail nicely
            raise HTTPError(404, "Study %s does not exist" % study_id)

        # We need to check if the user has access to the study
        check_access(self.current_user, study)
        return study
Exemple #6
0
    def _check_study_exists_and_user_access(self, study_id):
        try:
            study = Study(int(study_id))
        except QiitaDBUnknownIDError:
            # Study not in database so fail nicely
            raise HTTPError(404, "Study %s does not exist" % study_id)

        # We need to check if the user has access to the study
        check_access(self.current_user, study)
        return study
    def _get_template_variables(self, preprocessed_data_id, callback):
        """Generates all the variables needed to render the template

        Parameters
        ----------
        preprocessed_data_id : int
            The preprocessed data identifier
        callback : function
            The callback function to call with the results once the processing
            is done

        Raises
        ------
        HTTPError
            If the preprocessed data does not have a log file
        """
        # Get the objects and check user privileges
        ppd = Artifact(preprocessed_data_id)
        study = ppd.study
        check_access(self.current_user, study, raise_error=True)

        # Get the return address
        back_button_path = self.get_argument(
            'back_button_path',
            '/study/description/%d?top_tab=preprocessed_data_tab&sub_tab=%s' %
            (study.id, preprocessed_data_id))

        # Get all the filepaths attached to the preprocessed data
        files_tuples = ppd.filepaths

        # Group the files by filepath type
        files = defaultdict(list)
        for _, fp, fpt in files_tuples:
            files[fpt].append(fp)

        try:
            log_path = files['log'][0]
        except KeyError:
            raise HTTPError(
                500, "Log file not found in preprocessed data %s" %
                preprocessed_data_id)

        with open(log_path, 'U') as f:
            contents = f.read()
            contents = contents.replace('\n', '<br/>')
            contents = contents.replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;')

        title = 'Preprocessed Data: %d' % preprocessed_data_id

        callback((title, contents, back_button_path))
Exemple #8
0
    def _get_template_variables(self, preprocessed_data_id, callback):
        """Generates all the variables needed to render the template

        Parameters
        ----------
        preprocessed_data_id : int
            The preprocessed data identifier
        callback : function
            The callback function to call with the results once the processing
            is done

        Raises
        ------
        HTTPError
            If the preprocessed data does not have a log file
        """
        # Get the objects and check user privileges
        ppd = PreprocessedData(preprocessed_data_id)
        study = Study(ppd.study)
        check_access(self.current_user, study, raise_error=True)

        # Get the return address
        back_button_path = self.get_argument(
            'back_button_path',
            '/study/description/%d?top_tab=preprocessed_data_tab&sub_tab=%s'
            % (study.id, preprocessed_data_id))

        # Get all the filepaths attached to the preprocessed data
        files_tuples = ppd.get_filepaths()

        # Group the files by filepath type
        files = defaultdict(list)
        for _, fp, fpt in files_tuples:
            files[fpt].append(fp)

        try:
            log_path = files['log'][0]
        except KeyError:
            raise HTTPError(500, "Log file not found in preprocessed data %s"
                                 % preprocessed_data_id)

        with open(log_path, 'U') as f:
            contents = f.read()
            contents = contents.replace('\n', '<br/>')
            contents = contents.replace('\t', '&nbsp;&nbsp;&nbsp;&nbsp;')

        title = 'Preprocessed Data: %d' % preprocessed_data_id

        callback((title, contents, back_button_path))
    def get(self):
        study_id = int(self.get_argument('study_id'))
        study = Study(study_id)
        check_access(self.current_user, study, no_public=True,
                     raise_error=True)

        selected = self.get_argument('selected', None)
        deselected = self.get_argument('deselected', None)

        if selected is not None:
            yield Task(self._share, study, selected)
        if deselected is not None:
            yield Task(self._unshare, study, deselected)

        users, links = yield Task(self._get_shared_for_study, study)

        self.write(dumps({'users': users, 'links': links}))
    def get(self):
        study_id = int(self.get_argument('id'))
        study = Study(study_id)
        check_access(self.current_user, study, no_public=True,
                     raise_error=True)

        selected = self.get_argument('selected', None)
        deselected = self.get_argument('deselected', None)

        if selected is not None:
            yield Task(self._share, study, selected)
        if deselected is not None:
            yield Task(self._unshare, study, deselected)

        users, links = yield Task(self._get_shared_for_study, study)

        self.write(dumps({'users': users, 'links': links}))