[Rt-commit] rt branch, 4.6/core-customrole-visibility, created. rt-4.4.4-568-g092038f9af
Blaine Motsinger
blaine at bestpractical.com
Tue Dec 24 17:12:37 EST 2019
The branch, 4.6/core-customrole-visibility has been created
at 092038f9aff81387d85d0f4d04fae1a36e2130c7 (commit)
- Log -----------------------------------------------------------------
commit 092038f9aff81387d85d0f4d04fae1a36e2130c7
Author: Blaine Motsinger <blaine at bestpractical.com>
Date: Tue Dec 24 12:35:06 2019 -0600
Core RT-Extension-CustomRole-Visibility
diff --git a/lib/RT/CustomRole.pm b/lib/RT/CustomRole.pm
index 5d1bfb3d60..230ecbae45 100644
--- a/lib/RT/CustomRole.pm
+++ b/lib/RT/CustomRole.pm
@@ -704,6 +704,34 @@ sub SetDisabled {
}
}
+sub HiddenForURLs {
+ my $self = shift;
+ my $attr = $self->FirstAttribute('HiddenForURLs');
+ return {} if !$attr;
+ return $attr->Content;
+}
+
+sub SetHiddenForURLs {
+ my $self = shift;
+ my $hidden = shift;
+
+ return $self->SetAttribute(
+ Name => 'HiddenForURLs',
+ Content => $hidden,
+ );
+}
+
+sub IsHiddenForURL {
+ my $self = shift;
+ my $url = shift;
+
+ my $current_url = $HTML::Mason::Commands::r->path_info;
+ $current_url =~ s!/{2,}!/!g;
+
+ $url //= $current_url;
+ return $self->HiddenForURLs->{$url};
+}
+
sub _CoreAccessible {
{
id =>
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index afce228867..b93edc1f9b 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -1178,6 +1178,11 @@ sub _BuildAdminMenu {
if ( $obj and $obj->id ) {
$page->child( basics => title => loc('Basics'), path => "/Admin/CustomRoles/Modify.html?id=".$id );
$page->child( 'applies-to' => title => loc('Applies to'), path => "/Admin/CustomRoles/Objects.html?id=" . $id );
+
+ if ( $current_user->HasRight( Object => $obj, Right => 'AdminCustomRoles' ) ) {
+ $page->child( 'visibility' => title => loc('Visibility'), path => "/Admin/CustomRoles/Visibility.html?id=" . $id );
+ }
+
}
}
}
diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index dc286a756b..457ded3dc7 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -1325,6 +1325,20 @@ sub SetDefaultDueIn {
);
}
+sub HiddenCustomRoleIDsForURL {
+ my $self = shift;
+ my $url = shift;
+
+ my $roles = $self->CustomRoles;
+ my @ids;
+
+ while (my $role = $roles->Next) {
+ push @ids, $role->Id if $role->IsHiddenForURL($url);
+ }
+
+ return @ids;
+}
+
RT::Base->_ImportOverlays();
1;
diff --git a/share/html/Admin/CustomRoles/Visibility.html b/share/html/Admin/CustomRoles/Visibility.html
new file mode 100644
index 0000000000..f739866dd3
--- /dev/null
+++ b/share/html/Admin/CustomRoles/Visibility.html
@@ -0,0 +1,127 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<& /Admin/Elements/Header, Title => $title &>
+<& /Elements/Tabs &>
+<& /Elements/ListActions &>
+
+<form action="Visibility.html" method="post" name="Visibility">
+<input type="hidden" class="hidden" name="id" value="<% $id %>" />
+
+<h2><&|/l, $role->Name &>Visibility for [_1]</&></h2>
+<table cellspacing=10>
+% for (@pages) {
+% my ($label, $url) = @$_;
+ <tr>
+ <td align="left"><% $label %></td>
+ <td><label><input type="radio" class="radio" name="hide-<% $url %>" value="0" <% !$hidden{$url} ? qq[checked="checked"] : qq[] |n %>> <&|/l&>show</&></label></td>
+ <td><label><input type="radio" class="radio" name="hide-<% $url %>" value="1" <% $hidden{$url} ? qq[checked="checked"] : qq[] |n %>> <&|/l&>hide</&></label></td>
+ </tr>
+% }
+</table>
+
+<& /Elements/Submit, Name => 'Update' &>
+
+</form>
+
+<%ARGS>
+$id => undef
+$Update => 0
+</%ARGS>
+<%INIT>
+my $role = RT::CustomRole->new( $session{'CurrentUser'} );
+$role->Load($id) or Abort(loc("Could not load custom role #[_1]", $id));
+$id = $role->id;
+
+if ($role->Disabled) {
+ Abort(loc("Cannot modify objects of disabled custom role #[_1]", $id));
+}
+
+my %hidden = %{ $role->HiddenForURLs };
+
+if ( $Update ) {
+ my (@results);
+
+ for my $key (%ARGS) {
+ if (my ($url) = $key =~ /^hide-(.*)$/) {
+ $hidden{$url} = $ARGS{$key};
+ }
+ }
+
+ my ($ok, $msg) = $role->SetHiddenForURLs(\%hidden);
+ if ($ok) {
+ push @results, loc('Updated visibility');
+ }
+ else {
+ push @results, loc('Unable to update visibility: [_1]', $msg);
+ %hidden = $role->HiddenForURLs;
+ }
+
+ MaybeRedirectForResults(
+ Actions => \@results,
+ Arguments => {
+ id => $id,
+ },
+ );
+}
+
+my @pages = (
+ [loc('Ticket create') => '/Ticket/Create.html'],
+ [loc('Ticket display') => '/Ticket/Display.html'],
+ [loc('Ticket modify people') => '/Ticket/ModifyPeople.html'],
+ [loc('Ticket jumbo') => '/Ticket/ModifyAll.html'],
+);
+
+if ($role->SingleValue) {
+ push @pages, (
+ [loc('Ticket modify basics') => '/Ticket/Modify.html'],
+ [loc('Ticket reply/comment') => '/Ticket/Update.html'],
+ );
+}
+
+my $title = loc('Modify visibility for [_1]', $role->Name);
+</%INIT>
diff --git a/share/html/Elements/SelectWatcherType b/share/html/Elements/SelectWatcherType
index 0fe850d0be..dcc9665736 100644
--- a/share/html/Elements/SelectWatcherType
+++ b/share/html/Elements/SelectWatcherType
@@ -67,6 +67,17 @@ else {
@types = $Queue->Roles(Single => 0);
}
+my @NewTypes;
+for my $name (@types) {
+ if (my ($id) = $name =~ /^RT::CustomRole-(\d+)$/) {
+ my $role = RT::CustomRole->new($session{CurrentUser});
+ $role->Load($id);
+ next if $role->IsHiddenForURL;
+ }
+ push @NewTypes, $name;
+}
+ at types = @NewTypes;
+
$m->callback( Types => \@types, %ARGS, CallbackName => 'ModifyWatcherTypes' );
</%INIT>
<%ARGS>
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 35848d74be..a3425d68ca 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -174,6 +174,10 @@
% my $roles = $QueueObj->CustomRoles;
% $roles->LimitToMultipleValue;
+
+% my @hidden = $QueueObj->HiddenCustomRoleIDsForURL;
+% $roles->Limit(FIELD => 'id', OPERATOR => 'NOT IN', VALUE => \@hidden) if @hidden
+
% $m->callback( CallbackName => 'ModifyCustomRoles', ARGSRef => \%ARGS, CustomRoles => $roles );
% while (my $role = $roles->Next) {
<div class="form-row">
diff --git a/share/html/Ticket/Elements/EditBasics b/share/html/Ticket/Elements/EditBasics
index 56171cd439..f89782f4e2 100644
--- a/share/html/Ticket/Elements/EditBasics
+++ b/share/html/Ticket/Elements/EditBasics
@@ -140,6 +140,10 @@ my @role_fields;
unless ($ExcludeCustomRoles) {
my $roles = $QueueObj->CustomRoles;
$roles->LimitToSingleValue;
+
+ my @hidden = $QueueObj->HiddenCustomRoleIDsForURL;
+ $roles->Limit(FIELD => 'id', OPERATOR => 'NOT IN', VALUE => \@hidden) if @hidden;
+
$m->callback( CallbackName => 'ModifyCustomRoles', %ARGS, CustomRoles => $roles);
while (my $role = $roles->Next) {
push @role_fields, {
diff --git a/share/html/Ticket/Elements/EditPeople b/share/html/Ticket/Elements/EditPeople
index 862d5ed292..48ae64f3af 100644
--- a/share/html/Ticket/Elements/EditPeople
+++ b/share/html/Ticket/Elements/EditPeople
@@ -81,6 +81,10 @@
% my @role_fields;
% my $single_roles = $Ticket->QueueObj->CustomRoles;
% $single_roles->LimitToSingleValue;
+
+% my @hidden = $QueueObj->HiddenCustomRoleIDsForURL;
+% $single_roles->Limit(FIELD => 'id', OPERATOR => 'NOT IN', VALUE => \@hidden) if @hidden;
+
% $m->callback( CustomRoles => $single_roles, SingleRoles => 1, Ticket => $Ticket, %ARGS, CallbackName => 'ModifyCustomRoles' );
% while (my $role = $single_roles->Next) {
<div class="form-row">
@@ -125,6 +129,9 @@
% my $multi_roles = $Ticket->QueueObj->CustomRoles;
% $multi_roles->LimitToMultipleValue;
+
+% $multiple_roles->Limit(FIELD => 'id', OPERATOR => 'NOT IN', VALUE => \@hidden) if @hidden;
+
% $m->callback( CustomRoles => $multi_roles, SingleRoles => 0, Ticket => $Ticket, %ARGS, CallbackName => 'ModifyCustomRoles' );
% while (my $role = $multi_roles->Next) {
% my $group = $Ticket->RoleGroup($role->GroupType);
diff --git a/share/html/Ticket/Elements/ShowPeople b/share/html/Ticket/Elements/ShowPeople
index e9fe45a896..cbccce48e4 100644
--- a/share/html/Ticket/Elements/ShowPeople
+++ b/share/html/Ticket/Elements/ShowPeople
@@ -57,6 +57,10 @@
% my $single_roles = $Ticket->QueueObj->CustomRoles;
% $single_roles->LimitToSingleValue;
+
+% my @hidden = $QueueObj->HiddenCustomRoleIDsForURL;
+% $single_roles->Limit(FIELD => 'id', OPERATOR => 'NOT IN', VALUE => \@hidden) if @hidden;
+
% $m->callback( CustomRoles => $single_roles, SingleRoles => 1, Ticket => $Ticket, %ARGS, CallbackName => 'ModifyCustomRoles' );
% while (my $role = $single_roles->Next) {
% my $group = $Ticket->RoleGroup($role->GroupType);
@@ -88,6 +92,9 @@
% my $multi_roles = $Ticket->QueueObj->CustomRoles;
% $multi_roles->LimitToMultipleValue;
+
+% $multi_roles->Limit(FIELD => 'id', OPERATOR => 'NOT IN', VALUE => \@hidden) if @hidden;
+
% $m->callback( CustomRoles => $multi_roles, SingleRoles => 0, Ticket => $Ticket, %ARGS, CallbackName => 'ModifyCustomRoles' );
% while (my $role = $multi_roles->Next) {
<div class="form-row">
-----------------------------------------------------------------------
More information about the rt-commit
mailing list