Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dds motd send command #720

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,7 @@ _Empty sprint_

- New version and changelog([#714](https://github.com/ScilifelabDataCentre/dds_cli/pull/714))
- Added a new option to the motd send command to allow sending to unit personnel only ([#717](https://github.com/ScilifelabDataCentre/dds_cli/pull/717))

# 2024-10-07 - 2024-10-18

- Update MOTD command according to post merge review ([#720](https://github.com/ScilifelabDataCentre/dds_cli/pull/720))
8 changes: 4 additions & 4 deletions dds_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2071,21 +2071,21 @@ def deactivate_motd(click_ctx, motd_id):
@motd_group_command.command(name="send")
@click.argument("motd_id", metavar="[MOTD_ID]", nargs=1, type=int, required=True)
@click.option(
"--unit-personnel-only",
"--unit-only",
is_flag=True,
required=False,
default=False,
help="Send MOTD to unit personnel only.",
help="Only send MOTD to Unit Admins and Unit Personnel.",
)
@click.pass_obj
def send_motd(click_ctx, motd_id, unit_personnel_only):
def send_motd(click_ctx, motd_id, unit_only):
"""Send motd as email to all users."""
try:
with dds_cli.motd_manager.MotdManager(
no_prompt=click_ctx.get("NO_PROMPT", False),
token_path=click_ctx.get("TOKEN_PATH"),
) as sender:
sender.send_motd(motd_id=motd_id, unit_personnel_only=unit_personnel_only)
sender.send_motd(motd_id=motd_id, unit_only=unit_only)
except (
dds_cli.exceptions.AuthenticationError,
dds_cli.exceptions.ApiResponseError,
Expand Down
4 changes: 2 additions & 2 deletions dds_cli/motd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def deactivate_motd(self, motd_id) -> None:
)
LOG.info(response_message)

def send_motd(self, motd_id: int, unit_personnel_only=False) -> None:
def send_motd(self, motd_id: int, unit_only=False) -> None:
"""Send specific MOTD to users."""
response_json, _ = dds_cli.utils.perform_request(
endpoint=DDSEndpoint.MOTD_SEND,
headers=self.token,
method="post",
json={"motd_id": motd_id, "unit_personnel_only": unit_personnel_only},
json={"motd_id": motd_id, "unit_only": unit_only},
error_message="Failed sending the MOTD to users",
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_motd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_send_motd_all(caplog: LogCaptureFixture):

with motd_manager.MotdManager(authenticate=False, no_prompt=True) as mtdm:
mtdm.token = {} # required, otherwise none
mtdm.send_motd(motd_id=motd_id, unit_personnel_only=False) # Send motd
mtdm.send_motd(motd_id=motd_id, unit_only=False) # Send motd

assert (
"dds_cli.motd_manager",
Expand Down
Loading