From 736968b0490f3f9982f1885337acf3a875f33682 Mon Sep 17 00:00:00 2001 From: eikek Date: Tue, 7 Sep 2021 21:59:38 +0200 Subject: [PATCH] Fix adding a new user and don't allow to add non-local users The user structure must provide the correct account source now. --- .../main/scala/docspell/backend/ops/OCollective.scala | 11 +++++++---- .../src/main/scala/docspell/store/AddResult.scala | 2 ++ modules/webapp/src/main/elm/Comp/UserForm.elm | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala b/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala index b2479e3e..c49a31ae 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OCollective.scala @@ -214,10 +214,13 @@ object OCollective { store.transact(RUser.findAll(collective, _.login)) def add(s: RUser): F[AddResult] = - store.add( - RUser.insert(s.copy(password = PasswordCrypt.crypt(s.password))), - RUser.exists(s.login) - ) + if (s.source != AccountSource.Local) + AddResult.failure(new Exception("Only local accounts can be created!")).pure[F] + else + store.add( + RUser.insert(s.copy(password = PasswordCrypt.crypt(s.password))), + RUser.exists(s.login) + ) def update(s: RUser): F[AddResult] = store.add(RUser.update(s), RUser.exists(s.login)) diff --git a/modules/store/src/main/scala/docspell/store/AddResult.scala b/modules/store/src/main/scala/docspell/store/AddResult.scala index 86bcf218..b14b623a 100644 --- a/modules/store/src/main/scala/docspell/store/AddResult.scala +++ b/modules/store/src/main/scala/docspell/store/AddResult.scala @@ -50,4 +50,6 @@ object AddResult { def fold[A](fa: Success.type => A, fb: EntityExists => A, fc: Failure => A): A = fc(this) } + def failure(ex: Exception): AddResult = + Failure(ex) } diff --git a/modules/webapp/src/main/elm/Comp/UserForm.elm b/modules/webapp/src/main/elm/Comp/UserForm.elm index 046e5996..86eba889 100644 --- a/modules/webapp/src/main/elm/Comp/UserForm.elm +++ b/modules/webapp/src/main/elm/Comp/UserForm.elm @@ -85,6 +85,7 @@ getUser model = , email = model.email , state = state , password = model.password + , source = "local" }