1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Calendar event edit view should validate that start time preceeds end time

Summary: Closes T8023, Calendar event edit view should validate that start time preceeds end time .

Test Plan: Create Calendar event, add details, make end time be earlier than start time, try to save, get error, make sure all previously entered details are populated correctly.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T8023

Differential Revision: https://secure.phabricator.com/D12656
This commit is contained in:
lkassianik 2015-05-02 15:28:04 -07:00
parent 52a461a75c
commit 25b1fb1de2
5 changed files with 42 additions and 18 deletions

View file

@ -175,6 +175,34 @@ final class PhabricatorCalendarEventEditor
return parent::applyCustomExternalTransaction($object, $xaction);
}
protected function validateAllTransactions(
PhabricatorLiskDAO $object,
array $xactions) {
$start_date_xaction = PhabricatorCalendarEventTransaction::TYPE_START_DATE;
$end_date_xaction = PhabricatorCalendarEventTransaction::TYPE_END_DATE;
$start_date = $object->getDateFrom();
$end_date = $object->getDateTo();
$errors = array();
foreach ($xactions as $xaction) {
if ($xaction->getTransactionType() == $start_date_xaction) {
$start_date = $xaction->getNewValue()->getEpoch();
} else if ($xaction->getTransactionType() == $end_date_xaction) {
$end_date = $xaction->getNewValue()->getEpoch();
}
}
if ($start_date > $end_date) {
$type = PhabricatorCalendarEventTransaction::TYPE_END_DATE;
$errors[] = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Invalid'),
pht('End date must be after start date.'),
null);
}
return $errors;
}
protected function validateTransaction(
PhabricatorLiskDAO $object,
$type,

View file

@ -1,3 +0,0 @@
<?php
final class PhabricatorCalendarEventInvalidEpochException extends Exception {}

View file

@ -42,10 +42,6 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
}
public function save() {
if ($this->getDateTo() < $this->getDateFrom()) {
throw new PhabricatorCalendarEventInvalidEpochException();
}
if (!$this->mailKey) {
$this->mailKey = Filesystem::readRandomCharacters(20);
}

View file

@ -50,17 +50,13 @@ final class UserAddStatusConduitAPIMethod extends UserConduitAPIMethod {
$status = $request->getValue('status');
$description = $request->getValue('description', '');
try {
id(new PhabricatorCalendarEvent())
->setUserPHID($user_phid)
->setDateFrom($from)
->setDateTo($to)
->setTextStatus($status)
->setDescription($description)
->save();
} catch (PhabricatorCalendarEventInvalidEpochException $e) {
throw new ConduitException('ERR-BAD-EPOCH');
}
id(new PhabricatorCalendarEvent())
->setUserPHID($user_phid)
->setDateFrom($from)
->setDateTo($to)
->setTextStatus($status)
->setDescription($description)
->save();
}
}

View file

@ -639,6 +639,7 @@ abstract class PhabricatorApplicationTransactionEditor
$errors[] = $this->validateTransaction($object, $type, $type_xactions);
}
$errors[] = $this->validateAllTransactions($object, $xactions);
$errors = array_mergev($errors);
$continue_on_missing = $this->getContinueOnMissingFields();
@ -1824,6 +1825,12 @@ abstract class PhabricatorApplicationTransactionEditor
return clone $object;
}
protected function validateAllTransactions(
PhabricatorLiskDAO $object,
array $xactions) {
return array();
}
/**
* Check for a missing text field.
*