Skip to content

Commit 06a334c

Browse files
committed
fix #76 modifyRule method
1 parent ffabe6d commit 06a334c

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package: geosapi
22
Type: Package
33
Title: GeoServer REST API R Interface
44
Version: 0.8
5-
Date: 2026-01-09
5+
Date: 2026-01-11
66
Authors@R: c(person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com", comment = c(ORCID = "0000-0002-5870-5762")))
77
Maintainer: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
88
Description: Provides an R interface to the GeoServer REST API, allowing to upload

R/GSAccessControlListManager.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,54 @@ GSAccessControlListManager <- R6Class("GSAccessControlListManager",
255255

256256
},
257257

258+
#'@description Generic method to modify an access control rule
259+
#'@param rule object of class \link{GSRule}
260+
#'@return \code{TRUE} if modified, \code{FALSE} otherwise
261+
modifyRule = function(rule){
262+
263+
if(!is(rule, "GSRule")){
264+
msg = "Argument 'rule' should be an object of class 'GSLayerRule', 'GSServiceRule', or 'GSRestRule'"
265+
cli::cli_alert_danger(msg)
266+
self$ERROR(msg)
267+
stop(msg)
268+
}
269+
270+
domain <- switch(class(rule)[1],
271+
"GSLayerRule" = "layers",
272+
"GSServiceRule" = "services",
273+
"GSRestRule" = "rest"
274+
)
275+
276+
msg = sprintf("Modify %s rule for resource '%s'", domain, rule$attrs$resource)
277+
cli::cli_alert_info(msg)
278+
self$INFO(msg)
279+
280+
modified <- FALSE
281+
req <- GSUtils$PUT(
282+
url = self$getUrl(), user = private$user,
283+
pwd = private$keyring_backend$get(service = private$keyring_service, username = private$user),
284+
path = sprintf("/security/acl/%s.xml", domain),
285+
content = {
286+
xml = xml2::xml_new_root("rules")
287+
xml2::xml_add_child(xml, rule$encode())
288+
gsub("[\r\n ] ", "", as(xml, "character"))
289+
},
290+
contentType = "application/xml",
291+
verbose = self$verbose.debug
292+
)
293+
if(status_code(req) == 200){
294+
msg = "Successfuly modified access control rule!"
295+
cli::cli_alert_success(msg)
296+
self$INFO(msg)
297+
modified = TRUE
298+
}else{
299+
err = "Error while modifying access control rule"
300+
cli::cli_alert_danger(err)
301+
self$ERROR(err)
302+
}
303+
return(modified)
304+
},
305+
258306
#'@description Generic method to delete an access control rule
259307
#'@param rule object of class \link{GSRule}
260308
#'@return \code{TRUE} if deleted, \code{FALSE} otherwise

man/GSAccessControlListManager.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)