-
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.
Added tests and new grant based role functions. Still troubleshooting…
…. Added temp.R tests with some of these cases.
- Loading branch information
1 parent
82456c4
commit de5002e
Showing
9 changed files
with
183 additions
and
39 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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
roleId = "rp" | ||
roleLabel = "Reporting partner" | ||
|
||
# create a partner reference form | ||
partnerForm <- formSchema( | ||
databaseId = database$databaseId, | ||
label = "Reporting Partners") |> | ||
addFormField( | ||
textFieldSchema( | ||
code = "name", | ||
label = "Partner name", | ||
required = TRUE)) | ||
|
||
addForm(partnerForm) | ||
|
||
# create a reference partner table | ||
partnerTbl <- tibble(id = paste0("partner",1:3), name = paste0("Partner ",1:3)) | ||
|
||
# import partner records | ||
importRecords(partnerForm$id, data = partnerTbl, recordIdColumn = "id") | ||
|
||
# create a reporting table with a reporting partner field | ||
reportingForm <- formSchema( | ||
databaseId = database$databaseId, | ||
label = "Reports") |> | ||
addFormField( | ||
referenceFieldSchema( | ||
referencedFormId = partnerForm$id, | ||
code = "rp", | ||
label = "Partner", | ||
required = TRUE)) |> | ||
addFormField( | ||
textFieldSchema( | ||
label = "Report", | ||
required = TRUE)) | ||
|
||
addForm(reportingForm) | ||
|
||
# create a reports table | ||
reportingTbl <- tibble(Partner = rep(paste0("partner",1:3), 2), Report = rep(paste0("This is a report from Partner ",1:3),2)) | ||
|
||
# import reports | ||
importRecords(reportingForm$id, data = reportingTbl) | ||
|
||
# create a role | ||
newRole <- | ||
role(id = roleId, | ||
label = roleLabel, | ||
parameters = list( | ||
parameter(id = "partner", label = "Partner", range = partnerForm$id)), | ||
grants = list( | ||
grant(resourceId = reportingForm$id, | ||
permissions = permissions( | ||
view = sprintf("%s == @user.partner", partnerForm$id), | ||
edit_record = sprintf("%s == @user.partner", partnerForm$id), | ||
discover = TRUE, | ||
export_records = TRUE)), | ||
grant(resourceId = partnerForm$id, | ||
permissions = permissions( | ||
view = TRUE, | ||
discover = FALSE))), | ||
filters = list( | ||
roleFilter( | ||
id = "partner", | ||
label = "Partner is user's partner", | ||
filter = sprintf("%s == @user.partner", partnerForm$id))) | ||
) | ||
|
||
|
||
updateRole(databaseId = database$databaseId, role = newRole) | ||
|
||
newRoleAbridged <- | ||
role(id = roleId, | ||
label = roleLabel, | ||
parameters = list( | ||
parameter(id = "partner", label = "Partner", range = partnerForm$id)), | ||
grants = list( | ||
grant(resourceId = reportingForm$id, | ||
permissions = permissions( | ||
view = sprintf("%s == @user.partner", partnerForm$id), | ||
edit_record = sprintf("%s == @user.partner", partnerForm$id), | ||
discover = TRUE, | ||
export_records = TRUE)), | ||
grant(resourceId = partnerForm$id, | ||
permissions = permissions( | ||
view = TRUE, | ||
discover = FALSE)))) | ||
|
||
updateRole(databaseId = database$databaseId, role = newRoleAbridged) | ||
|
||
deprecatedNonGrantRole <- list( | ||
id = "rpold", | ||
label = "Reporting partner", | ||
permissions = permissions( | ||
view = sprintf("%s == @user.partner", partnerForm$id), | ||
edit_record = sprintf("%s == @user.partner", partnerForm$id), | ||
export_records = TRUE | ||
), | ||
parameters = list( | ||
list( | ||
id = "partner", | ||
label = "Partner", | ||
range = partnerForm$id | ||
) | ||
), | ||
filters = list( | ||
list( | ||
id = "partner", | ||
label = "partner is user's partner", | ||
filter = sprintf("%s == @user.partner", partnerForm$id) | ||
) | ||
)) | ||
|
||
|
||
updateRole(databaseId = database$databaseId, role = deprecatedNonGrantRole) | ||
|
||
deprecatedNonGrantRoleNoFilter <- list( | ||
id = "rpold", | ||
label = "Reporting partner", | ||
permissions = permissions( | ||
view = sprintf("%s == @user.partner", partnerForm$id), | ||
edit_record = sprintf("%s == @user.partner", partnerForm$id), | ||
export_records = TRUE | ||
), | ||
parameters = list( | ||
list( | ||
id = "partner", | ||
label = "Partner", | ||
range = partnerForm$id | ||
) | ||
), grantBased = FALSE) | ||
|
||
updateRole(databaseId = database$databaseId, role = deprecatedNonGrantRoleNoFilter) |
Oops, something went wrong.