55 lines
2.1 KiB
Dart
55 lines
2.1 KiB
Dart
import '../../../../../access/user_role.dart';
|
|
import '../../../../../api/marianumconnect/queries/timetable_get_element_week/timetable_element_type.dart';
|
|
import '../../capabilities/bloc/capabilities_state.dart';
|
|
import '../subject/timetable_subject.dart';
|
|
|
|
/// What the timetable view offers for a given subject. Resolved in one place
|
|
/// so the view never branches on roles or subject types itself.
|
|
class TimetablePolicy {
|
|
final bool canManageCustomEvents;
|
|
final bool canEditSubjectColors;
|
|
final bool showClassInsteadOfTeacher;
|
|
final bool canOpenForeign;
|
|
|
|
const TimetablePolicy({
|
|
required this.canManageCustomEvents,
|
|
required this.canEditSubjectColors,
|
|
required this.showClassInsteadOfTeacher,
|
|
required this.canOpenForeign,
|
|
});
|
|
|
|
static TimetablePolicy resolve({
|
|
required TimetableSubject subject,
|
|
required CapabilitiesState capabilities,
|
|
}) => switch (subject) {
|
|
OwnTimetable() => TimetablePolicy(
|
|
canManageCustomEvents: true,
|
|
canEditSubjectColors: true,
|
|
showClassInsteadOfTeacher: capabilities.role == UserRole.teacher,
|
|
canOpenForeign: capabilities.viewForeignTimetables,
|
|
),
|
|
// Subject colours are the viewer's own, global setting; editing them from
|
|
// a foreign plan would not refresh that plan, so it is not offered there.
|
|
ElementTimetable(:final element) => TimetablePolicy(
|
|
canManageCustomEvents: false,
|
|
canEditSubjectColors: false,
|
|
showClassInsteadOfTeacher: element.type == TimetableElementType.teacher,
|
|
canOpenForeign: capabilities.viewForeignTimetables,
|
|
),
|
|
// Custom events are the child's private data; subject colours are the
|
|
// guardian's own and apply to this (primary) plan directly.
|
|
ChildTimetable() => TimetablePolicy(
|
|
canManageCustomEvents: false,
|
|
canEditSubjectColors: true,
|
|
showClassInsteadOfTeacher: false,
|
|
canOpenForeign: capabilities.viewForeignTimetables,
|
|
),
|
|
NoTimetable() => const TimetablePolicy(
|
|
canManageCustomEvents: false,
|
|
canEditSubjectColors: false,
|
|
showClassInsteadOfTeacher: false,
|
|
canOpenForeign: false,
|
|
),
|
|
};
|
|
}
|