You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by th...@apache.org on 2021/11/15 19:24:44 UTC

[solr] branch main updated: SOLR-15774: Avoid weird off-by-one errors with Angular's 'chosen' select box directive for the security and schema-designer screens in Admin UI (#404)

This is an automated email from the ASF dual-hosted git repository.

thelabdude pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 0f9e482  SOLR-15774: Avoid weird off-by-one errors with Angular's 'chosen' select box directive for the security and schema-designer screens in Admin UI (#404)
0f9e482 is described below

commit 0f9e4824155e7dc02c0f59faecf6492a18f63145
Author: Timothy Potter <th...@gmail.com>
AuthorDate: Mon Nov 15 12:24:38 2021 -0700

    SOLR-15774: Avoid weird off-by-one errors with Angular's 'chosen' select box directive for the security and schema-designer screens in Admin UI (#404)
---
 solr/CHANGES.txt                                     |  2 ++
 .../web/js/angular/controllers/schema-designer.js    |  9 +++++++++
 solr/webapp/web/js/angular/controllers/security.js   |  7 +++++++
 solr/webapp/web/partials/schema-designer.html        | 20 ++++++++++----------
 solr/webapp/web/partials/security.html               |  6 ++++--
 5 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ec34717..24f20bd 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -396,6 +396,8 @@ Other Changes
 
 * SOLR-15791: Remove remaining unused <admin/> clauses from solrconfigs. (Eric Pugh)
 
+* SOLR-15774: Avoid weird off-by-one errors with Angular's 'chosen' select box directive for the security and schema-designer screens in Admin UI (Timothy Potter)
+
 Bug Fixes
 ---------------------
 * SOLR-14546: Fix for a relatively hard to hit issue in OverseerTaskProcessor that could lead to out of order execution
diff --git a/solr/webapp/web/js/angular/controllers/schema-designer.js b/solr/webapp/web/js/angular/controllers/schema-designer.js
index 17a41b9..f81cc7b 100644
--- a/solr/webapp/web/js/angular/controllers/schema-designer.js
+++ b/solr/webapp/web/js/angular/controllers/schema-designer.js
@@ -18,6 +18,13 @@
 solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout, $cookies, $window, Constants, SchemaDesigner, Luke) {
   $scope.resetMenu("schema-designer", Constants.IS_ROOT_PAGE);
 
+  $scope.schemas = [];
+  $scope.publishedSchemas = [];
+  $scope.sampleDocIds = [];
+  $scope.sortableFields = [];
+  $scope.hlFields = [];
+  $scope.types = [];
+
   $scope.onWarning = function (warnMsg, warnDetails) {
     $scope.updateWorking = false;
     delete $scope.updateStatusMessage;
@@ -437,6 +444,8 @@ solrAdminApp.controller('SchemaDesignerController', function ($scope, $timeout,
 
     if (data.docIds) {
       $scope.sampleDocIds = data.docIds;
+    } else {
+      $scope.sampleDocIds = [];
     }
 
     // re-apply the filters on the updated schema
diff --git a/solr/webapp/web/js/angular/controllers/security.js b/solr/webapp/web/js/angular/controllers/security.js
index 8ee97e3..54e1d6c 100644
--- a/solr/webapp/web/js/angular/controllers/security.js
+++ b/solr/webapp/web/js/angular/controllers/security.js
@@ -19,6 +19,7 @@ solrAdminApp.controller('SecurityController', function ($scope, $timeout, $cooki
   $scope.resetMenu("security", Constants.IS_ROOT_PAGE);
 
   $scope.params = [];
+  $scope.filteredPredefinedPermissions = [];
 
   var strongPasswordRegex = /^(?=.*[0-9])(?=.*[!@#$%^&*\-_()[\]])[a-zA-Z0-9!@#$%^&*\-_()[\]]{8,30}$/;
 
@@ -769,6 +770,12 @@ solrAdminApp.controller('SecurityController', function ($scope, $timeout, $cooki
       var action = isAdd ? "set-permission" : "update-permission";
       var postBody = {};
       postBody[action] = setPermJson;
+
+      // if they have the "all" permission in the last position, then keep it there when adding a new permission
+      if (!setPermJson["before"] && !setPermJson["index"] && $scope.permissionsTable && $scope.permissionsTable.length > 0 && $scope.permissionsTable[$scope.permissionsTable.length-1].name === "all") {
+        setPermJson["before"] = $scope.permissionsTable.length;
+      }
+
       Security.post({path: "authorization"}, postBody, function (data) {
         var errorCause = checkError(data);
         if (errorCause != null) {
diff --git a/solr/webapp/web/partials/schema-designer.html b/solr/webapp/web/partials/schema-designer.html
index 35e691c..332ec50 100644
--- a/solr/webapp/web/partials/schema-designer.html
+++ b/solr/webapp/web/partials/schema-designer.html
@@ -25,10 +25,10 @@ limitations under the License.
       <div id="schema-selector">
         <div class="left">
           <select id="select-schema" placeholder-text-single="'Schema Selector'"
-                  chosen
+                chosen
                 ng-model="currentSchema"
                 ng-change="loadSchema()"
-                ng-options="schema for schema in schemas"></select>
+                ng-options="schema for schema in schemas"><option value=""></option></select>
           <button id="add" class="action" ng-click="showNewSchemaDialog()"><span>New Schema</span></button>
         </div>
         <div class="middle">
@@ -43,7 +43,7 @@ limitations under the License.
                 <input type="text" id="add_name" ng-model="newField.name" focus-when="showAddField" placeholder="enter a name"></p>
 
               <p class="clearfix" ng-show="adding=='field'"><label for="add_type">field type:</label>
-                <select chosen type="text" id="add_type" ng-model="newField.type" ng-options="type for type in types"></select>
+                <select chosen type="text" id="add_type" ng-model="newField.type" ng-options="type for type in types"><option value=""></option></select>
               </p>
               <p class="clearfix" ng-show="adding=='type'"><label for="add_class">class:</label>
                 <input type="text" id="add_class" ng-model="newField.class" placeholder="class name"></p>
@@ -446,7 +446,7 @@ limitations under the License.
             <select id="copy_schema"
                     ng-model="copyFrom"
                     chosen
-                    ng-options="schema for schema in publishedSchemas"></select><a ng-click="showHelp('copyFromHelp')"><img class="help-ico" src="img/ico/question-white.png"/></a>
+                    ng-options="schema for schema in publishedSchemas"><option value=""></option></select><a ng-click="showHelp('copyFromHelp')"><img class="help-ico" src="img/ico/question-white.png"/></a>
             <div id="copyFromHelp" class="help" ng-show="helpId === 'copyFromHelp'" escape-pressed="hideAll()">
               <div class="help">
               <p>Copy an existing Configset (schema, solrconfig.xml, and supporting files) as the starting point for your new schema. The <b>_default</b> Configset includes a schema with field guessing enabled, dynamic fields for common field types, and field types for analyzing text data for a number of common languages supported by Lucene. For more information about Configsets, see: <div class="help-anchor"><a target="_blank" href="https://solr.apache.org/guide/config-sets.html">Config [...]
@@ -535,10 +535,10 @@ limitations under the License.
               <select id="unique_key"
                       placeholder-text-single="'Unique Key Field'"
                       ng-model="updateUniqueKeyField"
-                      chosen
+                      chosen disable-search="true"
                       disabled
                       ng-change="updateUniqueKey()"
-                      ng-options="field for field in possibleIdFields"></select>
+                      ng-options="field for field in possibleIdFields"><option value=""></option></select>
             </div>
             <div class="field-form-right">
               <label for="languages">Language(s):</label>
@@ -646,7 +646,7 @@ limitations under the License.
                             id="field_type"
                             ng-model="selectedNode.type"
                             ng-change="onFieldTypeChanged(type)"
-                            ng-options="type for type in types"></select><a ng-click="showHelp('fieldTypeHelp')"><img class="help-ico" src="img/ico/question-white.png"/></a>
+                            ng-options="type for type in types"><option value=""></option></select><a ng-click="showHelp('fieldTypeHelp')"><img class="help-ico" src="img/ico/question-white.png"/></a>
                     <div id="fieldTypeHelp" class="help" ng-show="helpId === 'fieldTypeHelp'">
                       <div class="help-wider">
                         <p>The field type defines how Solr should interpret data in a field and how the field can be queried. The properties on each field are inherited from the field type if not explicitly overridden in the field definition. In many cases, it's preferable to choose a different field type instead of overriding the field properties. For example, there's typically a multi-valued version of each type, such as <b>strings</b> is the multi-valued version of the <b>string</b> t [...]
@@ -872,7 +872,7 @@ limitations under the License.
                     ng-model="sampleDocId"
                     chosen
                     ng-change="updateSampleDocId()"
-                    ng-options="id for id in sampleDocIds"></select>
+                    ng-options="id for id in sampleDocIds"><option value=""></option></select>
           </div>
           <div class="field-form">
             <label for="analysis_fieldvalue_index">{{selectedNode.name}}</label>
@@ -959,7 +959,7 @@ limitations under the License.
               </div>
               <div class="field-form-right">
                 <label for="sort" title="Sort field">Sort by</label>
-                <select chosen placeholder-text-single="'Select Field'" id="sort" ng-model="query.sortBy" ng-options="field for field in sortableFields"></select> asc <input type="radio" ng-model="query.sortDir" value="asc"/> desc <input type="radio" ng-model="query.sortDir" value="desc"/>
+                <select chosen placeholder-text-single="'Select Field'" id="sort" ng-model="query.sortBy" ng-options="field for field in sortableFields"><option value=""></option></select> asc <input type="radio" ng-model="query.sortDir" value="asc"/> desc <input type="radio" ng-model="query.sortDir" value="desc"/>
                 <a ng-click="showHelp('querySortHelp')"><img class="help-ico" src="img/ico/question-white.png"/></a>
                 <div id="querySortHelp" class="help" ng-show="helpId === 'querySortHelp'">
                   <div class="help">
@@ -985,7 +985,7 @@ limitations under the License.
               </div>
               <div class="field-form-right">
                 <label for="hl" title="Highlight">Highlighting</label>
-                <select chosen placeholder-text-single="'Select Field'" id="hl" ng-model="query.highlight" ng-options="field for field in hlFields"></select>
+                <select chosen placeholder-text-single="'Select Field'" id="hl" ng-model="query.highlight" ng-options="field for field in hlFields"><option value=""></option></select>
               </div>
               <div class="field-form-right">
                 <label for="rawParams" title="Additional params">Additional params</label>
diff --git a/solr/webapp/web/partials/security.html b/solr/webapp/web/partials/security.html
index ec4a6f6..490f40e 100644
--- a/solr/webapp/web/partials/security.html
+++ b/solr/webapp/web/partials/security.html
@@ -137,11 +137,13 @@ limitations under the License.
               </div>
             </div>
             <div id="perm-select"><label for="predefined">Predefined:</label><select id="predefined"
-                chosen
+                chosen disable-search="true" allow-single-deselect="true"
                 ng-change="onPredefinedChanged()"
                 ng-model="selectedPredefinedPermission"
                 ng-disabled="permDialogMode === 'edit'"
-                ng-options="p for p in filteredPredefinedPermissions"></select><span id="add_perm_custom">or Custom: <input ng-disabled="permDialogMode === 'edit'" ng-change="onPredefinedChanged()" type="text" id="add_perm_name" ng-model="upsertPerm.name"><a ng-click="showHelp('permDialogHelp')"><img class="help-ico" src="img/ico/question-white.png"/></a>
+                ng-options="p for p in filteredPredefinedPermissions">
+              <option value=""></option>
+            </select><span id="add_perm_custom">or Custom: <input ng-disabled="permDialogMode === 'edit'" ng-change="onPredefinedChanged()" type="text" id="add_perm_name" ng-model="upsertPerm.name"><a ng-click="showHelp('permDialogHelp')"><img class="help-ico" src="img/ico/question-white.png"/></a>
               <div id="permDialogHelp" class="help" ng-show="helpId === 'permDialogHelp'">
                 <div class="help-perm">
                   <p>Permissions allow you to grant access to protected resources to one or more roles. Solr provides a list of <b>predefined</b> permissions to cover common use cases, such as collection administration. Otherwise, you can define a <b>custom permission</b> for fine-grained control over the API path(s), collection(s), request method(s) and params.