Skip to content

Commit

Permalink
Add Nobody as a possible owner in asset autocompletion
Browse files Browse the repository at this point in the history
Unlike with tickets, the owner autocompletion for assets was not
returning Nobody.

This commit updates the owner autocompletion logic to include Nobody for
assets as well.
  • Loading branch information
richieri-bps committed Jul 29, 2024
1 parent 7ad2215 commit 1a81dc9
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 8 deletions.
8 changes: 8 additions & 0 deletions share/html/Asset/Elements/AssetSearchPeople
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@
<% RT::Asset->LabelForRole($role) %>
</div>
<div class="value col-4">
% if ($role eq 'Owner') {
<& /Elements/SelectOwnerAutocomplete,
Name => "Role.$role",
Objects => [$CatalogObj],
Default => $ARGS{"Role.$role"},
&>
% } else {
<input class="form-control" type="text" id="Role.<% $role %>" name="Role.<% $role %>"
data-autocomplete="Users" value="<% $ARGS{"Role.$role"} || '' %>"
/>
% }
</div>
<div class="label col-2">
<&|/l&>not</&>
Expand Down
9 changes: 9 additions & 0 deletions share/html/Asset/Elements/EditCatalogPeople
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ $Object
% for my $role ($Object->Roles( ACLOnly => 0 )) {
<div class="role-<% CSSClass($role) %> role">
<h3><% $Object->LabelForRole($role) %></h3>
% if ($role eq 'Owner') {
<& /Elements/SelectOwnerAutocomplete,
Name => "SetRoleMember-".$role,
Objects => [$Object],
Default => ($Object->RoleGroup($role) ?
$Object->RoleGroup($role)->UserMembersObj->First->Id : undef),
&>
% } else {
<& EditRoleMembers, Object => $Object, Role => $role &>
% }
</div>
% }

Expand Down
8 changes: 8 additions & 0 deletions share/html/Asset/Elements/EditPeople
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@
% my $custom_role = $object->CustomRoleObj($role);
% my $hint = $custom_role ? $custom_role->EntryHint : '';
<&| /Elements/LabeledValue, Label => $object->LabelForRole($role), Class => "asset-people-".CSSClass($role), LabelTooltip => $hint &>
% if ($role eq 'Owner') {
<& /Elements/SelectOwnerAutocomplete,
Name => $role,
Objects => [$object],
Default => $ARGS{$role},
&>
% } else {
<& /Elements/EmailInput, Name => $role, Size => undef, Default => $ARGS{$role}, Autocomplete => 1, ($object->Role($role)->{Single} ? () : (AutocompleteType => 'Principals', AutocompleteMultiple => 1)) &>
% }
</&>
% }

Expand Down
9 changes: 9 additions & 0 deletions share/html/Asset/Elements/EditPeopleInline
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@
% for my $role ($AssetObj->Roles( ACLOnly => 0 )) {
<div class="role-<% CSSClass($role) %> role">
<h5 class="mt-2"><% $AssetObj->LabelForRole($role) %></h5>
% if ($role eq 'Owner') {
<& /Elements/SelectOwnerAutocomplete,
Name => "SetRoleMember-".$role,
Objects => [$AssetObj],
Default => ($AssetObj->RoleGroup($role) ?
$AssetObj->RoleGroup($role)->UserMembersObj->First->Id : undef),
&>
% } else {
<& EditRoleMembers, Object => $AssetObj, Role => $role &>
% }
</div>
% }

Expand Down
8 changes: 8 additions & 0 deletions share/html/Asset/Search/Bulk.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@
<div class="form-row">
<div class="col-6">
<&| /Elements/LabeledValue, Label => RT::Asset->LabelForRole($rname) &>
% if ( $rname eq 'Owner' ) {
<& /Elements/SelectOwnerAutocomplete,
Name => $input,
Objects => [$catalog_obj],
Default => $ARGS{ $input },
&>
% } else {
<input class="form-control" type="text" value="<% $ARGS{ $input } || '' %>" name="<% $input %>" id="<% $input %>" data-autocomplete="Users" data-autocomplete-return="Name" />
% }
</&>
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion share/html/Elements/ColumnMap
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,14 @@ if ($RecordClass->DOES("RT::Record::Role::Roles")) {
my $group = $_[0]->RoleGroup($role);
my $user = $group->UserMembersObj()->First || RT->Nobody;
my $user_name = $m->interp->apply_escapes( $user->Name, 'h' );
return \qq{<input class="form-control" type="text" value="$user_name" name="SetRoleMember-$role" data-autocomplete="Users" data-autocomplete-return="Name" />};
if ( $role eq 'Owner' ) {
return \( $m->scomp( "/Elements/SelectOwnerAutocomplete",
Name => "SetRoleMember-$role",
Objects => [$_[0]],
Default => $user->Id ) );
} else {
return \qq{<input class="form-control" type="text" value="$user_name" name="SetRoleMember-$role" data-autocomplete="Users" data-autocomplete-return="Name" />};
}
}
else {
return undef;
Expand Down
16 changes: 9 additions & 7 deletions share/html/Helpers/Autocomplete/Owners
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ $max //= 10;

# Turn RT::Ticket-1|RT::Queue-2 into ['RT::Ticket', 1], ['RT::Queue', 2]
foreach my $spec (map { [split /\-/, $_, 2] } split /\|/, $limit) {
next unless $spec->[0] =~ /^RT::(Ticket|Queue)$/;
next unless $spec->[0] =~ /^RT::(Ticket|Queue|Catalog|Asset)$/;

my $object = $spec->[0]->new( $session{'CurrentUser'} );

Expand All @@ -100,12 +100,14 @@ foreach my $spec (map { [split /\-/, $_, 2] } split /\|/, $limit) {
$m->callback( CallbackName => 'ModifyOwnerAutocompleteSearch',
ARGSRef => \%ARGS, Users => \$Users );

$Users->WhoHaveRight(
Right => 'OwnTicket',
Object => $object,
IncludeSystemRights => 1,
IncludeSuperusers => $isSU
);
if ( $object->isa('RT::Ticket') || $object->isa('RT::Queue') ) {
$Users->WhoHaveRight(
Right => 'OwnTicket',
Object => $object,
IncludeSystemRights => 1,
IncludeSuperusers => $isSU
);
}

while ( my $User = $Users->Next() ) {
next if $user_uniq_hash{ $User->Id };
Expand Down

0 comments on commit 1a81dc9

Please sign in to comment.