Fix how multiple pin name matches from a Connect board are filtered #835
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With a Connect board, pins can (and should) be specified with
owner/name
, as the pinname
is unique per user account. This PR fixes a bug that occurs when multiple pins have the samename
and theowner
is not the first match.To retrieve content from Connect:
name
into a list withowner
andname
fields, e.g."toph/penguins"
becomeslist(owner = "toph", name = "penguins", full = "toph/penguins)"
."taylor_steinberg/penguins"
, the second"toph/penguins"
.owner
must have been specified, so we can filter the list. Because the JSON returned from the API only contains owner GUIDs, we use the Connect API to create a character vector of owner names parallel to the content list, i.e.c("taylor_steinberg", "toph")
. We want to use this to filter the list of matching pins.The old code used
json[[name$owner %in% owner_names]]
.name$owner %in% owner_names
just evaluates toTRUE
though, and this would just select the first item in the list. This causes failures likepin_write
unexpected permissions errors or unexpectedly updating the wrong pin.Using
json[[which(name$owner == owner_names)]]
fixes the problem, aswhich(name$owner == owner_names)
evaluates to the integer index of the matching name.Tests
I added a test of the new filtering behavior using mocked bindings. Because the main Connect test files are skipped in CI, and this test uses mocks to avoid the need for any network access etc., I put this in a new file with no skip clauses. I'm not sure if there's a better pattern to follow, or if this file should still be skipped on CRAN — let me know if a different approach is better!