Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Get author's email token from within KMP when generating a NewUploadSession #131

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ class SwissTransferInjection(
}

/** A manager used to orchestrate Uploads operations. */
val uploadManager by lazy { UploadManager(uploadController, uploadRepository, transferManager, emailLanguageUtils) }
val uploadManager by lazy {
UploadManager(
uploadController,
uploadRepository,
transferManager,
emailLanguageUtils,
emailTokensManager,
)
}

/** An utils to help use shared routes */
val sharedApiUrlCreator by lazy { SharedApiUrlCreator(environment, transferController, uploadController) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.infomaniak.multiplatform_swisstransfer.managers

import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException
import com.infomaniak.multiplatform_swisstransfer.database.controllers.EmailTokensController
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.AuthorEmailToken
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.withContext
Expand All @@ -45,13 +46,13 @@ class EmailTokensManager(private val emailTokensController: EmailTokensControlle
* Asynchronously sets the email and it's corresponding token.
*
* @param email The validated email.
* @param token The valid token associated to the email.
* @param authorEmailToken The valid token associated to the email.
*
* @throws RealmException If an error occurs during database access.
* @throws CancellationException If the operation is cancelled.
*/
@Throws(RealmException::class, CancellationException::class)
suspend fun setEmailToken(email: String, token: String): Unit = withContext(Dispatchers.IO) {
emailTokensController.setEmailToken(email, token)
suspend fun setEmailToken(email: String, authorEmailToken: AuthorEmailToken): Unit = withContext(Dispatchers.IO) {
emailTokensController.setEmailToken(email, authorEmailToken.token)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package com.infomaniak.multiplatform_swisstransfer.managers

import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException
import com.infomaniak.multiplatform_swisstransfer.common.exceptions.UnknownException
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadFileSession
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadSession
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferStatus
import com.infomaniak.multiplatform_swisstransfer.common.models.*
import com.infomaniak.multiplatform_swisstransfer.data.NewUploadSession
import com.infomaniak.multiplatform_swisstransfer.database.controllers.UploadController
import com.infomaniak.multiplatform_swisstransfer.exceptions.NotFoundException
Expand Down Expand Up @@ -56,6 +56,7 @@ class UploadManager(
private val uploadRepository: UploadRepository,
private val transferManager: TransferManager,
private val emailLanguageUtils: EmailLanguageUtils,
private val emailTokensManager: EmailTokensManager,
) {

val lastUploadFlow get() = uploadController.getLastUploadFlow().flowOn(Dispatchers.IO)
Expand Down Expand Up @@ -108,6 +109,27 @@ class UploadManager(
uploadController.insertAndGet(newUploadSession)
}

suspend fun generateNewUploadSession(
duration: ValidityPeriod,
authorEmail: String,
password: String,
message: String,
numberOfDownload: DownloadLimit,
language: EmailLanguage,
recipientsEmails: Set<String>,
files: List<UploadFileSession>,
): NewUploadSession = NewUploadSession(
duration = duration,
authorEmail = authorEmail,
authorEmailToken = emailTokensManager.getTokenForEmail(authorEmail),
password = password,
message = message,
numberOfDownload = numberOfDownload,
language = language,
recipientsEmails = recipientsEmails,
files = files,
)

/**
* Initializes an upload session and update it in database with the remote data.
*
Expand Down
Loading