discourse/app/assets/javascripts/admin/templates/api-keys-show.hbs
Roman Rizzi f13ec11c64
FEATURE: Add scopes to API keys (#9844)
* Added scopes UI

* Create scopes when creating a new API key

* Show scopes on the API key show route

* Apply scopes on API requests

* Extend scopes from plugins

* Add missing scopes. A mapping can be associated with multiple controller actions

* Only send scopes if the use global key option is disabled. Use the discourse plugin registry to add new scopes

* Add not null validations and index for api_key_id

* Annotate model

* DEV: Move default mappings to ApiKeyScope

* Remove unused attribute and improve UI for existing keys

* Support multiple parameters separated by a comma
2020-07-16 15:51:24 -03:00

118 lines
3.5 KiB
Handlebars

{{#link-to "adminApiKeys.index" class="go-back"}}
{{d-icon "arrow-left"}}
{{i18n "admin.api.all_api_keys"}}
{{/link-to}}
<div class="api-key">
{{#admin-form-row label="admin.api.key"}}
{{#if model.revoked_at}}{{d-icon "times-circle"}}{{/if}}
{{model.truncatedKey}}
{{/admin-form-row}}
{{#admin-form-row label="admin.api.description"}}
{{#if editingDescription}}
{{input value=buffered.description maxlength="255" placeholder=(i18n "admin.api.description_placeholder")}}
{{else}}
<span>
{{if model.description model.description (i18n "admin.api.no_description")}}
</span>
{{/if}}
<div class="controls">
{{#if editingDescription}}
{{d-button class="ok" action=(action "saveDescription") icon="check"}}
{{d-button class="cancel" action=(action "editDescription") icon="times"}}
{{else}}
{{d-button class="btn-default" action=(action "editDescription") icon="pencil-alt"}}
{{/if}}
</div>
{{/admin-form-row}}
{{#admin-form-row label="admin.api.user"}}
{{#if model.user}}
{{#link-to "adminUser" model.user}}
{{avatar model.user imageSize="small"}} {{model.user.username}}
{{/link-to}}
{{else}}
{{i18n "admin.api.all_users"}}
{{/if}}
{{/admin-form-row}}
{{#admin-form-row label="admin.api.created"}}
{{format-date model.created_at leaveAgo="true"}}
{{/admin-form-row}}
{{#admin-form-row label="admin.api.updated"}}
{{format-date model.updated_at leaveAgo="true"}}
{{/admin-form-row}}
{{#admin-form-row label="admin.api.last_used"}}
{{#if model.last_used_at}}
{{format-date model.last_used_at leaveAgo="true"}}
{{else}}
{{i18n "admin.api.never_used"}}
{{/if}}
{{/admin-form-row}}
{{#admin-form-row label="admin.api.revoked"}}
{{#if model.revoked_at}}
{{format-date model.revoked_at leaveAgo="true"}}
{{/if}}
<div class="controls">
{{#if model.revoked_at}}
{{d-button
action=(action "undoRevokeKey")
actionParam=model icon="undo"
label="admin.api.undo_revoke"}}
{{d-button
action=(action "deleteKey")
actionParam=model icon="trash-alt"
label="admin.api.delete"
class="btn-danger"}}
{{else}}
{{d-button
class="btn-danger"
action=(action "revokeKey")
actionParam=model
icon="times"
label="admin.api.revoke"}}
{{/if}}
</div>
{{/admin-form-row}}
{{#if model.api_key_scopes.length}}
{{#admin-form-row label="admin.api.scopes.title"}}
{{/admin-form-row}}
<table class="scopes-table">
<thead>
<tr>
<td>{{i18n "admin.api.scopes.resource"}}</td>
<td>{{i18n "admin.api.scopes.action"}}</td>
<td>{{i18n "admin.api.scopes.allowed_parameters"}}</td>
</tr>
</thead>
<tbody>
{{#each model.api_key_scopes as |scope|}}
<tr>
<td>{{scope.resource}}</td>
<td>{{scope.action}}</td>
<td>
{{#each scope.parameters as |p|}}
<div>
<b>{{p}}:</b>
{{#if (get scope.allowed_parameters p)}}
{{get scope.allowed_parameters p}}
{{else}}
{{i18n "admin.api.scopes.any_parameter"}}
{{/if}}
</div>
{{/each}}
</td>
</tr>
{{/each}}
</tbody>
</table>
{{/if}}
</div>