mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
Refactor GroupService into Core org module (#4112)
* Refactor GroupService into Core org module - Move Group service folder into Core org folder - Remove GroupServiceAbstraction - Rename GroupService in components - Remove GroupService from list of Org Module providers (use @Injectable decorator instead) * Import/export SharedModule from SharedOrganizationModule * Move GroupView to core organization folder * Fix file names for org collection views * Cleanup core organization barrel files
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
export * from "./core-organization.module";
|
||||
export * from "./services/collection-admin.service";
|
||||
export * from "./views/collection-access-selection-view";
|
||||
export * from "./views/collection-admin-view";
|
||||
export * from "./services";
|
||||
export * from "./views";
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { CollectionView } from "@bitwarden/common/models/view/collection.view";
|
||||
|
||||
import { CoreOrganizationModule } from "../core-organization.module";
|
||||
import { CollectionAdminView } from "../views/collection-admin-view";
|
||||
import { CollectionAdminView } from "../views/collection-admin.view";
|
||||
|
||||
@Injectable({ providedIn: CoreOrganizationModule })
|
||||
export class CollectionAdminService {
|
||||
|
||||
@@ -4,14 +4,15 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { SelectionReadOnlyRequest } from "@bitwarden/common/models/request/selection-read-only.request";
|
||||
import { ListResponse } from "@bitwarden/common/models/response/list.response";
|
||||
|
||||
import { CoreOrganizationModule } from "../../core-organization.module";
|
||||
import { GroupView } from "../../views/group.view";
|
||||
import { GroupRequest, GroupServiceAbstraction } from "../abstractions/group";
|
||||
|
||||
import { GroupRequest } from "./requests/group.request";
|
||||
import { OrganizationGroupBulkRequest } from "./requests/organization-group-bulk.request";
|
||||
import { GroupDetailsResponse, GroupResponse } from "./responses/group.response";
|
||||
|
||||
@Injectable()
|
||||
export class GroupService implements GroupServiceAbstraction {
|
||||
@Injectable({ providedIn: CoreOrganizationModule })
|
||||
export class GroupService {
|
||||
constructor(private apiService: ApiService) {}
|
||||
|
||||
async delete(orgId: string, groupId: string): Promise<void> {
|
||||
2
apps/web/src/app/organizations/core/services/index.ts
Normal file
2
apps/web/src/app/organizations/core/services/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./group/group.service";
|
||||
export * from "./collection-admin.service";
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CollectionView } from "@bitwarden/common/models/view/collection.view";
|
||||
import { CollectionAccessDetailsResponse } from "@bitwarden/common/src/models/response/collection.response";
|
||||
|
||||
import { CollectionAccessSelectionView } from "./collection-access-selection-view";
|
||||
import { CollectionAccessSelectionView } from "./collection-access-selection.view";
|
||||
|
||||
export class CollectionAdminView extends CollectionView {
|
||||
groups: CollectionAccessSelectionView[] = [];
|
||||
@@ -1,7 +1,8 @@
|
||||
import { View } from "@bitwarden/common/models/view/view";
|
||||
|
||||
import { GroupDetailsResponse, GroupResponse } from "../services/group/responses/group.response";
|
||||
import { CollectionAccessSelectionView } from "../views/collection-access-selection.view";
|
||||
|
||||
import { CollectionAccessSelectionView } from "./collection-access-selection.view";
|
||||
|
||||
export class GroupView implements View {
|
||||
id: string;
|
||||
3
apps/web/src/app/organizations/core/views/index.ts
Normal file
3
apps/web/src/app/organizations/core/views/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./collection-access-selection.view";
|
||||
export * from "./collection-admin.view";
|
||||
export * from "./group.view";
|
||||
@@ -14,7 +14,7 @@ import { CollectionDetailsResponse } from "@bitwarden/common/models/response/col
|
||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||
import { DialogService } from "@bitwarden/components";
|
||||
|
||||
import { GroupServiceAbstraction } from "../services/abstractions/group";
|
||||
import { GroupService, GroupView } from "../core";
|
||||
import {
|
||||
AccessItemType,
|
||||
AccessItemValue,
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
convertToSelectionView,
|
||||
PermissionMode,
|
||||
} from "../shared/components/access-selector";
|
||||
import { GroupView } from "../views/group.view";
|
||||
|
||||
/**
|
||||
* Indices for the available tabs in the dialog
|
||||
@@ -173,7 +172,7 @@ export class GroupAddEditComponent implements OnInit, OnDestroy {
|
||||
@Inject(DIALOG_DATA) private params: GroupAddEditDialogParams,
|
||||
private dialogRef: DialogRef<GroupAddEditDialogResultType>,
|
||||
private apiService: ApiService,
|
||||
private groupService: GroupServiceAbstraction,
|
||||
private groupService: GroupService,
|
||||
private i18nService: I18nService,
|
||||
private collectionService: CollectionService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
|
||||
@@ -33,8 +33,7 @@ import { ListResponse } from "@bitwarden/common/models/response/list.response";
|
||||
import { CollectionView } from "@bitwarden/common/models/view/collection.view";
|
||||
import { DialogService } from "@bitwarden/components";
|
||||
|
||||
import { GroupServiceAbstraction } from "../services/abstractions/group";
|
||||
import { GroupView } from "../views/group.view";
|
||||
import { GroupService, GroupView } from "../core";
|
||||
|
||||
import {
|
||||
GroupAddEditDialogResultType,
|
||||
@@ -124,7 +123,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private groupApiService: GroupServiceAbstraction,
|
||||
private groupService: GroupService,
|
||||
private route: ActivatedRoute,
|
||||
private i18nService: I18nService,
|
||||
private modalService: ModalService,
|
||||
@@ -148,7 +147,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||
),
|
||||
// groups
|
||||
this.refreshGroups$.pipe(
|
||||
switchMap(() => this.groupApiService.getAll(this.organizationId))
|
||||
switchMap(() => this.groupService.getAll(this.organizationId))
|
||||
),
|
||||
])
|
||||
),
|
||||
@@ -246,7 +245,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
try {
|
||||
await this.groupApiService.delete(this.organizationId, groupRow.details.id);
|
||||
await this.groupService.delete(this.organizationId, groupRow.details.id);
|
||||
this.platformUtilsService.showToast(
|
||||
"success",
|
||||
null,
|
||||
@@ -278,7 +277,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.groupApiService.deleteMany(
|
||||
const result = await this.groupService.deleteMany(
|
||||
this.organizationId,
|
||||
groupsToDelete.map((g) => g.details.id)
|
||||
);
|
||||
|
||||
@@ -7,8 +7,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti
|
||||
import { Utils } from "@bitwarden/common/misc/utils";
|
||||
import { OrganizationUserUpdateGroupsRequest } from "@bitwarden/common/models/request/organization-user-update-groups.request";
|
||||
|
||||
import { GroupServiceAbstraction } from "../services/abstractions/group";
|
||||
import { GroupView } from "../views/group.view";
|
||||
import { GroupService, GroupView } from "../core";
|
||||
|
||||
@Component({
|
||||
selector: "app-user-groups",
|
||||
@@ -26,7 +25,7 @@ export class UserGroupsComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private groupApiService: GroupServiceAbstraction,
|
||||
private groupApiService: GroupService,
|
||||
private i18nService: I18nService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private logService: LogService
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
import { NgModule } from "@angular/core";
|
||||
|
||||
import { ApiService as ApiServiceAbstraction } from "@bitwarden/common/abstractions/api.service";
|
||||
|
||||
import { CoreOrganizationModule } from "./core";
|
||||
import { GroupAddEditComponent } from "./manage/group-add-edit.component";
|
||||
import { GroupsComponent } from "./manage/groups.component";
|
||||
import { UserGroupsComponent } from "./manage/user-groups.component";
|
||||
import { OrganizationsRoutingModule } from "./organization-routing.module";
|
||||
import { GroupServiceAbstraction } from "./services/abstractions/group";
|
||||
import { GroupService } from "./services/group/group.service";
|
||||
import { SharedOrganizationModule } from "./shared";
|
||||
|
||||
@NgModule({
|
||||
imports: [OrganizationsRoutingModule, SharedOrganizationModule, CoreOrganizationModule],
|
||||
imports: [SharedOrganizationModule, CoreOrganizationModule, OrganizationsRoutingModule],
|
||||
declarations: [GroupsComponent, GroupAddEditComponent, UserGroupsComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: GroupServiceAbstraction,
|
||||
useClass: GroupService,
|
||||
deps: [ApiServiceAbstraction],
|
||||
},
|
||||
],
|
||||
})
|
||||
export class OrganizationModule {}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { GroupView } from "../../../views/group.view";
|
||||
|
||||
export class GroupServiceAbstraction {
|
||||
delete: (orgId: string, groupId: string) => Promise<void>;
|
||||
deleteMany: (orgId: string, groupIds: string[]) => Promise<GroupView[]>;
|
||||
|
||||
get: (orgId: string, groupId: string) => Promise<GroupView>;
|
||||
getAll: (orgId: string) => Promise<GroupView[]>;
|
||||
|
||||
save: (group: GroupView) => Promise<GroupView>;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./group.service.abstraction";
|
||||
export * from "./requests/group.request";
|
||||
@@ -12,9 +12,12 @@ import { OrganizationUserUserDetailsResponse } from "@bitwarden/common/src/model
|
||||
import { CollectionView } from "@bitwarden/common/src/models/view/collection.view";
|
||||
import { BitValidators, DialogService } from "@bitwarden/components";
|
||||
|
||||
import { CollectionAdminService, CollectionAdminView } from "../../../core";
|
||||
import { GroupServiceAbstraction } from "../../../services/abstractions/group";
|
||||
import { GroupView } from "../../../views/group.view";
|
||||
import {
|
||||
CollectionAdminService,
|
||||
CollectionAdminView,
|
||||
GroupService,
|
||||
GroupView,
|
||||
} from "../../../core";
|
||||
import {
|
||||
AccessItemType,
|
||||
AccessItemValue,
|
||||
@@ -62,7 +65,7 @@ export class CollectionDialogComponent implements OnInit, OnDestroy {
|
||||
private dialogRef: DialogRef<CollectionDialogResult>,
|
||||
private apiService: ApiService,
|
||||
private organizationService: OrganizationService,
|
||||
private groupService: GroupServiceAbstraction,
|
||||
private groupService: GroupService,
|
||||
private collectionService: CollectionAdminService,
|
||||
private i18nService: I18nService,
|
||||
private platformUtilsService: PlatformUtilsService
|
||||
|
||||
@@ -18,9 +18,9 @@ import {
|
||||
CollectionAccessSelectionView,
|
||||
CollectionAdminService,
|
||||
CollectionAdminView,
|
||||
GroupService,
|
||||
GroupView,
|
||||
} from "../../../core";
|
||||
import { GroupServiceAbstraction } from "../../../services/abstractions/group/group.service.abstraction";
|
||||
import { GroupView } from "../../../views/group.view";
|
||||
import { AccessSelectorModule } from "../access-selector";
|
||||
|
||||
import { CollectionDialogComponent, CollectionDialogParams } from "./collection-dialog.component";
|
||||
@@ -96,8 +96,8 @@ function providers(data: ProviderData) {
|
||||
} as Partial<OrganizationService>,
|
||||
},
|
||||
{
|
||||
provide: GroupServiceAbstraction,
|
||||
useValue: { getAll: () => Promise.resolve(data.groups) } as Partial<GroupServiceAbstraction>,
|
||||
provide: GroupService,
|
||||
useValue: { getAll: () => Promise.resolve(data.groups) } as Partial<GroupService>,
|
||||
},
|
||||
{
|
||||
provide: ApiService,
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import { View } from "@bitwarden/common/models/view/view";
|
||||
|
||||
interface SelectionResponseLike {
|
||||
id: string;
|
||||
readOnly: boolean;
|
||||
hidePasswords: boolean;
|
||||
}
|
||||
|
||||
export class CollectionAccessSelectionView extends View {
|
||||
id: string;
|
||||
readOnly: boolean;
|
||||
hidePasswords: boolean;
|
||||
|
||||
constructor(source?: SelectionResponseLike) {
|
||||
super();
|
||||
|
||||
if (source == undefined) {
|
||||
return;
|
||||
}
|
||||
this.id = source.id;
|
||||
this.readOnly = source.readOnly;
|
||||
this.hidePasswords = source.hidePasswords;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user