Skip to content

Commit

Permalink
Feature/2609/force tos acceptance (#740)
Browse files Browse the repository at this point in the history
force logout users who have not accepted TOS and Privacy Policy
dockstore/dockstore#2609
  • Loading branch information
NatalieEO authored Aug 26, 2019
1 parent c0a27af commit 10ed758
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 43 deletions.
4 changes: 2 additions & 2 deletions cypress/integration/group2/starEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { resetDB, setTokenUserViewPortCurator } from '../../support/commands';
import {resetDB, setTokenUserViewPort} from '../../support/commands';

describe('Tool, Workflow, and Organization starring', () => {
resetDB();
setTokenUserViewPortCurator();
setTokenUserViewPort();

function typeInInput(fieldName: string, text: string) {
cy.contains(fieldName).parentsUntil('.mat-form-field-wrapper')
Expand Down
8 changes: 0 additions & 8 deletions cypress/integration/immutableDatabaseTests/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ import { setTokenUserViewPort } from '../../support/commands';
describe('Admin UI', () => {
setTokenUserViewPort();
beforeEach(() => {
cy.server();
const userObject = { id: 1, username: 'user_A', curator: false, isAdmin: true, name: 'user_A', setupComplete: false};
cy.route({
url: '/users/user',
method: 'GET',
status: 200,
response: userObject
});
cy.visit('');

// Select dropdown
Expand Down
12 changes: 2 additions & 10 deletions cypress/integration/immutableDatabaseTests/curator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { setTokenUserViewPort } from '../../support/commands';
import {setTokenUserViewPortCurator} from '../../support/commands';
describe('Curator UI', () => {
setTokenUserViewPort();
setTokenUserViewPortCurator();
beforeEach(() => {
cy.server();
const userObject = { id: 1, username: 'user_A', curator: true, isAdmin: false, name: 'user_A', setupComplete: false};
cy.route({
url: '*/users/user',
method: 'GET',
status: 200,
response: userObject
});
cy.visit('');

// Select dropdown
Expand Down
12 changes: 2 additions & 10 deletions cypress/integration/immutableDatabaseTests/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { goToTab, isActiveTab, setTokenUserViewPortCurator } from '../../support/commands';
import { goToTab, isActiveTab, setTokenUserViewPort, setTokenUserViewPortCurator } from '../../support/commands';

describe('Dropdown test', () => {
// TODO: GitLab tests are commented out
Expand All @@ -28,14 +28,6 @@ describe('Dropdown test', () => {
response: { 'canChangeUsername': true }
});

cy
.server()
.route({
method: 'GET',
url: '*/users/user',
response: { id: 4, username: 'user_curator', name: 'user_curator', curator: true, isAdmin: false }
});

cy.visit('');

// Select dropdown
Expand Down Expand Up @@ -75,7 +67,7 @@ describe('Dropdown test', () => {
it('Should show all accounts as linked (except GitLab and Bitbucket)', () => {
everythingOk();
});
setTokenUserViewPortCurator();
setTokenUserViewPort();
// Check that changing the tab changes the url
it('should default to accounts tab', () => {
cy.visit('/accounts');
Expand Down
10 changes: 5 additions & 5 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ export function resetDB() {
before(() => {
cy.exec('java -jar dockstore-webservice.jar db drop-all --confirm-delete-everything travisci/web.yml');
cy.exec('PGPASSWORD=dockstore psql -h localhost -f travisci/db_dump.sql webservice_test -U dockstore');
cy.exec('java -jar dockstore-webservice.jar db migrate -i 1.5.0,1.6.0,1.7.0 travisci/web.yml');
cy.exec('java -jar dockstore-webservice.jar db migrate -i 1.5.0,1.6.0,1.7.0,alter_test_user_1.7.0 travisci/web.yml');
});
}

// Sets it to the user where id = 1. Is an admin and curator.
export function setTokenUserViewPort() {
beforeEach(() => {
// Login by adding user obj and token to local storage
localStorage.setItem('dockstore.ui.userObj', '{\"id\": 1, \"username\": \"user_A\", \"isAdmin\": \"false\", \"name\": \"user_A\"}');
// Login by adding token to local storage
localStorage.setItem('ng2-ui-auth_token', 'imamafakedockstoretoken');
});
}

// Sets it to the user where id = 4. Is a curator.
export function setTokenUserViewPortCurator() {
beforeEach(() => {
// Login by adding user obj and token to local storage
localStorage.setItem('dockstore.ui.userObj',
'{\"id\": 4, \"username\": \"user_curator\", \"isAdmin\": \"false\", \"name\": \"user_curator\", \"curator\": \"true\"}');
localStorage.setItem('ng2-ui-auth_token', 'imamafakedockstoretoken2');
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.3.0",
"license": "Apache License 2.0",
"config": {
"webservice_version": "1.7.0-beta.4"
"webservice_version": "1.7.0-beta.6"
},
"scripts": {
"ng": "npx ng",
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-webservice-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ psql -h localhost -c "create user dockstore with password 'dockstore' createdb;"
psql -h localhost -c "ALTER USER dockstore WITH superuser;" -U postgres
psql -h localhost -c 'create database webservice_test with owner = dockstore;' -U postgres
psql -h localhost -f travisci/db_dump.sql webservice_test -U postgres
java -jar dockstore-webservice.jar db migrate -i 1.5.0,1.6.0,1.7.0,add_service_1.7.0 travisci/web.yml
java -jar dockstore-webservice.jar db migrate -i 1.5.0,1.6.0,1.7.0,add_service_1.7.0,alter_test_user_1.7.0 travisci/web.yml

4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import { SponsorsComponent } from './sponsors/sponsors.component';
import { StargazersModule } from './stargazers/stargazers.module';
import { StarredEntriesComponent } from './starredentries/starredentries.component';
import { StarringModule } from './starring/starring.module';
import { SessionExpiredComponent } from './session-expired/session-expired.component';

export const myCustomTooltipDefaults: MatTooltipDefaultOptions = {
showDelay: 500,
Expand Down Expand Up @@ -139,7 +140,8 @@ export function configurationServiceFactory(configurationService: ConfigurationS
YoutubeComponent,
SitemapComponent,
GithubCallbackComponent,
ConfirmationDialogComponent
ConfirmationDialogComponent,
SessionExpiredComponent
],
imports: [
environment.production ? [] : AkitaNgDevtools.forRoot(),
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { MaintenanceComponent } from './maintenance/maintenance.component';
import { AuthGuard } from './shared/auth.guard';
import { SitemapComponent } from './sitemap/sitemap.component';
import { StarredEntriesComponent } from './starredentries/starredentries.component';
import { SessionExpiredComponent } from './session-expired/session-expired.component';

export const CLIENT_ROUTER_PROVIDERS = [AuthGuard];

Expand Down Expand Up @@ -71,6 +72,7 @@ const APP_ROUTES: Routes = [
data: { title: 'Dockstore | Search' }
},
{ path: 'login', component: LoginComponent, data: { title: 'Dockstore | Login' } },
{ path: 'session-expired', component: SessionExpiredComponent, data: { title: 'Dockstore | Session Expired' } },
{ path: 'quick-start', component: QuickStartComponent, data: { title: 'Dockstore | Quick Start' } },
{ path: 'onboarding', component: OnboardingComponent, canActivate: [AuthGuard], data: { title: 'Dockstore | Onboarding' } },
{ path: 'accounts', component: AccountsComponent, canActivate: [AuthGuard], data: { title: 'Dockstore | Accounts' } },
Expand Down
4 changes: 2 additions & 2 deletions src/app/loginComponents/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Logout extends Base {
this.trackLoginService.isLoggedIn$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(state => (this.isLoggedIn = state));
}

logout() {
this.logoutService.logout();
logout(routeChange?: string) {
routeChange ? this.logoutService.logout(routeChange) : this.logoutService.logout();
}
}
13 changes: 12 additions & 1 deletion src/app/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class NavbarComponent extends Logout implements OnInit {
isExtended = false;
devMode = devMode;
protected ngUnsubscribe: Subject<{}> = new Subject();
private currentTOSVersion: User.TosversionEnum = User.TosversionEnum.TOSVERSION1;
private currentPrivacyPolicyVersion: User.PrivacyPolicyVersionEnum = User.PrivacyPolicyVersionEnum.PRIVACYPOLICYVERSION25;

constructor(
private pagenumberService: PagenumberService,
Expand All @@ -58,7 +60,12 @@ export class NavbarComponent extends Logout implements OnInit {
}

ngOnInit() {
this.userQuery.user$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(user => (this.user = user));
this.userQuery.user$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(user => {
this.user = user;
if (this.user && (user.privacyPolicyVersion !== this.currentPrivacyPolicyVersion || user.tosversion !== this.currentTOSVersion)) {
this.logOutUsersWithoutCurrentTOS();
}
});
this.userQuery.extendedUserData$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(extendedUser => (this.extendedUser = extendedUser));
}

Expand All @@ -73,4 +80,8 @@ export class NavbarComponent extends Logout implements OnInit {
this.pagenumberService.setToolsPageInfo(toolPageInfo);
this.pagenumberService.setWorkflowPageInfo(workflowPageInfo);
}

logOutUsersWithoutCurrentTOS() {
this.logout('/session-expired');
}
}
23 changes: 23 additions & 0 deletions src/app/session-expired/session-expired.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
Copyright 2019 OICR
*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
*
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<app-header>
Session Expired
</app-header>
<div class="container">
<div class="column">
<p class="lead">You have been signed out because your session has expired. Click <a routerLink="/login">here</a> to login again.</p>
</div>
</div>
24 changes: 24 additions & 0 deletions src/app/session-expired/session-expired.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2019 OICR
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component } from '@angular/core';

@Component({
selector: 'policy-update',
templateUrl: './session-expired.component.html'
})
export class SessionExpiredComponent {
constructor() {}
}
4 changes: 2 additions & 2 deletions src/app/shared/logout.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export class LogoutService {
private auth: AuthService
) {}

logout() {
logout(routeChange?: string) {
this.auth.logout().subscribe({
complete: () => {
this.userService.remove();
this.trackLoginService.switchState(false);
this.router.navigate(['/login']);
routeChange ? this.router.navigate([routeChange]) : this.router.navigate(['/login']);
}
});
}
Expand Down

0 comments on commit 10ed758

Please sign in to comment.