@@ -26,6 +26,7 @@ import {
2626 statusColorMap
2727} from '../../interfaces/IStatus' ;
2828import {
29+ IAction ,
2930 IClientSummary ,
3031 IClientVersionSummary ,
3132 IContract ,
@@ -54,6 +55,7 @@ import { SnackbarService } from '../../services/snackbar/snackbar.service';
5455import { ConfigService } from '../../services/config/config.service' ;
5556import { IPolicyExt , IPolicyProbe } from '../../interfaces/IPolicy' ;
5657import { PermissionsService } from '../../services/permissions/permissions.service' ;
58+ import { ClientService } from '../../services/client/client.service' ;
5759
5860@Component ( {
5961 selector : 'app-my-apps' ,
@@ -90,7 +92,8 @@ export class MyAppsComponent implements OnInit {
9092 private snackbarService : SnackbarService ,
9193 public configService : ConfigService ,
9294 private cdr : ChangeDetectorRef ,
93- private permissionsService : PermissionsService
95+ private permissionsService : PermissionsService ,
96+ private clientService : ClientService
9497 ) { }
9598
9699 ngOnInit ( ) : void {
@@ -194,7 +197,8 @@ export class MyAppsComponent implements OnInit {
194197 docsAvailable : this . apiService . isApiDocAvailable (
195198 contract . api
196199 ) ,
197- deletable : this . isDeleteAllowed ( contract )
200+ deletable : this . isDeleteAllowed ( contract ) ,
201+ registerable : this . isRegisterable ( contract )
198202 } as IContractExt ;
199203 } )
200204 ) ;
@@ -413,6 +417,21 @@ export class MyAppsComponent implements OnInit {
413417 return `${ contract . api . api . name } ${ contract . api . version } - ${ contract . plan . plan . name } ` ;
414418 }
415419
420+ register ( contract : IContractExt ) {
421+ const action : IAction = {
422+ type : 'registerClient' ,
423+ organizationId : contract . client . client . organization . id ,
424+ entityId : contract . client . client . id ,
425+ entityVersion : contract . client . version
426+ } ;
427+ this . clientService . registerClient ( action ) . subscribe ( ( ) => {
428+ console . info (
429+ `Client ${ action . organizationId } /${ action . entityId } /${ action . entityVersion } successfully registered`
430+ ) ;
431+ contract . client . status = 'Registered' ;
432+ } ) ;
433+ }
434+
416435 unregister ( contract : IContractExt , clientNameVersion : string ) : void {
417436 const dialogRef = this . dialog . open ( UnregisterClientComponent , {
418437 autoFocus : false
@@ -432,6 +451,12 @@ export class MyAppsComponent implements OnInit {
432451 } ) ;
433452 }
434453
454+ private getClientAdminOrgs ( ) {
455+ return this . permissionsService . getAllowedOrganizations ( {
456+ name : 'clientAdmin'
457+ } as IPermission ) ;
458+ }
459+
435460 private isDeleteAllowed ( contract : IContract ) : boolean {
436461 const clientAdminOrganizations =
437462 this . permissionsService . getAllowedOrganizations ( {
@@ -443,6 +468,16 @@ export class MyAppsComponent implements OnInit {
443468 ) ;
444469 }
445470
471+ private isRegisterable ( contract : IContract ) : boolean {
472+ const clientAdminOrganizations = this . getClientAdminOrgs ( ) ;
473+ return (
474+ ( contract . client . status === 'Ready' ||
475+ contract . client . status === 'Unregistered' ||
476+ contract . client . status === 'Retired' ) &&
477+ clientAdminOrganizations . includes ( contract . client . client . organization . id )
478+ ) ;
479+ }
480+
446481 onSetSection ( $event : { contract : IContractExt ; section : ISection } ) : void {
447482 this . setSection ( $event . contract , $event . section ) ;
448483 this . cdr . detectChanges ( ) ;
0 commit comments