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

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


The following commit(s) were added to refs/heads/master by this push:
     new 68dadcca33 JAMES-3171 - JMAP - Mailbox/get - Fix missing MailboxDelete 
right in response for shared mailbox (#2640)
68dadcca33 is described below

commit 68dadcca33cfe17919e3358ee62d4af449b18989
Author: vttran <vtt...@linagora.com>
AuthorDate: Thu Feb 20 10:45:29 2025 +0700

    JAMES-3171 - JMAP - Mailbox/get - Fix missing MailboxDelete right in 
response for shared mailbox (#2640)
---
 .../contract/MailboxGetMethodContract.scala        | 72 ++++++++++++++++++++++
 .../contract/MailboxSetMethodContract.scala        |  4 +-
 .../apache/james/jmap/mail/MailboxFactory.scala    |  2 +-
 .../scala/org/apache/james/jmap/mail/Rights.scala  |  3 +-
 .../org/apache/james/jmap/mail/RightsTest.scala    |  4 +-
 5 files changed, 79 insertions(+), 6 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/MailboxGetMethodContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala
index 4b92d4bb47..f378f52c7b 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxGetMethodContract.scala
@@ -812,6 +812,78 @@ trait MailboxGetMethodContract {
       .body(s"$FIRST_MAILBOX.rights['$targetUser2']", contains(LOOKUP, READ))
   }
 
+  @Test
+  def getMailboxesShouldReturnDeleteMailboxRight(server: GuiceJamesServer): 
Unit = {
+    val targetUser2: String = "touser2@" + DOMAIN.asString
+    val mailboxName: String = "myMailbox"
+    val mailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
+      .createMailbox(MailboxPath.forUser(BOB, mailboxName))
+      .serialize
+    server.getProbe(classOf[ACLProbeImpl])
+      .replaceRights(MailboxPath.forUser(BOB, mailboxName), targetUser2, new 
MailboxACL.Rfc4314Rights(Right.Read, Right.Lookup, Right.DeleteMailbox))
+
+    val response: String = `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(s"""{
+               |  "using": [
+               |    "urn:ietf:params:jmap:core",
+               |    "urn:ietf:params:jmap:mail",
+               |    "urn:apache:james:params:jmap:mail:shares"],
+               |  "methodCalls": [[
+               |      "Mailbox/get",
+               |      {
+               |        "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+               |        "ids": ["${mailboxId}"]
+               |      },
+               |      "c1"]]
+               |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .extract
+      .body
+      .asString
+
+    assertThatJson(response)
+      .withOptions(Option.IGNORING_ARRAY_ORDER)
+      .inPath("methodResponses[0][1].list[0].rights")
+      .isEqualTo("""{ "tous...@domain.tld": [ "l", "r", "x" ] }""")
+  }
+
+  @Test
+  def myRightsShouldReturnCorrectMayDeleteWhenHasRightInSharedMailbox(server: 
GuiceJamesServer): Unit = {
+    val sharedMailboxName = "AndreShared"
+    val andreMailboxPath = MailboxPath.forUser(ANDRE, sharedMailboxName)
+    val andreMailboxId: String = server.getProbe(classOf[MailboxProbeImpl])
+      .createMailbox(andreMailboxPath)
+      .serialize
+
+    server.getProbe(classOf[ACLProbeImpl])
+      .replaceRights(andreMailboxPath, BOB.asString, new 
MailboxACL.Rfc4314Rights(Right.Lookup, Right.DeleteMailbox))
+
+    `given`
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .body(s"""{
+               |  "using": [
+               |    "urn:ietf:params:jmap:core",
+               |    "urn:ietf:params:jmap:mail",
+               |    "urn:apache:james:params:jmap:mail:shares"],
+               |  "methodCalls": [[
+               |      "Mailbox/get",
+               |      {
+               |        "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+               |        "ids": ["${andreMailboxId}"]
+               |      },
+               |      "c1"]]
+               |}""".stripMargin)
+    .when
+      .post
+    .`then`
+      .statusCode(SC_OK)
+      .body("methodResponses[0][1].list[0].myRights.mayDelete", equalTo(true))
+  }
+
   @Test
   @Tag(CategoryTags.BASIC_FEATURE)
   def getMailboxesShouldReturnDelegatedNamespaceWhenSharedMailbox(server: 
GuiceJamesServer): Unit = {
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 7277fc2f98..2e92c93fd1 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
@@ -6525,7 +6525,7 @@ trait MailboxSetMethodContract {
          |                "accountId": 
"29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
          |                "update": {
          |                    "${mailboxId.serialize}": {
-         |                      "sharedWith/${ANDRE.asString()}": ["x"]
+         |                      "sharedWith/${ANDRE.asString()}": ["y"]
          |                    }
          |                }
          |           },
@@ -6561,7 +6561,7 @@ trait MailboxSetMethodContract {
          |                "notUpdated": {
          |                    "${mailboxId.serialize}": {
          |                        "type": "invalidArguments",
-         |                        "description": "Specified value do not match 
the expected JSON format: List(((0),List(JsonValidationError(List(Unknown right 
'x'),List()))))",
+         |                        "description": "Specified value do not match 
the expected JSON format: List(((0),List(JsonValidationError(List(Unknown right 
'y'),List()))))",
          |                        "properties": [
          |                            "sharedWith/an...@domain.tld"
          |                        ]
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxFactory.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxFactory.scala
index 7c28dd9d09..1ec73d5b77 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxFactory.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxFactory.scala
@@ -112,7 +112,7 @@ class MailboxFactory @Inject() (mailboxManager: 
MailboxManager,
         maySetKeywords = MaySetKeywords(rights.contains(Right.Write)),
         mayCreateChild = MayCreateChild(false),
         mayRename = MayRename(false),
-        mayDelete = MayDelete(false),
+        mayDelete = MayDelete(rights.contains(Right.DeleteMailbox)),
         maySubmit = MaySubmit(false))
   }
 
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Rights.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Rights.scala
index 4473fbb1f6..888cca1395 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Rights.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Rights.scala
@@ -67,8 +67,9 @@ object Right {
   val DeleteMessages = Right(JavaRight.DeleteMessages)
   val Write = Right(JavaRight.Write)
   val Post = Right(JavaRight.Post)
+  val DeleteMailbox = Right(JavaRight.DeleteMailbox)
 
-  private val allRights = Seq(Administer, Expunge, Insert, Lookup, Read, Seen, 
DeleteMessages, Write, Post)
+  private val allRights = Seq(Administer, Expunge, Insert, Lookup, Read, Seen, 
DeleteMessages, Write, Post, DeleteMailbox)
 
   def forRight(right: JavaRight): Option[Right] = 
allRights.find(_.right.equals(right))
 
diff --git 
a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/mail/RightsTest.scala
 
b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/mail/RightsTest.scala
index c6f6d594b1..33562f7ceb 100644
--- 
a/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/mail/RightsTest.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/mail/RightsTest.scala
@@ -19,7 +19,7 @@
 
 package org.apache.james.jmap.mail
 
-import org.apache.james.core.Username
+import org.apache.james.jmap.mail.Right.DeleteMailbox
 import org.apache.james.mailbox.model.MailboxACL.{EntryKey, Rfc4314Rights => 
JavaRfc4314Rights, Right => JavaRight}
 import org.apache.james.mailbox.model.{MailboxACL => JavaMailboxACL}
 import org.scalatest.matchers.must.Matchers
@@ -85,7 +85,7 @@ class RightsTest extends AnyWordSpec with Matchers {
       val acl = new JavaMailboxACL(Map(
         USER_ENTRYKEY -> 
JavaRfc4314Rights.fromSerializedRfc4314Rights("aetxk")).asJava)
 
-      Rights.fromACL(MailboxACL.fromJava(acl)) must 
be(Rights.of(USER_ENTRYKEY, Seq(Right.Administer, Right.Expunge, 
Right.DeleteMessages)))
+      Rights.fromACL(MailboxACL.fromJava(acl)) must 
be(Rights.of(USER_ENTRYKEY, Seq(Right.Administer, Right.Expunge, 
Right.DeleteMessages, Right.DeleteMailbox)))
     }
   }
   "To ACL" should  {


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

Reply via email to