securedrop-client icon indicating copy to clipboard operation
securedrop-client copied to clipboard

Issues creating and SDKSubmission and SDKReply

Open sssoleileraaa opened this issue 5 years ago • 2 comments

Description

There should be a clear API for creating SDK objects. What's needed when you want to fetch a reply, message, or file?

The code makes it look like all you need is uuid to retrieve a file or message:

class Submission:
    """
    This class represents a submission object in the server.
    """
    def __init__(self, **kwargs) -> None:  # type: ignore
        self.download_url = ""  # type: str
        self.filename = ""  # type: str
        self.is_read = False  # type: bool
        self.size = 0  # type: int
        self.source_url = ""  # type: str
        self.source_uuid = ""  # type: str
        self.submission_url = ""  # type: str
        self.uuid = ""  # type: str
    
        if ["uuid"] == list(kwargs.keys()):
            # Means we are creating an object only for fetching from server.
            self.uuid = kwargs["uuid"]
            return
...

The code makes it look like all you need is a uuid and filename to retrieve a reply:

class Reply:
    """
    This class represents a reply object in the server.
    """
    def __init__(self, **kwargs) -> None:  # type: ignore
        self.filename = ""  # type: str
        self.journalist_username = ""  # type: str
        self.journalist_uuid = ""  # type: str
        self.is_deleted_by_source = False  # type: bool
        self.reply_url = ""  # type: str
        self.size = 0  # type: int
        self.source_url = ""  # type: str
        self.source_uuid = ""  # type: str
        self.uuid = ""  # type: str
    
        if {"uuid", "filename"} == set(kwargs.keys()):
            # Then we are creating an object for fetching from the server.
            self.uuid = kwargs["uuid"]
            self.filename = kwargs["filename"]
            return
...

However when you call download_submission or download_reply and pass it one of these sdk objects, we are unable to fetch a submission or a reply. Also see examples of inconsistencies below.

Examples

Only this works

sdk_obj = SdkReply(uuid=db_object.uuid, filename=db_object.filename)
sdk_obj = SdkSubmission(uuid=db_object.uuid)

And passing all the keys in this list when instantiating:

            "download_url",
            "filename",
            "is_read",
            "size",
            "source_url",
            "submission_url",
            "uuid",

This doesn't work

sdk_obj = SdkReply(uuid=db_object.uuid)

...

E           KeyError: 'filename'

This doesn't work

SdkReply(uuid=db_object.uuid, filename=db_object.filename, source_uuid=db_object.source.uuid)

...

E           KeyError: 'journalist_username'

This doesn't work

SdkSubmission(uuid=db_object.uuid, filename=db_object.filename, source_uuid=db_object.source.uuid)

...

E           KeyError: 'download_url'

sssoleileraaa avatar Jun 18 '19 23:06 sssoleileraaa