Skip to content

Commit

Permalink
For #2753: new ignore-admin-permissions parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruchez committed Nov 30, 2022
1 parent 7a33f0d commit 30f06fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion form-runner/jvm/src/main/resources/apps/fr/home/home.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
id="read-local-metadata"
method="get"
serialization="none"
resource="/fr/service/persistence/form?all-versions={$is-admin}"
resource="/fr/service/persistence/form?all-versions={$is-admin}&ignore-admin-permissions={not($is-admin)}"
replace="instance"
targetref="instance('fr-metadata-local')">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ trait FormBuilderPermissionsOps {
* - annotates the `<form>` with an `operations="…"` attribute,
* - filters out forms the current user can perform no operation on.
*/
def filterFormsAndAnnotateWithOperations(formsEls: List[NodeInfo], allForms: Boolean): List[NodeInfo] = {
def filterFormsAndAnnotateWithOperations(
formsEls : List[NodeInfo],
allForms : Boolean,
ignoreAdminPermissions: Boolean
): List[NodeInfo] = {

// We only need one wrapper; create it when we encounter the first <form>
var wrapperOpt: Option[DocumentWrapper] = None
Expand All @@ -118,7 +122,7 @@ trait FormBuilderPermissionsOps {

val appName = formEl.elemValue(Names.AppName)
val formName = formEl.elemValue(Names.FormName)
val isAdmin = {
val hasAdminPermissionForAppForm = {
def canAccessEverything = fbPermissions.contains("*")
def canAccessAppForm = {
val formsUserCanAccess = fbPermissions.getOrElse(appName, Set.empty)
Expand All @@ -129,16 +133,16 @@ trait FormBuilderPermissionsOps {

// For each form, compute the operations the user can potentially perform
val operations = {
val adminOperation = isAdmin.list("admin")
val adminOperation = hasAdminPermissionForAppForm.list("admin")
val permissionsElement = formEl.child(Names.Permissions).headOption.orNull
val otherOperations = FormRunner.allAuthorizedOperationsAssumingOwnerGroupMember(permissionsElement, appName, formName)
adminOperation ++ otherOperations
}

// Is this form metadata returned by the API?
val keepForm =
allForms || // all forms are explicitly requested
isAdmin || // admins can see everything
allForms || // all forms are explicitly requested
(hasAdminPermissionForAppForm && ! ignoreAdminPermissions) || // admins can see everything
! (
formName == Names.LibraryFormName || // filter libraries
operations.isEmpty || // filter forms on which user can't possibly do anything
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ private object PersistenceProxyProcessor {
root = "forms",
content =
FormRunner.filterFormsAndAnnotateWithOperations(
formsEls = allFormElements.flatten,
allForms = request.getFirstParamAsString("all-forms") contains "true"
formsEls = allFormElements.flatten,
allForms = request.getFirstParamAsString("all-forms") contains "true",
ignoreAdminPermissions = request.getFirstParamAsString("ignore-admin-permissions") contains "true"
),
response = response
)
Expand Down

0 comments on commit 30f06fa

Please sign in to comment.