Skip to content

Commit

Permalink
Merge pull request #120 from bedatadriven/version-4.36
Browse files Browse the repository at this point in the history
Version 4.36
  • Loading branch information
jamiewhths authored Apr 19, 2024
2 parents ceb4722 + ef6f9b0 commit be655fa
Show file tree
Hide file tree
Showing 40 changed files with 847 additions and 268 deletions.
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
55 changes: 55 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- main
- master
- cran-*
- version-*
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
# - {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
# - {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
TEST_URL: ${{ secrets.TEST_URL }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Test
name: activityinfo-R-package-tests
on:
push:
branches:
- main
- master
- cran-*
- version-*
workflow_dispatch:

env:
TEST_URL: ${{ secrets.TEST_URL }}
Expand Down
93 changes: 0 additions & 93 deletions .github/workflows/tic.yml

This file was deleted.

12 changes: 7 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: activityinfo
Type: Package
Title: R interface to ActivityInfo.org, an information management software for
humanitarian and development operations.
Version: 4.35.1
humanitarian and development operations
Version: 4.36
Date: 2023-05-25
Authors@R: c(
person("Alex", "Bertram", email = "alex@bedatadriven.com",
Expand All @@ -18,7 +18,7 @@ Maintainer: Alex Bertram <alex@bedatadriven.com>
Description:
An interface to ActivityInfo, a web-based information management software
used for partner reporting, monitoring and evaluation and case management in
humanitarian aid, emergencies and international development
humanitarian aid, emergencies and international development.
License: GPL-3
Depends:
dplyr (>= 1.1.1)
Expand All @@ -31,10 +31,11 @@ Imports:
pillar (>= 1.8.1),
rlang (>= 1.1.0),
tibble (>= 3.2.1),
vctrs,
tidyselect (>= 1.2.0),
magrittr
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Suggests:
ggplot2,
Expand All @@ -46,6 +47,7 @@ Suggests:
markdown,
withr,
assertthat,
purrr
purrr,
tinytex
VignetteBuilder: knitr
Config/testthat/edition: 3
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ S3method(slice_max,tbl_activityInfoRemoteRecords)
S3method(slice_min,tbl_activityInfoRemoteRecords)
S3method(slice_sample,tbl_activityInfoRemoteRecords)
S3method(slice_tail,tbl_activityInfoRemoteRecords)
S3method(src_activityInfo,databaseTree)
S3method(src_activityInfo,formTree)
S3method(src_tbls,src_activityInfoDatabaseTree)
S3method(src_tbls,src_activityInfoFormTree)
S3method(summarise,tbl_activityInfoRemoteRecords)
Expand Down Expand Up @@ -128,6 +130,12 @@ export(formFieldSchema)
export(formSchema)
export(geopointFieldSchema)
export(getAttachment)
export(getBillingAccount)
export(getBillingAccountDatabaseUsers)
export(getBillingAccountDatabases)
export(getBillingAccountDomains)
export(getBillingAccountUsers)
export(getDatabaseBillingAccount)
export(getDatabaseResources)
export(getDatabaseSchema)
export(getDatabaseTree)
Expand Down Expand Up @@ -255,12 +263,15 @@ importFrom(magrittr,"%>%")
importFrom(pillar,align)
importFrom(pillar,style_subtle)
importFrom(pillar,tbl_format_header)
importFrom(rlang,.data)
importFrom(rlang,enquo)
importFrom(rlang,rep_named)
importFrom(rlang,set_names)
importFrom(stats,runif)
importFrom(stringr,str_replace)
importFrom(tibble,as_tibble)
importFrom(tibble,tbl_sum)
importFrom(tibble,tibble)
importFrom(tibble,view)
importFrom(tidyselect,eval_select)
importFrom(tidyselect,everything)
Expand All @@ -270,3 +281,4 @@ importFrom(utils,head)
importFrom(utils,lsf.str)
importFrom(utils,read.table)
importFrom(utils,tail)
importFrom(vctrs,vec_as_names)
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [4.36]
- API tokens are now stored per root URL of the server. The token will need to be added again using activityInfoToken(token). The location of the token file has changed from "~/.activityinfo.credentials" to "~/.activityinfo.server.credentials" to avoid accidentally overwriting and losing the old tokens. (#101)
- Column name de-duplication in getRecords() (#118)
- Updated GitHub Action checks (#116)
- Snapshot tests allow new properties
- Allow custom IDs in addRecord (#111, #104)
- Billing account info functions (#97)
- API Token now stored per root URL (#101)
- Only add parent columns to query if there are fields defined on parentVarNames (#103)

## [4.35.1]
- Fix for `getQuantityTable()` (#115)
Expand Down
53 changes: 41 additions & 12 deletions R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
options(activityinfo.verbose.tasks = FALSE)
}

credentialsFile <- "~/.activityinfo.credentials"
# the legacy credentials file was "~/.activityinfo.credentials", changing the name to ensure we don't overwrite the old key file accidentally
credentialsFile <- "~/.activityinfo.server.credentials"

credentials <- environment()

Expand Down Expand Up @@ -33,6 +34,7 @@ activityInfoRootUrl <- local({
function(newUrl) {
if (!missing(newUrl)) {
url <<- newUrl
activityInfoAuthentication(NULL)
invisible()
} else {
url
Expand All @@ -43,26 +45,27 @@ activityInfoRootUrl <- local({
# ---- ActivityInfoAuthentication() ----

#' Constructs a httr::authentication object from saved credentials
#' from the user's home directory at ~/.activityinfo.credentials
#' from the user's home directory at ~/.activityinfo.server.credentials
#'
#' @importFrom httr authenticate add_headers
#' @importFrom rlang .data
#' @noRd
activityInfoAuthentication <- local({
credentials <- NULL

function(newValue) {
if (!missing(newValue)) {
credentials <<- newValue
if (!is.null(credentials)&&credentialType(credentials) == "basic") deprecationOfBasicAuthWarning()
} else {
# Look for credentials first in ~/.activityinfo.credentials
if (is.null(credentials) && file.exists(credentialsFile)) {
# message(sprintf("Reading credentials from %s...\n", path.expand(path = credentialsFile)))
line <- readLines("~/.activityinfo.credentials", warn = FALSE)[1]
if (nchar(line) <= 2) {
warning(sprintf("...file exists, but is empty or improperly formatted.\n", path.expand(path = credentialsFile)))
} else {
if (credentialType(line) == "basic") deprecationOfBasicAuthWarning()
credentials <<- line
if (is.null(credentials)&&file.exists(credentialsFile)) {
authObj = readRDS(file = credentialsFile) %>% filter(.data$server == activityInfoRootUrl())

if (nrow(authObj) == 1) {
credentials <<- authObj %>% pull(credentials)
if (credentialType(credentials) == "basic") deprecationOfBasicAuthWarning()
} else if (nrow(authObj) > 1) {
warning(sprintf("...file exists, but has more than one key. Try saving the key again.\n", path.expand(path = credentialsFile)))
}
}

Expand Down Expand Up @@ -126,11 +129,20 @@ credentialType <- function(credentials) {
#' activityInfoToken("<API TOKEN>")
#' }
#' @export
#' @importFrom rlang .data
activityInfoToken <- function(token, prompt = TRUE) {

if (interactive() && missing(token)) {
token <- readline("Enter your token: ")
}

saveToAuthFile <- function(authObj) {
authObj <- authObj %>%
filter(.data$server != activityInfoRootUrl()) %>%
add_row(server = activityInfoRootUrl(), credentials = token)
saveRDS(object = authObj, file = credentialsFile)
}

activityInfoAuthentication(token)

if (interactive() && prompt) {
Expand All @@ -140,7 +152,24 @@ activityInfoToken <- function(token, prompt = TRUE) {

save <- readline("Save token? ")
if (substr(tolower(save), 1, 1) == "y") {
cat(token, file = credentialsFile)

if (file.exists(credentialsFile)) {
authObj <- readRDS(file = credentialsFile)
existingAuthObj <- authObj %>% filter(.data$server == activityInfoRootUrl())

if (nrow(existingAuthObj)==1) {
cat(sprintf("You already have a saved token. Do you want to replace existing token for %s?\n", activityInfoRootUrl()))
save2 <- readline("Save token? ")
if (substr(tolower(save2), 1, 1) == "y") {
saveToAuthFile(authObj)
}
} else {
saveToAuthFile(authObj)
}
} else {
authObj <- tibble(server = activityInfoRootUrl(), credentials = token)
saveToAuthFile(authObj)
}
}
}
}
Expand Down
Loading

0 comments on commit be655fa

Please sign in to comment.