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-unsubscr...@james.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to