1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-24 07:42:40 +01:00
phorge-phorge/src/applications/transactions
epriestley f7e8fa0764 Provide an Editor extension point for transaction validation
Summary:
Depends on D20040. Ref T13242. See PHI1039. See PHI873. Two reasonable cases have arisen recently where extending validation rules would help solve problems.

We can do this in a pretty straightforward way with a standard extension pattern.

Test Plan:
Used this extension to keep ducks away from projects:

```lang=php
<?php

final class NoDucksEditorExtension
  extends PhabricatorEditorExtension {

  const EXTENSIONKEY = 'no.ducks';

  public function getExtensionName() {
    return pht('No Ducks!');
  }

  public function supportsObject(
    PhabricatorApplicationTransactionEditor $editor,
    PhabricatorApplicationTransactionInterface $object) {
    return ($object instanceof PhabricatorProject);
  }

  public function validateTransactions($object, array $xactions) {
    $errors = array();

    $name_type = PhabricatorProjectNameTransaction::TRANSACTIONTYPE;

    $old_value = $object->getName();
    foreach ($xactions as $xaction) {
      if ($xaction->getTransactionType() !== $name_type) {
        continue;
      }

      $new_value = $xaction->getNewValue();
      if ($old_value === $new_value) {
        continue;
      }

      if (preg_match('/duck/i', $new_value)) {
        $errors[] = $this->newInvalidTransactionError(
          $xaction,
          pht('Project names must not contain the substring "duck".'));
      }
    }

    return $errors;
  }

}
```

{F6162585}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13242

Differential Revision: https://secure.phabricator.com/D20041
2019-01-30 06:18:41 -08:00
..
application Allow EditEngine forms for objects which support subtyping to have a subtype configured 2017-03-02 04:18:06 -08:00
bulk In "bin/bulk export", require "--output <path>" by default 2018-10-11 13:35:16 -07:00
commentaction When you "Request Review" of a draft revision, change the button text from "Submit Quietly" to "Publish Revision" 2018-11-15 20:50:21 -08:00
conduit Raise a tailored error when calling "transaction.search" with empty "phids" constraint 2018-08-03 14:29:36 -07:00
constants Allow any transaction group to be signed with a one-shot "Sign With MFA" action 2018-12-28 00:09:30 -08:00
controller Remove "willRenderTimeline()" from ApplicationTransactionInterface 2018-12-20 14:55:07 -08:00
data Don't re-mention users for comment edits 2016-06-13 13:57:59 -07:00
draft Show yellow "draft" bubble in Audit 2017-01-16 10:28:59 -08:00
edges Add "Mute/Unmute" for subscribable objects 2018-02-08 11:06:22 -08:00
editengine Always require MFA to edit contact numbers 2019-01-23 14:19:56 -08:00
editfield Bring Duo MFA upstream 2019-01-28 18:26:45 -08:00
editor Provide an Editor extension point for transaction validation 2019-01-30 06:18:41 -08:00
edittype Accept null via conduit.edit to unassign a task 2018-01-31 15:33:52 -08:00
engine Remove "willRenderTimeline()" from ApplicationTransactionInterface 2018-12-20 14:55:07 -08:00
engineextension Provide an Editor extension point for transaction validation 2019-01-30 06:18:41 -08:00
error Allow users to unset "Editor", tailor short error messages properly on settings forms 2016-06-05 14:03:02 -07:00
exception Raise a warning when mentioning a user in a comment on a draft revision 2018-03-12 17:03:14 -07:00
feed Separate "feed" and "notifications" better, allow stories to appear in notifications only 2018-12-10 16:02:43 -08:00
interface Remove "getApplicationTransactionObject()" from ApplicationTransactionInterface 2018-12-20 15:16:19 -08:00
phid Allow ApplicationEditor forms to be reconfigured 2015-11-10 10:24:40 -08:00
query Allow "maniphest.subtypes" to configure which options are presented by "Create Subtask" 2018-12-10 14:58:28 -08:00
replyhandler Remove "getApplicationTransactionObject()" from ApplicationTransactionInterface 2018-12-20 15:16:19 -08:00
response Pass timeline view data to comment previews, restoring Differential comment previews 2019-01-03 13:06:54 -08:00
storage Convert "Rename User" from session MFA to one-shot MFA 2019-01-28 09:41:10 -08:00
typeahead Don't allow forms which can't create objects to be added to profile menus 2017-02-16 15:45:11 -08:00
view Pass timeline view data to comment previews, restoring Differential comment previews 2019-01-03 13:06:54 -08:00
worker Cache user notification and message counts 2016-06-05 08:52:43 -07:00
xaction Modularize application transactions in Paste, mostly 2016-06-14 06:13:28 -07:00