Exemple #1
0
 def transferOwnership(self, entity, workspace_id):
     entityName = entity.__entityName__
     headers = getHeaders(entity.__user__)
     url = url_join(configService.getHost(), "api/generic/", entityName,
                    str(entity.id), "transfer-ownership")
     params = {"group_id": workspace_id}
     requestService.post(url, headers=headers, json=params)
Exemple #2
0
    def revokePermission(self, entity, workspace_id):
        entityName = entity.__entityName__

        headers = getHeaders(entity.__user__)
        url = url_join(configService.getHost(), "api/generic/", "acl")

        params = {
            "id": entity.id,
            "entity_class": entityName.replace("-", "_"),
            "action": "revoke",
            "group_id": workspace_id,
        }
        requestService.post(url, headers=headers, json=params)
        return entity
Exemple #3
0
 def newInvitations(self,
                    user,
                    invitationType,
                    emails,
                    organization_id,
                    workspace_id=None):
     url = url_join(configService.getHost(), 'api/generic',
                    'share-link-invitation', invitationType)
     headers = getHeaders(user=user)
     json = {
         'emails': emails,
         'organization_id': organization_id,
         'organization_group_id': workspace_id
     }
     requestService.post(url=url, headers=headers, json=json)
Exemple #4
0
 def downloadFile(self, user, fileId):
     headers = getHeaders(user=user)
     url = url_join(configService.getHost(), "/api/generic/file/download",
                    str(fileId))
     response = requestService.post(url, headers=headers)
     rawData = requestService.get(json.loads(
         response.content)["signed_url"],
                                  headers=None).content
     return rawData
Exemple #5
0
    def acceptSharelink(self, token):
        """
        Accept a sharelink

        Parameters
        ----------
        token (class)
            The token of the sharelink.

        Returns
        -------
        None
        """
        # FIXME Refactor
        headers = getHeaders(self)
        url = url_join(configService.getHost(), "/api/generic/", "share-link",
                       'accept', token)
        requestService.post(url, headers=headers)
        return None
Exemple #6
0
 def impersonate(self, username, apikey):
     user = self.getUser(username, apikey)
     url = url_join(configService.getHost(),
                    "api/generic/token/impersonate")
     response = requestService.post(url,
                                    json={'guid': user.guid},
                                    headers={"apikey": apikey})
     token = json.loads(response.content)['uuid']
     user.api_key = token
     return user
Exemple #7
0
 def newEntities(self, user, entityClass, items):
     headers = getHeaders(user=user)
     url = url_join(configService.getHost(), "/api/generic/",
                    entityClass.__entityName__, "batch")
     response = requestService.post(url,
                                    headers=headers,
                                    json={
                                        "items": items,
                                        "group_id": user.activeWorkspace
                                    })
     entities = json.loads(response.content)
     return list(map(lambda entity: entityClass(entity, user), entities))
Exemple #8
0
    def newEntity(self, user, entityClass, fields):
        headers = getHeaders(user=user)
        url = url_join(configService.getHost(), "/api/generic/",
                       entityClass.__entityName__)
        fields = dict(
            filter(lambda field: field[1] is not None, fields.items()))

        if "group_id" not in fields and getattr(entityClass,
                                                "__hasParentGroup__", False):
            fields["group_id"] = user.activeWorkspace

        response = requestService.post(url, headers=headers, json=fields)
        return entityClass(json.loads(response.content), user)
Exemple #9
0
    def newFile(self, user, filepath=None, rawData=None, extraParams={}):
        if filepath is not None:
            rawData = open(filepath, 'rb')
        if rawData is None:
            raise Exception('Please specify filepath or raw data')

        files = {'file': rawData}
        params = {"group_id": user.activeWorkspace, **extraParams}
        headers = getHeaders(user=user)
        url = url_join(configService.getHost(), "/api/generic/file/upload")
        response = requestService.post(url,
                                       headers=headers,
                                       files=files,
                                       data=params)
        data = json.loads(response.content)
        return File(list(data.values())[0], user)
Exemple #10
0
    def getHTML(self, entity):
        """
        Gets HTML summary of experiments / protocols.

        """
        headers = getHeaders(entity.__user__)

        body = {
            "group_id": entity.__user__.activeWorkspace,
            "query_entity_name": entity.__entityName__.replace("-", "_"),
            "query_parameters": {
                "id": entity.id
            },
            "type": "html"
        }

        url = url_join(configService.getHost(), 'api/generic', 'entity-export')
        response = requestService.post(url, json=body, headers=headers)

        return json.loads(response.content)['html']
    def parseHTML(self, authenticatedUser, html):
        """
        Converts HTML into the JSON format used in protocols
        and experiment entries.

        Parameters
        ----------
        authenticatedUser (:)
            An authenticated Labstep :class:`~labstep.entities.user.model.User`
            (see :func:`~labstep.authenticate`)
        html (str)
            HTML to be converted (as a string).
        """
        headers = {"Authorization": f"Bearer {authenticatedUser.token}"}

        body = {"html": html}

        url = "https://html-converter.labstep.com"
        response = requestService.post(url, json=body, headers=headers)
        return json.loads(response.content)
Exemple #12
0
    def newUser(
        self,
        first_name,
        last_name,
        email,
        password,
        share_link_token=None,
        extraParams={},
    ):
        url = url_join(configService.getHost(), "public-api/user")
        params = {
            "first_name": first_name,
            "last_name": last_name,
            "email": email,
            "password": password,
            "share_link_token": share_link_token,
            **extraParams,
        }

        params = dict(
            filter(lambda field: field[1] is not None, params.items()))

        response = requestService.post(url=url, json=params, headers=None)
        return User(json.loads(response.content))
Exemple #13
0
 def login(self, username, password):
     params = {"username": username, "password": password}
     url = url_join(configService.getHost(), "/public-api/user/login")
     response = requestService.post(url=url, json=params, headers={})
     return User(json.loads(response.content))