Skip to content

Commit

Permalink
Merge branch 'main' into PM-9022-scaffold-the-extension-and-build-pip…
Browse files Browse the repository at this point in the history
…eline
  • Loading branch information
coroiu committed Nov 13, 2024
2 parents 15aa3d9 + c496792 commit 22e790e
Show file tree
Hide file tree
Showing 35 changed files with 429 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[placeholder]="'search' | i18n"
[(ngModel)]="searchText"
(ngModelChange)="onSearchTextChanged()"
appAutofocus
>
</bit-search>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
</div>

<!-- Show search & filters outside of the scroll area of the page -->
<div slot="above-scroll-area" class="tw-p-4" *ngIf="vaultState !== VaultStateEnum.Empty">
<div
slot="above-scroll-area"
class="tw-p-4"
*ngIf="vaultState !== VaultStateEnum.Empty && !(loading$ | async)"
>
<app-vault-v2-search> </app-vault-v2-search>
<app-vault-list-filters></app-vault-list-filters>
</div>
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/desktop_native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/desktop/desktop_native/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bitwarden-russh = { git = "https://github.com/bitwarden/bitwarden-russh.git", br
tokio = { version = "=1.40.0", features = ["io-util", "sync", "macros", "net"] }
tokio-stream = { version = "=0.1.15", features = ["net"] }
tokio-util = "=0.7.12"
thiserror = "=1.0.68"
thiserror = "=1.0.69"
typenum = "=1.17.0"
rand_chacha = "=0.3.1"
pkcs8 = { version = "=0.10.2", features = ["alloc", "encryption", "pem"] }
Expand Down
10 changes: 5 additions & 5 deletions apps/desktop/native-messaging-test-runner/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/desktop/native-messaging-test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"yargs": "17.7.2"
},
"devDependencies": {
"@types/node": "20.17.1",
"@types/node": "22.9.0",
"@types/node-ipc": "9.2.3",
"typescript": "4.7.4"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/vault/app/vault/vault.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class VaultComponent implements OnInit, OnDestroy {
return;
}

this.addType = type;
this.addType = type || this.activeFilter.cipherType;
this.action = "add";
this.cipherId = null;
this.prefillNewCipherFromFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import { ListResponse } from "@bitwarden/common/models/response/list.response";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

import { CoreOrganizationModule } from "../../core-organization.module";
import { GroupDetailsView } from "../../views/group-details.view";
import { GroupView } from "../../views/group.view";

import { AddEditGroupDetail } from "./../../views/add-edit-group-detail";
import { GroupRequest } from "./requests/group.request";
import { OrganizationGroupBulkRequest } from "./requests/organization-group-bulk.request";
import { GroupDetailsResponse, GroupResponse } from "./responses/group.response";

@Injectable({
providedIn: "root",
})
export class GroupService {
export class GroupApiService {
constructor(
protected apiService: ApiService,
protected configService: ConfigService,
) {}

async get(orgId: string, groupId: string): Promise<GroupView> {
async get(orgId: string, groupId: string): Promise<GroupDetailsView> {
const r = await this.apiService.send(
"GET",
"/organizations/" + orgId + "/groups/" + groupId + "/details",
Expand All @@ -30,7 +32,7 @@ export class GroupService {
true,
);

return GroupView.fromResponse(new GroupDetailsResponse(r));
return GroupDetailsView.fromResponse(new GroupDetailsResponse(r));
}

async getAll(orgId: string): Promise<GroupView[]> {
Expand All @@ -44,12 +46,26 @@ export class GroupService {

const listResponse = new ListResponse(r, GroupDetailsResponse);

return Promise.all(listResponse.data?.map((gr) => GroupView.fromResponse(gr))) ?? [];
return listResponse.data.map((gr) => GroupView.fromResponse(gr));
}

async getAllDetails(orgId: string): Promise<GroupDetailsView[]> {
const r = await this.apiService.send(
"GET",
"/organizations/" + orgId + "/groups/details",
null,
true,
true,
);

const listResponse = new ListResponse(r, GroupDetailsResponse);

return listResponse.data.map((gr) => GroupDetailsView.fromResponse(gr));
}
}

@Injectable({ providedIn: CoreOrganizationModule })
export class InternalGroupService extends GroupService {
export class InternalGroupApiService extends GroupApiService {
constructor(
protected apiService: ApiService,
protected configService: ConfigService,
Expand Down Expand Up @@ -77,7 +93,7 @@ export class InternalGroupService extends GroupService {
);
}

async save(group: GroupView): Promise<GroupView> {
async save(group: AddEditGroupDetail): Promise<GroupView> {
const request = new GroupRequest();
request.name = group.name;
request.users = group.members;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./group/group.service";
export * from "./group/group-api.service";
export * from "./user-admin.service";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CollectionAccessSelectionView } from "@bitwarden/admin-console/common";

export interface AddEditGroupDetail {
id: string;
organizationId: string;
name: string;
externalId: string;
collections: CollectionAccessSelectionView[];
members: string[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CollectionAccessSelectionView } from "@bitwarden/admin-console/common";
import { View } from "@bitwarden/common/models/view/view";

import { GroupDetailsResponse } from "../services/group/responses/group.response";

export class GroupDetailsView implements View {
id: string;
organizationId: string;
name: string;
externalId: string;
collections: CollectionAccessSelectionView[] = [];

static fromResponse(response: GroupDetailsResponse): GroupDetailsView {
const view: GroupDetailsView = Object.assign(new GroupDetailsView(), response);

view.collections = response.collections.map((c) => new CollectionAccessSelectionView(c));

return view;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import { CollectionAccessSelectionView } from "@bitwarden/admin-console/common";
import { View } from "@bitwarden/common/models/view/view";

import { GroupDetailsResponse, GroupResponse } from "../services/group/responses/group.response";
import { GroupResponse } from "../services/group/responses/group.response";

export class GroupView implements View {
id: string;
organizationId: string;
name: string;
externalId: string;
collections: CollectionAccessSelectionView[] = [];
members: string[] = [];

static fromResponse(response: GroupResponse): GroupView {
const view: GroupView = Object.assign(new GroupView(), response) as GroupView;

if (response instanceof GroupDetailsResponse && response.collections != undefined) {
view.collections = response.collections.map((c) => new CollectionAccessSelectionView(c));
}

return view;
return Object.assign(new GroupView(), response);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./group.view";
export * from "./group-details.view";
export * from "./organization-user.view";
export * from "./organization-user-admin-view";
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { UserId } from "@bitwarden/common/types/guid";
import { DialogService, ToastService } from "@bitwarden/components";

import { InternalGroupService as GroupService, GroupView } from "../core";
import { InternalGroupApiService as GroupService } from "../core";
import {
AccessItemType,
AccessItemValue,
Expand All @@ -40,6 +40,8 @@ import {
PermissionMode,
} from "../shared/components/access-selector";

import { AddEditGroupDetail } from "./../core/views/add-edit-group-detail";

/**
* Indices for the available tabs in the dialog
*/
Expand Down Expand Up @@ -105,7 +107,7 @@ export class GroupAddEditComponent implements OnInit, OnDestroy {
title: string;
collections: AccessItemView[] = [];
members: Array<AccessItemView & { userId: UserId }> = [];
group: GroupView;
group: AddEditGroupDetail;

groupForm = this.formBuilder.group({
name: ["", [Validators.required, Validators.maxLength(100)]],
Expand Down Expand Up @@ -149,7 +151,7 @@ export class GroupAddEditComponent implements OnInit, OnDestroy {
);
}

private groupDetails$: Observable<GroupView | undefined> = of(this.editMode).pipe(
private groupDetails$: Observable<AddEditGroupDetail | undefined> = of(this.editMode).pipe(
concatMap((editMode) => {
if (!editMode) {
return of(undefined);
Expand All @@ -159,9 +161,11 @@ export class GroupAddEditComponent implements OnInit, OnDestroy {
this.groupService.get(this.organizationId, this.groupId),
this.apiService.getGroupUsers(this.organizationId, this.groupId),
]).pipe(
map(([groupView, users]) => {
groupView.members = users;
return groupView;
map(([groupView, users]): AddEditGroupDetail => {
return {
...groupView,
members: users,
};
}),
catchError((e: unknown) => {
if (e instanceof ErrorResponse) {
Expand Down Expand Up @@ -295,14 +299,16 @@ export class GroupAddEditComponent implements OnInit, OnDestroy {
return;
}

const groupView = new GroupView();
groupView.id = this.groupId;
groupView.organizationId = this.organizationId;

const formValue = this.groupForm.value;
groupView.name = formValue.name;
groupView.members = formValue.members?.map((m) => m.id) ?? [];
groupView.collections = formValue.collections.map((c) => convertToSelectionView(c));

const groupView: AddEditGroupDetail = {
id: this.groupId,
organizationId: this.organizationId,
name: formValue.name,
members: formValue.members?.map((m) => m.id) ?? [],
collections: formValue.collections.map((c) => convertToSelectionView(c)),
externalId: formValue.externalId,
};

await this.groupService.save(groupView);

Expand Down Expand Up @@ -346,7 +352,10 @@ export class GroupAddEditComponent implements OnInit, OnDestroy {
/**
* Maps the group's current collection access to AccessItemValues to populate the access-selector's FormControl
*/
function mapToAccessSelections(group: GroupView, items: AccessItemView[]): AccessItemValue[] {
function mapToAccessSelections(
group: AddEditGroupDetail,
items: AccessItemView[],
): AccessItemValue[] {
return (
group.collections
// The FormControl value only represents editable collection access - exclude readonly access selections
Expand All @@ -365,7 +374,7 @@ function mapToAccessSelections(group: GroupView, items: AccessItemView[]): Acces
function mapToAccessItemViews(
collections: CollectionAdminView[],
organization: Organization,
group?: GroupView,
group?: AddEditGroupDetail,
): AccessItemView[] {
return (
collections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { DialogService, TableDataSource, ToastService } from "@bitwarden/components";

import { InternalGroupService as GroupService, GroupView } from "../core";
import { GroupDetailsView, InternalGroupApiService as GroupService } from "../core";

import {
GroupAddEditDialogResultType,
Expand All @@ -40,7 +40,7 @@ type GroupDetailsRow = {
/**
* Details used for displaying group information
*/
details: GroupView;
details: GroupDetailsView;

/**
* True if the group is selected in the table
Expand Down Expand Up @@ -108,7 +108,7 @@ export class GroupsComponent {
),
// groups
this.refreshGroups$.pipe(
switchMap(() => this.groupService.getAll(this.organizationId)),
switchMap(() => this.groupService.getAllDetails(this.organizationId)),
),
]),
),
Expand Down
Loading

0 comments on commit 22e790e

Please sign in to comment.