This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 8601db717962b4ca1be9843f18925efb003c98e7
Author: Florent Azavant <fazav...@linagora.com>
AuthorDate: Wed Nov 6 11:09:25 2024 +0100

    [ISSUE-5314] refactored `MailboxSet` to use `EntryKey` instead of `Username`
---
 .../rfc8621/contract/MailboxSetMethodContract.scala    |  2 +-
 .../scala/org/apache/james/jmap/mail/MailboxSet.scala  | 18 +++++++++---------
 .../james/jmap/method/MailboxSetUpdatePerformer.scala  |  2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala
index ce234f8c88..63e07bb3de 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala
@@ -5923,7 +5923,7 @@ trait MailboxSetMethodContract {
          |      "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |      "notUpdated": {
          |        "${mailboxId.serialize}": {
-         |          "type": "invalidPatch",
+         |          "type": "invalidArguments",
          |          "description": "Domain parts ASCII chars must be a-z A-Z 
0-9 - or _"
          |        }
          |      }
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
index 6a37cc850c..1071271491 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala
@@ -24,7 +24,6 @@ import eu.timepit.refined.auto._
 import eu.timepit.refined.collection.NonEmpty
 import eu.timepit.refined.refineV
 import eu.timepit.refined.types.string.NonEmptyString
-import org.apache.james.core.Username
 import org.apache.james.jmap.core.CapabilityIdentifier.CapabilityIdentifier
 import org.apache.james.jmap.core.Id.Id
 import org.apache.james.jmap.core.Properties.toProperties
@@ -34,6 +33,7 @@ import org.apache.james.jmap.json.MailboxSerializer
 import org.apache.james.jmap.mail.MailboxName.MailboxName
 import org.apache.james.jmap.mail.MailboxPatchObject.MailboxPatchObjectKey
 import org.apache.james.jmap.method.{MailboxCreationParseException, 
SetRequest, WithAccountId}
+import org.apache.james.mailbox.model.MailboxACL.EntryKey
 import org.apache.james.mailbox.model.{MailboxId, MailboxACL => JavaMailboxACL}
 import org.apache.james.mailbox.{MailboxSession, Role}
 import play.api.libs.json.{JsBoolean, JsError, JsNull, JsObject, JsString, 
JsSuccess, JsValue}
@@ -136,7 +136,7 @@ case class MailboxPatchObject(value: Map[String, JsValue]) {
       }).headOption
 
     val partialRightsUpdates: Seq[SharedWithPartialUpdate] = 
asUpdatedIterable.flatMap(x => x match {
-      case scala.Right(SharedWithPartialUpdate(username, rights)) => 
Some(SharedWithPartialUpdate(username, rights))
+      case scala.Right(SharedWithPartialUpdate(entryKey, rights)) => 
Some(SharedWithPartialUpdate(entryKey, rights))
       case _ => None
     }).toSeq
 
@@ -290,15 +290,15 @@ object SharedWithPartialUpdate {
   def parse(serializer: MailboxSerializer, capabilities: 
Set[CapabilityIdentifier])
            ( property: String, newValue: JsValue): 
Either[PatchUpdateValidationException, Update] =
     if (capabilities.contains(CapabilityIdentifier.JAMES_SHARES)) {
-      parseUsername(property)
-        .flatMap(username => parseRights(newValue, property, serializer)
-          .map(rights => SharedWithPartialUpdate(username, rights)))
+      parseEntryKey(property)
+        .flatMap(entryKey => parseRights(newValue, property, serializer)
+          .map(rights => SharedWithPartialUpdate(entryKey, rights)))
     } else {
       MailboxPatchObject.notFound(property)
     }
 
-  def parseUsername(property: String): Either[PatchUpdateValidationException, 
Username] = try {
-    
scala.Right(Username.of(property.substring(MailboxPatchObject.sharedWithPrefix.length)))
+  def parseEntryKey(property: String): Either[PatchUpdateValidationException, 
EntryKey] = try {
+    
scala.Right(EntryKey.deserialize(property.substring(MailboxPatchObject.sharedWithPrefix.length)))
   } catch {
     case e: Exception => Left(InvalidPropertyException(property, e.getMessage))
   }
@@ -336,8 +336,8 @@ sealed trait Update
 case class NameUpdate(newName: String) extends Update
 case class SharedWithResetUpdate(rights: Rights) extends Update
 case class IsSubscribedUpdate(isSubscribed: Option[IsSubscribed]) extends 
Update
-case class SharedWithPartialUpdate(username: Username, rights: Rfc4314Rights) 
extends Update {
-  def asACLCommand(): JavaMailboxACL.ACLCommand = 
JavaMailboxACL.command().forUser(username).rights(rights.asJava).asReplacement()
+case class SharedWithPartialUpdate(entryKey: EntryKey, rights: Rfc4314Rights) 
extends Update {
+  def asACLCommand(): JavaMailboxACL.ACLCommand = 
JavaMailboxACL.command().key(entryKey).rights(rights.asJava).asReplacement()
 }
 
 class PatchUpdateValidationException() extends IllegalArgumentException
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala
index 728010bbe4..615d96b193 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala
@@ -255,7 +255,7 @@ class MailboxSetUpdatePerformer @Inject()(serializer: 
MailboxSerializer,
           .action("Mailbox/set update")
           .parameters(() => ImmutableMap.of("loggedInUser", 
mailboxSession.getLoggedInUser.toScala.map(_.asString()).getOrElse(""),
             "delegator", mailboxSession.getUser.asString(),
-            "delegatee", partialUpdate.username.asString(),
+            "delegatee", partialUpdate.entryKey.getName,
             "mailboxId", mailboxId.serialize(),
             "rights", partialUpdate.rights.asJava.serialize()))
           .log("JMAP mailbox shared.")),


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to