20after4 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/181780

Change subject: Use tokenizer in the rule editor ui. Cleanup code slightly.
......................................................................

Use tokenizer in the rule editor ui.
Cleanup code slightly.

Change-Id: Ied377189ce682d83df373ce54f19264f42c5d853
---
M PhabricatorPolicyRuleTaskSubscribers.php
M SecurityPolicyListener.php
M WMFSecurityPolicy.php
3 files changed, 62 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions 
refs/changes/80/181780/1

diff --git a/PhabricatorPolicyRuleTaskSubscribers.php 
b/PhabricatorPolicyRuleTaskSubscribers.php
index 1ae4cf9..7139614 100644
--- a/PhabricatorPolicyRuleTaskSubscribers.php
+++ b/PhabricatorPolicyRuleTaskSubscribers.php
@@ -11,9 +11,7 @@
 
   public function willApplyRules(PhabricatorUser $viewer, array $values) {
     $values = array_unique(array_filter(array_mergev($values)));
-    if (!$values) {
-      return;
-    }
+
     $this->subscribed_to = array();
     $viewer_phid = $viewer->getPHID();
     $tasks = id(new ManiphestTaskQuery())
@@ -40,7 +38,17 @@
   }
 
   public function getValueControlType() {
-    return self::CONTROL_TYPE_TEXT;
+    return self::CONTROL_TYPE_TOKENIZER;
+  }
+
+  public function getValueControlTemplate() {
+    $datasource = new PhabricatorTypeaheadMonogramDatasource();
+
+    return array(
+      'markup' => new AphrontTokenizerTemplateView(),
+      'uri' => $datasource->getDatasourceURI(),
+      'placeholder' => $datasource->getPlaceholderText(),
+    );
   }
 
   public function getRuleOrder() {
@@ -51,6 +59,7 @@
     if (!is_array($value)) {
       $value = array($value);
     }
+
     $handles = id(new PhabricatorHandleQuery())
       ->setViewer($viewer)
       ->withPHIDs($value)
@@ -60,7 +69,11 @@
   }
 
   public function ruleHasEffect($value) {
-    return !empty($value);
+    return true;
   }
 
+  public function getValueForStorage($value) {
+    PhutilTypeSpec::newFromString('list<string>')->check($value);
+    return array_values($value);
+  }
 }
diff --git a/SecurityPolicyListener.php b/SecurityPolicyListener.php
index 54970ad..c21c95e 100644
--- a/SecurityPolicyListener.php
+++ b/SecurityPolicyListener.php
@@ -19,6 +19,7 @@
     if ($is_new) {
       $security_setting = WMFSecurityPolicy::getSecurityFieldValue($task);
       $project = WMFSecurityPolicy::getSecurityProjectForTask($task);
+      $project_phids = array($project->getPHID() => $project->getPHID());
 
       if ($security_setting == 'ops-access-request') {
         // ops access requests don't modify the request task, instead
@@ -26,9 +27,13 @@
         // any returned transactions get applied to the parent task to record
         // the association with the subtask.
         $trans = WMFSecurityPolicy::createPrivateSubtask($task);
+        $trans[$type_edge] = id(new ManiphestTransaction())
+            ->setTransactionType($type_edge)
+            ->setMetadataValue('edge:type',$type_hasproj)
+            ->setNewValue(array('+' => $project_phids));
       } else if ($project) {
         // other secure tasks get standard policies applied:
-        $project_phids = array($project->getPHID() => $project->getPHID());
+
         $edit_policy = WMFSecurityPolicy::createCustomPolicy(
           $task,
           $task->getAuthorPHID(),
diff --git a/WMFSecurityPolicy.php b/WMFSecurityPolicy.php
index eab1778..d7eee93 100644
--- a/WMFSecurityPolicy.php
+++ b/WMFSecurityPolicy.php
@@ -32,6 +32,24 @@
   }
 
   /**
+   * get the security project for a task (based on the security_topic field)
+   * @return PhabricatorProject|null the project, or null if security_topic
+   *                                 is set to none
+   */
+  public static function getSecurityProjectForTask($task) {
+    switch (WMFSecurityPolicy::getSecurityFieldValue($task)) {
+      case 'sensitive':
+        return WMFSecurityPolicy::getProjectByName('operations');
+      case 'security-bug':
+        return WMFSecurityPolicy::getProjectByName('security');
+      case 'ops-access-request':
+        return WMFSecurityPolicy::getProjectByName('Ops-Access-Requests');
+      default:
+        return false;
+    }
+  }
+
+  /**
    * Creates a custom policy for the given task having the following 
properties:
    *
    * 1. The users listed in $user_phids can view/edit
@@ -42,7 +60,14 @@
    * @param array(PHID) $user_phids
    * @param array(PHID) $project_phids
    */
-  public static function createCustomPolicy($task, $user_phids, 
$project_phids, $include_subscribers=true, $old_policy=null) {
+  public static function createCustomPolicy(
+    $task,
+    $user_phids,
+    $project_phids,
+    $include_subscribers=true,
+    $old_policy=null,
+    $save=true) {
+
     if (!is_array($user_phids)) {
       $user_phids = array($user_phids);
     }
@@ -79,8 +104,9 @@
 
     $policy
       ->setRules($rules)
-      ->setDefaultAction(PhabricatorPolicy::ACTION_DENY)
-      ->save();
+      ->setDefaultAction(PhabricatorPolicy::ACTION_DENY);
+    if ($save)
+      $policy->save();
     return $policy;
   }
 
@@ -113,27 +139,16 @@
     return $field_value;
   }
 
-  /**
-   * get the security project for a task (based on the security_topic field)
-   * @return PhabricatorProject|null the project, or null if security_topic
-   *                                 is set to none
-   */
-  public static function getSecurityProjectForTask($task) {
-    switch (WMFSecurityPolicy::getSecurityFieldValue($task)) {
-      case 'sensitive':
-        return WMFSecurityPolicy::getProjectByName('operations');
-      case 'security-bug':
-        return WMFSecurityPolicy::getProjectByName('security');
-      case 'ops-access-request':
-        return WMFSecurityPolicy::getProjectByName('operations');
-      default:
-        return false;
-    }
-  }
 
   public static function createPrivateSubtask($task) {
-    $project = self::getProjectByName('operations');
-    $project_phids = array($project->getPHID() => $project->getPHID());
+    $ops = self::getProjectByName('operations');
+    $ops_phids = array($ops->getPHID() => $ops->getPHID());
+    $project = self::getProjectByName('Ops-Access-Requests');
+    $project_phids = array(
+      $project->getPHID(),$ops->getPHID()
+    );
+
+
     $viewer = PhabricatorUser::getOmnipotentUser();
 
     $transactions = array();
@@ -153,7 +168,7 @@
         ->withUsernames(array('admin'))
         ->executeOne();
 
-      $policy = createCustomPolicy($task, array(), $project_phids, true);
+      $policy = createCustomPolicy($task, array(), $ops_phids, true);
 
       $oid = $task->getID();
 

-- 
To view, visit https://gerrit.wikimedia.org/r/181780
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ied377189ce682d83df373ce54f19264f42c5d853
Gerrit-PatchSet: 1
Gerrit-Project: phabricator/extensions
Gerrit-Branch: master
Gerrit-Owner: 20after4 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to