Exemplo n.º 1
0
    def unpublish(self,
                  recipients: Optional[Union[UserOrGroup,
                                             List[UserOrGroup]]] = None):
        """Unpublish the document for all users it was previously published to.
        If `recipients` parameter is specified unpublishes the document for the
        given users.

        Args:
            recipients(list): list of users or user groups to publish the
                document to (can be a list of IDs or a list of User and
                UserGroup elements).
        """

        if recipients is None:
            library.unpublish_document(self.connection, id=self.id)
        else:
            if not isinstance(recipients, list):
                recipients = [recipients]
            if all([isinstance(el, User) for el in recipients]):
                recipients = [recipient.id for recipient in recipients]
            elif all([isinstance(el, UserGroup) for el in recipients]):
                users = [
                    user for group in recipients for user in group.members
                ]
                recipients = [user["id"] for user in users]
            elif any([not isinstance(el, str) for el in recipients]):
                raise ValueError(
                    'Please provide either list User and UserGroup elements or str elements.'
                )
            for user_id in recipients:
                library.unpublish_document_for_user(self.connection,
                                                    document_id=self.id,
                                                    user_id=user_id)
Exemplo n.º 2
0
    def unpublish(self, contents: Union[List, "Document", "Dossier", str]):
        """Publishes dossier or document to the authenticated user's library.

        contents: dossiers or documents to be published, can be Dossier/Document
            class object or ID
        """
        if not isinstance(contents, list):
            contents = [contents]
        for doc in contents:
            doc_id = doc.id if isinstance(doc, Document) else doc
            library.unpublish_document_for_user(self.connection,
                                                user_id=self.user_id,
                                                document_id=doc_id)