Skip to content

Commit 033df95

Browse files
authored
Merge pull request #66 from ScotGovAnalysis/workgroup-2fa
Add workgroup_mandate_2fa
2 parents c5bad31 + ca29fff commit 033df95

File tree

8 files changed

+142
-14
lines changed

8 files changed

+142
-14
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export(upload_file)
2424
export(upload_file_version)
2525
export(versions)
2626
export(workgroup_bypass_2fa)
27+
export(workgroup_mandate_2fa)
2728
export(workspaces)
2829
export(write_data)
2930
export(write_data_version)

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ to view status (`mobile_auth_staus()`) and to login (`mobile_auth_login()`)
2323
The `type` argument now only accepts an empty list (default to return all asset
2424
types) or a list of length 1.
2525

26+
* New `workgroup_mandate_2fa()` provides ability to enable or disable mandatory
27+
two-factor authentication (2FA) in workgroups (#65).
28+
2629
# objr 0.1.1
2730

2831
* Set minimum versions for `dplyr` and `tidyr` dependencies (#32).

R/bypass_2fa.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,46 @@ participant_bypass_2fa <- function(participant_uuid,
8686
invisible(response)
8787

8888
}
89+
90+
91+
#' Enable/disable mandatory two-factor authentication for workgroup
92+
#'
93+
#' @details
94+
#' More information on two-factor authentication can be found in
95+
#' `vignette("two-factor")`.
96+
#'
97+
#' More details on this endpoint are available in the
98+
# nolint start: line_length_linter
99+
#' \href{https://secure.objectiveconnect.co.uk/publicapi/1/swagger-ui/index.html#/Workgroups/setTwoStepMandatory}{API documentation}.
100+
# nolint end
101+
#'
102+
#' @param workgroup_uuid Workgroup UUID
103+
#' @param mandate Logical to indicate whether two-factor authentication should
104+
#' be mandatory in the workgroup
105+
#' @inheritParams objr
106+
#'
107+
#' @return API response (invisibly)
108+
#'
109+
#' @export
110+
111+
workgroup_mandate_2fa <- function(workgroup_uuid,
112+
mandate = TRUE,
113+
use_proxy = FALSE) {
114+
115+
response <- objr(
116+
endpoint = "workgroups",
117+
url_path = list(workgroup_uuid, "twostepmandatory"),
118+
method = "PUT",
119+
body = list(twoStepMandatory = tolower(mandate)),
120+
use_proxy = use_proxy
121+
)
122+
123+
if (httr2::resp_status(response) == 204) {
124+
cli::cli_alert_success(
125+
"Mandatory 2FA setting successfully updated for workgroup."
126+
)
127+
}
128+
129+
invisible(response)
130+
131+
}

_pkgdown.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
url: https://scotgovanalysis.github.io/objr
1+
url: https://ScotGovAnalysis.github.io/objr
22

33
development:
44
mode: auto
@@ -96,6 +96,7 @@ reference:
9696
- subtitle: Two-factor authentication
9797
desc: See `vignette("two-factor")` for more information.
9898
contents:
99+
- workgroup_mandate_2fa
99100
- workgroup_bypass_2fa
100101
- participant_bypass_2fa
101102

man/workgroup_mandate_2fa.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
structure(list(method = "PUT", url = "https://api/workgroups/test_workgroup/twostepmandatory",
2+
status_code = 204L, headers = structure(list(Date = "Mon, 22 Dec 2025 15:43:40 GMT",
3+
`Content-Length` = "0", Connection = "keep-alive", `X-CONNECT-MDC` = "api8ac74669e4e222120b3a73403ee82c2c",
4+
`X-Frame-Options` = "deny", `X-XSS-Protection` = "1; mode=block",
5+
`Cache-Control` = "no-cache, no-store", Expires = "0",
6+
Pragma = "no-cache", `Strict-Transport-Security` = "max-age=31536000 ; includeSubDomains",
7+
`Content-Security-Policy` = "script-src 'self' 'unsafe-inline'",
8+
`X-Content-Type-Options` = "nosniff", `Referrer-Policy` = "strict-origin-when-cross-origin",
9+
`Feature-Policy` = "vibrate 'none'; geolocation 'none'",
10+
Authorization = "REDACTED", `Set-Cookie` = "REDACTED"), class = "httr2_headers"),
11+
body = raw(0), cache = new.env(parent = emptyenv())), class = "httr2_response")

tests/testthat/test-bypass_2fa.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ without_internet({
3434
"{\"bypassTwoStep\":\"false\"}"
3535
)
3636

37+
expect_PUT(
38+
workgroup_mandate_2fa(workgroup_uuid = "test_workgroup"),
39+
paste0("https://secure.objectiveconnect.co.uk/publicapi/1/workgroups/",
40+
"test_workgroup/twostepmandatory"),
41+
"{\"twoStepMandatory\":\"true\"}"
42+
)
43+
44+
expect_PUT(
45+
workgroup_mandate_2fa(workgroup_uuid = "test_workgroup",
46+
mandate = FALSE),
47+
paste0("https://secure.objectiveconnect.co.uk/publicapi/1/workgroups/",
48+
"test_workgroup/twostepmandatory"),
49+
"{\"twoStepMandatory\":\"false\"}"
50+
)
51+
3752
})
3853

3954
})
@@ -54,12 +69,19 @@ with_mock_api({
5469
)
5570
)
5671

72+
expect_invisible(
73+
suppressMessages(
74+
workgroup_mandate_2fa("test_workgroup")
75+
)
76+
)
77+
5778
})
5879

5980
test_that("Functions return success message", {
6081

6182
expect_message(workgroup_bypass_2fa("test_workgroup"))
6283
expect_message(participant_bypass_2fa("test_participant"))
84+
expect_message(workgroup_mandate_2fa("test_workgroup"))
6385

6486
})
6587

vignettes/two-factor.Rmd

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,36 @@ These steps must be completed by a **workgroup admin**.
4646

4747
> If you work in the Scottish Government, please [contact the package maintainers](https://scotgovanalysis.github.io/objr/authors.html#authors) to arrange this step.
4848
49-
1. <a name = "workgroup-1">Navigate to the summary page for your workgroup in Objective Connect. Select 'Workgroup Options', un-check the option to 'Enforce Two-step verification', and click the blue 'Update' button.</a>
49+
1. <a name = "workgroup-1">Temporarily disable mandatory 2FA in your workgroup.</a> This can be done in one of the following ways:
50+
51+
* Navigate to the summary page for your workgroup in Objective Connect. Select 'Workgroup Options', un-check the option to 'Enforce Two-step verification', and click the blue 'Update' button.
52+
53+
```{r}
54+
#| eval: true
55+
#| echo: false
56+
#| out.width: "50%"
57+
#| fig-align: "center"
58+
#| fig-alt: >
59+
#| A button for 'Workgroup options' is selected. A menu is visible containing
60+
#| an option to 'Enforce Two-step verification' with a checkbox.
61+
knitr::include_graphics("workgroup-2fa.png", dpi = "retina")
62+
```
5063

51-
```{r}
52-
#| eval: true
53-
#| echo: false
54-
#| out.width: "50%"
55-
#| fig-align: "center"
56-
#| fig-alt: >
57-
#| A button for 'Workgroup options' is selected. A menu is visible containing
58-
#| an option to 'Enforce Two-step verification' with a checkbox.
59-
knitr::include_graphics("workgroup-2fa.png", dpi = "retina")
60-
```
64+
* In R, use `workgroup_mandate_2fa()`, providing the relevant workgroup UUID and setting `mandate = FALSE` to disable. For example:
65+
66+
```{r workgroup_mandate}
67+
workgroup_mandate_2fa("v09y-g5vk-5348-k68t-s462-c2vs-7kl8-7440", mandate = FALSE)
68+
```
69+
70+
```{r workgroup_mandate-output, eval = TRUE, echo = FALSE, message = TRUE}
71+
cli::cli_alert_success(
72+
"Mandatory 2FA setting successfully updated for workgroup."
73+
)
74+
```
75+
76+
To reinstate mandatory 2FA later, set `mandate = TRUE`.
77+
78+
> Non R users can also use the interactive documentation to [disable mandatory 2FA in the workgroup](https://secure.objectiveconnect.co.uk/publicapi/1/swagger-ui/index.html#/Workgroups/setTwoStepMandatory).
6179
6280
6381
2. In R, allow 2FA bypassing for the workgroup using `workgroup_bypass_2fa()`, providing the relevant workgroup UUID. For example:
@@ -74,7 +92,7 @@ knitr::include_graphics("workgroup-2fa.png", dpi = "retina")
7492

7593
> Non R users can use the interactive documentation to [allow 2FA bypassing in the workgroup](https://secure.objectiveconnect.co.uk/publicapi/1/swagger-ui/index.html#/Workgroups/setWorkgroupMfaBypassAllowed).
7694
77-
3. Continue to the next section to [give the workspace owner permission to bypass 2FA](#workspace-owner). Once this is complete, [reinstate 2FA enforcing for the workgroup](#workgroup-1).
95+
3. Continue to the next section to [give the workspace owner permission to bypass 2FA](#workspace-owner). Once this is complete, [reinstate mandatory 2FA for the workgroup](#workgroup-1).
7896

7997

8098
## Permission for the workspace owner {#workspace-owner}
@@ -114,7 +132,7 @@ knitr::include_graphics("workspace-2fa.png", dpi = "retina")
114132
115133
4. Reinstate 2FA for the workspace using the [same method as in step 1](#workspace-1).
116134

117-
5. The workgroup admin can now [reinstate 2FA enforcing for the workgroup](#workgroup-1).
135+
5. The workgroup admin can now [reinstate mandatory 2FA for the workgroup](#workgroup-1).
118136

119137

120138
## Permssion for other participants {#participants}

0 commit comments

Comments
 (0)