[Rt-commit] rt branch unique-conditions-and-actions created. rt-5.0.3-296-g7c002a9e13

BPS Git Server git at git.bestpractical.com
Fri Mar 10 21:19:23 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, unique-conditions-and-actions has been created
        at  7c002a9e1349dd6d02b5779bca9cb1bc1068ff32 (commit)

- Log -----------------------------------------------------------------
commit 7c002a9e1349dd6d02b5779bca9cb1bc1068ff32
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Fri Mar 10 17:12:35 2023 -0300

    Avoid rename of an Action to an existing one
    
    Actions were able to be renamed to an existing one, which caused
    confusion when managing actions and scrips.

diff --git a/lib/RT/ScripAction.pm b/lib/RT/ScripAction.pm
index bb10b6cfc0..46c52fcfdb 100644
--- a/lib/RT/ScripAction.pm
+++ b/lib/RT/ScripAction.pm
@@ -109,6 +109,26 @@ sub Create  {
     return($self->SUPER::Create( %args ));
 }
 
+=head2 Update
+
+Takes a hash. Updates an existing Action entry.
+
+=cut
+
+sub Update  {
+    my $self = shift;
+
+    my %args = ( @_ );
+    return (undef, $self->loc('Name is required')) unless $args{'ARGSRef'}{'Name'};
+    # check if the name is already in use
+    my $existing = RT::ScripAction->new( RT->SystemUser );
+    $existing->Load( $args{'ARGSRef'}{'Name'} );
+    if ( $existing->id && $existing->id != $self->id ) {
+        return (undef, $self->loc('Name already in use by another action'));
+    }
+    return($self->SUPER::Update( %args ));
+}
+
 sub Delete {
     my $self = shift;
 

commit 230e618f0a271eb5fa3888e2348c6ff752e7bfa1
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Fri Mar 10 17:05:27 2023 -0300

    Require unique name for creating new actions
    
    Checks if the same name is already in use when creating a new action,
    avoiding confusion when managing actions and scrips

diff --git a/lib/RT/ScripAction.pm b/lib/RT/ScripAction.pm
index 37b0ed7250..bb10b6cfc0 100644
--- a/lib/RT/ScripAction.pm
+++ b/lib/RT/ScripAction.pm
@@ -97,8 +97,16 @@ Takes a hash. Creates a new Action entry.
 
 sub Create  {
     my $self = shift;
-    #TODO check these args and do smart things.
-    return($self->SUPER::Create(@_));
+
+    my %args = ( @_ );
+    return (undef, $self->loc('Name is required')) unless $args{'Name'};
+    # check if the name is already in use
+    my $existing = RT::ScripAction->new( RT->SystemUser );
+    $existing->Load( $args{'Name'} );
+    if ( $existing->id ) {
+        return (undef, $self->loc('Name already in use by another action'));
+    }
+    return($self->SUPER::Create( %args ));
 }
 
 sub Delete {

commit e6e4ef0eb68e06d5e041d8a182e76a1c334a4190
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Fri Mar 10 17:00:43 2023 -0300

    Avoid rename of scrip condition to an existing one
    
    Conditions were able to be renamed to an existing one, which caused
    confusion when managing conditions and scrips.

diff --git a/lib/RT/ScripCondition.pm b/lib/RT/ScripCondition.pm
index 2738bab5e3..90398d4c87 100644
--- a/lib/RT/ScripCondition.pm
+++ b/lib/RT/ScripCondition.pm
@@ -114,6 +114,25 @@ sub Create  {
     return($self->SUPER::Create( %args ));
 }
 
+=head2 Update
+
+Takes a hash. Updates the Condition entry.
+
+=cut
+
+sub Update  {
+    my $self = shift;
+    my %args = ( @_ );
+
+    return (undef, $self->loc('Name is required')) unless $args{'ARGSRef'}{'Name'};
+    # check if the name is already in use
+    my $existing = RT::ScripCondition->new( RT->SystemUser );
+    $existing->Load( $args{'ARGSRef'}{'Name'} );
+    if ( $existing->id && $existing->id != $self->id ) {
+        return (undef, $self->loc('Name already in use by another condition'));
+    }
+    return($self->SUPER::Update( %args ));
+}
 
 =head2 Delete
 

commit 754210181c7c1880d1b3c1f4de8c239c6b3bb93f
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Fri Mar 10 16:54:55 2023 -0300

    Require unique name for creating new conditions
    
    Checks if the same name is already in use when creating a new condition,
    avoiding confusion when managing conditions and scrips

diff --git a/lib/RT/ScripCondition.pm b/lib/RT/ScripCondition.pm
index a186770f08..2738bab5e3 100644
--- a/lib/RT/ScripCondition.pm
+++ b/lib/RT/ScripCondition.pm
@@ -102,7 +102,16 @@ sub _Accessible  {
 
 sub Create  {
     my $self = shift;
-    return($self->SUPER::Create(@_));
+    my %args = ( @_ );
+
+    return (undef, $self->loc('Name is required')) unless $args{'Name'};
+    # check if the name is already in use
+    my $existing = RT::ScripCondition->new( RT->SystemUser );
+    $existing->Load( $args{'Name'} );
+    if ( $existing->id ) {
+        return (undef, $self->loc('Name already in use by another condition'));
+    }
+    return($self->SUPER::Create( %args ));
 }
 
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list