Skip to content

A platform for community discussion. Free, open, simple.

UX: Improve styling of Apps section in Profile > Security (#37408)

Penar Musarajaab48a88f11d
diff --git a/app/assets/stylesheets/common/base/user.scss b/app/assets/stylesheets/common/base/user.scss
index 17891fd7d43..1d8d2dbfaaf 100644
--- a/app/assets/stylesheets/common/base/user.scss
+++ b/app/assets/stylesheets/common/base/user.scss
@@ -976,7 +976,8 @@
}
.pref-passkeys,
- .pref-auth-tokens {
+ .pref-auth-tokens,
+ .pref-user-api-keys {
.row {
border-top: 1px solid var(--content-border-color);
padding: 0.5em 0;
@@ -1020,6 +1021,51 @@
}
}
+ .pref-user-api-keys {
+ .user-api-key {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: flex-start;
+ gap: 0.5em;
+ }
+
+ .user-api-key__info {
+ flex: 1;
+ min-width: 200px;
+ }
+
+ .user-api-key__name {
+ font-size: 1.1em;
+ font-weight: bold;
+ }
+
+ .user-api-key__dates {
+ color: var(--primary-medium);
+ }
+
+ .user-api-key__scopes-toggle {
+ width: 100%;
+ margin-top: 0.5em;
+
+ a {
+ color: var(--tertiary);
+ cursor: pointer;
+
+ .d-icon {
+ margin-right: 0.25em;
+ }
+ }
+ }
+
+ .user-api-key__scopes-list {
+ width: 100%;
+ margin: 0.5em 0 0 1.5em;
+ padding: 0;
+ list-style: disc;
+ color: var(--primary-medium);
+ }
+ }
+
.pref-second-factor {
margin-top: 0.5em;
}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index fbdc56706ce..574163b04dd 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1706,6 +1706,9 @@ en:
undo_revoke_access: "Undo Revoke Access"
api_approved: "Approved:"
api_last_used_at: "Last used at:"
+ api_show_permissions:
+ one: "Permissions granted (%{count})"
+ other: "Permissions granted (%{count})"
theme: "Theme"
save_to_change_theme: 'Theme will be updated after you click "%{save_text}"'
home: "Default Home Page"
diff --git a/frontend/discourse/app/components/user-preferences/user-api-keys.gjs b/frontend/discourse/app/components/user-preferences/user-api-keys.gjs
index d2e596bd96a..e99c0b363b3 100644
--- a/frontend/discourse/app/components/user-preferences/user-api-keys.gjs
+++ b/frontend/discourse/app/components/user-preferences/user-api-keys.gjs
@@ -1,9 +1,78 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
import { fn } from "@ember/helper";
+import { on } from "@ember/modifier";
+import { action } from "@ember/object";
import DButton from "discourse/components/d-button";
import ageWithTooltip from "discourse/helpers/age-with-tooltip";
+import icon from "discourse/helpers/d-icon";
import routeAction from "discourse/helpers/route-action";
import { i18n } from "discourse-i18n";
+class UserApiKeyRow extends Component {
+ @tracked showScopes = false;
+
+ @action
+ toggleScopes(event) {
+ event?.preventDefault();
+ this.showScopes = !this.showScopes;
+ }
+
+ <template>
+ <div class="row user-api-key">
+ <div class="user-api-key__info">
+ <div class="user-api-key__name">{{@apiKey.application_name}}</div>
+ <div class="user-api-key__dates">
+ <div class="user-api-key__date-approved">
+ <span>{{i18n "user.api_approved"}}</span>
+ {{ageWithTooltip @apiKey.created_at format="medium"}}
+ </div>
+ <div class="user-api-key__date-last-used">
+ <span>{{i18n "user.api_last_used_at"}}</span>
+ {{ageWithTooltip @apiKey.last_used_at format="medium"}}
+ </div>
+ </div>
+ </div>
+
+ <div class="user-api-key__actions">
+ {{#if @apiKey.revoked}}
+ <DButton
+ @action={{fn (routeAction "undoRevokeApiKey") @apiKey}}
+ @label="user.undo_revoke_access"
+ class="btn-default btn-small"
+ />
+ {{else}}
+ <DButton
+ @action={{fn (routeAction "revokeApiKey") @apiKey}}
+ @label="user.revoke_access"
+ class="btn-default btn-small"
+ />
+ {{/if}}
+ </div>
+
+ {{#if @apiKey.scopes.length}}
+ <div class="user-api-key__scopes-toggle">
+ <a href {{on "click" this.toggleScopes}}>
+ {{icon "caret-down"}}
+ <span>{{i18n
+ "user.api_show_permissions"
+ }}</span>
+ </a>
+ </div>
+
+ {{#if this.showScopes}}
+ <ul class="user-api-key__scopes-list">
+ {{#each @apiKey.scopes as |scope|}}
+ <li class="user-api-key__scopes-list-item">{{scope}}</li>
+ {{/each}}
+ </ul>
+ {{/if}}
+ {{/if}}
+ </div>
+ </template>
+}
+
const UserApiKeys = <template>
{{#if @model.userApiKeys}}
<div class="control-group pref-user-api-keys">
@@ -11,45 +80,9 @@ const UserApiKeys = <template>
"user.apps"
}}</label>
- <div class="controls">
+ <div class="user-api-keys">
{{#each @model.userApiKeys as |key|}}
- <div>
- <span
- class="pref-user-api-keys__application-name"
- >{{key.application_name}}</span>
-
- {{#if key.revoked}}
- <DButton
- @action={{fn (routeAction "undoRevokeApiKey") key}}
- @label="user.undo_revoke_access"
- />
- {{else}}
- <DButton
- @action={{fn (routeAction "revokeApiKey") key}}
- @label="user.revoke_access"
- />
- {{/if}}
-
- <p>
- <ul class="pref-user-api-keys__scopes-list">
- {{#each key.scopes as |scope|}}
- <li
- class="pref-user-api-keys__scopes-list-item"
- >{{scope}}</li>
- {{/each}}
- </ul>
- </p>
-
- <p class="pref-user-api-keys__created-at">
- <span>{{i18n "user.api_approved"}}</span>
- {{ageWithTooltip key.created_at format="medium"}}
- </p>
-
- <p class="pref-user-api-keys__last-used-at">
- <span>{{i18n "user.api_last_used_at"}}</span>
- {{ageWithTooltip key.last_used_at format="medium"}}
- </p>
- </div>
+ <UserApiKeyRow @apiKey={{key}} />
{{/each}}
</div>
</div>
diff --git a/frontend/discourse/tests/acceptance/user-preferences-security-test.js b/frontend/discourse/tests/acceptance/user-preferences-security-test.js
index b9bbdbc363a..823b0b39453 100644
--- a/frontend/discourse/tests/acceptance/user-preferences-security-test.js
+++ b/frontend/discourse/tests/acceptance/user-preferences-security-test.js
@@ -78,25 +78,27 @@ acceptance("User Preferences - Security", function (needs) {
await visit("/u/eviltrout/preferences/security");
assert
- .dom(".pref-user-api-keys__application-name")
+ .dom(".user-api-key__name")
.hasText(
"Discourse Hub",
"displays the application name for the API key"
);
+ await click(".user-api-key__scopes-toggle > a");
+
assert
- .dom(".pref-user-api-keys__scopes-list-item")
+ .dom(".user-api-key__scopes-list-item")
.hasText(
"Read and clear notifications",
"displays the scope for the API key"
);
assert
- .dom(".pref-user-api-keys__created-at")
+ .dom(".user-api-key__date-approved")
.exists("displays the created at date for the API key");
assert
- .dom(".pref-user-api-keys__last-used-at")
+ .dom(".user-api-key__date-last-used")
.exists("displays the last used at date for the API key");
});