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

[SM-1302] Initial config page #10196

Merged
merged 26 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ae81dbe
Initial config page
differsthecat Jul 19, 2024
277a6c4
Remove project actions
differsthecat Jul 22, 2024
0a1d218
Merge branch 'main' into sm-1302-config-page
differsthecat Jul 22, 2024
caa707f
Add copy projectId method to the project page
differsthecat Jul 22, 2024
b79e7c0
Update bitwarden_license/bit-web/src/app/secrets-manager/service-accoโ€ฆ
differsthecat Jul 24, 2024
8c9aa9a
Update bitwarden_license/bit-web/src/app/secrets-manager/shared/projeโ€ฆ
differsthecat Jul 24, 2024
7c72446
Update apps/web/src/locales/en/messages.json
differsthecat Jul 24, 2024
fc5cee6
Fix method and string naming
differsthecat Jul 24, 2024
a05dd4c
Ensure config component load logic happens after params observed
differsthecat Jul 24, 2024
044e4c6
Remove projectId emitted event
differsthecat Jul 24, 2024
2fe1820
Merge branch 'main' into sm-1302-config-page
differsthecat Jul 24, 2024
ffd9894
Update bitwarden_license/bit-web/src/app/secrets-manager/service-accoโ€ฆ
differsthecat Jul 29, 2024
4ed319e
Adjust load function
differsthecat Jul 29, 2024
c5500f0
Fix config translation
differsthecat Jul 29, 2024
b952c92
Remove unnecceary async from copy functions
differsthecat Jul 29, 2024
c144d80
Add project ID translation key
differsthecat Jul 29, 2024
2d24f16
Update bitwarden_license/bit-web/src/app/secrets-manager/service-accoโ€ฆ
differsthecat Jul 30, 2024
21e333c
Simplify load function
differsthecat Jul 30, 2024
5250093
Simplify variable definition
differsthecat Jul 30, 2024
18445fa
Merge branch 'main' into sm-1302-config-page
differsthecat Jul 30, 2024
c2c0317
Merge branch 'main' into sm-1302-config-page
differsthecat Sep 16, 2024
2ddba08
Add all machine account projects to the config page
differsthecat Sep 16, 2024
655f77d
Update bitwarden_license/bit-web/src/app/secrets-manager/service-accoโ€ฆ
differsthecat Sep 17, 2024
63a024b
Remove unused variable
differsthecat Sep 19, 2024
8f24b8c
Remove revision date in config project list
differsthecat Sep 19, 2024
f05e632
Merge branch 'main' into sm-1302-config-page
differsthecat Sep 20, 2024
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
18 changes: 18 additions & 0 deletions apps/web/src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -9002,6 +9002,24 @@
"purchasedSeatsRemoved": {
"message": "purchased seats removed"
},
"environmentVariables": {
"message": "Environment variables"
},
"organizationId": {
"message": "Organization ID"
},
"projectIds": {
"message": "Project IDs"
},
"projectId": {
"message": "Project ID"
},
"projectsAccessedByMachineAccount": {
"message": "The following projects can be accessed by this machine account."
},
"config": {
"message": "Config"
},
"learnMoreAboutEmergencyAccess": {
"message":"Learn more about emergency access"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export class ProjectListView {
revisionDate: string;
read: boolean;
write: boolean;
linkable: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
);
projectListView.creationDate = s.creationDate;
projectListView.revisionDate = s.revisionDate;
projectListView.linkable = true;

Check warning on line 134 in bitwarden_license/bit-web/src/app/secrets-manager/projects/project.service.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/projects/project.service.ts#L134

Added line #L134 was not covered by tests
return projectListView;
}),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<div *ngIf="!loading">
<div class="tw-p-6 tw-border tw-border-solid tw-border-secondary-600 tw-rounded">
<h2 bitTypography="h2">{{ "environmentVariables" | i18n }}</h2>
<div class="tw-flex tw-gap-6 tw-pt-4">
<bit-form-field class="tw-w-2/5 tw-min-w-80" tw>
<bit-label>{{ "identityUrl" | i18n }}</bit-label>
<input bitInput type="text" [(ngModel)]="identityUrl" [disabled]="true" />
Thomas-Avery marked this conversation as resolved.
Show resolved Hide resolved
<button
bitSuffix
type="button"
type="button"
bitIconButton="bwi-clone"
[bitAction]="copyIdentityUrl"
></button>
</bit-form-field>
<bit-form-field class="tw-w-2/5 tw-min-w-80">
<bit-label>{{ "apiUrl" | i18n }}</bit-label>
<input bitInput type="text" [(ngModel)]="apiUrl" [disabled]="true" />
<button bitSuffix type="button" bitIconButton="bwi-clone" [bitAction]="copyApiUrl"></button>
</bit-form-field>
</div>
<bit-form-field class="tw-w-2/5 tw-min-w-80">
<bit-label>{{ "organizationId" | i18n }}</bit-label>
<input bitInput type="text" [(ngModel)]="organizationId" [disabled]="true" />
<button
bitSuffix
type="button"
bitIconButton="bwi-clone"
[bitAction]="copyOrganizationId"
></button>
</bit-form-field>
</div>
<div class="tw-pt-12">
<h2 slot="summary" class="tw-mb-0" bitTypography="h2" noMargin>{{ "projectIds" | i18n }}</h2>
<p *ngIf="!hasProjects" class="tw-mt-6">{{ "projectsNoItemsTitle" | i18n }}</p>
<p *ngIf="hasProjects" class="tw-mt-4">{{ "projectsAccessedByMachineAccount" | i18n }}</p>
<sm-projects-list
class="tw-mt-8"
*ngIf="hasProjects"
[showMenus]="false"
[projects]="projects"
></sm-projects-list>
</div>
</div>
<div *ngIf="loading" class="tw-items-center tw-justify-center tw-pt-64 tw-text-center">
<i class="bwi bwi-spinner bwi-spin bwi-3x"></i>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { Component, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute, Params } from "@angular/router";
import { Subject, concatMap, takeUntil } from "rxjs";

Check warning on line 3 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ToastService } from "@bitwarden/components";

Check warning on line 8 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L5-L8

Added lines #L5 - L8 were not covered by tests

import { ProjectListView } from "../../models/view/project-list.view";
import { ProjectService } from "../../projects/project.service";
import { AccessPolicyService } from "../../shared/access-policies/access-policy.service";

Check warning on line 12 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L11-L12

Added lines #L11 - L12 were not covered by tests

class ServiceAccountConfig {
organizationId: string;
serviceAccountId: string;
identityUrl: string;
apiUrl: string;
projects: ProjectListView[];
}

@Component({
selector: "sm-service-account-config",
templateUrl: "./config.component.html",
})
export class ServiceAccountConfigComponent implements OnInit, OnDestroy {

Check warning on line 26 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L26

Added line #L26 was not covered by tests
identityUrl: string;
apiUrl: string;
organizationId: string;
serviceAccountId: string;
projects: ProjectListView[];
hasProjects = false;

Check warning on line 32 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L32

Added line #L32 was not covered by tests

private destroy$ = new Subject<void>();
loading = true;

Check warning on line 35 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L34-L35

Added lines #L34 - L35 were not covered by tests

constructor(
private environmentService: EnvironmentService,
private route: ActivatedRoute,
private platformUtilsService: PlatformUtilsService,
private toastService: ToastService,
private i18nService: I18nService,
private projectService: ProjectService,
private accessPolicyService: AccessPolicyService,

Check warning on line 44 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L44

Added line #L44 was not covered by tests
) {}

async ngOnInit() {
this.route.params

Check warning on line 48 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L48

Added line #L48 was not covered by tests
.pipe(
concatMap(async (params: Params) => {
return await this.load(params.organizationId, params.serviceAccountId);

Check warning on line 51 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L50-L51

Added lines #L50 - L51 were not covered by tests
}),
takeUntil(this.destroy$),
)
.subscribe((smConfig) => {
this.identityUrl = smConfig.identityUrl;
this.apiUrl = smConfig.apiUrl;
this.organizationId = smConfig.organizationId;
this.serviceAccountId = smConfig.serviceAccountId;
this.projects = smConfig.projects;

Check warning on line 60 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L56-L60

Added lines #L56 - L60 were not covered by tests

this.hasProjects = smConfig.projects.length > 0;
this.loading = false;

Check warning on line 63 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L62-L63

Added lines #L62 - L63 were not covered by tests
});
}

async load(organizationId: string, serviceAccountId: string): Promise<ServiceAccountConfig> {
const environment = await this.environmentService.getEnvironment();

Check warning on line 68 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L68

Added line #L68 was not covered by tests

const allProjects = await this.projectService.getProjects(organizationId);
const policies = await this.accessPolicyService.getServiceAccountGrantedPolicies(

Check warning on line 71 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L70-L71

Added lines #L70 - L71 were not covered by tests
organizationId,
serviceAccountId,
);

const projects = policies.grantedProjectPolicies.map((policy) => {
return {

Check warning on line 77 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L76-L77

Added lines #L76 - L77 were not covered by tests
id: policy.accessPolicy.grantedProjectId,
name: policy.accessPolicy.grantedProjectName,
organizationId: organizationId,
linkable: allProjects.some(
(project) => project.id === policy.accessPolicy.grantedProjectId,

Check warning on line 82 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L82

Added line #L82 was not covered by tests
),
} as ProjectListView;
});

return {

Check warning on line 87 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L87

Added line #L87 was not covered by tests
organizationId: organizationId,
serviceAccountId: serviceAccountId,
identityUrl: environment.getIdentityUrl(),
apiUrl: environment.getApiUrl(),
projects: projects,
} as ServiceAccountConfig;
}

copyIdentityUrl = () => {
this.platformUtilsService.copyToClipboard(this.identityUrl);
this.toastService.showToast({

Check warning on line 98 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L96-L98

Added lines #L96 - L98 were not covered by tests
variant: "success",
title: null,
message: this.i18nService.t("valueCopied", this.i18nService.t("identityUrl")),
});
};

copyApiUrl = () => {
this.platformUtilsService.copyToClipboard(this.apiUrl);
this.toastService.showToast({

Check warning on line 107 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L105-L107

Added lines #L105 - L107 were not covered by tests
variant: "success",
title: null,
message: this.i18nService.t("valueCopied", this.i18nService.t("apiUrl")),
});
};

copyOrganizationId = () => {
this.platformUtilsService.copyToClipboard(this.organizationId);
this.toastService.showToast({

Check warning on line 116 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L114-L116

Added lines #L114 - L116 were not covered by tests
variant: "success",
title: null,
message: this.i18nService.t("valueCopied", this.i18nService.t("organizationId")),
});
};

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();

Check warning on line 125 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/config/config.component.ts#L124-L125

Added lines #L124 - L125 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</div>
</bit-tab-link>
<bit-tab-link [route]="['events']">{{ "eventLogs" | i18n }}</bit-tab-link>
<bit-tab-link [route]="['config']">{{ "config" | i18n }}</bit-tab-link>
</bit-tab-nav-bar>
<button
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { RouterModule, Routes } from "@angular/router";

import { AccessTokenComponent } from "./access/access-tokens.component";
import { ServiceAccountConfigComponent } from "./config/config.component";

Check warning on line 5 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-accounts-routing.module.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-accounts-routing.module.ts#L5

Added line #L5 was not covered by tests
import { ServiceAccountEventsComponent } from "./event-logs/service-accounts-events.component";
import { serviceAccountAccessGuard } from "./guards/service-account-access.guard";
import { ServiceAccountPeopleComponent } from "./people/service-account-people.component";
Expand Down Expand Up @@ -40,6 +41,10 @@
path: "events",
component: ServiceAccountEventsComponent,
},
{
path: "config",
component: ServiceAccountConfigComponent,
},
],
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { AccessTokenCreateDialogComponent } from "./access/dialogs/access-token-create-dialog.component";
import { AccessTokenDialogComponent } from "./access/dialogs/access-token-dialog.component";
import { ExpirationOptionsComponent } from "./access/dialogs/expiration-options.component";
import { ServiceAccountConfigComponent } from "./config/config.component";

Check warning on line 12 in bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-accounts.module.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/service-accounts.module.ts#L12

Added line #L12 was not covered by tests
import { ServiceAccountDeleteDialogComponent } from "./dialog/service-account-delete-dialog.component";
import { ServiceAccountDialogComponent } from "./dialog/service-account-dialog.component";
import { ServiceAccountEventsComponent } from "./event-logs/service-accounts-events.component";
Expand All @@ -28,6 +29,7 @@
AccessTokenDialogComponent,
ExpirationOptionsComponent,
ServiceAccountComponent,
ServiceAccountConfigComponent,
ServiceAccountDeleteDialogComponent,
ServiceAccountDialogComponent,
ServiceAccountEventsComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<bit-table *ngIf="projects?.length >= 1" [dataSource]="dataSource">
<ng-container header>
<tr>
<th bitCell class="tw-w-0">
<th bitCell class="tw-w-0" *ngIf="showMenus">
<label class="!tw-mb-0 tw-flex tw-w-fit tw-gap-2 !tw-font-bold !tw-text-muted">
<input
type="checkbox"
Expand All @@ -32,7 +32,7 @@
</label>
</th>
<th bitCell bitSortable="name" default>{{ "name" | i18n }}</th>
<th bitCell bitSortable="revisionDate">{{ "lastEdited" | i18n }}</th>
<th bitCell bitSortable="revisionDate" *ngIf="showMenus">{{ "lastEdited" | i18n }}</th>
<th
bitCell
class="tw-w-0"
Expand All @@ -45,13 +45,14 @@
[bitMenuTriggerFor]="tableMenu"
[title]="'options' | i18n"
[attr.aria-label]="'options' | i18n"
*ngIf="showMenus"
></button>
</th>
</tr>
</ng-container>
<ng-template body let-rows$>
<tr bitRow *ngFor="let project of rows$ | async">
<td bitCell>
<td bitCell *ngIf="showMenus">
<input
type="checkbox"
(change)="$event ? selection.toggle(project.id) : null"
Expand All @@ -61,12 +62,32 @@
<td bitCell>
<div class="tw-flex tw-items-center tw-gap-4 tw-break-all">
<i class="bwi bwi-collection tw-text-muted" aria-hidden="true"></i>
<a bitLink [routerLink]="['/sm', project.organizationId, 'projects', project.id]">{{
project.name
}}</a>
<div>
<a
*ngIf="project.linkable"
bitLink
[routerLink]="['/sm', project.organizationId, 'projects', project.id]"
>{{ project.name }}</a
>
<span *ngIf="!project.linkable">{{ project.name }}</span>
<div class="tw-text-sm tw-text-muted tw-block">
{{ project.id }}
<button
type="button"
bitIconButton="bwi-clone"
buttonType="main"
size="small"
[title]="'copyUuid' | i18n"
[attr.aria-label]="'copyUuid' | i18n"
(click)="copyProjectUuidToClipboard(project.id)"
></button>
</div>
</div>
</div>
</td>
<td bitCell class="tw-whitespace-nowrap">{{ project.revisionDate | date: "medium" }}</td>
<td bitCell class="tw-whitespace-nowrap" *ngIf="showMenus">
{{ project.revisionDate | date: "medium" }}
</td>
<td bitCell>
<button
type="button"
Expand All @@ -75,6 +96,7 @@
[bitMenuTriggerFor]="projectMenu"
[title]="'options' | i18n"
[attr.aria-label]="'options' | i18n"
*ngIf="showMenus"
></button>
</td>
<bit-menu #projectMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
}
private _projects: ProjectListView[];

@Input() showMenus?: boolean = true;

Check warning on line 27 in bitwarden_license/bit-web/src/app/secrets-manager/shared/projects-list.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/shared/projects-list.component.ts#L27

Added line #L27 was not covered by tests

@Input()
set search(search: string) {
this.selection.clear();
Expand All @@ -33,6 +35,7 @@
@Output() editProjectEvent = new EventEmitter<string>();
@Output() deleteProjectEvent = new EventEmitter<ProjectListView[]>();
@Output() newProjectEvent = new EventEmitter();
@Output() copiedProjectUUIdEvent = new EventEmitter<string>();

Check warning on line 38 in bitwarden_license/bit-web/src/app/secrets-manager/shared/projects-list.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/shared/projects-list.component.ts#L38

Added line #L38 was not covered by tests

selection = new SelectionModel<string>(true, []);
protected dataSource = new TableDataSource<ProjectListView>();
Expand Down Expand Up @@ -90,4 +93,13 @@
}
return false;
}

copyProjectUuidToClipboard(id: string) {
this.platformUtilsService.copyToClipboard(id);
this.platformUtilsService.showToast(

Check warning on line 99 in bitwarden_license/bit-web/src/app/secrets-manager/shared/projects-list.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/shared/projects-list.component.ts#L98-L99

Added lines #L98 - L99 were not covered by tests
"success",
null,
this.i18nService.t("valueCopied", this.i18nService.t("projectId")),
);
}
}
Loading
Loading