Forum Discussion
yonicd
Jul 04, 2022Copper Contributor
Setting user permissions for a drive item to something other than role based {read, write, owner}
Is there a way to assign a permission level to a drive item?
My main goal is to let users read, but not download, the documents in the folder.
I am using the R package AzureGraph which is a wrapper of the azure graph api.
library(Microsoft365R)
sp <- list_sharepoint_sites()
general_drive <- sp[[1]]$list_drives()[[2]]
general_drive$create_folder('test folder')
item <- general_drive$get_item('test folder')
my_body <- list(
recipients = list(list(email= 'email address removed for privacy reasons')),
sendInvitation = FALSE,
requireSignIn = TRUE,
roles = list('read')
)
item$do_operation(op = 'invite', http_verb = 'POST', body = my_body)
# status 200
perms <- item$do_operation(op = 'permissions')
item$do_operation(op = file.path('permissions',perms$value[[6]]$id),
http_verb = 'PATCH',
body = list(roles = c('read','write')))
# status 200
item$do_operation(op = file.path('permissions',perms$value[[6]]$id),
http_verb = 'PATCH',
body = list(roles = c('resticted view')))
#> Error in process_response(res, match.arg(http_status_handler), simplify) :
#> Bad Request (HTTP 400). Failed to complete operation. Message:
#> [permissionInformation] An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A
#> 'StartArray' node was expected.
item$do_operation(op = file.path('permissions',perms$value[[6]]$id),
http_verb = 'PATCH',
body = list(roles = list('restricted view')))
#> Error in process_response(res, match.arg(http_status_handler), simplify) :
#> Bad Request (HTTP 400). Failed to complete operation. Message:
#> Invalid value for role.
If I do set it manually on the site and then query what it is using the API I get back an empty list
perms <- item$do_operation(op = 'permissions')
perms$value[[6]]
#> $id
#> [1] "aTowIy5mfG1lbWJlcnNoaXB8d2lsbGlhbS5oYXllc0BzYWdlcnguY29t"
#>
#> $roles
#> list()
No RepliesBe the first to reply