diff --git a/DESCRIPTION b/DESCRIPTION index 270a536..3afc557 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,7 @@ Authors@R: c( ) Maintainer: Rob Baker Description: This package contains a set of useful functions for data munging, quality control, and data flagging. Functions are contributed by multiple U.S. National Park Service staff, contractors, partners and others. These functions will likely be most useful for quality control of NPS data but may have utility beyond their intended functions. -License: CC0 +License: CC0 + file LICENSE Encoding: UTF-8 LazyData: true Imports: diff --git a/NAMESPACE b/NAMESPACE index dfcd2b6..f63564d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(get_dp_flags) export(get_elevation) export(get_park_polygon) export(get_taxon_rank) +export(get_user_email) export(get_utm_zone) export(long2UTM) export(order_cols) diff --git a/NEWS.md b/NEWS.md index 31aeca7..c631921 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # QCkit v0.1.8 (not yet released) +2024-07-09 +* Added function `get_user_email()`, which accesses NPS active directory via a powershell function to return the user's email address. Probably won't work for non-NPS users and probably won't work for non-windows users. +* Updated rest API from legacy v6 to current v7. + 2024-06-28 * Updated `get_park_polygon()` to use the new API (had been using a legacy API). Added documentation to specify that the function is getting the convexhull for the park, which may not work particularly well for some parks. 2024-06-27 diff --git a/R/utils.R b/R/utils.R index 33660d8..ef71488 100644 --- a/R/utils.R +++ b/R/utils.R @@ -4,13 +4,13 @@ .pkgglobalenv <- new.env(parent=emptyenv()) #data_store API base URL: -assign("QC_ds_api", "https://irmaservices.nps.gov/datastore/v6/rest/", envir=.pkgglobalenv) +assign("QC_ds_api", "https://irmaservices.nps.gov/datastore/v7/rest/", envir=.pkgglobalenv) #data_store secure API base URL: -assign("QC_ds_secure_api", "https://irmaservices.nps.gov/datastore-secure/v6/rest/", envir=.pkgglobalenv) +assign("QC_ds_secure_api", "https://irmaservices.nps.gov/datastore-secure/v7/rest/", envir=.pkgglobalenv) #data_store dev api (requires secure) -assign("QC_ds_dev_api", "https://irmadevservices.nps.gov/datastore-secure/v6/rest/", envir = .pkgglobalenv) +assign("QC_ds_dev_api", "https://irmadevservices.nps.gov/datastore-secure/v7/rest/", envir = .pkgglobalenv) .QC_ds_api <- function(x){ get("QC_ds_api", envir = .pkgglobalenv) @@ -39,4 +39,32 @@ globalVariables(c("any_of", "_UTMJOINCOL", "decimalLatitude", "decimalLongitude", - "LatLong_CRS")) \ No newline at end of file + "LatLong_CRS")) + + +#' Retrieves an NPS user's email address +#' +#' @details The function accesses the system username and then uses a powershell wrapper to access NPS active directory and supply information about the user. That information is then parsed down to the user's email address. +#' +#' This function probaby won't work for anyone outside of NPS and likely won't work for anyone who is not using a Windows machine. So build those prerequisites (NPS = FALSE) in when calling it from within other function. +#' +#' @return String. The user's email address. +#' @export +#' +#' @examples +#' \dontrun{ +#' email <- get_user_email() +#' } +get_user_email <- function() { + powershell_command <- '([adsisearcher]\\"(samaccountname=$env:USERNAME)\\").findone().properties.proxyaddresses' + + proxy_addresses <- system2("powershell", + args = c("-command", + powershell_command), + stdout = TRUE) + + email_address <- stringr::str_subset(proxy_addresses, "@") |> + stringr::str_remove("SMTP:") + + return(email_address) +} diff --git a/docs/news/index.html b/docs/news/index.html index 836f289..fd274e8 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -65,6 +65,7 @@

Changelog

+

2024-07-09 * Added function get_user_email(), which accesses NPS active directory via a powershell function to return the user’s email address. Probably won’t work for non-NPS users and probably won’t work for non-windows users. * Updated rest API from legacy v6 to current v7.

2024-06-28 * Updated get_park_polygon() to use the new API (had been using a legacy API). Added documentation to specify that the function is getting the convexhull for the park, which may not work particularly well for some parks. 2024-06-27 * bug fixes for generate_ll_from_utm() * add function remove_empty_tables() (and associated unit tests) * update documentation for replace blanks() to indicate it can replace blanks with more than just NA

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index c6ecf10..6e19b1b 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -5,5 +5,5 @@ articles: DRR_Purpose_and_Scope: DRR_Purpose_and_Scope.html Starting-a-DRR: Starting-a-DRR.html Using-the-DRR-Template: Using-the-DRR-Template.html -last_built: 2024-06-28T15:11Z +last_built: 2024-07-09T14:49Z diff --git a/docs/reference/get_user_email.html b/docs/reference/get_user_email.html new file mode 100644 index 0000000..b8bbd47 --- /dev/null +++ b/docs/reference/get_user_email.html @@ -0,0 +1,117 @@ + +Retrieves an NPS user's email address — get_user_email • QCkit + + +
+
+ + + +
+
+ + +
+

Retrieves an NPS user's email address

+
+ +
+
get_user_email()
+
+ +
+

Value

+ + +

String. The user's email address.

+
+
+

Details

+

The function accesses the system username and then uses a powershell wrapper to access NPS active directory and supply information about the user. That information is then parsed down to the user's email address.

+

This function probaby won't work for anyone outside of NPS and likely won't work for anyone who is not using a Windows machine. So build those prerequisites (NPS = FALSE) in when calling it from within other function.

+
+ +
+

Examples

+
if (FALSE) {
+email <- get_user_email()
+}
+
+
+
+ +
+ + +
+ +
+

Site built with pkgdown 2.0.9.

+
+ +
+ + + + + + + + diff --git a/docs/reference/index.html b/docs/reference/index.html index 47a6f20..268af56 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -122,6 +122,10 @@

All functions get_taxon_rank()

Taxonomic Rank Determination Function

+ +

get_user_email()

+ +

Retrieves an NPS user's email address

get_utm_zone()

diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 7247e4b..31e79b0 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -84,6 +84,9 @@ /reference/get_taxon_rank.html + + /reference/get_user_email.html + /reference/get_utm_zone.html diff --git a/man/get_user_email.Rd b/man/get_user_email.Rd new file mode 100644 index 0000000..6a1840f --- /dev/null +++ b/man/get_user_email.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{get_user_email} +\alias{get_user_email} +\title{Retrieves an NPS user's email address} +\usage{ +get_user_email() +} +\value{ +String. The user's email address. +} +\description{ +Retrieves an NPS user's email address +} +\details{ +The function accesses the system username and then uses a powershell wrapper to access NPS active directory and supply information about the user. That information is then parsed down to the user's email address. + +This function probaby won't work for anyone outside of NPS and likely won't work for anyone who is not using a Windows machine. So build those prerequisites (NPS = FALSE) in when calling it from within other function. +} +\examples{ +\dontrun{ +email <- get_user_email() +} +} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 765b1a3..4cb49fc 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,7 +1,3 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) -}) - test_that(".QC_ds_api returns correct url", { expect_equal(.QC_ds_api(x), "https://irmaservices.nps.gov/datastore/v6/rest/") }) @@ -12,4 +8,9 @@ test_that(".QC_ds_secure_api returns correct url", { test_that(".QC_ds_dev_api returns correct url", { expect_equal(.QC_ds_dev_api(x), "https://irmadevservices.nps.gov/datastore-secure/v6/rest/") +}) + +test_that("get_user_email returns a string approximating an email", { + email <- get_user_email() + expect_equal(grep("@", email), 1) }) \ No newline at end of file