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

Modify the command dds motd send to allow the option to send only to unit personnel #717

Merged
merged 4 commits into from
Oct 3, 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
1 change: 1 addition & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,4 @@ _Empty sprint_
# 2024-09-24 - 2024-10-04

- 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))
11 changes: 9 additions & 2 deletions dds_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2070,15 +2070,22 @@ def deactivate_motd(click_ctx, motd_id):
# -- dds motd send -- #
@motd_group_command.command(name="send")
@click.argument("motd_id", metavar="[MOTD_ID]", nargs=1, type=int, required=True)
@click.option(
"--unit-personnel-only",
is_flag=True,
required=False,
default=False,
help="Send MOTD to unit personnel only.",
)
Comment on lines +2073 to +2079
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather that this option is --unit-only:

  1. --unit-personnel-only partly sounds like it's only Unit Personnel who gets the email (Unit Admins should also get the email). This could cause confusion at some point.
  2. --unit-personnel-only is imo unnecessarily long

@click.pass_obj
def send_motd(click_ctx, motd_id):
def send_motd(click_ctx, motd_id, unit_personnel_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)
sender.send_motd(motd_id=motd_id, unit_personnel_only=unit_personnel_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) -> None:
def send_motd(self, motd_id: int, unit_personnel_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},
json={"motd_id": motd_id, "unit_personnel_only": unit_personnel_only},
error_message="Failed sending the MOTD to users",
)

Expand Down
27 changes: 27 additions & 0 deletions tests/test_motd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,30 @@ def test_add_new_motd_ok(caplog: LogCaptureFixture):
logging.INFO,
"Response from API about adding a MOTD.",
) in caplog.record_tuples


# send_motd


def test_send_motd_all(caplog: LogCaptureFixture):
"""Send a MOTD to all users."""

motd_id = 1
response_message = "Response from API about sending a MOTD."
returned_response: Dict = {"message": response_message}

with caplog.at_level(logging.INFO):
# Create mocker
with Mocker() as mock:
# Create mocked request - real request not executed
mock.post(DDSEndpoint.MOTD_SEND, status_code=200, json=returned_response)

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

assert (
"dds_cli.motd_manager",
logging.INFO,
response_message,
) in caplog.record_tuples
Loading