1
1
import { SelectionModel } from "@angular/cdk/collections" ;
2
- import { Component , EventEmitter , inject , Input , Output } from "@angular/core" ;
2
+ import { Component , EventEmitter , Input , Output } from "@angular/core" ;
3
3
4
- import { CollectionAdminView , Unassigned } from "@bitwarden/admin-console/common" ;
4
+ import { Unassigned } from "@bitwarden/admin-console/common" ;
5
5
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization" ;
6
- import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service" ;
7
6
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view" ;
8
7
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view" ;
9
8
import { TableDataSource } from "@bitwarden/components" ;
10
9
11
10
import { GroupView } from "../../../admin-console/organizations/core" ;
12
11
13
- import {
14
- CollectionPermission ,
15
- convertToPermission ,
16
- } from "./../../../admin-console/organizations/shared/components/access-selector/access-selector.models" ;
17
12
import { VaultItem } from "./vault-item" ;
18
13
import { VaultItemEvent } from "./vault-item-event" ;
19
14
@@ -30,7 +25,6 @@ const MaxSelectionCount = 500;
30
25
// changeDetection: ChangeDetectionStrategy.OnPush,
31
26
} )
32
27
export class VaultItemsComponent {
33
- protected i18nService = inject ( I18nService ) ;
34
28
protected RowHeight = RowHeight ;
35
29
36
30
@Input ( ) disabled : boolean ;
@@ -203,7 +197,7 @@ export class VaultItemsComponent {
203
197
private refreshItems ( ) {
204
198
const collections : VaultItem [ ] = this . collections . map ( ( collection ) => ( { collection } ) ) ;
205
199
const ciphers : VaultItem [ ] = this . ciphers . map ( ( cipher ) => ( { cipher } ) ) ;
206
- let items : VaultItem [ ] = [ ] . concat ( collections ) . concat ( ciphers ) ;
200
+ const items : VaultItem [ ] = [ ] . concat ( collections ) . concat ( ciphers ) ;
207
201
208
202
this . selection . clear ( ) ;
209
203
@@ -214,11 +208,6 @@ export class VaultItemsComponent {
214
208
( item . collection !== undefined && item . collection . id !== Unassigned ) ,
215
209
) ;
216
210
217
- // Apply sorting only for organization vault
218
- if ( this . showAdminActions ) {
219
- items = items . sort ( this . sortByGroups ) ;
220
- }
221
-
222
211
this . dataSource . data = items ;
223
212
}
224
213
@@ -304,112 +293,6 @@ export class VaultItemsComponent {
304
293
return false ;
305
294
}
306
295
307
- /**
308
- * Sorts VaultItems, grouping collections before ciphers, and sorting each group alphabetically by name.
309
- */
310
- protected sortByName = ( a : VaultItem , b : VaultItem ) => {
311
- const getName = ( item : VaultItem ) => item . collection ?. name || item . cipher ?. name ;
312
-
313
- // First, sort collections before ciphers
314
- if ( a . collection && ! b . collection ) {
315
- return - 1 ;
316
- }
317
- if ( ! a . collection && b . collection ) {
318
- return 1 ;
319
- }
320
-
321
- return getName ( a ) . localeCompare ( getName ( b ) ) ;
322
- } ;
323
-
324
- /**
325
- * Sorts VaultItems based on group names
326
- */
327
- protected sortByGroups = ( a : VaultItem , b : VaultItem ) : number => {
328
- const getGroupNames = ( item : VaultItem ) : string => {
329
- if ( item . collection instanceof CollectionAdminView ) {
330
- return item . collection . groups
331
- . map ( ( group ) => this . getGroupName ( group . id ) )
332
- . filter ( Boolean )
333
- . join ( "," ) ;
334
- }
335
-
336
- return "" ;
337
- } ;
338
-
339
- const aGroupNames = getGroupNames ( a ) ;
340
- const bGroupNames = getGroupNames ( b ) ;
341
-
342
- if ( aGroupNames . length !== bGroupNames . length ) {
343
- return bGroupNames . length - aGroupNames . length ;
344
- }
345
-
346
- return aGroupNames . localeCompare ( bGroupNames ) ;
347
- } ;
348
-
349
- /**
350
- * Sorts VaultItems based on their permissions, with higher permissions taking precedence.
351
- * If permissions are equal, it falls back to sorting by name.
352
- */
353
- protected sortByPermissions = ( a : VaultItem , b : VaultItem ) : number => {
354
- const getPermissionPriority = ( item : VaultItem ) : number => {
355
- if ( item . collection instanceof CollectionAdminView ) {
356
- const permission = this . getCollectionPermission ( item . collection ) ;
357
-
358
- switch ( permission ) {
359
- case CollectionPermission . Manage :
360
- return 5 ;
361
- case CollectionPermission . Edit :
362
- return 4 ;
363
- case CollectionPermission . EditExceptPass :
364
- return 3 ;
365
- case CollectionPermission . View :
366
- return 2 ;
367
- case CollectionPermission . ViewExceptPass :
368
- return 1 ;
369
- case "NoAccess" :
370
- return 0 ;
371
- }
372
- }
373
-
374
- return - 1 ;
375
- } ;
376
-
377
- const priorityA = getPermissionPriority ( a ) ;
378
- const priorityB = getPermissionPriority ( b ) ;
379
-
380
- // Higher priority first
381
- if ( priorityA !== priorityB ) {
382
- return priorityB - priorityA ;
383
- }
384
-
385
- return this . sortByName ( a , b ) ;
386
- } ;
387
-
388
- /**
389
- * Default sorting function for vault items.
390
- * Sorts by: 1. Collections before ciphers
391
- * 2. Highest permission first
392
- * 3. Alphabetical order of collections and ciphers
393
- */
394
- private defaultSort = ( a : VaultItem , b : VaultItem ) => {
395
- // First, sort collections before ciphers
396
- if ( a . collection && ! b . collection ) {
397
- return - 1 ;
398
- }
399
- if ( ! a . collection && b . collection ) {
400
- return 1 ;
401
- }
402
-
403
- // Next, sort by permissions
404
- const permissionSort = this . sortByPermissions ( a , b ) ;
405
- if ( permissionSort !== 0 ) {
406
- return permissionSort ;
407
- }
408
-
409
- // Finally, sort by name
410
- return this . sortByName ( a , b ) ;
411
- } ;
412
-
413
296
private hasPersonalItems ( ) : boolean {
414
297
return this . selection . selected . some ( ( { cipher } ) => cipher ?. organizationId === null ) ;
415
298
}
@@ -423,24 +306,4 @@ export class VaultItemsComponent {
423
306
private getUniqueOrganizationIds ( ) : Set < string > {
424
307
return new Set ( this . selection . selected . flatMap ( ( i ) => i . cipher ?. organizationId ?? [ ] ) ) ;
425
308
}
426
-
427
- private getGroupName ( groupId : string ) : string | undefined {
428
- return this . allGroups . find ( ( g ) => g . id === groupId ) ?. name ;
429
- }
430
-
431
- private getCollectionPermission (
432
- collection : CollectionAdminView ,
433
- ) : CollectionPermission | "NoAccess" {
434
- const organization = this . allOrganizations . find ( ( o ) => o . id === collection . organizationId ) ;
435
-
436
- if ( collection . id == Unassigned && organization ?. canEditUnassignedCiphers ) {
437
- return CollectionPermission . Edit ;
438
- }
439
-
440
- if ( collection . assigned ) {
441
- return convertToPermission ( collection ) ;
442
- }
443
-
444
- return "NoAccess" ;
445
- }
446
309
}
0 commit comments