linagora / tmail-backend

GNU Affero General Public License v3.0
30 stars 17 forks source link

PublicAssetRepository + memory implementation #1039

Closed quantranhong1999 closed 1 month ago

quantranhong1999 commented 1 month 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 1 month ago

I think this POJO should go with the repository ticket.

chibenwa commented 1 month ago

agree

Arsnael commented 1 month ago

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

vttranlina commented 1 month ago

Do we need a column for the storage Assets metadata?

eg: For storage Content-Type

quantranhong1999 commented 1 month 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 1 month ago

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

quantranhong1999 commented 1 month 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 1 month 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 1 month 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 1 month ago

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

Arsnael commented 1 month ago

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

chibenwa commented 1 month ago

We think probably better the backend handles this though

I prefer the back to expose a fixed URL

chibenwa commented 1 month ago

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

Default one is OK?

vttranlina commented 1 month ago

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