[Rt-commit] rt branch, 5.0/articles-unique-only-within-own-class, repushed
Steve Burr
steve at bestpractical.com
Fri Jun 25 14:51:06 EDT 2021
The branch 5.0/articles-unique-only-within-own-class was deleted and repushed:
was 710eaefa951e1051bc1e5b4642760d0d2a7bc60b
now 2c818ce3cbe33df2b09ee5287347257523b47681
1: 5dcbf9879d ! 1: cd2550e0f8 Allow articles with same name in different classes
@@ -18,23 +18,12 @@
--- a/lib/RT/Article.pm
+++ b/lib/RT/Article.pm
@@
- use RT::URI::fsck_com_article;
- use RT::Transactions;
--
- sub Table {'Articles'}
+ return ( undef, $self->loc('Name is required') ) unless $args{Name};
- # This object takes custom fields
-@@
- return ( 0, $self->loc('Invalid Class') );
- }
-
-+ $self->{->'_creating_class'} = $class->id;
++ # only here for ValidateName, on create, being called in the context of DBIx::SB
++ $self->{'_creating_class'} = $class->id;
+
- unless ( $class->CurrentUserHasRight('CreateArticle') ) {
- return ( 0, $self->loc("Permission Denied") );
- }
-
return ( undef, $self->loc('Name in use') )
- unless $self->ValidateName( $args{'Name'} );
+ unless $self->ValidateName( $args{'Name'}, $class->id );
@@ -50,16 +39,16 @@
+
+If no class is supplied, returns true if that name isn't used by any other article at all.
- Empty names are permitted.
+ Empty names are not permitted.
@@
sub ValidateName {
my $self = shift;
my $name = shift;
-+ my $class = shift || ($self->ClassObj && $self->ClassObj->id) || $self->{'_creating_class'};
++ my $class_id = shift || ($self->ClassObj && $self->ClassObj->id) || $self->{'_creating_class'};
if ( !$name ) {
- return (1);
+ return (0);
}
- my $temp = RT::Article->new($RT::SystemUser);
@@ -67,20 +56,19 @@
- if ( $temp->id &&
- (!$self->id || ($temp->id != $self->id ))) {
- return (undef);
-+ if ( $class ) {
++ if ( $class_id ) {
+ my $articles = RT::Articles->new($RT::SystemUser);
+ $articles->Limit( FIELD => 'Name', OPERATOR => '=', VALUE => $name ); # cannot use LimitName() as it hardcodes 'LIKE'
-+ $articles->Limit( FIELD => 'Class', OPERATOR => '=', VALUE => $class );
++ $articles->Limit( FIELD => 'Class', OPERATOR => '=', VALUE => $class_id );
+ while ( my $article = $articles->Next ) {
-+ if ( $article->id && ( !$self->id || ($article->id))) {
++ if ( $article->id && ( !$self->id || ($article->id != $self->id )) ) {
+ return (undef);
+ }
+ }
+ } else {
+ my $temp = RT::Article->new($RT::SystemUser);
+ $temp->LoadByCols( Name => $name );
-+ if ( $temp->id &&
-+ (!$self->id || ($temp->id != $self->id ))) {
++ if ( $temp->id && ( !$self->id || ($temp->id != $self->id )) ) {
+ return (undef);
+ }
}
2: dda7e71209 < -: ------- Refactor class argument to ValidateName
3: 211daa2517 < -: ------- Disallow multiple articles with empty names
4: 4b98e51eea < -: ------- Allow resetting to the same name
5: 56ac13ff5b ! 2: 2c818ce3cb Add tests for per-class article uniqueness
@@ -15,9 +15,11 @@
use_ok 'RT::Articles';
use_ok 'RT::Classes';
@@
+ $a2->Load($id);
+ ok ($a2->Disabled, "the article is disabled");
-
-
++
++
+my $class1 = RT::Class->new($RT::SystemUser);
+($id, $msg) = $class1->Create(Name => "ScopedClassTest1-$$");
+ok ($id, $msg);
@@ -39,7 +41,7 @@
+ok ($id, $msg);
+
+
++
+ # NOT OK
+ #$RT::Handle->SimpleQuery("DELETE FROM Links");
-
- my $newart = RT::Article->new($RT::SystemUser);
-
6: 710eaefa95 < -: ------- Allow multiple articles with empty names
More information about the rt-commit
mailing list