From 9a890b06be77a5dc0355852dcb33469315aaff23 Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Sat, 11 Mar 2023 23:59:31 +0100 Subject: [PATCH 1/5] Hide Developer Tokens section in Security view if there is nothing to display or create. --- .../src/forum/components/UserSecurityPage.tsx | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/framework/core/js/src/forum/components/UserSecurityPage.tsx b/framework/core/js/src/forum/components/UserSecurityPage.tsx index d0fdac8aa3..3e38e3e9d2 100644 --- a/framework/core/js/src/forum/components/UserSecurityPage.tsx +++ b/framework/core/js/src/forum/components/UserSecurityPage.tsx @@ -51,17 +51,30 @@ export default class UserSecurityPage(); - ['developerTokens', 'sessions'].forEach((section) => { - const sectionName = `${section}Items` as 'developerTokensItems' | 'sessionsItems'; - const sectionLocale = camelCaseToSnakeCase(section); - + if ( + app.forum.attribute('canCreateAccessToken') || app.forum.attribute('canModerateAccessTokens') + || (this.state.hasLoadedTokens() && this.state.getDeveloperTokens()?.length) + ) { items.add( - section, -
- {this[sectionName]().toArray()} + 'developerTokensItems', +
+ {this.developerTokensItems().toArray()}
); - }); + } else if (!this.state.hasLoadedTokens()) { + items.add('developerTokensItems', ); + } + + items.add( + 'sessionsItems', +
+ {this.sessionsItems().toArray()} +
+ ); if (this.user!.id() === app.session.user!.id()) { items.add( From 8e65036b0b77c0557b74abdc34a43aea0c1bf3f6 Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Sun, 12 Mar 2023 00:22:03 +0100 Subject: [PATCH 2/5] Fix CS. --- .../core/js/src/forum/components/UserSecurityPage.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/framework/core/js/src/forum/components/UserSecurityPage.tsx b/framework/core/js/src/forum/components/UserSecurityPage.tsx index 3e38e3e9d2..e6f519bd01 100644 --- a/framework/core/js/src/forum/components/UserSecurityPage.tsx +++ b/framework/core/js/src/forum/components/UserSecurityPage.tsx @@ -52,21 +52,22 @@ export default class UserSecurityPage(); if ( - app.forum.attribute('canCreateAccessToken') || app.forum.attribute('canModerateAccessTokens') - || (this.state.hasLoadedTokens() && this.state.getDeveloperTokens()?.length) + app.forum.attribute('canCreateAccessToken') || + app.forum.attribute('canModerateAccessTokens') || + (this.state.hasLoadedTokens() && this.state.getDeveloperTokens()?.length) ) { items.add( 'developerTokensItems',
{this.developerTokensItems().toArray()}
); } else if (!this.state.hasLoadedTokens()) { - items.add('developerTokensItems', ); + items.add('developerTokensItems', ); } items.add( From 6a43a1dc714142ad5716bd89363728550b9fe101 Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Sun, 12 Mar 2023 02:59:37 +0100 Subject: [PATCH 3/5] Revert invalid change. --- framework/core/js/src/forum/components/UserSecurityPage.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/framework/core/js/src/forum/components/UserSecurityPage.tsx b/framework/core/js/src/forum/components/UserSecurityPage.tsx index e6f519bd01..f9874182fb 100644 --- a/framework/core/js/src/forum/components/UserSecurityPage.tsx +++ b/framework/core/js/src/forum/components/UserSecurityPage.tsx @@ -58,11 +58,7 @@ export default class UserSecurityPage +
{this.developerTokensItems().toArray()}
); From 8b020a865dcaea40041676476783ef6193dbbb8d Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Sun, 12 Mar 2023 03:01:28 +0100 Subject: [PATCH 4/5] Fix classes names. --- framework/core/js/src/forum/components/UserSecurityPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/js/src/forum/components/UserSecurityPage.tsx b/framework/core/js/src/forum/components/UserSecurityPage.tsx index f9874182fb..7f915983ae 100644 --- a/framework/core/js/src/forum/components/UserSecurityPage.tsx +++ b/framework/core/js/src/forum/components/UserSecurityPage.tsx @@ -58,7 +58,7 @@ export default class UserSecurityPage +
{this.developerTokensItems().toArray()}
); @@ -68,7 +68,7 @@ export default class UserSecurityPage +
{this.sessionsItems().toArray()}
); From 2f70a50e8ebdb87b53d4b783997fa0f9571e832d Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Sun, 12 Mar 2023 10:47:58 +0100 Subject: [PATCH 5/5] Fix key name for `items.add()` calls. --- framework/core/js/src/forum/components/UserSecurityPage.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/js/src/forum/components/UserSecurityPage.tsx b/framework/core/js/src/forum/components/UserSecurityPage.tsx index 7f915983ae..bb32f9f31f 100644 --- a/framework/core/js/src/forum/components/UserSecurityPage.tsx +++ b/framework/core/js/src/forum/components/UserSecurityPage.tsx @@ -57,17 +57,17 @@ export default class UserSecurityPage {this.developerTokensItems().toArray()}
); } else if (!this.state.hasLoadedTokens()) { - items.add('developerTokensItems', ); + items.add('developerTokens', ); } items.add( - 'sessionsItems', + 'sessions',
{this.sessionsItems().toArray()}