diff --git a/lib/models/ConsultationSlot.php b/lib/models/ConsultationSlot.php index f79568d3aea2031b0b754e7e1af0535cc7b481fd..5a59208c8a409acaf28c1f444fa72dba39b5aeff 100644 --- a/lib/models/ConsultationSlot.php +++ b/lib/models/ConsultationSlot.php @@ -25,6 +25,8 @@ */ class ConsultationSlot extends SimpleORMap { + private const EVENT_PREFIX = 'Stud.IP-Consultation-Event#'; + /** * Configures the model. * @param array $config Configuration @@ -165,6 +167,14 @@ class ConsultationSlot extends SimpleORMap ]); } + /** + * Returns whether the given event is an event for a consultation slot. + */ + public static function isSlotEvent(CalendarDate $event): bool + { + return str_starts_with($event->unique_id, self::EVENT_PREFIX); + } + /** * Returns whether this slot is occupied (by a given user). */ @@ -233,10 +243,9 @@ class ConsultationSlot extends SimpleORMap * @param User $user [description] * @return string unique event id */ - protected function createEventId(User $user) + protected function createEventId(User $user): string { - $rand_id = md5(uniqid(self::class, true)); - return "Termin{$rand_id}-{$user->id}"; + return self::EVENT_PREFIX . "{$this->id}:{$user->id}"; } /** diff --git a/lib/models/calendar/CalendarDate.php b/lib/models/calendar/CalendarDate.php index 0318dab5ef8de330a130938f30f954102b5e2ffe..fc31d52f9122ea2ebb2ec0028ce77b3f036085d3 100644 --- a/lib/models/calendar/CalendarDate.php +++ b/lib/models/calendar/CalendarDate.php @@ -189,6 +189,15 @@ class CalendarDate extends SimpleORMap implements PrivacyObject public function isWritable(string $range_id) { + if (ConsultationSlot::isSlotEvent($this)) { + return false; + } + + if ($this->author_id === $range_id) { + //The author may always modify one of their dates: + return true; + } + if (CalendarDateAssignment::exists([$range_id, $this->id])) { //The date is in the calendar of the user/course //and therefore, the user or course administrator (tutor, dozent) diff --git a/lib/models/calendar/CalendarDateAssignment.php b/lib/models/calendar/CalendarDateAssignment.php index e0e2135452d066260cac2000604e3bef6d33f6b1..53d54d86608ec284453c473e30ed58773a4baced 100644 --- a/lib/models/calendar/CalendarDateAssignment.php +++ b/lib/models/calendar/CalendarDateAssignment.php @@ -521,10 +521,6 @@ class CalendarDateAssignment extends SimpleORMap implements Event public function isWritable(string $user_id): bool { - if ($this->calendar_date->author_id === $user_id) { - //The author may always modify one of their dates: - return true; - } if ($this->calendar_date->isWritable($user_id)) { //The date is writable. return true;