diff --git a/share/html/Admin/Articles/Classes/Modify.html b/share/html/Admin/Articles/Classes/Modify.html
index 5d8f436552a..63ae0d0680f 100644
--- a/share/html/Admin/Articles/Classes/Modify.html
+++ b/share/html/Admin/Articles/Classes/Modify.html
@@ -150,12 +150,7 @@
<&|/l&>Change email subject:&>
% my $CFs = $ClassObj->CustomFields;
% if ($CFs->Count) {
<&|/l&>Class Custom Fields:&>
-% }
-% while (my $CF = $CFs->Next) {
- <&| /Elements/LabeledValue, Label => $CF->Name, LabelSpanClass => ($CF->EntryHint ? 'prev-icon-helper' : '' ),
- LabelTooltip => $CF->EntryHint &>
- <& /Elements/EditCustomField, CustomField => $CF, Object => $ClassObj, &>
- &>
+<& /Elements/EditCustomFields, Object => $ClassObj &>
% }
%$m->callback( CallbackName => 'BeforeSubmit', CustomFields => $cfs, ClassObj => $ClassObj );
@@ -177,12 +172,42 @@ <&|/l&>Class Custom Fields:&>
my $ClassObj = RT::Class->new($session{'CurrentUser'});
my ($title, @results, $Disabled);
+my $skip_update = 0;
+
+my ( $val, $msg );
+if ( ($id && $id ne 'new') || ( $Name && not $id ) ) {
+ if ( $id ) {
+ ( $val, $msg ) = $ClassObj->Load($id);
+ }
+ else {
+ ( $val, $msg ) = $ClassObj->Load($Name);
+ }
+ if ( not $val ) {
+ RT->Logger->error("Unable to load class with id $id: $msg");
+ Abort(loc("Couldn't load class '[_1]'", $Name));
+ }
+}
+
+my $CustomFields = $ClassObj->CustomFields;
+
+my ($status, @msg) = $m->comp(
+ '/Elements/ValidateCustomFields',
+ Object => $ClassObj,
+ CustomFields => $CustomFields,
+ ARGSRef => \%ARGS,
+);
+unless ($status) {
+ push @results, @msg;
+ $skip_update = 1;
+ if ( $id && $id eq 'new' ) {
+ $Create = 1;
+ }
+}
if ($Create) {
$title = loc("Create a Class");
} else {
- my ( $val, $msg );
- if ($id eq 'new') {
+ if ( $id && $id eq 'new' && not $skip_update ) {
($val, $msg) = $ClassObj->Create(Name => $Name);
if ( $val ) {
push @results, $msg;
@@ -190,12 +215,9 @@ <&|/l&>Class Custom Fields:&>
else {
push @results, loc('Class could not be created: [_1]', $msg);
}
- } else {
- $ClassObj->Load($id) || $ClassObj->Load($Name) || $m->comp("/Elements/Error", Why => "Couldn't load class '$Name'");
- $val = $ClassObj->id;
}
- if ( $val ) {
+ if ( $ClassObj->Id ) {
$title = loc('Modify the Class [_1]', $ClassObj->Name);
}
else {
@@ -204,7 +226,7 @@ <&|/l&>Class Custom Fields:&>
}
}
-if ($ClassObj->Id()) {
+if ( $ClassObj->Id && not $skip_update ) {
if ($ARGS{SubjectOverride}) {
$ARGS{SubjectOverride} = $m->comp('/Widgets/Form/Select:Process',
@@ -236,7 +258,7 @@ <&|/l&>Class Custom Fields:&>
my $subject_cf_labels = {};
my $cfs;
-if ( $ClassObj->id ) {
+if ( $ClassObj->Id && not $skip_update ) {
$cfs = $ClassObj->ArticleCustomFields;
while ( my $cf = $cfs->Next ) {
$include{"CF-Title-".$cf->Id} = $include{"CF-Value-".$cf->Id} = 1;
@@ -245,7 +267,7 @@ <&|/l&>Class Custom Fields:&>
}
}
-if ( $ClassObj->id && $Submitted ) {
+if ( $ClassObj->id && $Submitted && not $skip_update ) {
if ( $Disabled != $ClassObj->Disabled) {
my ($code, $msg) = $ClassObj->SetDisabled($Disabled);
push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
@@ -261,11 +283,12 @@ <&|/l&>Class Custom Fields:&>
}
# This code does automatic redirection if any updates happen.
-MaybeRedirectForResults(
- Actions => \@results,
- Arguments => { id => $ClassObj->Id },
-) if $ClassObj->id;
-
+unless ( $skip_update ) {
+ MaybeRedirectForResults(
+ Actions => \@results,
+ Arguments => { id => $ClassObj->Id },
+ ) if $ClassObj->id;
+}
if ( $ClassObj->id ) {
$include{$_} = not $ClassObj->FirstAttribute("Skip-$_") for keys %include;
diff --git a/share/html/Admin/Groups/Modify.html b/share/html/Admin/Groups/Modify.html
index 659daa0eaa3..673a3cbefc4 100644
--- a/share/html/Admin/Groups/Modify.html
+++ b/share/html/Admin/Groups/Modify.html
@@ -92,13 +92,35 @@
<%INIT>
my ($title, @results, @warnings, $Disabled, $EnabledChecked);
+my $skip_update = 0;
my $Group = RT::Group->new($session{'CurrentUser'});
+if ( $id && $id ne 'new' ) {
+ my ( $ok,$msg ) = $Group->Load($id);
+ if ( not $ok ) {
+ RT->Logger->error("Unable to load group with id $id: $msg");
+ Abort('Could not load group');
+ }
+}
+
+my $CustomFields = $Group->CustomFields;
+
+my ($status, @msg) = $m->comp(
+ '/Elements/ValidateCustomFields',
+ Object => $Group,
+ CustomFields => $CustomFields,
+ ARGSRef => \%ARGS,
+);
+unless ($status) {
+ push @results, @msg;
+ $skip_update = 1;
+}
+
if ($Create) {
$title = loc("Create a new group");
} else {
- if ($id eq 'new' ) {
+ if ($id eq 'new' && not $skip_update ) {
my ($create_id, $create_msg) = $Group->CreateUserDefinedGroup(Name => $Name );
if ($create_id) {
$id = $Group->Id;
@@ -107,8 +129,6 @@
} else {
push @results, loc("Group could not be created: [_1]", $create_msg);
}
- } else {
- $Group->Load($id) || Abort('Could not load group');
}
if ($Group->Id) {
@@ -122,7 +142,7 @@
}
}
-if ($Group->Id) {
+if ( $Group->Id && not $skip_update ) {
my @fields = qw(Description Name );
my @fieldresults = UpdateRecordObject ( AttributesRef => \@fields,
Object => $Group,
@@ -145,16 +165,18 @@
} else {
$Disabled = 1;
}
-if ( $Group->Id and ($SetEnabled) and ( $Disabled != $Group->Disabled) ) {
+if ( $Group->Id and (not $skip_update) and ($SetEnabled) and ( $Disabled != $Group->Disabled) ) {
my ($code, $msg) = $Group->SetDisabled($Disabled);
push @results, $msg;
}
# This code does automatic redirection if any updates happen.
-MaybeRedirectForResults(
- Actions => \@results,
- Arguments => { id => $Group->id },
-) if $Group->Id;
+unless ( $skip_update ) {
+ MaybeRedirectForResults(
+ Actions => \@results,
+ Arguments => { id => $Group->id },
+ ) if $Group->Id;
+}
push @results, @warnings;
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index f47410290fc..701828d81a3 100644
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -114,14 +114,8 @@
&>
-% my $CFs = $QueueObj->CustomFields;
-% while (my $CF = $CFs->Next) {
-<&| /Elements/LabeledValue, Label => $CF->Name, LabelTooltip => $CF->EntryHint &>
- <& /Elements/EditCustomField, CustomField => $CF,
- Object => $QueueObj, &>
-&>
-% }
+ <& /Elements/EditCustomFields, Object => $QueueObj &>
% if ( RT->Config->Get('Crypt')->{'Enable'} ) {
<&| /Elements/LabeledValue, Label => '' &>
@@ -203,24 +197,53 @@
<%INIT>
my ($title, @results, @no_redirect_results, $Disabled, $EnabledChecked);
+my $skip_update = 0;
+
my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
-$QueueObj->Load( $id ) if !$id || $id eq 'new';
+
+my ( $ok, $msg );
+if ( ($id && $id ne 'new') || ( $Name && not $id ) ) {
+ if ( $id ) {
+ ( $ok, $msg ) = $QueueObj->Load($id);
+ }
+ else {
+ ( $ok, $msg ) = $QueueObj->Load($Name);
+ }
+ if ( not $ok ) {
+ RT->Logger->error("Unable to load queue with id $id: $msg");
+ Abort(loc("Couldn't load queue '[_1]'", $Name));
+ }
+}
+
+my $CustomFields = $QueueObj->CustomFields;
+
+my ($status, @msg) = $m->comp(
+ '/Elements/ValidateCustomFields',
+ Object => $QueueObj,
+ CustomFields => $CustomFields,
+ ARGSRef => \%ARGS,
+);
+unless ($status) {
+ push @results, @msg;
+ $skip_update = 1;
+ if ( $id && $id eq 'new' ) {
+ $Create = 1;
+ }
+}
$EnabledChecked = 'checked="checked"';
unless ($Create) {
- if ( defined $id && $id eq 'new' ) {
+ if ( defined $id && $id eq 'new' && not $skip_update ) {
my ($val, $msg) = $QueueObj->Create( Name => $Name );
if (!$val) {
$Create = 1; # Create failed, so bring us back to step 1
}
push @results, $msg;
- } else {
- $QueueObj->Load($id) || $QueueObj->Load($Name) || Abort(loc("Couldn't load queue '[_1]'", $Name));
}
}
-if ( $QueueObj->Id ) {
+if ( $QueueObj->Id && not $skip_update ) {
$title = loc('Configuration for queue [_1]', $QueueObj->Name );
my @attribs= qw(Description CorrespondAddress CommentAddress Name SortOrder
Sign SignAuto Encrypt Lifecycle SubjectTag SLADisabled Disabled);
@@ -280,10 +303,12 @@
my $InternalQueue = ($QueueObj->Id and $QueueObj->Disabled == 2);
# This code does automatic redirection if any updates happen.
-MaybeRedirectForResults(
- Actions => \@results,
- Arguments => { id => $QueueObj->Id },
-) if $QueueObj->id;
+unless ( $skip_update ) {
+ MaybeRedirectForResults(
+ Actions => \@results,
+ Arguments => { id => $QueueObj->Id },
+ ) if $QueueObj->id;
+}
push @results, @no_redirect_results;
%INIT>
diff --git a/share/html/Admin/Users/Modify.html b/share/html/Admin/Users/Modify.html
index 0bb2330e27b..7ae1241badc 100644
--- a/share/html/Admin/Users/Modify.html
+++ b/share/html/Admin/Users/Modify.html
@@ -255,9 +255,46 @@ <&|/l&>Anonymize User&>
my $UserObj = RT::User->new($session{'CurrentUser'});
my ($title, @results);
+my $skip_update = 0;
my ($val, $msg);
+if ( ($id && $id ne 'new') || ( $ARGS{Name} && not $id ) ) {
+ if ( $id ) {
+ ( $val, $msg ) = $UserObj->Load($id);
+ }
+ else {
+ ( $val, $msg ) = $UserObj->Load($ARGS{Name});
+ }
+ if ( not $val ) {
+ RT->Logger->error("Unable to load user with id $id: $msg");
+ Abort(loc("Couldn't load user '[_1]'", ( $ARGS{Name} || '')));
+ }
+}
+
+# Handle case when Modify is called with no params
+if ( not $UserObj->Id
+ and not $Create
+ and $id ne 'new' ) {
+ Abort(loc("Couldn't load user '[_1]'", ( $ARGS{Name} || '')));
+}
+
+my $CustomFields = $UserObj->CustomFields;
+
+my ($status, @msg) = $m->comp(
+ '/Elements/ValidateCustomFields',
+ Object => $UserObj,
+ CustomFields => $CustomFields,
+ ARGSRef => \%ARGS,
+);
+unless ($status) {
+ push @results, @msg;
+ $skip_update = 1;
+ if ( $id && $id eq 'new' ) {
+ $Create = 1;
+ }
+}
+
$ARGS{Privileged} = $ARGS{Privileged} ? 1 : 0;
delete $ARGS{Privileged} unless $ARGS{SetPrivileged};
@@ -272,7 +309,7 @@ <&|/l&>Anonymize User&>
if ($Create) {
$title = loc("Create a new user");
-} elsif ( defined $id && $id eq 'new') {
+} elsif ( defined $id && $id eq 'new' && not $skip_update ) {
$m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, Fields => \@fields, Results => \@results );
( $val, $msg ) = $UserObj->Create(
(map {($_ => $ARGS{$_})} @fields),
@@ -290,10 +327,8 @@ <&|/l&>Anonymize User&>
$title = loc("Create a new user");
$Create = 1;
}
-} else {
- $UserObj->Load($id) || $UserObj->Load($ARGS{Name})
- || Abort("Couldn't load user '" . ( $ARGS{Name} || '') . "'");
-
+}
+elsif ( $UserObj->Id && not $skip_update ) {
$title = loc("Modify the user [_1]", $UserObj->Name);
$m->callback( %ARGS, CallbackName => 'BeforeUpdate', User => $UserObj, ARGSRef => \%ARGS, Results => \@results );
@@ -315,12 +350,12 @@ <&|/l&>Anonymize User&>
}
}
-if ( $ARGS{'Anonymize'} and $UserObj->Id ) {
+if ( $ARGS{'Anonymize'} and $UserObj->Id && not $skip_update ) {
my ($ret, $msg) = $UserObj->AnonymizeUser(ClearCustomFields => $ARGS{'clear_customfields'});
push @results, $msg;
}
-if ( $UserObj->Id ) {
+if ( $UserObj->Id && not $skip_update ) {
# Deal with Password field
my ($status, $msg) = $UserObj->SafeSetPassword(
Current => $CurrentPass,
@@ -335,10 +370,12 @@ <&|/l&>Anonymize User&>
}
# This code does automatic redirection if any updates happen.
-MaybeRedirectForResults(
- Actions => \@results,
- Arguments => { id => $UserObj->Id },
-) if $UserObj->Id;
+unless ( $skip_update ) {
+ MaybeRedirectForResults(
+ Actions => \@results,
+ Arguments => { id => $UserObj->Id },
+ ) if $UserObj->Id;
+}
%INIT>