diff --git a/NAMESPACE b/NAMESPACE index 11c6f12..6b72a29 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export(get_dp_flags) export(get_elevation) export(get_park_polygon) export(get_taxon_rank) +export(get_user_orcid) export(get_utm_zone) export(long2UTM) export(order_cols) diff --git a/NEWS.md b/NEWS.md index 4135283..063330a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,7 @@ # QCkit v1.1.0 +## 2025-07-25 +* add function `get_user_orcid`, which will look up a users orcid using active directory. + ## 2025-05-16 * create_datastore_script now invisibly returns the DataStore reference URL diff --git a/R/utils.R b/R/utils.R index 225a72c..c44abdb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -69,3 +69,34 @@ get_user_email <- function() { return(email_address) } + +#' Returns the user's ORCID ID from active directory +#' +#' @description +#' This is a function to grab a users ORCID from Active Directory. Requires VPN to access AD. If the user does not have an ORCID, returns "NA". +#' +#' +#' @returns Sting. The user's ORCID ID +#' @export +#' +#' @examples +#' \dontrun{ +#' orcid <- get_user_orcid() +#' } +get_user_orcid <- function() { + powershell_command <- '([adsisearcher]\\"(samaccountname=$env:USERNAME)\\").FindAll().Properties' + + AD_output <- system2("powershell", + args = c("-Command", + powershell_command), + stdout = TRUE) + #get extensionAttribute2 (holds orcid) + orcid <- AD_output[which(AD_output %>% + stringr::str_detect("extensionattribute2"))] + # extract orcid + orcid <- stringr::str_extract(orcid, "\\{.*?\\}") + # remove curly braces: + orcid <- stringr::str_remove_all(orcid, "[{}]") + + return(orcid) +} diff --git a/docs/404.html b/docs/404.html index 50285fd..d6e5d18 100644 --- a/docs/404.html +++ b/docs/404.html @@ -20,7 +20,7 @@ QCkit - 1.0.2 + 1.1.0