-
Notifications
You must be signed in to change notification settings - Fork 10
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 #82 from pepfar-datim/RC-0.2.0
Rc 0.2.0
- Loading branch information
Showing
31 changed files
with
801 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# datimutils 0.2.0 | ||
|
||
## Features | ||
|
||
* add `getUserGroups` | ||
* add `listMechs` | ||
* add `getMyStreams` | ||
* add `getMyUserType` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#' @export | ||
#' @title getMyStreams(d2_session = dynGet("d2_default_session", inherits = TRUE)) | ||
#' @description Returns datim user streams. For an implementation | ||
#' example see: https://github.com/flopez-bao/shinyapps-datimutils-security-example-usgandpartners | ||
#' @param d2_session the d2Session object, default is "d2_default_session", | ||
|
||
|
||
getMyStreams <- | ||
function(d2_session = dynGet("d2_default_session", inherits = TRUE)) { | ||
# pull all user groups streams | ||
tryCatch( | ||
expr = { | ||
user_groups <- getUserGroups(values = d2_session$me$userGroups$id, | ||
d2_session = d2_session) | ||
}, | ||
error = function(e) { | ||
stop("There was an error retrieving the user group information! Make sure you are logged into DATIM.") | ||
} | ||
) | ||
|
||
# select from user_groups everything that is a data stream and needed for classification | ||
user_groups <- user_groups[grepl("Data (.+?) access", user_groups)] | ||
|
||
# remove Data Access strings | ||
streams <- sort(gsub("Data | access", "", user_groups)) | ||
|
||
return(streams) | ||
} |
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,46 @@ | ||
#' @export | ||
#' @title getMyUserType(d2_session = dynGet("d2_default_session", inherits = TRUE)) | ||
#' @description Returns a classified user type based on accessible data streams. For an implementation | ||
#' example see: https://github.com/flopez-bao/shinyapps-datimutils-security-example-usgandpartners | ||
#' @param d2_session the d2Session object, default is "d2_default_session" | ||
|
||
getMyUserType <- function(d2_session = dynGet("d2_default_session",inherits = TRUE)) { | ||
|
||
#pull streams and classify | ||
tryCatch( | ||
expr = { | ||
user_groups <- getUserGroups( | ||
values = d2_session$me$userGroups$id, | ||
d2_session = d2_session | ||
) | ||
}, | ||
error = function(e){ | ||
stop("There was an error retrieving the user group information! Make sure you are logged into DATIM.") | ||
} | ||
) | ||
|
||
# select from user_groups everything that is a data stream and needed for classification | ||
streams <- user_groups[grepl("Data (.+?) access|^Global|^OU",user_groups)] | ||
|
||
# classify user | ||
if( length( regmatches(streams ,regexpr("OU (.+?) MOH users", streams)) ) > 0 ) { | ||
return("MOH") | ||
} else if ( length(regmatches(streams ,regexpr("Global users", streams)) ) > 0 ) { | ||
return("Global") | ||
} else if ( length( regmatches(streams, regexpr("OU (.+?) Partner (.+?) users - (.+?)",streams)) ) > 0 ) { | ||
return("Partner") | ||
} else if ( length( regmatches(streams, regexpr("OU (.+?) Agency (.+?) users",streams)) ) > 0 ) { | ||
return("Agency") | ||
} else if ( length( regmatches(streams, regexpr("OU (.+?) Interagency users",streams)) ) > 0 ) { | ||
return("Interagency") | ||
} else if ( length( regmatches(streams, regexpr("Global Agency (.+?) users",streams)) ) > 0 ) { | ||
return("Global Agency") | ||
} else if ( length( regmatches(streams, regexpr("Global Partner (.+?) users - (.+?)",streams)) ) > 0 ) { | ||
return("Global Partner") | ||
} else { | ||
return("Unclassified User") | ||
} | ||
} | ||
|
||
|
||
|
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,45 @@ | ||
#' @export | ||
#' @title listMechs(option_fields = c("name", "id", "code"), | ||
#' combo_fields = "id", | ||
#' d2_session = dynGet("d2_default_session",inherits = TRUE) | ||
#' @description Returns a dataframe with all mechanisms a user has access to. For an implementation | ||
#' example see: https://github.com/flopez-bao/shinyapps-datimutils-security-example-usgandpartners | ||
#' @param option_fields fields passed to the getMetaData endpoint. | ||
#' @param combo_fields fields passed to getCatOptionCombos call. | ||
#' @param d2_session the d2Session object, default is "d2_default_session" | ||
#' @importFrom magrittr "%>%" | ||
|
||
listMechs <- function(option_fields = c("name", "id", "code"), | ||
combo_fields = "id", | ||
d2_session = dynGet("d2_default_session", | ||
inherits = TRUE)) { | ||
|
||
|
||
if (isFALSE(setequal(option_fields, c("name", "id", "code")))) { | ||
stop("other fields are currently not supported.") | ||
} else if (combo_fields != "id") { | ||
stop("other fields are currently not supported.") | ||
} else { | ||
|
||
df <- getMetadata(categoryOptions, | ||
categories.id %.in% "SH885jaRe0o", | ||
fields = option_fields, | ||
d2_session = d2_session | ||
) %>% | ||
dplyr::mutate(option_id = id, | ||
combo_id = datimutils::getCatOptionCombos(code, | ||
by = code, | ||
fields = combo_fields, | ||
d2_session = d2_session | ||
)) %>% | ||
dplyr::select(-id, | ||
mech_code = code, | ||
name, | ||
option_id, | ||
combo_id | ||
) | ||
|
||
return(df) | ||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
tests/testthat/play.dhis2.org/2.37.2/api/userGroups.json-3eb0bf.json
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,8 @@ | ||
{ | ||
"userGroups": [ | ||
{ | ||
"name": "Family Health Partner", | ||
"id": "ZrsVF7IJ93y" | ||
} | ||
] | ||
} |
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
Oops, something went wrong.