11// Copyright The Linux Foundation and each contributor to CommunityBridge.
22// SPDX-License-Identifier: MIT
33
4- import { Component , EventEmitter , OnInit , Output , TemplateRef , ViewChild } from '@angular/core' ;
4+ import {
5+ Component ,
6+ EventEmitter ,
7+ OnInit ,
8+ Output ,
9+ TemplateRef ,
10+ ViewChild ,
11+ } from '@angular/core' ;
512import { ClaContributorService } from 'src/app/core/services/cla-contributor.service' ;
613import { AuthService } from 'src/app/shared/services/auth.service' ;
714import { AppSettings } from 'src/app/config/app-settings' ;
815import { StorageService } from 'src/app/shared/services/storage.service' ;
916import { NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
10- import { CompanyModel , OrganizationModel } from 'src/app/core/models/organization' ;
17+ import {
18+ CompanyModel ,
19+ OrganizationModel ,
20+ } from 'src/app/core/models/organization' ;
1121import { AlertService } from 'src/app/shared/services/alert.service' ;
1222import { UserModel } from 'src/app/core/models/user' ;
1323import { LoaderService } from 'src/app/shared/services/loader.service' ;
1424
1525@Component ( {
1626 selector : 'app-configure-cla-manager-modal' ,
1727 templateUrl : './configure-cla-manager-modal.component.html' ,
18- styleUrls : [ './configure-cla-manager-modal.component.scss' ]
28+ styleUrls : [ './configure-cla-manager-modal.component.scss' ] ,
1929} )
2030export class ConfigureClaManagerModalComponent implements OnInit {
2131 @ViewChild ( 'errorModal' ) errorModal : TemplateRef < any > ;
@@ -48,12 +58,17 @@ export class ConfigureClaManagerModalComponent implements OnInit {
4858 ngOnInit ( ) {
4959 this . showRetryBtn = false ;
5060 this . failedCount = 0 ;
51- this . company = JSON . parse ( this . storageService . getItem ( AppSettings . SELECTED_COMPANY ) ) ;
61+ this . company = JSON . parse (
62+ this . storageService . getItem ( AppSettings . SELECTED_COMPANY )
63+ ) ;
5264 }
5365
5466 manageAuthRedirection ( ) {
55- this . spinnerMessage = 'Please wait while we configure the initial CLA Manager settings for this CLA.' ;
56- const actionType = JSON . parse ( this . storageService . getItem ( AppSettings . ACTION_TYPE ) ) ;
67+ this . spinnerMessage =
68+ 'Please wait while we configure the initial CLA Manager settings for this CLA.' ;
69+ const actionType = JSON . parse (
70+ this . storageService . getItem ( AppSettings . ACTION_TYPE )
71+ ) ;
5772 if ( actionType === AppSettings . SIGN_CLA ) {
5873 this . addContributorAsDesignee ( ) ;
5974 } else {
@@ -62,27 +77,33 @@ export class ConfigureClaManagerModalComponent implements OnInit {
6277 }
6378
6479 addOrganizationIfNotAdded ( ) {
65- const data = JSON . parse ( this . storageService . getItem ( AppSettings . NEW_ORGANIZATIONS ) ) ;
80+ const data = JSON . parse (
81+ this . storageService . getItem ( AppSettings . NEW_ORGANIZATIONS )
82+ ) ;
6683 if ( data !== undefined && data !== null ) {
6784 // Add organization if it is not created.
68- this . spinnerMessage = 'Please wait for a moment, we are adding the organization.' ;
85+ this . spinnerMessage =
86+ 'Please wait for a moment, we are adding the organization.' ;
6987 this . addNewOrganization ( data ) ;
7088 } else {
7189 this . manageAuthRedirection ( ) ;
7290 }
7391 }
7492
75-
7693 addNewOrganization ( data ) {
77- const userModel : UserModel = JSON . parse ( this . storageService . getItem ( AppSettings . USER ) ) ;
94+ const userModel : UserModel = JSON . parse (
95+ this . storageService . getItem ( AppSettings . USER )
96+ ) ;
7897 this . claContributorService . addCompany ( userModel . user_id , data ) . subscribe (
7998 ( response : CompanyModel ) => {
8099 this . storageService . removeItem ( AppSettings . NEW_ORGANIZATIONS ) ;
81100 this . getOrganizationInformation ( response . companyID ) ;
82101 } ,
83102 ( exception ) => {
84103 this . title = 'Request Failed' ;
85- this . message = exception . error . Message ? exception . error . Message : exception . error . message ;
104+ this . message = exception . error . Message
105+ ? exception . error . Message
106+ : exception . error . message ;
86107 this . openDialog ( this . errorModal ) ;
87108 }
88109 ) ;
@@ -99,7 +120,8 @@ export class ConfigureClaManagerModalComponent implements OnInit {
99120 // To add org in salesforce take couple of seconds
100121 // So called getOrganizationInformation metod till result comes
101122 this . failedCount ++ ;
102- if ( this . failedCount >= AppSettings . MAX_FAILED_COUNT ) { // end API call after 20 time failed
123+ if ( this . failedCount >= AppSettings . MAX_FAILED_COUNT ) {
124+ // end API call after 20 time failed
103125 this . title = 'Request Failed' ;
104126 this . message = exception . error . Message ;
105127 this . openDialog ( this . errorModal ) ;
@@ -122,7 +144,8 @@ export class ConfigureClaManagerModalComponent implements OnInit {
122144 if ( this . authService . loggedIn ) {
123145 this . addContributorAsDesignee ( ) ;
124146 } else {
125- this . message = '<p>You will need to use your LF account to access the CLA Manager console,' +
147+ this . message =
148+ '<p>You will need to use your LF account to access the CLA Manager console,' +
126149 ' or create an LF Login account if you do not have one already.</p>' +
127150 '<p>After logging in, you will be redirected to ' +
128151 'the CLA Manager console where you can sign the CLA (or send it to an authorized signatory) and approve contributors on behalf of your organization.</p>' ;
@@ -134,76 +157,90 @@ export class ConfigureClaManagerModalComponent implements OnInit {
134157 addContributorAsDesignee ( ) {
135158 this . failedCount = 0 ;
136159 const interval = setInterval ( ( ) => {
137- const authData = JSON . parse ( this . storageService . getItem ( AppSettings . AUTH_DATA ) ) ;
160+ const authData = JSON . parse (
161+ this . storageService . getItem ( AppSettings . AUTH_DATA )
162+ ) ;
138163 if ( authData ) {
139164 const data = {
140- userEmail : authData . user_email
165+ userEmail : authData . user_email ,
141166 } ;
142167 this . addAsCLAManagerDesignee ( data ) ;
143168 clearInterval ( interval ) ;
144169 } else {
145- // Wait 15 sec to get response from Auth0 otherwise show an error.
146- this . failedCount ++ ;
147- if ( this . failedCount > 15 ) {
148- this . failedCount = 0 ;
149- this . title = 'Request Failed' ;
150- this . message = 'Error while fetching user info from Auth0 service, please refresh the page.' ;
151- this . openDialog ( this . errorModal ) ;
152- clearInterval ( interval ) ;
153- }
170+ this . authService . login ( ) ;
171+ clearInterval ( interval ) ;
154172 }
155- } , 1000 ) ;
173+ } , 2000 ) ;
156174 }
157175
158176 addAsCLAManagerDesignee ( data : any ) {
159- const projectId = JSON . parse ( this . storageService . getItem ( AppSettings . PROJECT_ID ) ) ;
160- this . claContributorService . addAsCLAManagerDesignee ( this . company . companyID , projectId , data ) . subscribe (
161- ( ) => {
162- this . failedCount = 0 ;
163- this . checkRoleAssignment ( ) ;
164- } ,
165- ( exception ) => {
166- if ( exception . status === 409 ) {
167- // User has already CLA manager designee.
168- this . hasCLAManagerDesignee = true ;
169- this . proceedToCorporateConsole ( ) ;
170- } else if ( exception . status === 401 ) {
171- this . authService . login ( ) ;
172- } else {
173- this . failedCount ++ ;
174- if ( this . failedCount <= AppSettings . MAX_CLA_MANAGER_DESIGNEE_RETRY_COUNT ) {
175- setTimeout ( ( ) => {
176- this . addAsCLAManagerDesignee ( data ) ;
177- } , 200 ) ;
177+ const projectId = JSON . parse (
178+ this . storageService . getItem ( AppSettings . PROJECT_ID )
179+ ) ;
180+ this . claContributorService
181+ . addAsCLAManagerDesignee ( this . company . companyID , projectId , data )
182+ . subscribe (
183+ ( ) => {
184+ this . failedCount = 0 ;
185+ this . checkRoleAssignment ( ) ;
186+ } ,
187+ ( exception ) => {
188+ if ( exception . status === 409 ) {
189+ // User has already CLA manager designee.
190+ this . hasCLAManagerDesignee = true ;
191+ this . proceedToCorporateConsole ( ) ;
192+ } else if ( exception . status === 401 ) {
193+ this . authService . login ( ) ;
178194 } else {
179- this . title = 'Request Failed' ;
180- this . storageService . removeItem ( AppSettings . ACTION_TYPE ) ;
181- this . message = exception . error . Message ? exception . error . Message : exception . error . message ;
182- this . openDialog ( this . errorModal ) ;
195+ this . failedCount ++ ;
196+ if (
197+ this . failedCount <=
198+ AppSettings . MAX_CLA_MANAGER_DESIGNEE_RETRY_COUNT
199+ ) {
200+ setTimeout ( ( ) => {
201+ this . addAsCLAManagerDesignee ( data ) ;
202+ } , 200 ) ;
203+ } else {
204+ this . title = 'Request Failed' ;
205+ this . storageService . removeItem ( AppSettings . ACTION_TYPE ) ;
206+ this . message = exception . error . Message
207+ ? exception . error . Message
208+ : exception . error . message ;
209+ this . openDialog ( this . errorModal ) ;
210+ }
183211 }
184212 }
185- }
186- ) ;
213+ ) ;
187214 }
188215
189216 checkRoleAssignment ( ) {
190- const projectId = JSON . parse ( this . storageService . getItem ( AppSettings . PROJECT_ID ) ) ;
191- const authData = JSON . parse ( this . storageService . getItem ( AppSettings . AUTH_DATA ) ) ;
192- this . claContributorService . hasRoleAssigned ( this . company . companyExternalID , projectId , authData . userid ) . subscribe (
193- ( result ) => {
194- if ( result . hasRole ) {
195- this . hasCLAManagerDesignee = true ;
196- this . proceedToCorporateConsole ( ) ;
197- } else {
198- this . retryRoleAssignement ( ) ;
199- }
200- } ,
201- ( exception ) => {
202- this . title = 'Request Failed' ;
203- this . message = exception . error . Message ;
204- this . openDialog ( this . errorModal ) ;
205- }
217+ const projectId = JSON . parse (
218+ this . storageService . getItem ( AppSettings . PROJECT_ID )
219+ ) ;
220+ const authData = JSON . parse (
221+ this . storageService . getItem ( AppSettings . AUTH_DATA )
206222 ) ;
223+ this . claContributorService
224+ . hasRoleAssigned (
225+ this . company . companyExternalID ,
226+ projectId ,
227+ authData . userid
228+ )
229+ . subscribe (
230+ ( result ) => {
231+ if ( result . hasRole ) {
232+ this . hasCLAManagerDesignee = true ;
233+ this . proceedToCorporateConsole ( ) ;
234+ } else {
235+ this . retryRoleAssignement ( ) ;
236+ }
237+ } ,
238+ ( exception ) => {
239+ this . title = 'Request Failed' ;
240+ this . message = exception . error . Message ;
241+ this . openDialog ( this . errorModal ) ;
242+ }
243+ ) ;
207244 }
208245
209246 retryRoleAssignement ( ) {
@@ -213,9 +250,12 @@ export class ConfigureClaManagerModalComponent implements OnInit {
213250 } else {
214251 this . showRetryBtn = true ;
215252 this . title = 'Request Failed' ;
216- this . message = 'The initial CLA manager settings could not be assigned.</br>' +
253+ this . message =
254+ 'The initial CLA manager settings could not be assigned.</br>' +
217255 'Please click on Retry to allow platform more time to assign settings.</br>' +
218- 'Otherwise you can file a <a href="' + AppSettings . TICKET_URL + '" target="_blank"><b>support ticket</b>.</a>' +
256+ 'Otherwise you can file a <a href=""' +
257+ AppSettings . TICKET_URL +
258+ 'target="_blank"><b>support ticket</b>.</a>' +
219259 ' Once the support ticket is resolved, you will be able to proceed with the CLA.' ;
220260 this . openDialog ( this . errorModal ) ;
221261 }
@@ -230,7 +270,8 @@ export class ConfigureClaManagerModalComponent implements OnInit {
230270
231271 onClickProceedBtn ( ) {
232272 this . modalService . dismissAll ( ) ;
233- this . message = '<p>You will be redirected to the CLA Manager console where you can sign the CLA (or send it to an authorized signatory) and approve contributors on behalf of your organization.</p>' ;
273+ this . message =
274+ '<p>You will be redirected to the CLA Manager console where you can sign the CLA (or send it to an authorized signatory) and approve contributors on behalf of your organization.</p>' ;
234275 this . openDialog ( this . warningModal ) ;
235276 }
236277
@@ -246,7 +287,9 @@ export class ConfigureClaManagerModalComponent implements OnInit {
246287 this . storageService . removeItem ( AppSettings . ACTION_TYPE ) ;
247288 window . open ( corporateUrl , '_self' ) ;
248289 } else {
249- this . alertService . error ( 'Error occurred during redirecting to the corporate console.' ) ;
290+ this . alertService . error (
291+ 'Error occurred during redirecting to the corporate console.'
292+ ) ;
250293 this . loaderService . hide ( ) ;
251294 }
252295 }
@@ -260,7 +303,7 @@ export class ConfigureClaManagerModalComponent implements OnInit {
260303 onClickBackBtn ( ) {
261304 const data = {
262305 action : 'CLA_NOT_SIGN' ,
263- payload : false
306+ payload : false ,
264307 } ;
265308 this . claContributorService . openDialogModalEvent . next ( data ) ;
266309 }
@@ -273,7 +316,7 @@ export class ConfigureClaManagerModalComponent implements OnInit {
273316 this . modalService . dismissAll ( ) ;
274317 const data = {
275318 action : 'RETRY_CONFIG_CLA_MANAGER' ,
276- payload : false
319+ payload : false ,
277320 } ;
278321 this . claContributorService . openDialogModalEvent . next ( data ) ;
279322 }
@@ -282,7 +325,7 @@ export class ConfigureClaManagerModalComponent implements OnInit {
282325 this . modalService . open ( content , {
283326 centered : true ,
284327 backdrop : 'static' ,
285- keyboard : false
328+ keyboard : false ,
286329 } ) ;
287330 }
288331}
0 commit comments