linagora / tmail-backend

GNU Affero General Public License v3.0
41 stars 22 forks source link

PublicAssetRepository + memory implementation #1039

Closed quantranhong1999 closed 5 months ago

quantranhong1999 commented 5 months ago

Why

We need storage APIs for PublicAsset.

How

POJO

Transform the JMAP object:

id (serverSet)
publicURI (serverSet)
size (serverSet)
blobId
identityIds: Id[]|null, default to null

Notes: I removed username from the object as I think it is useless to expose the username to the client side. Meanwhile, in DB we still need to store the user owns the asset.

Introduce in tmail-backend/jmap/extensions/src/main/scala/com/linagora/tmail/james/jmap/model something like:

package com.linagora.tmail.james.jmap.model

import java.net.URI
import java.util.UUID

import org.apache.james.blob.api.BlobId
import org.apache.james.jmap.api.model.IdentityId
import org.apache.james.jmap.api.model.Size.Size

case class PublicAssetId(value: UUID)

case class PublicURI(value: URI) extends AnyVal

case class PublicAssetCreationRequest(blobId: BlobId)

case class PublicAsset(id: PublicAssetId,
                       publicURI: PublicURI,
                       size: Size,
                       blobId: BlobId,
                       identityIds: Seq[IdentityId])

PublicAssetRepository

public interface PublicAssetRepository {
    Publisher<PublicAsset> create(Username username, PublicAssetCreationRequest creationRequest);

    Publisher<Void> update(Username username, Set<IdentityId> identityIds);

    Publisher<Void> revoke(Username username, PublicAssetId id);

    Publisher<Void> revoke(Username username);

    Publisher<PublicAsset> get(Username username, Set<PublicAssetId> ids);

    Publisher<PublicAsset> list(Username username);
}

DoD

Memory implementation + contract tests.

quantranhong1999 commented 5 months ago

I think this POJO should go with the repository ticket.

chibenwa commented 5 months ago

agree

Arsnael commented 5 months ago

Feel free to edit this ticket and include the repository with it :)

vttranlina commented 5 months ago

Do we need a column for the storage Assets metadata?

eg: For storage Content-Type

quantranhong1999 commented 5 months ago

Do we need a column for the storage Assets metadata? eg: For storage Content-Type

That is what I doubted too. If we need it, then yes.

Arsnael commented 5 months ago

Isn't that info in the attachment table, that you can get with the blob_id?

quantranhong1999 commented 5 months ago

Isn't that info in the attachment table, that you can get with the blob_id?

Hmm, that is true, but it is just a pure blob and has nothing to do with attachment yet.

Arsnael commented 5 months ago

My bad, uploadsv2 table has the metadata of the upload with content type and should be enough to verify it upon /set create

Arsnael commented 5 months ago

@chibenwa actually no need of publicURI to be stored on db right, as we can build it up with accountId and assetId?

However, do we:

We think probably better the backend handles this though

Arsnael commented 5 months ago

Still maybe need contentType for when we return to the front the image from object storage?

Arsnael commented 5 months ago

Need a dedicated bucket for storing PublicAsset or can use the default one?

chibenwa commented 5 months ago

We think probably better the backend handles this though

I prefer the back to expose a fixed URL

chibenwa commented 5 months ago

Need a dedicated bucket for storing PublicAsset or can use the default one?

Default one is OK?

vttranlina commented 5 months ago

pr https://github.com/linagora/tmail-backend/pull/1055