Skip to content
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 AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ tests/ # pytest suite (file naming: *_test.py)
├── logout_pair_test.py # logout revokes the pair (Bearer or refresh-body form)
├── auth_backend_unavailable_test.py # 503 auth_backend_unavailable: bounded retry, never a logout
├── standalone_org_login_test.py # standalone Dailybot orgs in the login picker
├── kudos_send_as_user_test.py # kudos give --send-as-user (admin-only, in a member's name)
├── effective_tier_test.py # cached plan tier refreshed from /v1/organization/
├── org_channels_test.py # `dailybot org` chat platforms (ChatPlatformSummary)
├── cli_auth_deprecation_test.py # the cli_auth_deprecated notice on email-code sign-in
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ dailybot kudos give --to "Jane Doe" --message "Great!" --value <company-value-uu

# Machine-readable
dailybot kudos give --to "Jane Doe" --message "Great!" --yes --json

# Organization admins: give the kudos in another member's name
dailybot kudos give --to "Jane Doe" --message "Thanks for covering my shift!" --send-as-user <user-uuid>
```

If `--to` or `--team` matches more than one name partially, the CLI lists the ambiguous matches and exits — it never guesses. Pass the full name or a UUID to be precise. At least one of `--to` or `--team` is required.
Expand All @@ -450,6 +453,7 @@ Team kudos pass through the backend's team manager, which expands the team into
| `--team` | | Team name or UUID. Optional when `--to` is provided. |
| `--message` | `-m` | Kudos message (team-visible). Required. |
| `--value` | | Optional company value UUID. |
| `--send-as-user` | | Give the kudos in the name of this member (user UUID). Organization admins only; the kudos rules (not to yourself, daily limits) apply to that member. |
| `--yes` | `-y` | Skip the confirmation prompt. |
| `--json` | | Emit machine-readable JSON to stdout. |

Expand Down
6 changes: 6 additions & 0 deletions dailybot_cli/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2273,13 +2273,17 @@ def give_kudos(
user_uuid_receivers: list[str] | None = None,
team_uuid_receivers: list[str] | None = None,
company_value: str | None = None,
send_as_user: str | None = None,
) -> dict[str, Any]:
"""POST /v1/kudos/

Sends the canonical ``receivers`` list (users + teams merged, for
validation) plus the type-specific ``users_receivers`` / ``teams_receivers``
lists the server uses to expand teams into their members. At least one
receiver must be present — the backend rejects an empty set.

``send_as_user`` (a member UUID, org admins only) gives the kudos in that
member's name. It is sent only when set, so the default body is unchanged.
"""
payload: dict[str, Any] = {"content": content}
receivers: list[str] = [*(user_uuid_receivers or []), *(team_uuid_receivers or [])]
Expand All @@ -2291,6 +2295,8 @@ def give_kudos(
payload["teams_receivers"] = team_uuid_receivers
if company_value:
payload["company_value"] = company_value
if send_as_user is not None:
payload["send_as_user"] = send_as_user
response: httpx.Response = self._request(
"POST",
f"{self.api_url}/v1/kudos/",
Expand Down
94 changes: 89 additions & 5 deletions dailybot_cli/commands/kudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dailybot_cli.commands.public_api_helpers import (
EXIT_PERMISSION_DENIED,
EXIT_USAGE_ERROR,
UUID_PATTERN,
confirm_write,
emit_json,
enforce_plan_access,
Expand All @@ -27,6 +28,28 @@
print_pagination_footer,
)

# Server refusals of ``send_as_user`` reworded for this command. The shared
# messages in ``ERROR_CODE_MESSAGES`` name the chat-send flags.
SEND_AS_USER_OVERRIDES: dict[str, str] = {
"org_admin_required": (
"Giving kudos in another member's name (--send-as-user) requires organization "
"admin privileges. Run it with an admin account or an org admin's API key. "
"No kudos was given."
),
"send_as_user_invalid_uuid": "Invalid UUID for --send-as-user.",
"send_as_user_not_found": (
"--send-as-user must be the UUID of an active member of your organization. "
"Run 'dailybot user list' to find it."
),
# The API refuses send_as_user together with by_dailybot (a kudos credited to
# Dailybot itself) or is_anonymous (a kudos given in someone's name can't hide
# its sender). The CLI sends neither; kept in case a server returns it anyway.
"send_as_user_conflict": (
"--send-as-user can't be combined with an anonymous kudos or one given by "
"Dailybot itself: a kudos given in someone's name always shows its sender."
),
}


def execute_kudos_give(
client: DailyBotClient,
Expand All @@ -40,23 +63,34 @@ def execute_kudos_give(
json_mode: bool = False,
receiver_uuid: str | None = None,
receiver_name: str | None = None,
send_as_user: str | None = None,
send_as_name: str | None = None,
) -> None:
"""Send kudos with already-resolved user / team receivers.

``receiver_uuid`` / ``receiver_name`` are a legacy single-user shortcut kept
for interactive mode; new callers should use ``user_receivers`` /
``team_receivers`` lists of (uuid, display_name) pairs.

``send_as_user`` gives the kudos in that member's name (org admins only).
The server applies the kudos rules to that member, so the local
"not to yourself" check compares the receivers with them, not the caller.
"""
users: list[tuple[str, str]] = list(user_receivers or [])
teams: list[tuple[str, str]] = list(team_receivers or [])

if receiver_uuid:
users.append((receiver_uuid, receiver_name or receiver_uuid))

if current_uuid:
giver_uuid: str | None = send_as_user or current_uuid
if giver_uuid:
for user_uuid, _name in users:
if user_uuid == current_uuid:
error_message: str = "You cannot give kudos to yourself."
if user_uuid.lower() == giver_uuid.lower():
error_message: str = (
"A member cannot receive kudos given in their own name."
if send_as_user
else "You cannot give kudos to yourself."
)
if json_mode:
emit_json({"error": error_message, "status": 403})
else:
Expand All @@ -83,26 +117,36 @@ def execute_kudos_give(
summary_lines.append(f"Message: {message}")
if value:
summary_lines.append(f"Company value: {value}")
if send_as_user:
summary_lines.append(
f"Given in the name of: {send_as_name} ({send_as_user})"
if send_as_name
else f"Given in the name of: {send_as_user} (not found in your directory)"
)

confirm_write(summary_lines, assume_yes)

extra_fields: dict[str, Any] = {"send_as_user": send_as_user} if send_as_user else {}
try:
with console.status("Sending kudos..."):
result: dict[str, Any] = client.give_kudos(
content=message,
user_uuid_receivers=[u for u, _ in users] or None,
team_uuid_receivers=[t for t, _ in teams] or None,
company_value=value,
**extra_fields,
)
except APIError as exc:
exit_for_api_error(exc, json_mode)
exit_for_api_error(
exc, json_mode, code_overrides=SEND_AS_USER_OVERRIDES if send_as_user else None
)

if json_mode:
emit_json(result)
return

label_parts: list[str] = [name for _, name in users] + [f"team {name}" for _, name in teams]
print_kudos_result(", ".join(label_parts) or "receiver", result)
print_kudos_result(", ".join(label_parts) or "receiver", result, given_as=send_as_user)


@click.group()
Expand Down Expand Up @@ -139,13 +183,23 @@ def kudos() -> None:
default=None,
help="Optional company value UUID.",
)
@click.option(
"--send-as-user",
"send_as_user",
default=None,
help=(
"Give the kudos in the name of this member (user UUID). Admin-only; use it "
"only when asked to give kudos on someone else's behalf."
),
)
@click.option("--yes", "-y", "assume_yes", is_flag=True, help="Skip the confirmation prompt.")
@click.option("--json", "json_mode", is_flag=True, help="Emit machine-readable JSON to stdout.")
def kudos_give(
receiver: str | None,
team_identifier: str | None,
message: str,
value: str | None,
send_as_user: str | None,
assume_yes: bool,
json_mode: bool,
) -> None:
Expand All @@ -163,7 +217,19 @@ def kudos_give(
dailybot kudos give --to "Jane Doe" --message "Great release work!"
dailybot kudos give --team "Engineering" --message "Shipped flawlessly"
dailybot kudos give --to "Alice" --team "QA" --message "Both nailed it"
dailybot kudos give --to "Jane Doe" --message "Thanks!" --send-as-user <user-uuid>

\b
--send-as-user gives the kudos in another member's name (org admins only;
the kudos rules apply to that member).
"""
if send_as_user is not None and not UUID_PATTERN.match(send_as_user):
invalid_message: str = "Invalid UUID for --send-as-user."
if json_mode:
emit_json({"error": invalid_message, "status": 0})
else:
print_error(invalid_message)
raise SystemExit(EXIT_USAGE_ERROR)
if not receiver and not team_identifier:
message_err: str = "At least one of --to or --team is required."
if json_mode:
Expand All @@ -177,6 +243,7 @@ def kudos_give(
user_receivers: list[tuple[str, str]] = []
team_receivers: list[tuple[str, str]] = []
current_uuid: str | None = None
send_as_name: str | None = None

try:
if receiver:
Expand All @@ -185,6 +252,21 @@ def kudos_give(
user_uuid, user_name = resolve_user_by_name_or_uuid(users, receiver)
user_receivers.append((user_uuid, user_name))
current_uuid = get_current_user_uuid(client)
if send_as_user:
# Name the member in the confirmation, so a wrong UUID is easy to catch.
with console.status("Resolving the member..."):
directory: list[dict[str, Any]] = client.list_users(include_inactive=True)
send_as_name = (
next(
(
str(u.get("full_name") or u.get("name") or "")
for u in directory
if str(u.get("uuid") or "").lower() == send_as_user.lower()
),
None,
)
or None
)
if team_identifier:
with console.status("Resolving team receiver..."):
teams: list[dict[str, Any]] = client.list_teams()
Expand All @@ -208,6 +290,8 @@ def kudos_give(
value=value,
assume_yes=assume_yes,
json_mode=json_mode,
send_as_user=send_as_user,
send_as_name=send_as_name,
)


Expand Down
6 changes: 3 additions & 3 deletions dailybot_cli/commands/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2062,9 +2062,9 @@ def task_delete(
"""Archive a task. An alias of `task archive` — nothing is destroyed.

\b
The server treats DELETE on a task as an archive: it is reversible and audited
as `task.archived`. This command says "archived" for that reason, and names
the restore path, rather than implying a deletion that does not happen.
This command posts to the archive door, so the task is archived: it is
reversible with `task restore` and audited as `task.archived`. (The API's own
DELETE on a task now moves it to a trash instead; this command does not use it.)

\b
Examples:
Expand Down
26 changes: 24 additions & 2 deletions dailybot_cli/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,32 @@ def print_form_submit_result(form_name: str, data: dict[str, Any]) -> None:
print_info(f"Response ID: {response_id}")


def print_kudos_result(receiver_name: str, data: dict[str, Any]) -> None:
"""Display the result of giving kudos."""
def print_kudos_result(
receiver_name: str, data: dict[str, Any], *, given_as: str | None = None
) -> None:
"""Display the result of giving kudos.

``given_as`` names the member the kudos was given in the name of
(``--send-as-user``); the server's ``user`` in the answer wins when present.
"""
kudos_id: str = resource_uuid(data) or "N/A"
print_success(f"Kudos sent to {receiver_name}")
if given_as:
Comment on lines 1243 to +1244

This comment was marked as outdated.

giver: Any = data.get("user")
giver_uuid: str = str(giver.get("uuid") or "") if isinstance(giver, dict) else ""
if giver_uuid and giver_uuid.lower() == given_as.lower():
giver_label: str = str(giver.get("full_name") or giver.get("name") or given_as)
print_info(f"Given in the name of: {plain_text(giver_label)}")
elif giver_uuid:
print_warning(
f"The server recorded a different giver ({plain_text(giver_uuid)}) than "
f"--send-as-user ({plain_text(given_as)}). Check the kudos before relying on it."
)
else:
print_warning(
"The server did not confirm the giver. An API without --send-as-user support "
"gives the kudos as you."
)
print_info(f"Kudos ID: {kudos_id}")


Expand Down
9 changes: 6 additions & 3 deletions docs/API_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,21 @@ Creating and configuring forms/check-ins (as opposed to filling them in). All au

### `dailybot kudos` (group) — user-scoped, Bearer or API key auth

#### `dailybot kudos give [--to <user>] [--team <team>] --message <text> [--value <uuid>] [--yes] [--json]`
#### `dailybot kudos give [--to <user>] [--team <team>] --message <text> [--value <uuid>] [--send-as-user <user-uuid>] [--yes] [--json]`

Gives kudos to a user, a team, or both. Users are resolved by name (exact then partial match) against `GET /v1/users/`. Teams are resolved by name against `GET /v1/teams/` (server-scoped by role). At least one of `--to` / `--team` is required.

The POST `/v1/kudos/` payload uses a single `receivers` list of UUIDs (users and teams merged — the server resolves each UUID's type); the backend manager expands team UUIDs into their active members and excludes the caller, so giving kudos to a team you belong to is valid. (The legacy `user_uuid_receivers` / `team_uuid_receivers` fields are still accepted server-side during a deprecation window, but the CLI now sends `receivers`.)

`--send-as-user <user-uuid>` (organization admins only) adds `send_as_user` to the body: the kudos is given in that member's name, and the kudos rules (no kudos to yourself, daily limits) apply to that member. The member must be active in the caller's organization. The refusals are `403 org_admin_required` (nothing is created), `400 send_as_user_invalid_uuid`, `400 send_as_user_not_found` and `400 send_as_user_conflict` (sent with `by_dailybot` or `is_anonymous`, which the CLI never sends); `kudos give` maps each to its own message. An API that predates the field ignores it and gives the kudos as the caller, so this flag needs an API that supports it.

| Flag | Short | Notes |
|------|-------|-------|
| `--to` | `-t` | User full name or UUID. Optional when `--team` is provided. |
| `--team` | | Team name or UUID. Optional when `--to` is provided. |
| `--message` | `-m` | Kudos message. Required. |
| `--value` | | Optional company value UUID. |
| `--send-as-user` | | Give the kudos in the name of this member (user UUID). Org admins only. The confirmation names the member from your directory; the success line names them only when the server's answer confirms it, and warns otherwise. |
| `--yes` | `-y` | Skip confirmation prompt. |
| `--json` | | Machine-readable JSON output. |

Expand Down Expand Up @@ -445,7 +448,7 @@ Server-side `code` values mapped to messages (see `ERROR_CODE_MESSAGES` in `comm
| `free_plan_daily_limit_exceeded` | 403 → exit 4 |
| `send_as_user_conflict` | 400 → exit 2 |
| `send_as_user_invalid_uuid` | 400 → exit 2 |
| `send_as_user_not_found` | 404 → exit 5 |
| `send_as_user_not_found` | 404 → exit 5 on `chat send`; 400 → exit 2 on `kudos give` |

The CLI dispatches on the machine-readable `code` field (never the `detail` prose). `plan_upgrade_required` additionally surfaces the `upgrade_url` from the payload.

Expand Down Expand Up @@ -743,7 +746,7 @@ key, so all of these commands work with `DAILYBOT_API_KEY` set even without
| `GET` | `/v1/teams/` | — | `{ results: [{ uuid, name, active, members_count, is_default }], next? }` | Server-scoped: admins see all, members see own |
| `GET` | `/v1/teams/<uuid>/` | — | `{ uuid, name, active, ... }` | Same scoping |
| `GET` | `/v1/teams/<uuid>/members/` | — | `[{ uuid, full_name, email }]` | Members of a team the caller can see |
| `POST` | `/v1/kudos/` | `{ content, receivers: [...uuid], users_receivers?: [...], teams_receivers?: [...], company_value? }` | `{ uuid }` | `receivers` = users+teams merged (validation); `users_receivers`/`teams_receivers` drive team expansion. Payload contract is being reconciled server-side — see the integration prompt. 406 = daily limit |
| `POST` | `/v1/kudos/` | `{ content, receivers: [...uuid], users_receivers?: [...], teams_receivers?: [...], company_value?, send_as_user? }` | `{ uuid }` | `receivers` = users+teams merged (validation); `users_receivers`/`teams_receivers` drive team expansion. `send_as_user` (`--send-as-user`, org admins only) gives the kudos in that member's name; sent only when set. Refusals: 403 `org_admin_required`, 400 `send_as_user_invalid_uuid` / `send_as_user_not_found` / `send_as_user_conflict`. 406 = daily limit |
| `GET` | `/v1/kudos/` | `?filter=kudos_received\|kudos_given` (the CLI accepts `received`/`given` and the `KUDOS_*` forms and normalizes them), shared list params (all optional) | `{ count, next, previous, results }` | `kudos list` |
| `GET` | `/v1/kudos/organization/` | list flags | `{count, next, previous, results}` | `kudos org`; admin-only (Bearer or X-API-KEY) |
| `GET` | `/v1/kudos/wall-of-fame/` | `?limit` (optional) | `{ top_receiver, top_giver, dna_distribution, leaderboard: { count, next, previous, results }, leaderboard_summary }` | `kudos wall-of-fame` |
Expand Down
Loading
Loading