Skip to content

Commit b413b9d

Browse files
committed
fix: address review feedback for access-control
- Replace enable/disable button with Bootstrap switch toggle - Split auth checks and add CSRF validation per new pattern - Add @api_examples for updateClient endpoint - Remove blank doc comment line
1 parent f1f733d commit b413b9d

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

docs/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ curl -u user:pass -H "X-CSRF-Token: your_token_here" \
6161
## POST /api/clients/unpair-all
6262
@copydoc confighttp::unpairAll()
6363

64+
## POST /api/clients/update
65+
@copydoc confighttp::updateClient()
66+
6467
## GET /api/config
6568
@copydoc confighttp::getConfig()
6669

src/confighttp.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,17 +847,25 @@ namespace confighttp {
847847
* @brief Enable or disable a client.
848848
* @param response The HTTP response object.
849849
* @param request The HTTP request object.
850-
*
851850
* The body for the POST request should be JSON serialized in the following format:
852851
* @code{.json}
853852
* {
854853
* "uuid": "<uuid>",
855854
* "enabled": true
856855
* }
857856
* @endcode
857+
*
858+
* @api_examples{/api/clients/update| POST| {"uuid":"<uuid>","enabled":true}}
858859
*/
859860
void updateClient(resp_https_t response, req_https_t request) {
860-
if (!check_content_type(response, request, "application/json") || !authenticate(response, request)) {
861+
if (!check_content_type(response, request, "application/json")) {
862+
return;
863+
}
864+
if (!authenticate(response, request)) {
865+
return;
866+
}
867+
std::string client_id = get_client_id(request);
868+
if (!validate_csrf_token(response, request, client_id)) {
861869
return;
862870
}
863871

src_assets/common/assets/web/troubleshooting.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ <h2 id="unpair" class="mb-0">{{ $t('troubleshooting.unpair_title') }}</h2>
137137
<li v-for="client in clients" :key="client.uuid" class="list-group-item d-flex align-items-center">
138138
<div class="flex-grow-1">
139139
{{ client.name !== "" ? client.name : $t('troubleshooting.unpair_single_unknown') }}
140-
<span class="badge ms-2" :class="client.enabled ? 'bg-success' : 'bg-secondary'">
141-
{{ client.enabled ? 'Enabled' : 'Disabled' }}
142-
</span>
143140
</div>
144-
<button class="btn btn-sm ms-2" :class="client.enabled ? 'btn-warning' : 'btn-success'" @click="toggleClient(client.uuid, !client.enabled)">
145-
{{ client.enabled ? 'Disable' : 'Enable' }}
146-
</button>
141+
<div class="form-check form-switch ms-2 mb-0">
142+
<input class="form-check-input" type="checkbox" role="switch"
143+
:id="'toggle-' + client.uuid"
144+
:checked="client.enabled"
145+
@change="toggleClient(client.uuid, !client.enabled)">
146+
</div>
147147
<button class="btn btn-danger btn-sm ms-2" @click="unpairSingle(client.uuid)">
148148
<trash-2 :size="18" class="icon"></trash-2>
149149
</button>

0 commit comments

Comments
 (0)