def __init__(
            self,
            id_: uuid.UUID,
            duid: DataUnitID,
            sample_node_address: SampleNodeAddress,
            created: datetime.datetime,
            created_by: UserID,
            expired: datetime.datetime = None,
            expired_by: UserID = None):
        '''
        Create the link. If expired is provided expired_by must also be provided. If expired
        is falsy expired_by is ignored.

        :param id_: the link ID. This is generally expected to be unique per link.
        :param duid: the data ID.
        :param sample_node_address: the sample node address.
        :param created: the creation time for the link.
        :param created_by: the user that created the link.
        :param expired: the expiration time for the link or None if the link is not expired.
        :param expired_by: the user that expired the link or None if the link is not expired.
        '''
        # may need to make this non ws specific. YAGNI for now.
        self.id = _not_falsy(id_, 'id_')
        self.duid = _not_falsy(duid, 'duid')
        self.sample_node_address = _not_falsy(sample_node_address, 'sample_node_address')
        self.created = _check_timestamp(created, 'created')
        self.created_by = _not_falsy(created_by, 'created_by')
        self.expired = None
        self.expired_by = None
        if expired:
            self.expired = _check_timestamp(expired, 'expired')
            if expired < created:
                raise ValueError('link cannot expire before it is created')
            self.expired_by = _not_falsy(expired_by, 'expired_by')
Exemple #2
0
 def _resolve_timestamp(self,
                        timestamp: datetime.datetime = None
                        ) -> datetime.datetime:
     if timestamp:
         _check_timestamp(timestamp, 'timestamp')
     else:
         timestamp = self._now()
     return timestamp
Exemple #3
0
 def __init__(self,
              id_: UUID,
              user: UserID,
              nodes: List[SampleNode],
              savetime: datetime.datetime,
              name: Optional[str] = None,
              version: Optional[int] = None):
     '''
     Create the sample.
     :param id_: The ID of the sample.
     :param user: The user who saved the sample.
     :param nodes: The tree nodes in the sample. BIOLOGICAL_REPLICATES must come first in
         the list, and parents must come before children in the list.
     :param savetime: The time the sample was saved. Cannot be a naive datetime.
     :param name: The name of the sample. Cannot contain control characters or be longer than
         255 characters.
     :param version: The version of the sample, or None if unknown.
     :raise MissingParameterError: if no nodes are provided.
     :raises IllegalParameterError: if the name is too long or contains illegal characters,
         the first node in the list is not a BIOLOGICAL_REPLICATE, all the BIOLOGICAL_REPLICATES
         are not at the start of this list, node names are not unique, or parent nodes
         do not appear in the list prior to their children.
     '''
     # having None as a possible version doesn't sit well with me, but that means we need
     # yet another class, so...
     super().__init__(nodes, name)
     self.id = _not_falsy(id_, 'id_')
     self.user = _not_falsy(user, 'user')
     self.savetime = _check_timestamp(savetime, 'savetime')
     if version is not None and version < 1:
         raise ValueError('version must be > 0')
     self.version = version
Exemple #4
0
    def __init__(self,
                 owner: UserID,
                 lastupdate: datetime.datetime,
                 admin: Sequence[UserID] = None,
                 write: Sequence[UserID] = None,
                 read: Sequence[UserID] = None,
                 public_read: bool = False):
        '''
        Create the ACLs.

        :param owner: the owner username.
        :param lastupdate: the last time the ACLs were updated.
        :param admin: the list of admin usernames.
        :param write: the list of usernames with write privileges.
        :param read: the list of usernames with read privileges.
        :param public_read: a boolean designating whether the sample is publically readable.
            None is considered false.
        :raises IllegalParameterError: If a user appears in more than one ACL
        '''
        self.owner = _not_falsy(owner, 'owner')
        self.lastupdate = _check_timestamp(lastupdate, 'lastupdate')
        super().__init__(admin, write, read, public_read)
        all_ = (self.admin, self.write, self.read)
        for i in range(len(all_)):
            if self.owner in all_[i]:
                raise _IllegalParameterError(
                    'The owner cannot be in any other ACL')