Page MenuHomePhabricator

Provide an Editor extension point for transaction validation
ClosedPublic

Authored by epriestley on Jan 27 2019, 6:31 PM.
Tags
None
Referenced Files
F18807117: D20041.id47853.diff
Sat, Oct 18, 11:14 PM
F18772777: D20041.id.diff
Thu, Oct 9, 4:40 AM
F18769396: D20041.diff
Wed, Oct 8, 7:28 AM
F18765756: D20041.id47854.diff
Tue, Oct 7, 12:50 PM
F18651334: D20041.diff
Sun, Sep 21, 3:56 AM
F18646230: D20041.id.diff
Sep 19 2025, 9:45 AM
F18591562: D20041.diff
Sep 12 2025, 9:33 AM
F18566932: D20041.id.diff
Sep 9 2025, 3:01 PM
Subscribers
None

Details

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:

<?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;
  }

}

Screen Shot 2019-01-27 at 10.28.48 AM.png (1×1 px, 217 KB)

Diff Detail

Repository
rP Phabricator
Branch
subtype2
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 21708
Build 29617: Run Core Tests
Build 29616: arc lint + arc unit