Skip to content

Commit

Permalink
For #5397: backward compatibility support
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruchez committed Aug 11, 2022
1 parent e01c954 commit 9838648
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,24 @@ trait FormRunnerPermissionsOps {
/**
* Given a permission element, e.g. <permission operations="read update delete">, returns the tokenized value of
* the operations attribute.
*
* See backward compatibility handling: https://github.com/orbeon/orbeon-forms/issues/5397
*/
def permissionOperations(permissionElement: NodeInfo): List[String] =
permissionElement attTokens "operations" toList
def permissionOperationsHandleList(permissionElement: NodeInfo): List[String] = {

val tokens = permissionElement.attTokens("operations")
val hasMinusListToken = tokens(Operation.MinusListToken) // https://github.com/orbeon/orbeon-forms/issues/5397

val updatedTokens =
if (! hasMinusListToken && tokens(Operation.Read.entryName))
tokens + Operation.List.entryName
else if (hasMinusListToken)
tokens.filter(_ != Operation.MinusListToken)
else
tokens

updatedTokens.to
}

//@XPathFunction
def authorizedOperationsBasedOnRolesXPath(permissionsElOrNull: NodeInfo): List[String] =
Expand Down Expand Up @@ -131,7 +146,7 @@ trait FormRunnerPermissionsOps {
if currentUsernameOrGroupname == dataUsernameOrGroupname =>
val allPermissions = permissionsElOrNull.child("permission").toList
val permissionsForOwnerOrGroupMember = allPermissions.filter(p => p / * forall (_.localname == condition))
permissionsForOwnerOrGroupMember.flatMap(permissionOperations)
permissionsForOwnerOrGroupMember.flatMap(permissionOperationsHandleList)
case _ => Nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package org.orbeon.oxf.fr.permission

import org.orbeon.oxf.fr.FormRunner
import org.orbeon.oxf.fr.FormRunnerCommon.frc
import org.orbeon.saxon.om.NodeInfo
import org.orbeon.scaxon.SimplePath._
import org.orbeon.oxf.util.StringUtils._
Expand Down Expand Up @@ -54,7 +54,7 @@ object PermissionsXML {
}

private def parsePermission(permissionEl: NodeInfo): Permission = {
val operations = Operations.parse(FormRunner.permissionOperations(permissionEl))
val operations = Operations.parse(frc.permissionOperationsHandleList(permissionEl))
val conditions =
permissionEl.child(*).toList.map(
conditionEl =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ object Operation extends Enum[Operation] {
case object Update extends Operation
case object Delete extends Operation
case object List extends Operation

val MinusListToken: String = s"-${List.entryName}"
}

object Operations {
Expand Down

0 comments on commit 9838648

Please sign in to comment.