Merge branch 'feature/viewer-attachment' of bitbucket.org:equilibriumito/gabinete-digital-fo into feature/viewer-attachment

This commit is contained in:
Peter Maquiran
2024-03-05 10:06:57 +01:00
5 changed files with 164 additions and 6 deletions
+3 -1
View File
@@ -87,6 +87,7 @@ import { LoggingInterceptorService } from './services/logging-interceptor.servic
import { PopupQuestionPipe } from './modals/popup-question.pipe';
import '@teamhive/capacitor-video-recorder';
import { tokenInterceptor } from './interceptors/token.interceptors';
import { ChatTokenInterceptor } from './interceptors/chatToken.interceptor';
import { InputFilterDirective } from './services/directives/input-filter.directive';
import { VisibilityDirective } from './services/directives/visibility.directive';
@@ -216,7 +217,8 @@ import { FirebaseX } from '@ionic-native/firebase-x/ngx'; */
DocumentViewer,
FFMpeg,
{ provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptorService, multi: true },
tokenInterceptor
tokenInterceptor,
/* ChatTokenInterceptor */
],
bootstrap: [AppComponent],
@@ -0,0 +1,152 @@
import { Injectable } from '@angular/core';
import {
HttpInterceptor,
HttpRequest,
HttpHandler,
HttpEvent,
HttpErrorResponse,
HTTP_INTERCEPTORS,
HttpHeaders,
} from '@angular/common/http';
import { Observable, throwError, BehaviorSubject } from 'rxjs';
import { catchError, switchMap, filter, take } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import { SessionStore } from '../store/session.service';
import { environment } from "src/environments/environment";
import { PermissionService } from '../services/permission.service';
import { NetworkServiceService , ConnectionStatus} from 'src/app/services/network-service.service';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
@Injectable()
export class ChatTokenInterceptor implements HttpInterceptor {
private isRefreshing = false;
headers: HttpHeaders;
options: any;
private refreshTokenSubject: BehaviorSubject<any> = new BehaviorSubject<any>(
null
);
private excludedDomain = 'https://gdchat-dev.dyndns.info';// Add other domains as needed
constructor(private http: HttpClient, private router: Router,private p: PermissionService,private NetworkServiceService: NetworkServiceService,
private RochetChatConnectorService: RochetChatConnectorService) {}
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
if (this.shouldExcludeDomain(request)) {
return next.handle(request);
}
return next.handle(request).pipe(
catchError((error) => {
if (error instanceof HttpErrorResponse && error.status === 401) {
return this.handle401Error(request, next);
} else {
return throwError(error);
}
})
);
}
private shouldExcludeDomain(request: HttpRequest<any>): boolean {
const url = request.url.toLowerCase();
return !url.includes(this.excludedDomain.toLowerCase());
}
private handle401Error(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
if (!this.isRefreshing) {
this.isRefreshing = true;
this.refreshTokenSubject.next(null);
return this.refreshToken().pipe(
switchMap((token: any) => {
this.isRefreshing = false;
let data = {
status: token['status'],
data: {
userId: token['data'].userId,
authToken: token['data'].authToken
}
}
SessionStore.user.ChatData = data
SessionStore.save()
this.setheader()
this.refreshTokenSubject.next(token.Authorization);
return next.handle(this.addToken(request, token.Authorization));
})
);
} else {
return this.refreshTokenSubject.pipe(
filter((token) => token != null),
take(1),
switchMap((jwt) => {
return next.handle(this.addToken(request, jwt));
})
);
}
}
private addToken(request: HttpRequest<any>, token: string) {
return request.clone({
/* setHeaders: {
Authorization: `Bearer ${token}`,
}, */
});
}
private refreshToken(): Observable<any> {
return this.http
.get<any>(environment.apiURL + 'UserAuthentication/RegenereChatToken', {
/* refreshToken: SessionStore.user.RefreshToken, */
})
.pipe(
catchError((error) => {
// Handle token refresh failure
console.log('ChatToken refresh failed:', error);
return throwError(error);
})
);
}
setheader() {
try {
if (this.p.userPermission(this.p.permissionList.Chat.access) && SessionStore.user.ChatData) {
this.headers = new HttpHeaders();;
if (this.p.userPermission(this.p.permissionList.Chat.access)) {
//
this.headers = this.headers.set('X-User-Id', SessionStore.user.ChatData.data.userId);
this.headers = this.headers.set('X-Auth-Token', SessionStore.user.ChatData.data.authToken);
this.options = {
headers: this.headers,
};
}
}
} catch (error) {
}
}
}
export const tokenInterceptor = {
provide: HTTP_INTERCEPTORS,
useClass: ChatTokenInterceptor,
multi: true
};
+5 -3
View File
@@ -14,6 +14,7 @@ import { catchError, filter, take, switchMap, tap } from "rxjs/operators";
import { SessionStore } from '../store/session.service';
import { environment } from "src/environments/environment";
import { Router } from "@angular/router";
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
@Injectable()
export class TokenInterceptor implements HttpInterceptor {
@@ -24,7 +25,7 @@ export class TokenInterceptor implements HttpInterceptor {
private excludedDomains = ['Login', environment.apiChatUrl]; // Add the domains you want to exclude
constructor(private http: HttpClient, private router: Router,) { }
constructor(private http: HttpClient, private router: Router,private httpErrorHandle: HttpErrorHandle,) { }
intercept(
@@ -119,8 +120,9 @@ export class TokenInterceptor implements HttpInterceptor {
window.location.pathname = '/auth'
} else {
/* const pathBeforeGoOut = window.location.pathname */
this.router.navigateByUrl('/auth', { replaceUrl: true });
this.router.navigateByUrl('/auth', { replaceUrl: true }).then(() =>{
this.httpErrorHandle.httpsSucessMessagge('sessonExpired')
})
}
return of(false);
})
@@ -223,7 +223,9 @@ export class HttpErrorHandle {
case 'new event to aprove':
this.toastService._successMessage('Enviado para os eventos para aprovação!');
break;
case 'sessonExpired':
this.toastService._successMessage('Sessão expirada, por favor efectuar login novamente!');
break;
default:
this.toastService._successMessage('Processo efetuado!')
break;
@@ -215,7 +215,7 @@ export class DiplomaOptionsPage implements OnInit {
"ActionTypeId": 99999842,
"FolderId": this.task.FolderID,
"dataFields": {
"ReviewUserComment": note,
"ReviewUserComment": "",
"InstanceIDNew": this.task.InstanceID,
"DraftIds": "",
},