Skip to content

Commit

Permalink
Merge pull request #2430 from umbraco/v15/bugfix/sysinfo-for-everyone
Browse files Browse the repository at this point in the history
Hotfix: System information should be visible to anyone
  • Loading branch information
iOvergaard authored Oct 9, 2024
2 parents 3f29b61 + e044c02 commit 198e2aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ export class UmbBackofficeHeaderLogoElement extends UmbLitElement {
<a href="https://umbraco.com" target="_blank" rel="noopener">Umbraco.com</a>
${this._isUserAdmin
? html`<uui-button
@click=${this.#openSystemInformation}
look="secondary"
label="System information"></uui-button>`
: ''}
<uui-button @click=${this.#openSystemInformation} look="secondary" label="System information"></uui-button>
</div>
</umb-popover-layout>
</uui-popover-container>
Expand Down
42 changes: 28 additions & 14 deletions src/packages/sysinfo/components/sysinfo.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
import type { UUIButtonState } from '@umbraco-cms/backoffice/external/uui';
import { UmbCurrentUserRepository } from '@umbraco-cms/backoffice/current-user';

type ServerKeyValue = {
name: string;
Expand All @@ -21,31 +22,26 @@ export class UmbSysinfoElement extends UmbModalBaseElement {
@state()
private _buttonState?: UUIButtonState;

#serverKeyValues: Array<ServerKeyValue> = [];
#sysinfoRepository = new UmbSysinfoRepository(this);
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;

constructor() {
super();

this.consumeContext(UMB_NOTIFICATION_CONTEXT, (context) => {
this.#notificationContext = context;
});
readonly #serverKeyValues: Array<ServerKeyValue> = [];
readonly #sysinfoRepository = new UmbSysinfoRepository(this);
readonly #currentUserRepository = new UmbCurrentUserRepository(this);

override connectedCallback(): void {
super.connectedCallback();
this.#populate();
}

async #populate() {
this._loading = true;
this.#serverKeyValues = [];
this.#serverKeyValues.length = 0;

const [serverTroubleshooting, serverInformation] = await Promise.all([
this.#sysinfoRepository.requestTroubleShooting(),
this.#sysinfoRepository.requestServerInformation(),
]);

if (serverTroubleshooting) {
this.#serverKeyValues = serverTroubleshooting.items;
this.#serverKeyValues.push(...serverTroubleshooting.items);
}

if (serverInformation) {
Expand All @@ -59,6 +55,22 @@ export class UmbSysinfoElement extends UmbModalBaseElement {
this.#serverKeyValues.push({ name: 'Browser language', data: navigator.language });
this.#serverKeyValues.push({ name: 'Browser location', data: location.href });

// User information
const { data: currentUser } = await this.#currentUserRepository.requestCurrentUser();
if (currentUser) {
this.#serverKeyValues.push({ name: 'User is admin', data: currentUser.isAdmin ? 'Yes' : 'No' });
this.#serverKeyValues.push({ name: 'User sections', data: currentUser.allowedSections.join(', ') });
this.#serverKeyValues.push({ name: 'User culture', data: currentUser.languageIsoCode });
this.#serverKeyValues.push({
name: 'User languages',
data: currentUser.hasAccessToAllLanguages ? 'All' : currentUser.languages.join(', '),
});
this.#serverKeyValues.push({
name: 'User document start nodes',
data: currentUser.documentStartNodeUniques.length ? currentUser.documentStartNodeUniques.join(', ') : 'None',
});
}

this._systemInformation = this.#renderServerKeyValues();
this._loading = false;
}
Expand Down Expand Up @@ -100,6 +112,8 @@ export class UmbSysinfoElement extends UmbModalBaseElement {
}

async #copyToClipboard() {
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);

try {
this._buttonState = 'waiting';
const text = `Umbraco system information
Expand All @@ -109,7 +123,7 @@ ${this._systemInformation}`;
await navigator.clipboard.writeText(textAsCode);

setTimeout(() => {
this.#notificationContext?.peek('positive', {
notificationContext?.peek('positive', {
data: {
headline: 'System information',
message: this.localize.term('speechBubbles_copySuccessMessage'),
Expand All @@ -119,7 +133,7 @@ ${this._systemInformation}`;
}, 250);
} catch {
this._buttonState = 'failed';
this.#notificationContext?.peek('danger', {
notificationContext?.peek('danger', {
data: {
headline: 'System information',
message: this.localize.term('speechBubbles_cannotCopyInformation'),
Expand Down

0 comments on commit 198e2aa

Please sign in to comment.