mirror of
https://github.com/bitwarden/browser
synced 2026-02-27 01:53:23 +00:00
[EC-86] Refactor/rename GroupApiService
- Re-name GroupApiService to GroupService as there is no need for a separate Api service (no sync or local data for admin services) - Add GroupView for use in the GroupService instead of raw API models - Update views to use GroupView instead of raw GroupResponse models
This commit is contained in:
@@ -2,7 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
||||
import { GroupApiServiceAbstraction, GroupResponse } from "@bitwarden/common/abstractions/group";
|
||||
import { GroupServiceAbstraction } from "@bitwarden/common/abstractions/group";
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
|
||||
@@ -12,6 +12,7 @@ import { EncString } from "@bitwarden/common/models/domain/encString";
|
||||
import { SymmetricCryptoKey } from "@bitwarden/common/models/domain/symmetricCryptoKey";
|
||||
import { CollectionRequest } from "@bitwarden/common/models/request/collectionRequest";
|
||||
import { SelectionReadOnlyRequest } from "@bitwarden/common/models/request/selectionReadOnlyRequest";
|
||||
import { GroupView } from "@bitwarden/common/models/view/groupView";
|
||||
|
||||
@Component({
|
||||
selector: "app-collection-add-edit",
|
||||
@@ -31,7 +32,7 @@ export class CollectionAddEditComponent implements OnInit {
|
||||
title: string;
|
||||
name: string;
|
||||
externalId: string;
|
||||
groups: GroupResponse[] = [];
|
||||
groups: GroupView[] = [];
|
||||
formPromise: Promise<any>;
|
||||
deletePromise: Promise<any>;
|
||||
|
||||
@@ -39,7 +40,7 @@ export class CollectionAddEditComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private groupApiService: GroupApiServiceAbstraction,
|
||||
private groupApiService: GroupServiceAbstraction,
|
||||
private i18nService: I18nService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private cryptoService: CryptoService,
|
||||
@@ -53,9 +54,7 @@ export class CollectionAddEditComponent implements OnInit {
|
||||
this.editMode = this.loading = this.collectionId != null;
|
||||
if (this.accessGroups) {
|
||||
const groupsResponse = await this.groupApiService.getAll(this.organizationId);
|
||||
this.groups = groupsResponse.data
|
||||
.map((r) => r)
|
||||
.sort(Utils.getSortFunction(this.i18nService, "name"));
|
||||
this.groups = groupsResponse.sort(Utils.getSortFunction(this.i18nService, "name"));
|
||||
}
|
||||
this.orgKey = await this.cryptoService.getOrgKey(this.organizationId);
|
||||
|
||||
@@ -98,7 +97,7 @@ export class CollectionAddEditComponent implements OnInit {
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
check(g: GroupResponse, select?: boolean) {
|
||||
check(g: GroupView, select?: boolean) {
|
||||
if (g.accessAll) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
|
||||
import { GroupApiServiceAbstraction } from "@bitwarden/common/abstractions/group";
|
||||
import { GroupServiceAbstraction } from "@bitwarden/common/abstractions/group";
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
||||
@@ -35,7 +35,7 @@ export class GroupAddEditComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private groupApiService: GroupApiServiceAbstraction,
|
||||
private groupApiService: GroupServiceAbstraction,
|
||||
private i18nService: I18nService,
|
||||
private collectionService: CollectionService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
|
||||
@@ -17,10 +17,7 @@ import { SearchPipe } from "@bitwarden/angular/pipes/search.pipe";
|
||||
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
|
||||
import {
|
||||
GroupApiServiceAbstraction,
|
||||
GroupDetailsResponse,
|
||||
} from "@bitwarden/common/abstractions/group";
|
||||
import { GroupServiceAbstraction } from "@bitwarden/common/abstractions/group";
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
||||
@@ -34,6 +31,7 @@ import {
|
||||
} from "@bitwarden/common/models/response/collectionResponse";
|
||||
import { ListResponse } from "@bitwarden/common/models/response/listResponse";
|
||||
import { CollectionView } from "@bitwarden/common/models/view/collectionView";
|
||||
import { GroupView } from "@bitwarden/common/models/view/groupView";
|
||||
|
||||
import { GroupAddEditComponent } from "./group-add-edit.component";
|
||||
|
||||
@@ -45,7 +43,7 @@ type GroupDetailsRow = {
|
||||
/**
|
||||
* Details used for displaying group information
|
||||
*/
|
||||
details: GroupDetailsResponse;
|
||||
details: GroupView;
|
||||
|
||||
/**
|
||||
* True if the group is selected in the table
|
||||
@@ -108,7 +106,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private groupApiService: GroupApiServiceAbstraction,
|
||||
private groupApiService: GroupServiceAbstraction,
|
||||
private route: ActivatedRoute,
|
||||
private i18nService: I18nService,
|
||||
private modalService: ModalService,
|
||||
@@ -131,10 +129,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||
),
|
||||
// groups
|
||||
this.refreshGroups$.pipe(
|
||||
switchMap(() => this.groupApiService.getAll(this.organizationId)),
|
||||
map((response) =>
|
||||
response.data != null && response.data.length > 0 ? response.data : []
|
||||
)
|
||||
switchMap(() => this.groupApiService.getAll(this.organizationId))
|
||||
),
|
||||
])
|
||||
),
|
||||
@@ -267,7 +262,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||
this.platformUtilsService.showToast(
|
||||
"success",
|
||||
null,
|
||||
this.i18nService.t("deletedManyGroups", result.data.length.toString())
|
||||
this.i18nService.t("deletedManyGroups", result.length.toString())
|
||||
);
|
||||
|
||||
groupsToDelete.forEach((g) => this.removeGroup(g.details.id));
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
||||
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import { GroupApiServiceAbstraction, GroupResponse } from "@bitwarden/common/abstractions/group";
|
||||
import { GroupServiceAbstraction } from "@bitwarden/common/abstractions/group";
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
||||
import { Utils } from "@bitwarden/common/misc/utils";
|
||||
import { OrganizationUserUpdateGroupsRequest } from "@bitwarden/common/models/request/organizationUserUpdateGroupsRequest";
|
||||
import { GroupView } from "@bitwarden/common/models/view/groupView";
|
||||
|
||||
@Component({
|
||||
selector: "app-user-groups",
|
||||
@@ -19,20 +20,19 @@ export class UserGroupsComponent implements OnInit {
|
||||
@Output() onSavedUser = new EventEmitter();
|
||||
|
||||
loading = true;
|
||||
groups: GroupResponse[] = [];
|
||||
groups: GroupView[] = [];
|
||||
formPromise: Promise<any>;
|
||||
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private groupApiService: GroupApiServiceAbstraction,
|
||||
private groupApiService: GroupServiceAbstraction,
|
||||
private i18nService: I18nService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private logService: LogService
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
const groupsResponse = await this.groupApiService.getAll(this.organizationId);
|
||||
const groups = groupsResponse.data.map((r) => r);
|
||||
const groups = await this.groupApiService.getAll(this.organizationId);
|
||||
groups.sort(Utils.getSortFunction(this.i18nService, "name"));
|
||||
this.groups = groups;
|
||||
|
||||
@@ -56,7 +56,7 @@ export class UserGroupsComponent implements OnInit {
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
check(g: GroupResponse, select?: boolean) {
|
||||
check(g: GroupView, select?: boolean) {
|
||||
(g as any).checked = select == null ? !(g as any).checked : select;
|
||||
if (!(g as any).checked) {
|
||||
(g as any).readOnly = false;
|
||||
|
||||
Reference in New Issue
Block a user