-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from bedatadriven/advanced-user-mangement-vig…
…nette-4.38 Advanced user mangement vignette 4.38
- Loading branch information
Showing
5 changed files
with
564 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,32 @@ addTestUsers <- function(database, tree, nUsers = 1, roleId, roleParameters = li | |
}) | ||
} | ||
|
||
|
||
addTestUsersWithAssignment <- function(database, tree, nUsers = 1, assignment) { | ||
lapply(1:nUsers, function(x) { | ||
newUserEmail <- sprintf("test%[email protected]", cuid()) | ||
newDatabaseUser <- addDatabaseUser( | ||
databaseId = database$databaseId, | ||
email = newUserEmail, | ||
name = "Test database user", | ||
locale = "en", | ||
assignment = assignment | ||
) | ||
|
||
if (newDatabaseUser$added) { | ||
testthat::expect_identical(newDatabaseUser$user$email, newUserEmail) | ||
testthat::expect_identical(newDatabaseUser$user$role$id, assignment$id) | ||
testthat::expect_true(newDatabaseUser$user$role$resources[[1]] %in% assignment$resources) | ||
newDatabaseUser | ||
} else { | ||
warning("Could not add user with assignment.") | ||
NULL | ||
} | ||
}) | ||
} | ||
|
||
|
||
|
||
deleteTestUsers <- function(database, returnedUsers) { | ||
lapply(returnedUsers, function(newDatabaseUser) { | ||
if (newDatabaseUser$added) { | ||
|
@@ -340,7 +366,7 @@ testthat::test_that("addRole() and deleteRoles() work", { | |
|
||
testthat::expect_length(addedTree$roles, length(originalTree$roles)+2) | ||
|
||
testthat::test_that("deleteRoles", { | ||
testthat::test_that("deleteRoles()", { | ||
deleteRoles(database$databaseId, roleIds = c(roleId1, roleId2)) | ||
|
||
deletedTree <- getDatabaseTree(database$databaseId) | ||
|
@@ -356,16 +382,11 @@ testthat::test_that("addRole() and deleteRoles() work", { | |
|
||
}) | ||
|
||
testthat::test_that("deleteRole() works", { | ||
|
||
}) | ||
|
||
|
||
testthat::test_that("updateRole() works for both legacy and new roles", { | ||
roleId <- "rp" | ||
roleLabel <- "Reporting partner" | ||
|
||
# create a partner reference form | ||
# create a partner reference form with label "Reporting Partners". Label is reused to find the form later on. | ||
partnerForm <- formSchema( | ||
databaseId = database$databaseId, | ||
label = "Reporting Partners") |> | ||
|
@@ -579,6 +600,26 @@ testthat::test_that("roleAssignment() works", { | |
)) | ||
}) | ||
|
||
|
||
testthat::test_that("addDatabaseUser() accepts a role assignment with parameters and optional grants", { | ||
rpRole <- getDatabaseRole(database$databaseId, roleId = "rp") | ||
|
||
optionalGrants <- as.list(unlist(lapply(rpRole$grants, function(x) {if (x$optional) return(x$resourceId)}))) | ||
|
||
partnerFormId = optionalGrants[[1]] # could also use the label "Reporting Partners" if multiple grants are given | ||
|
||
userRoleParam <- list( | ||
partner = reference(formId = partnerFormId, recordId = "partner1") | ||
) | ||
|
||
addTestUsersWithAssignment(database, tree, nUsers = 1, assignment = roleAssignment( | ||
roleId = "rp", | ||
roleParameters = userRoleParam, | ||
roleResources = optionalGrants | ||
)) | ||
}) | ||
|
||
|
||
testthat::test_that("updateGrant() works", { | ||
#old method - not tested# | ||
}) |
Oops, something went wrong.