Skip to content

Commit

Permalink
Merge branch '5.0/validate-group-cfs' into 5.0-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Oct 6, 2023
2 parents 34180a3 + ab0dbcf commit 96c105f
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 56 deletions.
63 changes: 43 additions & 20 deletions share/html/Admin/Articles/Classes/Modify.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,7 @@ <h5 class="mt-3"><&|/l&>Change email subject:</&></h5>
% my $CFs = $ClassObj->CustomFields;
% if ($CFs->Count) {
<h5 class="mt-3"><&|/l&>Class Custom Fields:</&></h5>
% }
% 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 );
Expand All @@ -177,25 +172,52 @@ <h5 class="mt-3"><&|/l&>Class Custom Fields:</&></h5>

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;
}
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 {
Expand All @@ -204,7 +226,7 @@ <h5 class="mt-3"><&|/l&>Class Custom Fields:</&></h5>
}
}

if ($ClassObj->Id()) {
if ( $ClassObj->Id && not $skip_update ) {

if ($ARGS{SubjectOverride}) {
$ARGS{SubjectOverride} = $m->comp('/Widgets/Form/Select:Process',
Expand Down Expand Up @@ -236,7 +258,7 @@ <h5 class="mt-3"><&|/l&>Class Custom Fields:</&></h5>
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;
Expand All @@ -245,7 +267,7 @@ <h5 class="mt-3"><&|/l&>Class Custom Fields:</&></h5>
}
}

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));
Expand All @@ -261,11 +283,12 @@ <h5 class="mt-3"><&|/l&>Class Custom Fields:</&></h5>
}

# 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;
Expand Down
40 changes: 31 additions & 9 deletions share/html/Admin/Groups/Modify.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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;

Expand Down
57 changes: 41 additions & 16 deletions share/html/Admin/Queues/Modify.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,8 @@
<input type="hidden" class="hidden" name="SetSLAEnabled" value="1" />
</div>
</&>
% 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 => '' &>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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>
Expand Down
59 changes: 48 additions & 11 deletions share/html/Admin/Users/Modify.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,46 @@ <h5 class="modal-title"><&|/l&>Anonymize User</&></h5>

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};

Expand All @@ -272,7 +309,7 @@ <h5 class="modal-title"><&|/l&>Anonymize User</&></h5>

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),
Expand All @@ -290,10 +327,8 @@ <h5 class="modal-title"><&|/l&>Anonymize User</&></h5>
$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 );
Expand All @@ -315,12 +350,12 @@ <h5 class="modal-title"><&|/l&>Anonymize User</&></h5>
}
}

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,
Expand All @@ -335,10 +370,12 @@ <h5 class="modal-title"><&|/l&>Anonymize User</&></h5>
}

# 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>

Expand Down

0 comments on commit 96c105f

Please sign in to comment.