From a2fb2ba0a7cba72e1f744462a836e99a2a800fe4 Mon Sep 17 00:00:00 2001
From: Rob Baker <robert_baker@nps.gov>
Date: Tue, 9 Jul 2024 08:37:53 -0600
Subject: [PATCH 1/7] Add info about new get_user_email function

---
 NEWS.md | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/NEWS.md b/NEWS.md
index 31aeca7..78b3c68 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,8 @@
 # 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.
+
 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

From a1f14dce3a10041c7fa2a6a382cf66fa5fc012d2 Mon Sep 17 00:00:00 2001
From: Rob Baker <robert_baker@nps.gov>
Date: Tue, 9 Jul 2024 08:38:06 -0600
Subject: [PATCH 2/7] add new function, get_user_email

---
 R/utils.R | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/R/utils.R b/R/utils.R
index 33660d8..3ceb61f 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -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)
+}

From 882e3c61f56f46094241ab6e00887258872c08ac Mon Sep 17 00:00:00 2001
From: Rob Baker <robert_baker@nps.gov>
Date: Tue, 9 Jul 2024 08:40:37 -0600
Subject: [PATCH 3/7] update API from v6 to v7

---
 R/utils.R | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/R/utils.R b/R/utils.R
index 3ceb61f..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)

From 28bae4ef88e361fc66e17565b4d904b7647caafb Mon Sep 17 00:00:00 2001
From: Rob Baker <robert_baker@nps.gov>
Date: Tue, 9 Jul 2024 08:45:09 -0600
Subject: [PATCH 4/7] Add info about updating rest API from v6 to v7

---
 NEWS.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/NEWS.md b/NEWS.md
index 78b3c68..c631921 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 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.

From fe7b57c7b454aa141a2e3246301eabae78cc6e7b Mon Sep 17 00:00:00 2001
From: Rob Baker <robert_baker@nps.gov>
Date: Tue, 9 Jul 2024 08:47:12 -0600
Subject: [PATCH 5/7] add unit test for get_user_email... test passes, but
 dubious it will pass build checks.

---
 tests/testthat/test-utils.R | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

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

From df3d45f728c47a31e818e1de5a4105f7fbe96090 Mon Sep 17 00:00:00 2001
From: Rob Baker <robert_baker@nps.gov>
Date: Tue, 9 Jul 2024 09:13:09 -0600
Subject: [PATCH 6/7] Changed license from MIT to CC0. Added + file License.
 licensing issues still not totally resolved.

---
 DESCRIPTION | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 270a536..3afc557 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -35,7 +35,7 @@ Authors@R: c(
            )
 Maintainer: Rob Baker <robert_baker@nps.gov>
 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: 

From 8cc0cb2d72d3f6b063dab0ed6197bc1184b7a1ea Mon Sep 17 00:00:00 2001
From: Rob Baker <robert_baker@nps.gov>
Date: Tue, 9 Jul 2024 09:13:22 -0600
Subject: [PATCH 7/7] updates via pkgdown and devtools::document

---
 NAMESPACE                          |   1 +
 docs/news/index.html               |   1 +
 docs/pkgdown.yml                   |   2 +-
 docs/reference/get_user_email.html | 117 +++++++++++++++++++++++++++++
 docs/reference/index.html          |   4 +
 docs/sitemap.xml                   |   3 +
 man/get_user_email.Rd              |  24 ++++++
 7 files changed, 151 insertions(+), 1 deletion(-)
 create mode 100644 docs/reference/get_user_email.html
 create mode 100644 man/get_user_email.Rd

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/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 @@ <h1 data-toc-skip>Changelog <small></small></h1>
 
     <div class="section level2">
 <h2 class="page-header" data-toc-text="0.1.8" id="qckit-v018-not-yet-released">QCkit v0.1.8 (not yet released)<a class="anchor" aria-label="anchor" href="#qckit-v018-not-yet-released"></a></h2>
+<p>2024-07-09 * Added function <code><a href="../reference/get_user_email.html">get_user_email()</a></code>, 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.</p>
 <p>2024-06-28 * Updated <code><a href="../reference/get_park_polygon.html">get_park_polygon()</a></code> 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 <code><a href="../reference/generate_ll_from_utm.html">generate_ll_from_utm()</a></code> * add function <code><a href="../reference/remove_empty_tables.html">remove_empty_tables()</a></code> (and associated unit tests) * update documentation for <code>replace blanks()</code> to indicate it can replace blanks with more than just NA</p>
 </div>
     <div class="section level2">
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 @@
+<!DOCTYPE html>
+<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Retrieves an NPS user's email address — get_user_email • QCkit</title><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css"><script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet"><script src="../pkgdown.js"></script><meta property="og:title" content="Retrieves an NPS user's email address — get_user_email"><meta property="og:description" content="Retrieves an NPS user's email address"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
+<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
+<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
+<![endif]--></head><body data-spy="scroll" data-target="#toc">
+    
+
+    <div class="container template-reference-topic">
+      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
+  <div class="container">
+    <div class="navbar-header">
+      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
+        <span class="sr-only">Toggle navigation</span>
+        <span class="icon-bar"></span>
+        <span class="icon-bar"></span>
+        <span class="icon-bar"></span>
+      </button>
+      <span class="navbar-brand">
+        <a class="navbar-link" href="../index.html">QCkit</a>
+        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">0.1.7</span>
+      </span>
+    </div>
+
+    <div id="navbar" class="navbar-collapse collapse">
+      <ul class="nav navbar-nav"><li>
+  <a href="../reference/index.html">Reference</a>
+</li>
+<li class="dropdown">
+  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
+    Articles
+     
+    <span class="caret"></span>
+  </a>
+  <ul class="dropdown-menu" role="menu"><li>
+      <a href="../articles/DRR_Purpose_and_Scope.html">DRR Purpose and Scope</a>
+    </li>
+    <li>
+      <a href="../articles/Starting-a-DRR.html">Starting a DRR</a>
+    </li>
+    <li>
+      <a href="../articles/Using-the-DRR-Template.html">Using the DRR Template</a>
+    </li>
+  </ul></li>
+<li>
+  <a href="../news/index.html">Changelog</a>
+</li>
+      </ul><ul class="nav navbar-nav navbar-right"><li>
+  <a href="https://github.com/nationalparkservice/QCkit/" class="external-link">
+    <span class="fab fa-github fa-lg"></span>
+     
+  </a>
+</li>
+      </ul></div><!--/.nav-collapse -->
+  </div><!--/.container -->
+</div><!--/.navbar -->
+
+      
+
+      </header><div class="row">
+  <div class="col-md-9 contents">
+    <div class="page-header">
+    <h1>Retrieves an NPS user's email address</h1>
+    <small class="dont-index">Source: <a href="https://github.com/nationalparkservice/QCkit/blob/HEAD/R/utils.R" class="external-link"><code>R/utils.R</code></a></small>
+    <div class="hidden name"><code>get_user_email.Rd</code></div>
+    </div>
+
+    <div class="ref-description">
+    <p>Retrieves an NPS user's email address</p>
+    </div>
+
+    <div id="ref-usage">
+    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">get_user_email</span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
+    </div>
+
+    <div id="value">
+    <h2>Value</h2>
+    
+
+<p>String. The user's email address.</p>
+    </div>
+    <div id="details">
+    <h2>Details</h2>
+    <p>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.</p>
+<p>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.</p>
+    </div>
+
+    <div id="ref-examples">
+    <h2>Examples</h2>
+    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="kw">if</span> <span class="op">(</span><span class="cn">FALSE</span><span class="op">)</span> <span class="op">{</span></span></span>
+<span class="r-in"><span><span class="va">email</span> <span class="op">&lt;-</span> <span class="fu">get_user_email</span><span class="op">(</span><span class="op">)</span></span></span>
+<span class="r-in"><span><span class="op">}</span></span></span>
+</code></pre></div>
+    </div>
+  </div>
+  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
+    <nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
+    </nav></div>
+</div>
+
+
+      <footer><div class="copyright">
+  <p></p><p>Developed by Robert Baker, Judd Patterson, Joe DeVivo, Issac Quevedo, Sarah Wright.</p>
+</div>
+
+<div class="pkgdown">
+  <p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.9.</p>
+</div>
+
+      </footer></div>
+
+  
+
+
+  
+
+  </body></html>
+
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 @@ <h2 id="all-functions">All functions <a href="#all-functions" class="anchor" ari
           <p><code><a href="get_taxon_rank.html">get_taxon_rank()</a></code> </p>
         </td>
         <td><p>Taxonomic Rank Determination Function</p></td>
+      </tr><tr><td>
+          <p><code><a href="get_user_email.html">get_user_email()</a></code> </p>
+        </td>
+        <td><p>Retrieves an NPS user's email address</p></td>
       </tr><tr><td>
           <p><code><a href="get_utm_zone.html">get_utm_zone()</a></code> </p>
         </td>
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 @@
   <url>
     <loc>/reference/get_taxon_rank.html</loc>
   </url>
+  <url>
+    <loc>/reference/get_user_email.html</loc>
+  </url>
   <url>
     <loc>/reference/get_utm_zone.html</loc>
   </url>
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()
+}
+}