[Rt-commit] rt branch, 4.0/sanity-check-add-principal, created. rt-3.9.7-1166-g3cd6946
Thomas Sibley
trs at bestpractical.com
Tue Jan 4 13:05:51 EST 2011
The branch, 4.0/sanity-check-add-principal has been created
at 3cd6946bb89bfe062557751339cddb9540631335 (commit)
- Log -----------------------------------------------------------------
commit 3cd6946bb89bfe062557751339cddb9540631335
Author: Thomas Sibley <trs at bestpractical.com>
Date: Tue Jan 4 12:52:11 2011 -0500
Let the admin know if they try to add rights for an invalid principal
Show a warning message and disable the checkboxes. Note that for users
you must enter a Name if you ignore the autocompleter.
If the user types a custom value ignoring the autocompleter, than an
ajax check is done to the autocomplete helper to verify that the value
is valid. If a value is picked from the autocompleter, then the extra
ajax check is skipped.
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 74bf759..6fa55e9 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1689,8 +1689,8 @@ Set($OnlySearchActiveTicketsInSimpleSearch, 1);
=item C<$UserAutocompleteFields>
Specifies which fields of L<RT::User> to match against and how to match each
-field when autocompleting users. Valid match methods are LIKE, STARTSWITH, and
-ENDSWITH.
+field when autocompleting users. Valid match methods are LIKE, STARTSWITH,
+ENDSWITH, =, and !=.
Not all User fields are publically accessible and hence won't work for
autocomplete unless you override their accessibility using a local overlay or a
diff --git a/share/html/Admin/Elements/EditRights b/share/html/Admin/Elements/EditRights
index fb252e5..069afb9 100644
--- a/share/html/Admin/Elements/EditRights
+++ b/share/html/Admin/Elements/EditRights
@@ -103,19 +103,26 @@ for my $category (@$Principals) {
</%perl>
% if ( $AddPrincipal ) {
<li class="category"><&|/l, loc($AddPrincipal) &>Add [_1]</&></li>
- <li>
+ <li class="addprincipal">
<a href="#acl-AddPrincipal">
<input type="text" value=""
name="AddPrincipalForRights-<% lc $AddPrincipal %>"
id="AddPrincipalForRights-<% lc $AddPrincipal %>" />
-% if (lc $AddPrincipal eq 'group') {
<script type="text/javascript">
+ jQuery("#AddPrincipalForRights-<% lc $AddPrincipal %>").keyup(function(){
+ toggle_addprincipal_validity(this, true);
+ });
+
+% if (lc $AddPrincipal eq 'group') {
jQuery("#AddPrincipalForRights-<% lc $AddPrincipal %>").autocomplete({
source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Groups",
- select: update_addprincipal_title
+ select: addprincipal_onselect,
+ change: addprincipal_onchange
});
- </script>
% }
+ </script>
+% my $type = lc $AddPrincipal eq 'user' ? loc('username') : loc($AddPrincipal);
+ <div class="warning"><&|/l, $type &>Invalid [_1]</&></div>
</a>
</li>
% }
diff --git a/share/html/Helpers/Autocomplete/Groups b/share/html/Helpers/Autocomplete/Groups
index 6ef4a7c..cf17dd3 100644
--- a/share/html/Helpers/Autocomplete/Groups
+++ b/share/html/Helpers/Autocomplete/Groups
@@ -45,12 +45,14 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
+% $r->content_type('application/json');
<% JSON::to_json( \@suggestions ) |n %>
% $m->abort;
<%ARGS>
$term => undef
$max => 10
$exclude => ''
+$op => 'LIKE'
</%ARGS>
<%INIT>
require JSON;
@@ -63,12 +65,15 @@ my $CurrentUser = $session{'CurrentUser'};
# Require privileged users
$m->abort unless $CurrentUser->Privileged;
+# Sanity check the operator
+$op = 'LIKE' unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
+
my $groups = RT::Groups->new( $CurrentUser );
$groups->RowsPerPage( $max );
$groups->LimitToUserDefinedGroups();
$groups->Limit(
FIELD => 'Name',
- OPERATOR => 'LIKE',
+ OPERATOR => $op,
VALUE => $term,
);
diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index e270c75..e70e770 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -45,6 +45,7 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
+% $r->content_type('application/json');
<% JSON::to_json( \@suggestions ) |n %>
% $m->abort;
<%ARGS>
@@ -54,6 +55,7 @@ $delim => undef
$max => 10
$privileged => undef
$exclude => ''
+$op => undef
</%ARGS>
<%INIT>
require JSON;
@@ -87,6 +89,10 @@ $m->abort unless $CurrentUser->Privileged
my %fields = %{ RT->Config->Get('UserAutocompleteFields')
|| { EmailAddress => 1, Name => 1, RealName => 'LIKE' } };
+# If an operator is provided, check against only the returned field
+# using that operator
+%fields = ( $return => $op ) if $op;
+
my $users = RT::Users->new( $CurrentUser );
$users->RowsPerPage( $max );
@@ -94,7 +100,7 @@ $users->LimitToPrivileged() if $privileged;
while (my ($name, $op) = each %fields) {
$op = 'STARTSWITH'
- unless $op =~ /^(?:LIKE|(?:START|END)SWITH)$/i;
+ unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
$users->Limit(
FIELD => $name,
diff --git a/share/html/NoAuth/css/base/rights-editor.css b/share/html/NoAuth/css/base/rights-editor.css
index 43f82fa..4837b03 100644
--- a/share/html/NoAuth/css/base/rights-editor.css
+++ b/share/html/NoAuth/css/base/rights-editor.css
@@ -85,6 +85,11 @@ li.category ~ li.category {
margin-top: 1em;
}
+.rights-editor li.addprincipal .warning {
+ color: #a00;
+ display: none;
+}
+
/* Position the outer-most panel */
.rights-editor > .ui-tabs-panel {
position: static;
diff --git a/share/html/NoAuth/js/userautocomplete.js b/share/html/NoAuth/js/userautocomplete.js
index 3e7bad4..1e84b98 100644
--- a/share/html/NoAuth/js/userautocomplete.js
+++ b/share/html/NoAuth/js/userautocomplete.js
@@ -77,7 +77,8 @@ jQuery(function() {
if (inputName.match("AddPrincipalForRights-user")) {
queryargs.push("return=Name");
- options.select = update_addprincipal_title;
+ options.select = addprincipal_onselect;
+ options.change = addprincipal_onchange;
}
if (inputName.match(onlyPrivileged)) {
diff --git a/share/html/NoAuth/js/util.js b/share/html/NoAuth/js/util.js
index 16a0159..2125e4f 100644
--- a/share/html/NoAuth/js/util.js
+++ b/share/html/NoAuth/js/util.js
@@ -293,7 +293,50 @@ function ReplaceAllTextareas(encoded) {
}
};
-function update_addprincipal_title(ev, ui) {
+function toggle_addprincipal_validity(input, good) {
+ if (good) {
+ jQuery(input).nextAll(".warning").hide();
+ jQuery("#acl-AddPrincipal input[type=checkbox]").removeAttr("disabled");
+ } else {
+ jQuery(input).nextAll(".warning").show();
+ jQuery("#acl-AddPrincipal input[type=checkbox]").attr("disabled", "disabled");
+ }
+ update_addprincipal_title(input);
+}
+
+function update_addprincipal_title(input) {
var h3 = jQuery("#acl-AddPrincipal h3");
- h3.html( h3.text().replace(/: .+$/,'') + ": " + ui.item.value );
+ h3.html( h3.text().replace(/: .*$/,'') + ": " + jQuery(input).val() );
+}
+
+// when a value is selected from the autocompleter
+function addprincipal_onselect() {
+ toggle_addprincipal_validity(this, true);
}
+
+// when the input is actually changed, through typing or autocomplete
+function addprincipal_onchange(ev, ui) {
+ // if we have a ui.item, then they selected from autocomplete and it's good
+ if (!ui.item) {
+ var input = jQuery(this);
+ // Check using the same autocomplete source if the value typed would
+ // have been autocompleted and is therefore valid
+ jQuery.ajax({
+ url: input.autocomplete("option", "source"),
+ data: {
+ op: "=",
+ term: input.val()
+ },
+ dataType: "json",
+ success: function(data) {
+ if (data)
+ toggle_addprincipal_validity(input, data.length ? true : false );
+ else
+ toggle_addprincipal_validity(input, true);
+ }
+ });
+ } else {
+ toggle_addprincipal_validity(this, true);
+ }
+}
+
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list