You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "florentos17 (via GitHub)" <gi...@apache.org> on 2024/11/06 14:32:23 UTC
[PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
florentos17 opened a new pull request, #2491:
URL: https://github.com/apache/james-project/pull/2491
tackling [issue #5314](https://github.com/linagora/james-project/issues/5314)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1835551276
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala:
##########
@@ -265,13 +267,28 @@ object NameUpdate {
}
}
+object IsSubscribedUpdate {
+ def parse(newValue: JsValue): Either[PatchUpdateValidationException, Update] = newValue match {
+ case JsBoolean(value) => scala.Right(IsSubscribedUpdate(Some(IsSubscribed(value))))
+ case JsNull => scala.Right(IsSubscribedUpdate(None))
+ case _ => Left(InvalidUpdateException("isSubscribed", "Expecting a JSON boolean as an argument"))
+ }
+}
+
+object SharedWithAnyoneValidator {
+ def isValidPatch(entryKey: EntryKey, rights: Seq[Right]): Boolean = {
+ !((entryKey == ANYONE_KEY || entryKey == ANYONE_NEGATIVE_KEY) && rights.exists(_ != Right.Post))}
+
+ def areValidPatches(rightsMap: Map[EntryKey, Seq[Right]]): Boolean = {
+ rightsMap.forall { case (entryKey, rightsSeq) => isValidPatch(entryKey, rightsSeq)}}
+}
Review Comment:
```suggestion
def areValidPatches(rightsMap: Map[EntryKey, Seq[Right]]): Boolean =
rightsMap.forall { case (entryKey, rightsSeq) => isValidPatch(entryKey, rightsSeq)}}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1835551276
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala:
##########
@@ -265,13 +267,28 @@ object NameUpdate {
}
}
+object IsSubscribedUpdate {
+ def parse(newValue: JsValue): Either[PatchUpdateValidationException, Update] = newValue match {
+ case JsBoolean(value) => scala.Right(IsSubscribedUpdate(Some(IsSubscribed(value))))
+ case JsNull => scala.Right(IsSubscribedUpdate(None))
+ case _ => Left(InvalidUpdateException("isSubscribed", "Expecting a JSON boolean as an argument"))
+ }
+}
+
+object SharedWithAnyoneValidator {
+ def isValidPatch(entryKey: EntryKey, rights: Seq[Right]): Boolean = {
+ !((entryKey == ANYONE_KEY || entryKey == ANYONE_NEGATIVE_KEY) && rights.exists(_ != Right.Post))}
+
+ def areValidPatches(rightsMap: Map[EntryKey, Seq[Right]]): Boolean = {
+ rightsMap.forall { case (entryKey, rightsSeq) => isValidPatch(entryKey, rightsSeq)}}
+}
Review Comment:
```suggestion
def areValidPatches(rightsMap: Map[EntryKey, Seq[Right]]): Boolean =
rightsMap.forall { case (entryKey, rightsSeq) => isValidPatch(entryKey, rightsSeq)}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1831139228
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala:
##########
@@ -87,6 +87,10 @@ object MailboxSetUpdatePerformer {
case e: IllegalArgumentException =>
LOGGER.info("Illegal argument in Mailbox/set update", e)
SetError.invalidArguments(SetErrorDescription(e.getMessage), None)
+ case e: DifferentDomainException =>
+ LOGGER.info("Invalid arguments in Mailbox/set update", e)
+ Thread.currentThread().getStackTrace.foreach(println)
Review Comment:
Remove this debug statement
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "florentos17 (via GitHub)" <gi...@apache.org>.
florentos17 commented on PR #2491:
URL: https://github.com/apache/james-project/pull/2491#issuecomment-2459928733
- 1st commit: when implementing [frontend support for subbaddressing](https://github.com/linagora/tmail-flutter/pull/3241), i had issues with a plain `serverFail` error without any description. it was actually a `DifferentDomainException`, the error handling can now pick it up ;
- 2nd & 3rd commits: some refactorings to be able to use `anyone` in a special entry key
- 4th commit: the integration test that show that a mailbox can now be shared with `anyone`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1833608044
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala:
##########
@@ -75,6 +75,9 @@ object MailboxSetUpdatePerformer {
case e: InvalidPatchException =>
LOGGER.info("Unsupported patch in Mailbox/set update: {}", e.getMessage)
SetError.invalidPatch(SetErrorDescription(s"${e.cause}"))
+ case e if e.isInstanceOf[IllegalArgumentException] && e.getMessage == "Domain parts ASCII chars must be a-z A-Z 0-9 - or _" =>
Review Comment:
This is evil, we shall have a specific exception
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1831156830
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Rights.scala:
##########
@@ -104,15 +103,17 @@ object Rights {
}
.fold(EMPTY)(_ combine _)
- private def toRights(entryKey: EntryKey, aclRights: Rfc4314Rights): Rights = of(Username.of(entryKey.getName), aclRights.toRights)
+ private def toRights(entryKey: EntryKey, aclRights: Rfc4314Rights): Rights = of(entryKey, aclRights.toRights)
private def isSupported(key: EntryKey): Boolean = key match {
Review Comment:
While we are at it do we support negative entry key?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1835551379
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala:
##########
@@ -281,30 +298,25 @@ object SharedWithResetUpdate {
}
}
-object IsSubscribedUpdate {
- def parse(newValue: JsValue): Either[PatchUpdateValidationException, Update] = newValue match {
- case JsBoolean(value) => scala.Right(IsSubscribedUpdate(Some(IsSubscribed(value))))
- case JsNull => scala.Right(IsSubscribedUpdate(None))
- case _ => Left(InvalidUpdateException("isSubscribed", "Expecting a JSON boolean as an argument"))
- }
-}
-
object SharedWithPartialUpdate {
def parse(serializer: MailboxSerializer, capabilities: Set[CapabilityIdentifier])
( property: String, newValue: JsValue): Either[PatchUpdateValidationException, Update] =
if (capabilities.contains(CapabilityIdentifier.JAMES_SHARES)) {
parseEntryKey(property)
.flatMap(entryKey => parseRights(newValue, property, serializer)
- .flatMap {rights =>
- if ((entryKey == ANYONE_KEY || entryKey == ANYONE_NEGATIVE_KEY) && rights.toRights.exists(_ != Right.Post)) {
- scala.Left(InvalidPatchException("only the `Post` right can be granted to the identifier `anyone`"))
- } else {
- scala.Right(SharedWithPartialUpdate(entryKey, rights))
- }})
+ .flatMap(rights => createUpdateIfValidPatch(entryKey, rights)))
} else {
MailboxPatchObject.notFound(property)
}
+ private def createUpdateIfValidPatch(entryKey: EntryKey, rights: Rfc4314Rights): Either[PatchUpdateValidationException, Update] = {
+ if (SharedWithAnyoneValidator.isValidPatch(entryKey, rights.toRights)) {
+ scala.Right(SharedWithPartialUpdate(entryKey, rights))
+ } else {
+ scala.Left(InvalidPatchException("only the `Post` right can be granted to the identifier `anyone`"))
+ }
+ }
Review Comment:
```suggestion
private def createUpdateIfValidPatch(entryKey: EntryKey, rights: Rfc4314Rights): Either[PatchUpdateValidationException, Update] =
if (SharedWithAnyoneValidator.isValidPatch(entryKey, rights.toRights)) {
scala.Right(SharedWithPartialUpdate(entryKey, rights))
} else {
scala.Left(InvalidPatchException("only the `Post` right can be granted to the identifier `anyone`"))
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa merged PR #2491:
URL: https://github.com/apache/james-project/pull/2491
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1833607876
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxSetUpdatePerformer.scala:
##########
@@ -75,6 +75,9 @@ object MailboxSetUpdatePerformer {
case e: InvalidPatchException =>
LOGGER.info("Unsupported patch in Mailbox/set update: {}", e.getMessage)
SetError.invalidPatch(SetErrorDescription(s"${e.cause}"))
+ case e if e.isInstanceOf[IllegalArgumentException] && e.getMessage == "Domain parts ASCII chars must be a-z A-Z 0-9 - or _" =>
+ LOGGER.info("Unsupported patch in Mailbox/set update: {}", e.getMessage)
Review Comment:
```suggestion
LOGGER.info("Unsupported patch in Mailbox/set update", e)
```
Otherwise stacktrace is lost...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "florentos17 (via GitHub)" <gi...@apache.org>.
florentos17 commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1831160706
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Rights.scala:
##########
@@ -104,15 +103,17 @@ object Rights {
}
.fold(EMPTY)(_ combine _)
- private def toRights(entryKey: EntryKey, aclRights: Rfc4314Rights): Rights = of(Username.of(entryKey.getName), aclRights.toRights)
+ private def toRights(entryKey: EntryKey, aclRights: Rfc4314Rights): Rights = of(entryKey, aclRights.toRights)
private def isSupported(key: EntryKey): Boolean = key match {
Review Comment:
that's exactly what i was gonna ask next: using `EntryKey` instead of `Username` is so that negative entry keys, group entry keys, etc are all de facto supported now.
i suggest to write some tests about it ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "florentos17 (via GitHub)" <gi...@apache.org>.
florentos17 commented on PR #2491:
URL: https://github.com/apache/james-project/pull/2491#issuecomment-2459936416
the 5th commit comes with an open question, here is the spec:
```
`rights` of type `Rights`. The owner can see the full rights, but sharee MUST only see their rights if they do not have the administer right on the mailbox. Sharee without administer right MUST NOT be able to see another SHAREE rights.
```
a sharee can see its own rights (as specified by the doc), but currently cannot see the rights granted to `anyone`. to me it would make sense to make this visible to the sharee. what do you think ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1831162303
##########
server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala:
##########
@@ -5928,6 +5928,154 @@ trait MailboxSetMethodContract {
|}""".stripMargin)
}
+ @Test
+ def partialRightsUpdateShouldCorrectlyHandleAnyoneKeyword(server: GuiceJamesServer): Unit = {
+ val path = MailboxPath.forUser(BOB, "mailbox")
+ val mailboxId = server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)
+
+ val request =
+ s"""
+ |{
+ | "using": [ "urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:apache:james:params:jmap:mail:shares" ],
+ | "methodCalls": [
+ | [
+ | "Mailbox/set",
+ | {
+ | "accountId": "29883977c13473ae7cb7678ef767cbfbaffc8a44a6e463d971d23a65c1dc4af6",
+ | "update": {
+ | "${mailboxId.serialize}": {
+ | "sharedWith/anyone": ["r", "l"]
Review Comment:
IMO with anyone we shall only accept 'p'
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] refactor and test the use of the `anyone` keyword when sharing with JMAP [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2491:
URL: https://github.com/apache/james-project/pull/2491#discussion_r1833608369
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala:
##########
@@ -292,7 +295,12 @@ object SharedWithPartialUpdate {
if (capabilities.contains(CapabilityIdentifier.JAMES_SHARES)) {
parseEntryKey(property)
.flatMap(entryKey => parseRights(newValue, property, serializer)
- .map(rights => SharedWithPartialUpdate(entryKey, rights)))
+ .flatMap {rights =>
+ if ((entryKey == ANYONE_KEY || entryKey == ANYONE_NEGATIVE_KEY) && rights.toRights.exists(_ != Right.Post)) {
Review Comment:
This complicated condition needs refactoring (method / variable extraction)
##########
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/MailboxSet.scala:
##########
@@ -270,6 +270,9 @@ object SharedWithResetUpdate {
(newValue: JsValue): Either[PatchUpdateValidationException, Update] =
if (capabilities.contains(CapabilityIdentifier.JAMES_SHARES)) {
serializer.deserializeRights(input = newValue) match {
+ case JsSuccess(value, _) if value.rights.get(ANYONE_KEY).exists(_.exists(_ != Right.Post))
+ || value.rights.get(ANYONE_NEGATIVE_KEY).exists(_.exists(_ != Right.Post)) =>
Review Comment:
This complicated condition needs refactoring (method / variable extraction)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org