mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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:
parent
52a461a75c
commit
25b1fb1de2
5 changed files with 42 additions and 18 deletions
|
@ -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,
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarEventInvalidEpochException extends Exception {}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue