Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/2.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gallayl committed Sep 26, 2017
2 parents 14cf468 + bdde0b0 commit cc99fe4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sn-client-js",
"version": "2.4.0",
"version": "2.4.1",
"description": "A JavaScript client for Sense/Net ECM that makes it easy to use the REST API of the Content Repository.",
"main": "dist/src/SN.js",
"files": [
Expand All @@ -18,7 +18,7 @@
"pretest": "npm run build",
"test": "nyc mocha -p tsconfig.json dist/test/index.js",
"check-coverage": "istanbul check-coverage ",
"report-coverage": "cat ./coverage/lcov.info | codecov",
"report-coverage": "cat ./coverage/lcov.info | ./node_modules/.bin/codecov",
"semantic-release": "semantic-release pre && semantic-release post",
"prebuild": "npm run lint && npm run clean",
"build": "tsc",
Expand Down Expand Up @@ -69,6 +69,7 @@
"@types/mocha": "2.2.43",
"@types/node": "^8.0.0",
"chai": "4.1.2",
"codecov": "^2.3.0",
"commitizen": "2.9.6",
"mocha": "3.5.3",
"mocha-typescript": "^1.0.23",
Expand Down
9 changes: 7 additions & 2 deletions src/Authentication/JwtService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class JwtService implements IAuthenticationService {
}

/**
* Logs out the current user, sets the tokes to 'empty'
* Logs out the current user, sets the tokens to 'empty'
* ```
* service.Logout();
* ```
Expand All @@ -176,6 +176,11 @@ export class JwtService implements IAuthenticationService {
this.TokenStore.AccessToken = Token.CreateEmpty();
this.TokenStore.RefreshToken = Token.CreateEmpty();
this.stateSubject.next(LoginState.Unauthenticated);
return new BehaviorSubject(false).asObservable();

return this.httpProviderRef.Ajax(LoginResponse, {
method: 'POST',
url: ODataHelper.joinPaths(this.repositoryUrl, 'sn-token/logout'),
}).map(() => true);

}
}
9 changes: 8 additions & 1 deletion src/Repository/BaseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,14 @@ export class BaseRepository<TProviderType extends BaseHttpProvider = BaseHttpPro


private readonly currentUserSubject = new BehaviorSubject<ContentTypes.User>(this._staticContent.VisitorUser);
public GetCurrentUser: () => Observable<ContentTypes.User> = () => this.currentUserSubject.distinctUntilChanged();
public GetCurrentUser: () => Observable<ContentTypes.User> = () => {
return this.currentUserSubject
.distinctUntilChanged()
.filter(u => {
const [userDomain, userName] = this.Authentication.CurrentUser.split('\\');
return u.LoginName === userName && u.Domain === userDomain
});
}

private _lastKnownUserName = 'BuiltIn\\Visitor';
private initUserUpdate() {
Expand Down
13 changes: 8 additions & 5 deletions test/RepositoryTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export class RepositoryTests {
__count: 1,
results: [{
Name: 'NewUser',
Domain: 'BuiltIn',
Id: 1000,
LoginName: 'NewUser',
Type: 'User',
Expand All @@ -297,7 +298,7 @@ export class RepositoryTests {
repo.Authentication.CurrentUser = 'BuiltIn\\NewUser';
repo.Authentication.stateSubject.next(LoginState.Pending);
repo.Authentication.stateSubject.next(LoginState.Authenticated);
repo.GetCurrentUser().skipWhile(u => u.Name === 'Visitor').subscribe(u => {
repo.GetCurrentUser().subscribe(u => {
expect(u.Name).to.be.eq('NewUser');
done();
}, done)
Expand All @@ -306,8 +307,10 @@ export class RepositoryTests {

@test 'GetCurrentUser() should not update if multiple users found on change '(done: MochaDone) {
let repo = new MockRepository();
repo.Authentication.stateSubject.next(LoginState.Pending);
repo.Authentication.CurrentUser = 'BuiltIn\\NewUser';

repo.GetCurrentUser().skipWhile(u => u.Name === 'Visitor').subscribe(u => {
repo.GetCurrentUser().subscribe(u => {
done('Error should be thrown here.');
}, err => {
expect(err).to.be.eq("Error getting current user: found multiple users with login name 'NewUser' in domain 'BuiltIn'")
Expand All @@ -321,18 +324,18 @@ export class RepositoryTests {
Name: 'NewUser',
Id: 1000,
LoginName: 'NewUser',
Domain: 'BuiltIn',
Type: 'User',
},
{
Name: 'NewUser',
Id: 1000,
LoginName: 'NewUser',
Domain: 'BuiltIn',
Type: 'User',
}]
}
})
repo.Authentication.CurrentUser = 'BuiltIn\\NewUser';
repo.Authentication.stateSubject.next(LoginState.Pending);
});
repo.Authentication.stateSubject.next(LoginState.Authenticated);
}

Expand Down

0 comments on commit cc99fe4

Please sign in to comment.