Skip to content

Commit bb7dc5b

Browse files
Exclude recently connected devices prior to filtering by date. (#333)
* drop most-recently-connected devices prior to filtering by date-connected or date-created. * changelog
1 parent 6e49d47 commit bb7dc5b

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
1313
### Fixed
1414

1515
- Incorrect column title on `code42 trusted-activities bulk create` command help text.
16+
- `code42 devices list` will now process `--exclude-most-recently-connected` prior to `--last-connected-before` instead of after.
1617

1718
### Added
1819

src/code42cli/cmds/devices.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ def list_devices(
334334
org_uid,
335335
(include_backup_usage or include_total_storage),
336336
)
337+
if exclude_most_recently_connected:
338+
most_recent = (
339+
df.sort_values(["userUid", "lastConnected"], ascending=False)
340+
.groupby("userUid")
341+
.head(exclude_most_recently_connected)
342+
)
343+
df = df.drop(most_recent.index)
337344
if last_connected_after:
338345
df = df.loc[to_datetime(df.lastConnected) > last_connected_after]
339346
if last_connected_before:
@@ -342,13 +349,6 @@ def list_devices(
342349
df = df.loc[to_datetime(df.creationDate) > created_after]
343350
if created_before:
344351
df = df.loc[to_datetime(df.creationDate) < created_before]
345-
if exclude_most_recently_connected:
346-
most_recent = (
347-
df.sort_values(["userUid", "lastConnected"], ascending=False)
348-
.groupby("userUid")
349-
.head(exclude_most_recently_connected)
350-
)
351-
df = df.drop(most_recent.index)
352352
if include_total_storage:
353353
df = _add_storage_totals_to_dataframe(df, include_backup_usage)
354354
if include_settings:

tests/cmds/test_devices.py

+18
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,24 @@ def test_list_invalid_org_uid_raises_error(runner, cli_state, custom_error):
742742
)
743743

744744

745+
def test_list_excludes_recently_connected_devices_before_filtering_by_date(
746+
runner, cli_state, get_all_devices_success,
747+
):
748+
result = runner.invoke(
749+
cli,
750+
[
751+
"devices",
752+
"list",
753+
"--exclude-most-recently-connected",
754+
"1",
755+
"--last-connected-before",
756+
TEST_DATE_NEWER,
757+
],
758+
obj=cli_state,
759+
)
760+
assert "839648314463407622" in result.output
761+
762+
745763
def test_list_backup_sets_invalid_org_uid_raises_error(runner, cli_state, custom_error):
746764
custom_error.response.text = "Unable to find org"
747765
invalid_org_uid = "invalid_org_uid"

0 commit comments

Comments
 (0)