Commit Graph
11 Commits
Author SHA1 Message Date
OpenClaw 51a87655d6 feat(auth): add scope-based access control to all existing routes (TRU-149)
Adds a scope-based access control layer to all 81 existing API routes.
Sits alongside existing session-cookie auth (does not replace it).

What this PR does:
- Audits every existing route and documents required scope per route
  (see documentation/auth/route-scope-audit.md)
- Adds classes/auth/scope.php with 10 scope constants and role→scope defaults
- Adds classes/auth/scope_middleware.php with requireScope/requireAnyScope/requireRole
- Applies require*() calls to all 81 existing routes
- Adds ScopeMiddlewareTest (unit, 178 lines) and RouteScopeTest (integration, 212 lines)

Coexistence note:
This branch's classes/auth/scope.php is a stub that will be replaced
by classes/auth/scope_registry.php (from TRU-145 / PR #396) when that
PR merges first. The two have compatible APIs.

Refs: TRU-149
2026-08-17 11:43:13 +00:00
Jeppe Bundgaard b547a8b029 Refactor permission handling to leverage standardized "forbidden" responses and enhance unit test coverage. 2026-03-19 15:59:25 +01:00
Jeppe Bundgaard 11a677416b Enhance department goal criteria handling
- Refactored department daily targets logic for optimization and better maintainability.
- Ensured department-specific targets are validated, sanitized, and consistently applied in updates.
- Improved database interaction safety by preventing unnecessary updates for unchanged object properties.
- Adjusted route and API behavior for criteria and department updates to handle validations comprehensively.
2026-02-25 14:15:19 +01:00
Jeppe Bundgaard 17325f565e Update Slack notification logic and refine COUNT_ONLY summary rendering
- Swap `send_message` with `send_webhook_message` to fix departmental Slack notification issues.
- Adjust `COUNT_ONLY` in `renderDanishPeriodSummary` to exclude targets for raw count-focused alerts.
2026-01-29 20:31:05 +01:00
Jeppe Bundgaard 84bfbdad25 Refactor Slack notifications and enhance departmental progress calculation
- Replace `send_webhook_message` with `send_message` for improved Slack notification rendering using `goals_progress_alert_renderer`.
- Add methods for calculating and retrieving departmental progress and distribution in `goals_criteria`.
- Update `renderDanishPeriodSummary` and Slack cron logic to support departmental-specific summaries.
- Include departmental progress in serialized goal objects for better reporting.
2026-01-29 18:30:04 +01:00
Jeppe Bundgaard d01bdb7ea3 Enhance Slack notifications and pluralize Danish labels in goals_progress_alert_renderer
- Add support for sending Slack notifications to multiple department webhooks.
- Adjust Danish label pluralization based on counts for departments, customers, and products.
2026-01-27 09:57:13 +01:00
Jeppe Bundgaard 6468bcb481 Add endpoint to send test progress alerts for department goals
- Implement `/goals/department/progress-alert/test` POST endpoint to send test progress alerts.
- Support email, SMS, and Slack as alert destinations with customizable parameters.
- Validate user permissions, goal existence, and alert configuration before dispatch.
- Extend alert rendering logic with destination-specific delivery methods.
2026-01-27 09:09:10 +01:00
Jeppe Bundgaard ad0277ff17 Enhance input validation, unicode handling, and sanitization across department goal criteria
- Add `validateAndSanitize` method to `goals_criteria` for input validation and defaulting incorrect values.
- Ensure JSON encoding in `response` and database interactions respects Unicode (`JSON_UNESCAPED_UNICODE`).
- Sanitize and validate input for `department_goals_o::add` and criteria usage.
- Fix header character encoding in response (`Content-Type: application/json; charset=utf-8`).
- Update criteria `label` sanitization with trimming, length limits, and safe character handling.
2026-01-27 08:20:33 +01:00
Jeppe Bundgaard f5e715d113 Preserve unicode characters in goals_criteria JSON encoding for department goals 2026-01-27 07:51:58 +01:00
Jeppe Bundgaard b4b72d7537 Add access control for department goal operations in departmentGoalsRoute
- Restrict goal listing and retrieval based on user permissions and department access.
- Enforce department-level access control for goal creation, updates, and deletions.
- Validate user actions against `superuser` status and department memberships.
2026-01-26 17:22:17 +01:00
Jeppe Bundgaard 4a0e86164c Add departmentGoalsRoute for CRUD operations on department goals
- Implement route for listing department goals with optional pagination and single-goal retrieval.
- Add logic to create, update, and delete department goals with validation for input and permissions.
- Support department and criteria management via JSON parsing and object transformation.
2026-01-26 17:18:01 +01:00