Skip to content

Commit edd4877

Browse files
authored
Bugfix/watchlist csv handle extra headers (#374)
* allow bulk watchlists CSVs to have extra headers * CHANGELOG and documentation note for watchlist + update-risk-profile * clean up doc note * clean up doc note
1 parent 03acea3 commit edd4877

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
99
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.
1010

11+
## Unreleased
12+
13+
### Fixed
14+
- `watchlists bulk` commands now accept CSVs with extra headers
1115

1216
## 1.14.0 - 2022-05-19
1317

docs/userguides/watchlists.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,20 @@ code42 watchlists bulk generate-template [add|remove]
5757
If both username and user_id are provided in the CSV row, the user_id value will take precedence. If watchlist_type and watchlist_id columns
5858
are both provided, the watchlist_id will take precedence.
5959

60-
## Add Watchlist-related metadata to User's Profile
60+
```{eval-rst}
61+
.. note::
6162
62-
Some Watchlists store related metadata to the watchlist member on the User Risk Profile. For example, when adding a user
63-
to the Departing Watchlist in the Code42 admin console, you can specify a "departure date" for the user. These values
64-
can be set/updated from the CLI under the [Users command group](./users.md#manage-user-risk-profile-info)
63+
For watchlists that track additional metadata for a user (e.g. the "departure date" for a user on the Departing watchlist), that data
64+
can be added/updated via the `code42 users bulk update-risk-profile <../commands/users.html#users-bulk-update-risk-profile>`_ command.
65+
66+
You can re-use the same CSV file for both commands, just add the required risk profile columns to the CSV.
67+
68+
For example, to bulk add users to multiple watchlists, with appropriate ``start_date``, ``end_date``, and ``notes`` values, create a CSV (in this example named ``watchlists.csv``) with the following::
69+
70+
username,watchlist_type,start_date,end_date,notes
71+
[email protected],DEPARTING_EMPLOYEE,,2023-10-10,
72+
[email protected],NEW_EMPLOYEE,2022-07-04,,2022 Summer Interns
73+
74+
Then run ``code42 watchlists bulk add watchlists.csv``
75+
followed by ``code42 users bulk update-risk-profile watchlists.csv``
76+
```

src/code42cli/cmds/watchlists.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ def bulk_add(state, csv_rows):
186186

187187
sdk = state.sdk
188188

189-
def handle_row(watchlist_id=None, watchlist_type=None, user_id=None, username=None):
189+
def handle_row(
190+
watchlist_id=None, watchlist_type=None, user_id=None, username=None, **kwargs
191+
):
190192
if username and not user_id:
191193
user_id = sdk.userriskprofile.get_by_username(username)["userId"]
192194
if watchlist_id:
@@ -240,7 +242,9 @@ def bulk_remove(state, csv_rows):
240242

241243
sdk = state.sdk
242244

243-
def handle_row(watchlist_id=None, watchlist_type=None, user_id=None, username=None):
245+
def handle_row(
246+
watchlist_id=None, watchlist_type=None, user_id=None, username=None, **kwargs
247+
):
244248
if username and not user_id:
245249
user_id = sdk.userriskprofile.get_by_username(username)["userId"]
246250
if watchlist_id:

tests/cmds/test_watchlists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def test_handle_row_when_passed_all_headers_uses_user_id_and_watchlist_id(
579579
with runner.isolated_filesystem():
580580
with open("csv", "w") as file:
581581
file.write(
582-
"username,user_id,watchlist_id,watchlist_type\n[email protected],1234,abcd,DEPARTING_EMPLOYEE\n"
582+
"username,user_id,watchlist_id,watchlist_type,extra_header\n[email protected],1234,abcd,DEPARTING_EMPLOYEE,\n"
583583
)
584584
runner.invoke(cli, ["watchlists", "bulk", "add", "csv"], obj=cli_state)
585585
cli_state.sdk.watchlists.add_included_users_by_watchlist_id.assert_called_once_with(

0 commit comments

Comments
 (0)