Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed token preparation for assessment removal #4365

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions CSETWebNg/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
import { MatMenuModule } from '@angular/material/menu';
import {
MAT_DATE_LOCALE,
MatNativeDateModule,
MatRippleModule
MAT_DATE_LOCALE,
MatNativeDateModule,
MatRippleModule
} from '@angular/material/core';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatProgressBarModule } from '@angular/material/progress-bar';
Expand Down Expand Up @@ -688,9 +688,11 @@ import { AllReviewedComponent } from './reports/all-reviewed/all-reviewed.compon
import { QuestionsReviewedComponent } from './reports/questions-reviewed/questions-reviewed.component';
import { RolesChangedComponent } from './dialogs/roles-changed/roles-changed.component';
import { AnalyticsResultsComponent } from './assessment/results/analytics-results/analytics-results.component';
import { firstValueFrom } from 'rxjs';


@NgModule({ declarations: [
@NgModule({
declarations: [
AppComponent,
InitialComponent,
LoginComponent,
Expand Down Expand Up @@ -1225,8 +1227,8 @@ import { AnalyticsResultsComponent } from './assessment/results/analytics-result
AllAnsweredquestionsComponent,
AllCommentsmarkedComponent,
AllReviewedComponent,
QuestionsReviewedComponent,
RolesChangedComponent,
QuestionsReviewedComponent,
RolesChangedComponent,
AnalyticsResultsComponent
],
bootstrap: [AppComponent], imports: [BrowserModule,
Expand Down Expand Up @@ -1324,8 +1326,8 @@ import { AnalyticsResultsComponent } from './assessment/results/analytics-result
CodeEditorModule.forRoot({
typingsWorkerUrl: 'assets/workers/typings-worker.js',
baseUrl: 'assets/monaco'
})],
providers: [
})],
providers: [
TranslocoService,
provideTranslocoScope('tutorial', 'reports'),
ConfigService,
Expand All @@ -1336,10 +1338,10 @@ import { AnalyticsResultsComponent } from './assessment/results/analytics-result
return () => {
return configSvc.loadConfig().then(() => {
// Load and set the language based on config
return tSvc
.load(configSvc.config.defaultLang)
.toPromise()
.then(() => {

const obs = tSvc.load(configSvc.config.defaultLang);
const prom = firstValueFrom(obs);
return prom.then(() => {
tSvc.setActiveLang(configSvc.config.defaultLang);
return authSvc.checkLocal();
});
Expand Down Expand Up @@ -1406,5 +1408,6 @@ import { AnalyticsResultsComponent } from './assessment/results/analytics-result
FooterService,
AnalyticsService,
provideHttpClient(withInterceptorsFromDi())
] })
]
})
export class AppModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class QuestionExtrasComponent implements OnInit {

async fetchDetails(): Promise<QuestionDetailsContentViewModel> {
const details = this.questionsSvc.getDetails(this.myQuestion.questionId, this.myQuestion.questionType).toPromise();
return details
return details;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EditUserComponent } from '../edit-user/edit-user.component';
import { TranslocoService } from '@jsverse/transloco';
import { ConfigService } from '../../services/config.service';
import { DateAdapter } from '@angular/material/core';
import { firstValueFrom } from 'rxjs';

@Component({
selector: 'app-user-language',
Expand Down Expand Up @@ -50,7 +51,10 @@ export class UserLanguageComponent implements OnInit {
*
*/
save() {
this.tSvc.load(this.langSelection).toPromise().then(() => {
const obs = this.tSvc.load(this.langSelection);
const prom = firstValueFrom(obs);

prom.then(() => {
this.tSvc.setActiveLang(this.langSelection);
this.authSvc.setUserLang(this.langSelection).subscribe(() => {
this.dateAdapter.setLocale(this.langSelection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import { Title } from "@angular/platform-browser";
import { NavigationService } from "../../services/navigation/navigation.service";
import { QuestionFilterService } from '../../services/filtering/question-filter.service';
import { ReportService } from '../../services/report.service';
import { concatMap, map } from "rxjs/operators";
import { of } from "rxjs";
import { concatMap, map, tap, catchError } from "rxjs/operators";
import { NCUAService } from "../../services/ncua.service";
import { NavTreeService } from "../../services/navigation/nav-tree.service";
import { LayoutService } from "../../services/layout.service";
Expand Down Expand Up @@ -335,48 +336,57 @@ export class MyAssessmentsComponent implements OnInit {
}
}

/**
* "Deletes" an assessment by removing the current user from it. The assessment
* is not deleted, but will no longer appear in the current user's list.
*/
removeAssessment(assessment: UserAssessment, assessmentIndex: number) {
// first, call the API to see if this is a legal move
this.assessSvc
.isDeletePermitted()
.subscribe(canDelete => {
if (!canDelete) {
this.dialog.open(AlertComponent, {
data: {
messageText:
"You cannot remove an assessment that has other users."
// first, get a token branded for the target assessment
this.assessSvc.getAssessmentToken(assessment.assessmentId).then(() => {

// next, call the API to see if this is a legal move
this.assessSvc
.isDeletePermitted()
.subscribe(canDelete => {
if (!canDelete) {
this.dialog.open(AlertComponent, {
data: {
messageText:
"You cannot remove an assessment that has other users."
}
});
return;
}

// if it's legal, see if they really want to
const dialogRef = this.dialog.open(ConfirmComponent);
dialogRef.componentInstance.confirmMessage =
this.tSvc.translate('dialogs.remove assessment', { assessmentName: assessment.assessmentName });

dialogRef.afterClosed().subscribe(result => {
if (result) {
this.assessSvc.removeMyContact(assessment.assessmentId).pipe(
tap(() => {
this.sortedAssessments.splice(assessmentIndex, 1);
}),
catchError(error => {
this.dialog.open(AlertComponent, {
data: { messageText: error.statusText }
});
return of(null);
})
).subscribe();
}
});
return;
}

// if it's legal, see if they really want to
const dialogRef = this.dialog.open(ConfirmComponent);
dialogRef.componentInstance.confirmMessage =
// "Are you sure you want to remove '" +
// assessment.assessmentName +
// "'?";
this.tSvc.translate('dialogs.remove assessment', { assessmentName: assessment.assessmentName });
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.assessSvc.removeMyContact(assessment.assessmentId).subscribe(
x => {
this.sortedAssessments.splice(assessmentIndex, 1);
},
x => {
this.dialog.open(AlertComponent, {
data: { messageText: x.statusText }
});
});
}
});
});
});
}

/**
*
*/
sortData(sort: Sort) {

if (!sort.active || sort.direction === "") {
// this.sortedAssessments = data;
return;
}

Expand All @@ -401,10 +411,16 @@ export class MyAssessmentsComponent implements OnInit {
});
}

/**
*
*/
logout() {
this.authSvc.logout();
}

/**
*
*/
clickDownloadLink(ment_id: number, jsonOnly: boolean = false) {
let encryption = this.preventEncrypt;
// Only allow encryption on .csetw files and only allow PCII scrubbing on JSON files
Expand Down
9 changes: 5 additions & 4 deletions CSETWebNg/src/app/services/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { HttpClient } from '@angular/common/http';
import { ConfigService } from './config.service';
import { Router } from '@angular/router';
import { Aggregation } from '../models/aggregation.model';
import { firstValueFrom } from 'rxjs';

@Injectable()
export class AggregationService {
Expand Down Expand Up @@ -110,10 +111,10 @@ export class AggregationService {
* @param aggId
*/
getAggregationToken(aggId: number) {
return this.http
.get(this.configSvc.apiUrl + 'auth/token?aggregationId=' + aggId)
.toPromise()
.then((response: { token: string }) => {
const obs = this.http.get(this.configSvc.apiUrl + 'auth/token?aggregationId=' + aggId);
const prom = firstValueFrom(obs);

return prom.then((response: { token: string }) => {
localStorage.removeItem('userToken');
localStorage.setItem('userToken', response.token);
if (aggId) {
Expand Down
10 changes: 5 additions & 5 deletions CSETWebNg/src/app/services/assess-compare-analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { AssessmentService } from './assessment.service';
import {
AssessmentDetail
} from '../models/assessment-info.model';
import { Observable } from 'rxjs';
import { firstValueFrom, Observable } from 'rxjs';
import { Router } from '@angular/router';
const headers = {
headers: new HttpHeaders().set("Content-Type", "application/json"),
Expand Down Expand Up @@ -69,10 +69,10 @@ export class AssessCompareAnalyticsService {
}

getAssessmentToken(assessId: number) {
return this.http
.get(this.configSvc.apiUrl + 'auth/token?assessmentId=' + assessId)
.toPromise()
.then((response: { token: string }) => {
const obs = this.http.get(this.configSvc.apiUrl + 'auth/token?assessmentId=' + assessId);
const prom = firstValueFrom(obs);

return prom.then((response: { token: string }) => {
localStorage.removeItem('userToken');
localStorage.setItem('userToken', response.token);
if (assessId) {
Expand Down
Loading
Loading