Skip to content

Commit

Permalink
Pull request #85: Bugfix/RIHAKB-961 rakendust ei kuvata esimesel laad…
Browse files Browse the repository at this point in the history
…imisel

Merge in RIHA/riha-browser from bugfix/RIHAKB-961-rakendust-ei-kuvata-esimesel-laadimisel to develop

* commit '2780908dd7527ebc2c9ef3a2690853e8e9e0fbb7':
  made getActiveUser() method safe to be invoked.
  WIP - possible fix
  • Loading branch information
KristjanKruusRIA committed Aug 31, 2020
2 parents 08422f5 + 2780908 commit 6f7f62e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Component, OnInit, Input, DoCheck, KeyValueDiffers } from '@angular/core';
import { SystemsService } from '../../../../services/systems.service';
import { ToastrService } from 'ngx-toastr';
import { GridData } from '../../../../models/grid-data';
import { EnvironmentService } from '../../../../services/environment.service';
import { GeneralHelperService } from '../../../../services/general-helper.service';
import { classifiers } from "../../../../services/environment.service";
import { UserMatrix } from '../../../../models/user-matrix';
import {Component, DoCheck, Input, KeyValueDiffers, OnInit} from '@angular/core';
import {SystemsService} from '../../../../services/systems.service';
import {ToastrService} from 'ngx-toastr';
import {GridData} from '../../../../models/grid-data';
import {classifiers, EnvironmentService} from '../../../../services/environment.service';
import {GeneralHelperService} from '../../../../services/general-helper.service';
import {UserMatrix} from '../../../../models/user-matrix';

@Component({
selector: 'app-discussions-list',
Expand All @@ -23,7 +22,7 @@ export class DiscussionsListComponent implements OnInit, DoCheck {

public isNewDiscussion(ad){
if (ad.lastComment){
return ad.lastComment.organizationCode != this.environmentService.getActiveUser().activeOrganization.code;
return this.environmentService.getActiveUser() != null && ad.lastComment.organizationCode != this.environmentService.getActiveUser().activeOrganization.code;
} else {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component, OnInit, KeyValueDiffers } from '@angular/core';
import { SystemsService } from '../../../services/systems.service';
import { ToastrService } from 'ngx-toastr';
import { GridData } from '../../../models/grid-data';
import { EnvironmentService, classifiers } from '../../../services/environment.service';
import { GeneralHelperService } from '../../../services/general-helper.service';
import {Component, KeyValueDiffers, OnInit} from '@angular/core';
import {SystemsService} from '../../../services/systems.service';
import {ToastrService} from 'ngx-toastr';
import {GridData} from '../../../models/grid-data';
import {classifiers, EnvironmentService} from '../../../services/environment.service';
import {GeneralHelperService} from '../../../services/general-helper.service';
import * as moment from 'moment';
import { UserMatrix } from '../../../models/user-matrix';
import {UserMatrix} from '../../../models/user-matrix';

@Component({
selector: 'app-systems-for-approval-list',
Expand Down Expand Up @@ -43,7 +43,7 @@ export class SystemsForApprovalListComponent implements OnInit {
const eventsCount = ar.events.length;
for (let i = 0; i < eventsCount; i++){
const event = ar.events[i];
const activeOrganization = this.environmentService.getActiveUser().getActiveOrganization();
const activeOrganization = this.environmentService.getActiveUser() ? this.environmentService.getActiveUser().getActiveOrganization() : null;
if (event.type == this.classifiers.event_type.DECISION.code && activeOrganization && activeOrganization.code == event.organizationCode){
hasDecision = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class ApproverIssueDetailsComponent implements OnInit, CanDeactivateModal
&& this.feedback.type != classifiers.issue_type.MODIFICATION_REQUEST.code
&& this.feedback.type != classifiers.issue_type.FINALIZATION_REQUEST.code
&& this.feedback.type != classifiers.issue_type.ESTABLISHMENT_REQUEST.code){
ret = bHasApproverRole || this.activeUser.canEdit(this.system.getOwnerCode());
ret = bHasApproverRole || (this.activeUser && this.activeUser.canEdit(this.system.getOwnerCode()));
}
}
return ret;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, OnInit, DoCheck, KeyValueDiffers } from '@angular/core';
import { UserMatrix } from '../../models/user-matrix';
import { EnvironmentService } from '../../services/environment.service';
import { GridData } from '../../models/grid-data';
import { SystemsService } from '../../services/systems.service';
import { GeneralHelperService } from '../../services/general-helper.service';
import {Component, DoCheck, KeyValueDiffers, OnInit} from '@angular/core';
import {UserMatrix} from '../../models/user-matrix';
import {EnvironmentService} from '../../services/environment.service';
import {GridData} from '../../models/grid-data';
import {SystemsService} from '../../services/systems.service';
import {GeneralHelperService} from '../../services/general-helper.service';

@Component({
selector: 'app-producer-dashboard',
Expand All @@ -23,7 +23,7 @@ export class ProducerDashboardComponent implements OnInit, DoCheck {
}

private getOwnOpenIssues(){
if (this.userMatrix.isLoggedIn && this.userMatrix.isOrganizationSelected) {
if (this.userMatrix.isLoggedIn && this.userMatrix.isOrganizationSelected && this.environmentService.getActiveUser()) {
this.systemsService.getActiveIssuesForOrganization(this.environmentService.getActiveUser().activeOrganization.code, this.gridData.sort).subscribe(res =>{
this.gridData.updateData(res);
this.loaded = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class ProducerDetailsComponent implements OnInit, DoCheck, CanDeactivateM
break;
}
case 'contacts': {
ret = (this.system.hasContacts() && this.environmentService.getActiveUser() != null) || editable;
ret = (this.system.hasContacts() && typeof this.environmentService.getActiveUser() !== 'undefined' && this.environmentService.getActiveUser() != null) || editable;
break;
}
case 'security': {
Expand Down Expand Up @@ -106,7 +106,7 @@ export class ProducerDetailsComponent implements OnInit, DoCheck, CanDeactivateM
this.userMatrix = this.environmentService.getUserMatrix();
if (this.loaded && this.userMatrix.isLoggedIn){
const user = this.environmentService.getActiveUser();
return this.issueId && this.userMatrix.isLoggedIn && !(user.canEdit(this.system.getOwnerCode()) || this.userMatrix.hasApproverRole);
return this.issueId && this.userMatrix.isLoggedIn && user && !(user.canEdit(this.system.getOwnerCode()) || this.userMatrix.hasApproverRole);
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, OnInit, Input } from '@angular/core';
import { System } from '../../../models/system';
import { SystemsService } from '../../../services/systems.service';
import { EnvironmentService, classifiers } from "../../../services/environment.service";
import { WindowRefService } from '../../../services/window-ref.service';
import { Router, ActivatedRoute } from '@angular/router';
import {Component, Input, OnInit} from '@angular/core';
import {System} from '../../../models/system';
import {SystemsService} from '../../../services/systems.service';
import {classifiers, EnvironmentService} from "../../../services/environment.service";
import {WindowRefService} from '../../../services/window-ref.service';
import {ActivatedRoute, Router} from '@angular/router';

@Component({
selector: 'app-producer-edit-general',
Expand Down Expand Up @@ -76,7 +76,7 @@ export class ProducerEditGeneralComponent implements OnInit {
}

isLoggedIn(){
return this.environmentService.getActiveUser() != null;
return typeof this.environmentService.getActiveUser() !== 'undefined' && this.environmentService.getActiveUser() != null;
}

goBackToDetails(f){
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/app/components/riha-navbar/riha-navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class RihaNavbarComponent implements OnInit, AfterContentChecked {
public _dc: number = 0;

isUserLoggedIn(): boolean {
return this.environmentService.getActiveUser() != null;
return typeof this.environmentService.getActiveUser() !== 'undefined' && this.environmentService.getActiveUser() != null;
}

getRand() {
Expand Down Expand Up @@ -67,22 +67,22 @@ export class RihaNavbarComponent implements OnInit, AfterContentChecked {

isAllowedToChangeOrganization(): boolean {
const user = this.environmentService.getActiveUser();
return user.getOrganizations().length > 1 || (user.getOrganizations().length == 1 && user.getActiveOrganization() == null);
return user && user.getOrganizations().length > 1 || (user.getOrganizations().length == 1 && user.getActiveOrganization() == null);
}

isNoOrganizationPresent(): boolean {
const user = this.environmentService.getActiveUser();
return user.getOrganizations().length == 0;
return user && user.getOrganizations().length == 0;
}

noOrganizationSelected(): boolean {
const user = this.environmentService.getActiveUser();
return user.getActiveOrganization() == null;
return user && user.getActiveOrganization() == null;
}

getUserText(): string {
const user = this.environmentService.getActiveUser();
return user.getFullNameWithActiveOrganization();
return user && user.getFullNameWithActiveOrganization();
}

searchInfosystems(input) {
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/app/services/environment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class EnvironmentService {
private userInfoUrl = environment.api.userInfoUrl;
private classifiersUrl = environment.api.classifiersUrl;

public globalEnvironment: any;
public globalEnvironment = new Environment({});

private lastVisitedLocations = [null, null];

Expand Down Expand Up @@ -106,7 +106,7 @@ export class EnvironmentService {
}

public onAppStart(): Promise<any> {
const promise = this.loadEnvironmentData().toPromise();
const promise = this.loadEnvironmentDataProperly();
promise.then(env => {
this.runTrackingScripts(new Environment(env));
});
Expand All @@ -129,6 +129,11 @@ export class EnvironmentService {
return observable;
}

public async loadEnvironmentDataProperly(): Promise<Environment> {
this.globalEnvironment = new Environment(await this.http.get<Environment>(this.environmentUrl).toPromise());
return this.globalEnvironment;
}

public doLogout(): Observable<any> {
return this.http.post('/logout',null);
}
Expand Down

0 comments on commit 6f7f62e

Please sign in to comment.