diff options
author | sunnavy <sunnavy@bestpractical.com> | 2022-10-04 22:39:17 +0300 |
---|---|---|
committer | sunnavy <sunnavy@bestpractical.com> | 2022-10-19 00:25:59 +0300 |
commit | a25e815eec6414668cb25d014b461316cdc97664 (patch) | |
tree | d5667ece58299089f236ee7d24e03b8663105c5d | |
parent | 76f93bf82b0039ae58b352f9becc58c26de4382a (diff) |
Relax requirements about role names to be unique for each lookup type
-rw-r--r-- | lib/RT/Action/Notify.pm | 1 | ||||
-rw-r--r-- | lib/RT/CustomRole.pm | 25 | ||||
-rw-r--r-- | sbin/rt-validator.in | 2 | ||||
-rw-r--r-- | share/html/Admin/CustomRoles/Modify.html | 2 |
4 files changed, 25 insertions, 5 deletions
diff --git a/lib/RT/Action/Notify.pm b/lib/RT/Action/Notify.pm index f6fcbc0654..e1ad1b4458 100644 --- a/lib/RT/Action/Notify.pm +++ b/lib/RT/Action/Notify.pm @@ -122,6 +122,7 @@ sub SetRecipients { } else { my $roles = RT::CustomRoles->new( $self->CurrentUser ); + $roles->LimitToLookupType( RT::Ticket->CustomFieldLookupType ); $roles->Limit( FIELD => 'Name', VALUE => $name, CASESENSITIVE => 0 ); # custom roles are named uniquely, but just in case there are diff --git a/lib/RT/CustomRole.pm b/lib/RT/CustomRole.pm index 6c8b8b47fa..cf22198491 100644 --- a/lib/RT/CustomRole.pm +++ b/lib/RT/CustomRole.pm @@ -104,7 +104,7 @@ sub Create { } { - my ($val, $msg) = $self->_ValidateName( $args{'Name'} ); + my ($val, $msg) = $self->_ValidateName( $args{'Name'}, $args{'LookupType'} ); return ($val, $msg) unless $val; } @@ -261,8 +261,9 @@ a new custom role. Returns undef if there's already a role by that name. sub ValidateName { my $self = shift; my $name = shift; + my $type = shift || $self->LookupType || 'RT::Queue-RT::Ticket'; - my ($ok, $msg) = $self->_ValidateName($name); + my ($ok, $msg) = $self->_ValidateName($name, $type); return $ok ? 1 : 0; } @@ -270,6 +271,7 @@ sub ValidateName { sub _ValidateName { my $self = shift; my $name = shift; + my $type = shift || $self->LookupType || 'RT::Queue-RT::Ticket'; return (undef, "Role name is required") unless length $name; @@ -305,7 +307,7 @@ sub _ValidateName { } my $temp = RT::CustomRole->new(RT->SystemUser); - $temp->LoadByCols(Name => $name); + $temp->LoadByCols(Name => $name, LookupType => $type); if ( $temp->Name && $temp->id != ($self->id||0)) { return (undef, $self->loc("Role already exists") ); @@ -314,6 +316,23 @@ sub _ValidateName { return (1); } +=head2 ValidateLookupType TYPE + +Takes a custom role lookup type. Returns true unless there's another role +with the same name and lookup type. + +=cut + +sub ValidateLookupType { + my $self = shift; + my $type = shift; + if ( $self->Id && lc $self->LookupType ne lc $type ) { + return $self->ValidateName( $self->Name, $type ); + } + return 1; +} + + =head2 Delete Delete this object. You should Disable instead. diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in index fa6730547b..ba67577e23 100644 --- a/sbin/rt-validator.in +++ b/sbin/rt-validator.in @@ -420,7 +420,7 @@ push @CHECKS, 'User Defined Group Name uniqueness' => sub { push @CHECKS, 'Custom Role Name uniqueness' => sub { return check_uniqueness( 'CustomRoles', - columns => ['Name'], + columns => ['Name', 'LookupType'], action => sub { return unless prompt( 'Rename', "Found a custom role with a non-unique Name." diff --git a/share/html/Admin/CustomRoles/Modify.html b/share/html/Admin/CustomRoles/Modify.html index f6a73baa3d..35b14b7fb9 100644 --- a/share/html/Admin/CustomRoles/Modify.html +++ b/share/html/Admin/CustomRoles/Modify.html @@ -133,7 +133,7 @@ $EnabledChecked = 'checked="checked"'; unless ($Create) { if ( defined $id && $id eq 'new' ) { - my ($val, $msg) = $RoleObj->Create( Name => $Name ); + my ($val, $msg) = $RoleObj->Create( Name => $Name, LookupType => $LookupType ); if (!$val) { $Create = 1; # Create failed, so bring us back to step 1 push @results, $msg; |