Commit 248ec4e8 authored by davelopez's avatar davelopez
Browse files

Allow admin access to datasets API (before refactoring)

This patch contains the changes in #13060 and it is meant to be applied only to 21.09 do not merge forward this commit into 22.01 since it is already fixed there
parent 6bbf5f65
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -46,6 +46,10 @@ class DatasetsController(BaseGalaxyAPIController, UsesVisualizationMixin):
    def serializer_by_type(self):
        return {'dataset': self.hda_serializer, 'dataset_collection': self.hdca_serializer}

    @property
    def dataset_manager_by_type(self):
        return {'hda': self.hda_manager, 'ldda': self.ldda_manager}

    def _parse_serialization_params(self, kwd, default_view):
        view = kwd.get('view', None)
        keys = kwd.get('keys')
@@ -131,7 +135,8 @@ class DatasetsController(BaseGalaxyAPIController, UsesVisualizationMixin):
        Displays information about and/or content of a dataset.
        """
        # Get dataset.
        dataset = self.get_hda_or_ldda(trans, hda_ldda=hda_ldda, dataset_id=id)
        decoded_dataset_id = self.decode_id(id)
        dataset = self.dataset_manager_by_type[hda_ldda].get_accessible(decoded_dataset_id, trans.user)

        # Use data type to return particular type of data.
        if data_type == 'state':
@@ -169,7 +174,8 @@ class DatasetsController(BaseGalaxyAPIController, UsesVisualizationMixin):
        Display user-facing storage details related to the objectstore a
        dataset resides in.
        """
        dataset_instance = self.get_hda_or_ldda(trans, hda_ldda=hda_ldda, dataset_id=dataset_id)
        decoded_dataset_id = self.decode_id(dataset_id)
        dataset_instance = self.dataset_manager_by_type[hda_ldda].get_accessible(decoded_dataset_id, trans.user)
        dataset = dataset_instance.dataset
        object_store = self.app.object_store
        object_store_id = dataset.object_store_id
@@ -198,7 +204,8 @@ class DatasetsController(BaseGalaxyAPIController, UsesVisualizationMixin):

        For internal use, this endpoint may change without warning.
        """
        dataset_instance = self.get_hda_or_ldda(trans, hda_ldda=hda_ldda, dataset_id=dataset_id)
        decoded_dataset_id = self.decode_id(dataset_id)
        dataset_instance = self.dataset_manager_by_type[hda_ldda].get_accessible(decoded_dataset_id, trans.user)
        inherit_chain = dataset_instance.source_dataset_chain
        result = []
        for dep in inherit_chain:
@@ -218,13 +225,11 @@ class DatasetsController(BaseGalaxyAPIController, UsesVisualizationMixin):
        if payload:
            kwd.update(payload)
        hda_ldda = kwd.get('hda_ldda', 'hda')
        dataset_assoc = self.get_hda_or_ldda(trans, hda_ldda=hda_ldda, dataset_id=dataset_id)
        if hda_ldda == "hda":
            self.hda_manager.update_permissions(trans, dataset_assoc, **kwd)
            return self.hda_manager.serialize_dataset_association_roles(trans, dataset_assoc)
        else:
            self.ldda_manager.update_permissions(trans, dataset_assoc, **kwd)
            return self.ldda_manager.serialize_dataset_association_roles(trans, dataset_assoc)
        decoded_dataset_id = self.decode_id(dataset_id)
        dataset_manager = self.dataset_manager_by_type[hda_ldda]
        dataset = dataset_manager.get_accessible(decoded_dataset_id, trans.user)
        dataset_manager.update_permissions(trans, dataset, **payload)
        return dataset_manager.serialize_dataset_association_roles(trans, dataset)

    def _dataset_in_use_state(self, dataset):
        """
+17 −2
Original line number Diff line number Diff line
@@ -106,8 +106,23 @@ class DatasetsApiTestCase(ApiTestCase):
        self.dataset_populator.make_private(history_id=self.history_id, dataset_id=hda['id'])
        with self._different_user():
            show_response = self._get(f"datasets/{hda['id']}")
            self._assert_status_code_is(show_response, 400)
            assert show_response.json()['err_msg'] == 'You are not allowed to access this dataset'
            self._assert_status_code_is(show_response, 403)

    def test_admin_can_update_permissions(self):
        # Create private dataset
        hda = self.dataset_populator.new_dataset(self.history_id)
        dataset_id = hda['id']
        self.dataset_populator.make_private(history_id=self.history_id, dataset_id=dataset_id)

        # Admin removes restrictions
        payload = {"action": "remove_restrictions"}
        update_response = self._put(f"datasets/{dataset_id}/permissions", payload, admin=True, json=True)
        self._assert_status_code_is_ok(update_response)

        # Other users can access the dataset
        with self._different_user():
            show_response = self._get(f"datasets/{hda['id']}")
            self._assert_status_code_is_ok(show_response)

    def __assert_matches_hda(self, input_hda, query_hda):
        self._assert_has_keys(query_hda, "id", "name")
+1 −1
Original line number Diff line number Diff line
@@ -575,7 +575,7 @@ class SharingHistoryTestCase(ApiTestCase, BaseHistories, SharingApiTests):
        # Other users cannot access the dataset
        with self._different_user():
            show_response = self._get(f"datasets/{hda_id}")
            self._assert_status_code_is(show_response, 400)
            self._assert_status_code_is(show_response, 403)

        sharing_response = self._set_resource_sharing(history_id, "publish")
        assert sharing_response["published"] is True