Changeset 3802562 for aiwend/trunk/src/Rest/AdminController.php
- Timestamp:
- 11/14/2026 10:49:34 PM (less than one hour ago)
- File:
-
- 1 edited
-
aiwend/trunk/src/Rest/AdminController.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
aiwend/trunk/src/Rest/AdminController.php
r3789777 r3802562 19 19 final class AdminController 20 20 { 21 private Plugin $plugin; 21 22 private const NS = 'aiwend/v1'; 22 23 23 public function __construct(private Plugin $plugin) 24 { 24 public function __construct(Plugin $plugin) 25 { 26 $this->plugin = $plugin; 25 27 } 26 28 … … 62 64 } 63 65 64 public function setModule(\WP_REST_Request $r): \WP_REST_Response|\WP_Error 66 /** 67 * @return \WP_REST_Response|\WP_Error 68 */ 69 public function setModule(\WP_REST_Request $r) 65 70 { 66 71 $id = (string) $r['id']; … … 74 79 } 75 80 76 public function listConnections(): \WP_REST_Response|\WP_Error 81 /** 82 * @return \WP_REST_Response|\WP_Error 83 */ 84 public function listConnections() 77 85 { 78 86 $repo = $this->plugin->connections(); … … 83 91 } 84 92 85 /** Write-only secret: the response contains only the fingerprint, never the credential. */ 86 public function createConnection(\WP_REST_Request $r): \WP_REST_Response|\WP_Error 93 /** Write-only secret: the response contains only the fingerprint, never the credential. 94 * @return \WP_REST_Response|\WP_Error */ 95 public function createConnection(\WP_REST_Request $r) 87 96 { 88 97 $repo = $this->plugin->connections(); … … 91 100 } 92 101 try { 93 $id = $repo->create(get_current_blog_id(), (string) $r['provider'], sanitize_text_field((string) $r['label']), (string) $r['secret']);102 $id = $repo->create(get_current_blog_id(), (string) $r['provider'], sanitize_text_field((string) $r['label']), new \Aiwend\Secrets\SecretString((string) $r['secret'])); 94 103 } catch (\InvalidArgumentException $e) { 95 104 return new \WP_Error('aiwend_invalid', $e->getMessage(), ['status' => 400]); … … 99 108 } 100 109 101 public function deleteConnection(\WP_REST_Request $r): \WP_REST_Response|\WP_Error 110 /** 111 * @return \WP_REST_Response|\WP_Error 112 */ 113 public function deleteConnection(\WP_REST_Request $r) 102 114 { 103 115 $repo = $this->plugin->connections(); … … 117 129 { 118 130 $site = get_current_blog_id(); 131 $uncertainRows = $this->plugin->ledger->uncertain($site, 101); // one more than listed, only to report that the window is cut 119 132 return new \WP_REST_Response([ 120 133 'site' => $this->plugin->ledger->balance($site, 'site'), … … 124 137 // Counts only (no addresses): site, client, shared, unknown. 125 138 'exhaustion' => $this->plugin->alerts->current(), 126 'uncertain' => array_map(static fn($r) => ['request_id' => $r->requestId, 'held_units' => $r->reservedUnits, 'note' => $r->note], $this->plugin->ledger->uncertain($site)), 139 'uncertain' => array_map(static fn($r) => ['request_id' => $r->requestId, 'held_units' => $r->reservedUnits, 'note' => $r->note], array_slice($uncertainRows, 0, 100)), 140 // Additive: true when more than the 100 oldest unresolved holds exist (the list is a bounded window, oldest first). 141 'uncertain_truncated' => count($uncertainRows) > 100, 127 142 // Estimates and held amounts are kept apart from usage the provider reported or an administrator entered. 128 143 'by_basis' => $this->plugin->ledger->usageSummary($site), … … 131 146 } 132 147 133 public function setBudget(\WP_REST_Request $r): \WP_REST_Response|\WP_Error 148 /** 149 * @return \WP_REST_Response|\WP_Error 150 */ 151 public function setBudget(\WP_REST_Request $r) 134 152 { 135 153 $site = get_current_blog_id(); … … 187 205 'callback' => $callback, 188 206 'args' => $args, 189 'permission_callback' => function () use ($operation) : bool|\WP_Error{207 'permission_callback' => function () use ($operation) { 190 208 $decision = $this->plugin->policy->check($this->plugin->currentPrincipal(), $operation); 191 209 return $decision->allowed ? true : Errors::response($decision->code, $decision->httpStatus());
Note:
See TracChangeset
for help on using the changeset viewer.