Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: System information should be visible to anyone #2430

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading