Skip to content

Commit 44b0594

Browse files
committed
Only show study courses with leadership on current events #723
1 parent ad0e496 commit 44b0594

File tree

6 files changed

+209
-60
lines changed

6 files changed

+209
-60
lines changed

src/app/events/services/events-state.service.spec.ts

+38-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as t from "io-ts/lib/index";
44
import { Course } from "src/app/shared/models/course.model";
55
import { Event } from "src/app/shared/models/event.model";
66
import { StudyClass } from "src/app/shared/models/study-class.model";
7+
import { StorageService } from "src/app/shared/services/storage.service";
78
import {
89
buildCourse,
910
buildFinalGrading,
@@ -30,7 +31,28 @@ describe("EventsStateService", () => {
3031
let assessmentEntries: EventEntry[];
3132

3233
beforeEach(() => {
33-
TestBed.configureTestingModule(buildTestModuleMetadata());
34+
TestBed.configureTestingModule(
35+
buildTestModuleMetadata({
36+
providers: [
37+
{
38+
provide: StorageService,
39+
useValue: {
40+
getPayload() {
41+
return {
42+
culture_info: "de_CH",
43+
fullname: "Jane Doe",
44+
id_person: "123",
45+
holder_id: "456",
46+
instance_id: "678",
47+
roles: "",
48+
substitution_id: undefined,
49+
};
50+
},
51+
},
52+
},
53+
],
54+
}),
55+
);
3456

3557
httpTestingController = TestBed.inject(HttpTestingController);
3658
service = TestBed.inject(EventsStateService);
@@ -170,11 +192,24 @@ describe("EventsStateService", () => {
170192
},
171193
];
172194

173-
studyCourses = [{ Id: 10, Designation: "Zoologie", StudentCount: 42 }];
195+
studyCourses = [
196+
{
197+
Id: 10,
198+
Designation: "Zentraler Gymnasialer Bildungsgang",
199+
Leadership: "Jane Doe",
200+
StudentCount: 42,
201+
},
202+
{
203+
Id: 20,
204+
Designation: "Berufsmaturität",
205+
Leadership: "John Doe", // Other leader (study course is ignored)
206+
StudentCount: 10,
207+
},
208+
];
174209
studyCoursesEntries = [
175210
{
176211
id: 10,
177-
designation: "Zoologie",
212+
designation: "Zentraler Gymnasialer Bildungsgang",
178213
studentCount: 42,
179214
detailLink: "link-to-event-detail-module/10",
180215
state: null,

src/app/events/services/events-state.service.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { StudyClass } from "src/app/shared/models/study-class.model";
1717
import { CoursesRestService } from "src/app/shared/services/courses-rest.service";
1818
import { EventsRestService } from "src/app/shared/services/events-rest.service";
1919
import { LoadingService } from "src/app/shared/services/loading-service";
20+
import { StorageService } from "src/app/shared/services/storage.service";
2021
import { StudyClassesRestService } from "src/app/shared/services/study-classes-rest.service";
2122
import { spread } from "src/app/shared/utils/function";
2223
import { hasRole } from "src/app/shared/utils/roles";
@@ -26,6 +27,7 @@ import {
2627
getCourseDesignation,
2728
getEventState,
2829
isRated,
30+
isStudyCourseLeader,
2931
} from "../utils/events";
3032

3133
export enum EventState {
@@ -96,6 +98,7 @@ export class EventsStateService {
9698
private eventsRestService: EventsRestService,
9799
private studyClassRestService: StudyClassesRestService,
98100
private loadingService: LoadingService,
101+
private storageService: StorageService,
99102
private translate: TranslateService,
100103
@Inject(SETTINGS) private settings: Settings,
101104
) {}
@@ -209,13 +212,16 @@ export class EventsStateService {
209212
private createFromStudyCourses(
210213
studyCourses: ReadonlyArray<Event>,
211214
): ReadonlyArray<EventEntry> {
212-
return studyCourses.map((studyCourse) => ({
213-
id: studyCourse.Id,
214-
designation: studyCourse.Designation,
215-
detailLink: this.buildLink(studyCourse.Id, "eventdetail"),
216-
studentCount: studyCourse.StudentCount,
217-
state: null,
218-
}));
215+
const tokenPayload = this.storageService.getPayload();
216+
return studyCourses
217+
.filter((studyCourse) => isStudyCourseLeader(tokenPayload, studyCourse)) // The user sees only the study courses he/she is leader of
218+
.map((studyCourse) => ({
219+
id: studyCourse.Id,
220+
designation: studyCourse.Designation,
221+
detailLink: this.buildLink(studyCourse.Id, "eventdetail"),
222+
studentCount: studyCourse.StudentCount,
223+
state: null,
224+
}));
219225
}
220226

221227
private createFromAssessments(

0 commit comments

Comments
 (0)