diff --git a/src/applications/legalpad/xaction/LegalpadDocumentRequireSignatureTransaction.php b/src/applications/legalpad/xaction/LegalpadDocumentRequireSignatureTransaction.php index 3819f38a70..9932baab80 100644 --- a/src/applications/legalpad/xaction/LegalpadDocumentRequireSignatureTransaction.php +++ b/src/applications/legalpad/xaction/LegalpadDocumentRequireSignatureTransaction.php @@ -1,72 +1,83 @@ getRequireSignature(); } public function applyInternalEffects($object, $value) { $object->setRequireSignature((int)$value); } public function applyExternalEffects($object, $value) { if ($value) { $session = new PhabricatorAuthSession(); queryfx( $session->establishConnection('w'), 'UPDATE %T SET signedLegalpadDocuments = 0', $session->getTableName()); } } public function getTitle() { $new = $this->getNewValue(); if ($new) { return pht( '%s set the document to require signatures.', $this->renderAuthor()); } else { return pht( '%s set the document to not require signatures.', $this->renderAuthor()); } } public function getTitleForFeed() { $new = $this->getNewValue(); if ($new) { return pht( '%s set the document %s to require signatures.', $this->renderAuthor(), $this->renderObject()); } else { return pht( '%s set the document %s to not require signatures.', $this->renderAuthor(), $this->renderObject()); } } public function validateTransactions($object, array $xactions) { $errors = array(); - $is_admin = $this->getActor()->getIsAdmin(); + $old = (bool)$object->getRequireSignature(); + foreach ($xactions as $xaction) { + $new = (bool)$xaction->getNewValue(); - if (!$is_admin) { - $errors[] = $this->newInvalidError( - pht('Only admins may require signature.')); + if ($old === $new) { + continue; + } + + $is_admin = $this->getActor()->getIsAdmin(); + if (!$is_admin) { + $errors[] = $this->newInvalidError( + pht( + 'Only administrators may change whether a document '. + 'requires a signature.'), + $xaction); + } } return $errors; } public function getIcon() { return 'fa-pencil-square'; } }