-
Notifications
You must be signed in to change notification settings - Fork 63
[aca-4419] add new event once user is logged in #1105
Changes from 9 commits
f4f8613
c4d4ba2
2309da7
5d74f2e
fd75952
2c35673
f93c70f
c2a6551
e36a568
d6d2f0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ export class AlfrescoApi implements Emitter { | |
on: EmitterMethod; | ||
off: EmitterMethod; | ||
once: EmitterMethod; | ||
|
||
bufferEvents: string[] = []; | ||
|
||
emit: (type: string, ...args: any[]) => void; | ||
|
||
username: string; | ||
|
@@ -69,7 +72,16 @@ export class AlfrescoApi implements Emitter { | |
this.processClient = new ProcessClient(this.config); | ||
|
||
this.errorListeners(); | ||
this.initAuth(config); | ||
|
||
if(this.isLoggedIn()){ | ||
this.emitBuffer('logged-in'); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
private initAuth(config: AlfrescoApiConfig): void { | ||
if (this.isOauthConfiguration()) { | ||
|
||
if (!this.oauth2Auth) { | ||
|
@@ -78,6 +90,10 @@ export class AlfrescoApi implements Emitter { | |
this.oauth2Auth.setConfig(this.config, this); | ||
} | ||
|
||
this.oauth2Auth?.on('logged-in', () => { | ||
this.emitBuffer('logged-in'); | ||
}); | ||
|
||
this.setAuthenticationClientECMBPM(this.oauth2Auth.getAuthentication(), this.oauth2Auth.getAuthentication()); | ||
} else { | ||
|
||
|
@@ -87,16 +103,23 @@ export class AlfrescoApi implements Emitter { | |
this.processAuth.setConfig(this.config); | ||
} | ||
|
||
this.processAuth?.on('logged-in', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By this time, can't we be sure, that we have this.processAuth? |
||
this.emitBuffer('logged-in'); | ||
}); | ||
|
||
if (!this.contentAuth) { | ||
this.contentAuth = new ContentAuth(this.config, this); | ||
} else { | ||
this.contentAuth.setConfig(config); | ||
} | ||
|
||
this.contentAuth?.on('logged-in', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By this time, can't we be sure, that we have this.contentAuth? |
||
this.emitBuffer('logged-in'); | ||
}); | ||
|
||
this.setAuthenticationClientECMBPM(this.contentAuth.getAuthentication(), this.processAuth.getAuthentication()); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
private clientsFactory() { | ||
|
@@ -144,6 +167,7 @@ export class AlfrescoApi implements Emitter { | |
} | ||
|
||
errorListeners() { | ||
|
||
this.contentClient.off('error', () => { | ||
}); | ||
|
||
|
@@ -199,7 +223,7 @@ export class AlfrescoApi implements Emitter { | |
this.invalidateSession(); | ||
} | ||
|
||
this.emit('error', error); | ||
this.emitBuffer('error', error); | ||
} | ||
|
||
changeWithCredentialsConfig(withCredentials: boolean) { | ||
|
@@ -251,7 +275,7 @@ export class AlfrescoApi implements Emitter { | |
|
||
oauth2AuthPromise.then((accessToken) => { | ||
this.config.accessToken = accessToken; | ||
}, (e) => { | ||
}, (e) => { | ||
console.log('login OAUTH error', e); | ||
}); | ||
|
||
|
@@ -264,7 +288,7 @@ export class AlfrescoApi implements Emitter { | |
|
||
processPromise.then((ticketBpm) => { | ||
this.config.ticketBpm = ticketBpm; | ||
}, () => { | ||
}, () => { | ||
console.log('login BPM error'); | ||
}); | ||
|
||
|
@@ -276,7 +300,7 @@ export class AlfrescoApi implements Emitter { | |
this.setAuthenticationClientECMBPM(this.contentAuth.getAuthentication(), null); | ||
|
||
this.config.ticketEcm = ticketEcm; | ||
}, () => { | ||
}, () => { | ||
console.log('login ECM error'); | ||
}); | ||
|
||
|
@@ -559,4 +583,17 @@ export class AlfrescoApi implements Emitter { | |
isEcmBpmConfiguration(): boolean { | ||
return this.config.provider && this.config.provider.toUpperCase() === 'ALL'; | ||
} | ||
|
||
private emitBuffer(event: string, callback ?: any): void { | ||
this.emit(event, callback); | ||
this.bufferEvents.push(event); | ||
} | ||
|
||
reply(event: string, callback ?: any): void { | ||
if (this.bufferEvents.indexOf(event) >= 0) { | ||
Function.prototype.apply.call(callback, this, arguments); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this reply method for? |
||
} else { | ||
this.on(event, callback); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ export class AlfrescoApiCompatibility extends AlfrescoApi { | |
moduleCopy[currentClass] = module[currentClass]; | ||
let obj = this._stringToObject(currentClass, module); | ||
let nameObj = this._lowerFirst(currentClass); | ||
obj.init(this); | ||
obj?.init(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this, if 2 lines above, we explicitly assigned a value to this variable? Is the returned interface of _stringToObject amboguous? |
||
moduleCopy[nameObj] = obj; | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By this time, can't we be sure, that we have this.oauth2Auth?