From 1ca63119567022d3cccf70f3d03b514aeefffa3c Mon Sep 17 00:00:00 2001 From: RoB Murdock Date: Tue, 18 Jul 2023 22:33:50 -0400 Subject: [PATCH] removing another execute usage --- .../action/connection/ConnectPartyUserCommand.kt | 12 ++++++------ .../coupling/server/AuthActionDispatcher.kt | 6 +----- .../coupling/server/CommandDispatcher.kt | 15 +++++++-------- .../server/express/route/UserLoadingMiddleware.kt | 13 ++++++++++--- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/connection/ConnectPartyUserCommand.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/connection/ConnectPartyUserCommand.kt index 57fab2a199..204e57ded0 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/connection/ConnectPartyUserCommand.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/connection/ConnectPartyUserCommand.kt @@ -5,19 +5,18 @@ import com.zegreatrob.coupling.model.CouplingConnection import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.model.player.Player import com.zegreatrob.coupling.model.user.CurrentUserProvider +import com.zegreatrob.coupling.server.action.CannonProvider import com.zegreatrob.coupling.server.action.user.UserIsAuthorizedWithDataAction import com.zegreatrob.testmints.action.annotation.ActionMint -import com.zegreatrob.testmints.action.async.SuspendActionExecuteSyntax @ActionMint data class ConnectPartyUserCommand(val partyId: PartyId, val connectionId: String) { - interface Dispatcher : - UserIsAuthorizedWithDataAction.Dispatcher, - SuspendActionExecuteSyntax, + interface Dispatcher : + CannonProvider, CouplingConnectionSaveSyntax, CouplingConnectionGetSyntax, - CurrentUserProvider { + CurrentUserProvider where D : UserIsAuthorizedWithDataAction.Dispatcher { suspend fun perform(command: ConnectPartyUserCommand) = with(command) { partyId.getAuthorizationData()?.let { (_, players) -> @@ -28,7 +27,8 @@ data class ConnectPartyUserCommand(val partyId: PartyId, val connectionId: Strin } } - private suspend fun PartyId.getAuthorizationData() = execute(UserIsAuthorizedWithDataAction(this)).valueOrNull() + private suspend fun PartyId.getAuthorizationData() = cannon.fire(UserIsAuthorizedWithDataAction(this)) + .valueOrNull() private fun userPlayer(players: List, email: String): Player { val existingPlayer = players.find { it.email == email } diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/AuthActionDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/AuthActionDispatcher.kt index 58d0d35fa8..acd13dedcc 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/AuthActionDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/AuthActionDispatcher.kt @@ -1,7 +1,6 @@ package com.zegreatrob.coupling.server import com.benasher44.uuid.Uuid -import com.zegreatrob.coupling.action.DispatchingActionExecutor import com.zegreatrob.coupling.action.TraceIdProvider import com.zegreatrob.coupling.repository.user.UserRepository import com.zegreatrob.coupling.server.action.user.FindOrCreateUserActionDispatcher @@ -12,7 +11,4 @@ class AuthActionDispatcher internal constructor( override val traceId: Uuid, ) : TraceIdProvider, FindOrCreateUserActionDispatcher, - UserRepository by userRepository, - DispatchingActionExecutor { - override val actionDispatcher = this -} + UserRepository by userRepository diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt index c4f19bc9d9..a459b57539 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt @@ -1,7 +1,6 @@ package com.zegreatrob.coupling.server import com.benasher44.uuid.Uuid -import com.zegreatrob.coupling.action.DispatchingActionExecutor import com.zegreatrob.coupling.action.LoggingActionPipe import com.zegreatrob.coupling.action.TraceIdProvider import com.zegreatrob.coupling.action.pairassignmentdocument.AssignPinsAction @@ -44,6 +43,7 @@ import com.zegreatrob.coupling.server.action.player.ServerSavePlayerCommandDispa import com.zegreatrob.coupling.server.action.secret.SecretListQuery import com.zegreatrob.coupling.server.action.slack.ServerGrantSlackAccessCommandDispatcher import com.zegreatrob.coupling.server.action.slack.SlackRepository +import com.zegreatrob.coupling.server.action.user.UserIsAuthorizedWithDataAction import com.zegreatrob.coupling.server.action.user.UserQuery import com.zegreatrob.coupling.server.entity.pairassignment.PairAssignmentDispatcher import com.zegreatrob.coupling.server.entity.party.PartyDispatcher @@ -60,26 +60,26 @@ import kotlinx.coroutines.async import kotlin.js.json interface ICommandDispatcher : - TraceIdProvider, AwsManagementApiSyntax, AwsSocketCommunicator, - ConnectPartyUserCommand.Dispatcher, ConnectionsQuery.Dispatcher, CurrentPairAssignmentDocumentQuery.Dispatcher, DisconnectPartyUserCommand.Dispatcher, GlobalStatsQuery.Dispatcher, PairAssignmentDocumentListQuery.Dispatcher, PartyDispatcher, - PinsQuery.Dispatcher, PartyIntegrationQuery.Dispatcher, + PinsQuery.Dispatcher, PlayersQuery.Dispatcher, ReportDocCommand.Dispatcher, RepositoryCatalog, RetiredPlayersQuery.Dispatcher, - ServerGrantSlackAccessCommandDispatcher, ScopeSyntax, SecretListQuery.Dispatcher, + ServerGrantSlackAccessCommandDispatcher, + TraceIdProvider, UserDispatcher, + UserIsAuthorizedWithDataAction.Dispatcher, UserQuery.Dispatcher class CommandDispatcher( @@ -91,7 +91,8 @@ class CommandDispatcher( ) : ICommandDispatcher, RepositoryCatalog by repositoryCatalog, TraceIdProvider, - BroadcastAction.Dispatcher { + BroadcastAction.Dispatcher, + ConnectPartyUserCommand.Dispatcher { override val cannon: ActionCannon = ActionCannon(this, LoggingActionPipe(traceId)) override val slackRepository: SlackRepository by lazy { FetchSlackRepository() } @@ -124,7 +125,6 @@ class CurrentPartyDispatcher( private val commandDispatcher: CommandDispatcher, ) : ICommandDispatcher by commandDispatcher, - DispatchingActionExecutor, CreatePairCandidateReportListAction.Dispatcher, ShufflePairsAction.Dispatcher, AssignPinsAction.Dispatcher, @@ -147,7 +147,6 @@ class CurrentPartyDispatcher( override val userId: String get() = commandDispatcher.userId override val cannon: ActionCannon = ActionCannon(this, LoggingActionPipe(traceId)) suspend fun isAuthorized() = currentPartyId.validateAuthorized() != null - override val actionDispatcher = this private suspend fun PartyId.validateAuthorized() = if (userIsAuthorized(this)) this else null private suspend fun userIsAuthorized(partyId: PartyId) = currentUser.authorizedPartyIds.contains(partyId) || diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/express/route/UserLoadingMiddleware.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/express/route/UserLoadingMiddleware.kt index 9995d8c0e1..1a60d9d87e 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/express/route/UserLoadingMiddleware.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/express/route/UserLoadingMiddleware.kt @@ -1,6 +1,7 @@ package com.zegreatrob.coupling.server.express.route -import com.benasher44.uuid.uuid4 +import com.benasher44.uuid.Uuid +import com.zegreatrob.coupling.action.LoggingActionPipe import com.zegreatrob.coupling.action.valueOrNull import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.model.party.PartyId @@ -12,6 +13,7 @@ import com.zegreatrob.coupling.server.express.async import com.zegreatrob.coupling.server.external.express.Handler import com.zegreatrob.coupling.server.external.express.Request import com.zegreatrob.coupling.server.secretRepository +import com.zegreatrob.testmints.action.ActionCannon fun userLoadingMiddleware(): Handler = { request, _, next -> val auth = request.auth @@ -30,8 +32,8 @@ fun userLoadingMiddleware(): Handler = { request, _, next -> null } } else { - UserDataService.authActionDispatcher("$userEmail", uuid4()) - .invoke(FindOrCreateUserAction) + authCannon(userEmail, request.traceId) + .fire(FindOrCreateUserAction) .valueOrNull() } .let(request::setUser) @@ -39,6 +41,11 @@ fun userLoadingMiddleware(): Handler = { request, _, next -> } } +private suspend fun authCannon(userEmail: Any?, traceId: Uuid) = ActionCannon( + UserDataService.authActionDispatcher("$userEmail", traceId), + LoggingActionPipe(traceId), +) + private suspend fun secretIsNotDeleted(secretId: String, partyId: PartyId): Boolean = secretRepository(secretId) .getSecrets(partyId) .elements