Skip to content

Commit

Permalink
Only show study courses with leadership on current events #723
Browse files Browse the repository at this point in the history
  • Loading branch information
hupf committed Dec 4, 2024
1 parent ad0e496 commit ac31a0f
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 60 deletions.
41 changes: 38 additions & 3 deletions src/app/events/services/events-state.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as t from "io-ts/lib/index";
import { Course } from "src/app/shared/models/course.model";
import { Event } from "src/app/shared/models/event.model";
import { StudyClass } from "src/app/shared/models/study-class.model";
import { StorageService } from "src/app/shared/services/storage.service";
import {
buildCourse,
buildFinalGrading,
Expand All @@ -30,7 +31,28 @@ describe("EventsStateService", () => {
let assessmentEntries: EventEntry[];

beforeEach(() => {
TestBed.configureTestingModule(buildTestModuleMetadata());
TestBed.configureTestingModule(
buildTestModuleMetadata({
providers: [
{
provide: StorageService,
useValue: {
getPayload() {
return {
culture_info: "de_CH",
fullname: "Jane Doe",
id_person: "123",
holder_id: "456",
instance_id: "678",
roles: "",
substitution_id: undefined,
};
},
},
},
],
}),
);

httpTestingController = TestBed.inject(HttpTestingController);
service = TestBed.inject(EventsStateService);
Expand Down Expand Up @@ -170,11 +192,24 @@ describe("EventsStateService", () => {
},
];

studyCourses = [{ Id: 10, Designation: "Zoologie", StudentCount: 42 }];
studyCourses = [
{
Id: 10,
Designation: "Zentraler Gymnasialer Bildungsgang",
Leadership: "Jane Doe",
StudentCount: 42,
},
{
Id: 20,
Designation: "Berufsmaturität",
Leadership: "John Doe", // Other leader (study course is ignored)
StudentCount: 10,
},
];
studyCoursesEntries = [
{
id: 10,
designation: "Zoologie",
designation: "Zentraler Gymnasialer Bildungsgang",
studentCount: 42,
detailLink: "link-to-event-detail-module/10",
state: null,
Expand Down
20 changes: 13 additions & 7 deletions src/app/events/services/events-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { StudyClass } from "src/app/shared/models/study-class.model";
import { CoursesRestService } from "src/app/shared/services/courses-rest.service";
import { EventsRestService } from "src/app/shared/services/events-rest.service";
import { LoadingService } from "src/app/shared/services/loading-service";
import { StorageService } from "src/app/shared/services/storage.service";
import { StudyClassesRestService } from "src/app/shared/services/study-classes-rest.service";
import { spread } from "src/app/shared/utils/function";
import { hasRole } from "src/app/shared/utils/roles";
Expand All @@ -26,6 +27,7 @@ import {
getCourseDesignation,
getEventState,
isRated,
isStudyCourseLeader,
} from "../utils/events";

export enum EventState {
Expand Down Expand Up @@ -96,6 +98,7 @@ export class EventsStateService {
private eventsRestService: EventsRestService,
private studyClassRestService: StudyClassesRestService,
private loadingService: LoadingService,
private storageService: StorageService,
private translate: TranslateService,
@Inject(SETTINGS) private settings: Settings,
) {}
Expand Down Expand Up @@ -209,13 +212,16 @@ export class EventsStateService {
private createFromStudyCourses(
studyCourses: ReadonlyArray<Event>,
): ReadonlyArray<EventEntry> {
return studyCourses.map((studyCourse) => ({
id: studyCourse.Id,
designation: studyCourse.Designation,
detailLink: this.buildLink(studyCourse.Id, "eventdetail"),
studentCount: studyCourse.StudentCount,
state: null,
}));
const tokenPayload = this.storageService.getPayload();
return studyCourses
.filter((studyCourse) => isStudyCourseLeader(tokenPayload, studyCourse)) // The user sees only the study courses he/she is leader of
.map((studyCourse) => ({
id: studyCourse.Id,
designation: studyCourse.Designation,
detailLink: this.buildLink(studyCourse.Id, "eventdetail"),
studentCount: studyCourse.StudentCount,
state: null,
}));
}

private createFromAssessments(
Expand Down
Loading

0 comments on commit ac31a0f

Please sign in to comment.