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

Only show study courses with leadership on current events #723 #749

Merged
merged 1 commit into from
Dec 5, 2024
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
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
Loading