Skip to content
Open
10 changes: 6 additions & 4 deletions bin/update-cached.pl
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@
{
my $datum = $record->fields->{$column->id};
$datum->re_evaluate(no_errors => 1);
$datum->write_value;
$changed{$column->id} ||= [];
push @{$changed{$column->id}}, $record->current_id
if $datum->changed;
if($datum->changed) {
$datum->write_value;
$changed{$column->id} ||= [];
push @{$changed{$column->id}}, $record->current_id
if $datum->changed;
}
}
$layout->clear_cached_records;
}
Expand Down
1 change: 1 addition & 0 deletions lib/GADS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use GADS::Record;
use GADS::Records;
use GADS::RecordsGraph;
use GADS::SAML;
use GADS::SchemaInstance;
use GADS::Type::Permissions;
use GADS::Users;
use GADS::Util;
Expand Down
23 changes: 23 additions & 0 deletions lib/GADS/Datum.pm
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,28 @@ sub date_for_code
};
}

has schema => (
is => 'lazy',
builder => sub { shift->record->schema },
);

sub _rs
{ my $self = shift;
return if $self->column->internal;
$self->schema->resultset($self->column->table)->search({
record_id => $self->record_id,
layout_id => $self->column->id,
},{
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
});
}

sub is_purged
{ my $self = shift;
my $rs = $self->_rs or return 0;
my @all = $rs->all or return 0;
!!(grep { defined $_->{purged_by} && $_->{purged_by} } @all);
}

1;

2 changes: 1 addition & 1 deletion lib/GADS/Datum/Calc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ sub equal
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = [$self->as_strings];
$return->{values} = $self->is_purged ? ["[purged]"] : [$self->as_strings];
$return;
}

Expand Down
6 changes: 6 additions & 0 deletions lib/GADS/Datum/Code.pm
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ sub write_cache
sub re_evaluate
{ my ($self, %options) = @_;
return if $options{no_errors} && $self->column->return_type eq 'error';
if ($self->is_purged) {
info __x"Not running code for purged field {field} in record {record_id}",
field => $self->column->name,
record_id => $self->record_id;
return;
}
my $old = $self->value;
my $original = $self->clone;
# If this is a new value, don't re-evaluate, otherwise we'll just get
Expand Down
11 changes: 1 addition & 10 deletions lib/GADS/Datum/Date.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

package GADS::Datum::Date;

use GADS::SchemaInstance;
use DateTime;
use DateTime::Format::DateManip;
use Log::Report 'linkspace';
Expand All @@ -29,14 +28,6 @@ use namespace::clean;
extends 'GADS::Datum';
with 'GADS::DateTime';

has schema => (
is => 'ro',
lazy => 1,
builder => sub {
GADS::SchemaInstance->instance;
},
);

after set_value => sub {
my ($self, $all, %options) = @_;
$all ||= [];
Expand Down Expand Up @@ -67,7 +58,7 @@ after set_value => sub {
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = $self->text_all;
$return->{values} = $self->is_purged ? ["[purged]"] : $self->text_all;
$return;
}

Expand Down
11 changes: 1 addition & 10 deletions lib/GADS/Datum/Daterange.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package GADS::Datum::Daterange;
use DateTime;
use DateTime::Format::DateManip;
use DateTime::Span;
use GADS::SchemaInstance;
use Log::Report 'linkspace';
use Moo;
use MooX::Types::MooseLike::Base qw/ArrayRef/;
Expand All @@ -30,14 +29,6 @@ extends 'GADS::Datum';

with 'GADS::DateTime';

has schema => (
is => 'ro',
lazy => 1,
builder => sub {
GADS::SchemaInstance->instance;
},
);

# Set datum value with value from user
after set_value => sub {
my ($self, $all, %options) = @_;
Expand Down Expand Up @@ -147,7 +138,7 @@ sub _as_string
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = $self->text_all;
$return->{values} = $self->is_purged ? ["[purged]"] : $self->text_all;
$return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Datum/Enum.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ has text_all => (
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = $self->text_all;
$return->{values} = $self->is_purged ? ["[purged]"] : $self->text_all;
$return;
}

Expand Down
35 changes: 13 additions & 22 deletions lib/GADS/Datum/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ after set_value => sub {
if (@values == 1 && @old == 1)
{
my $old_value = $self->schema->resultset('Fileval')->find($old[0]); # Only do one fetch here
my $old_content = $old_value->content;
my $old_name = $old_value->name;
if(my $fl = $self->schema->resultset('Fileval')->search({
id => $values[0],
name => $old_name
})->next) {
$changed = 0 if $fl && $fl->content eq $old_content;
# Fix - if the data is originally purged, then the fileval record will have been deleted, so we need to account for that
Comment thread
droberts-ctrlo marked this conversation as resolved.
my $old_content = $old_value ? $old_value->content : undef;
my $old_name = $old_value ? $old_value->name : undef;
if (defined $old_content && defined $old_name) {
if (my $fl = $self->schema->resultset('Fileval')->search({
id => $values[0],
name => $old_name
})->next) {
$changed = 0 if $fl && $fl->content eq $old_content;
}
} else {
$changed = 1;
}
}
}
Expand Down Expand Up @@ -167,20 +172,6 @@ sub _build_files
return \@return;
}

sub _files_rs
{ my $self = shift;
[$self->schema->resultset('File')->search({
record_id => $self->record_id,
layout_id => $self->column->id,
})->all];
}

sub is_purged {
my $self = shift;
my @files = @{$self->_files_rs};
return grep { $_->is_purged } @files;
}

sub _ids_to_files
{ my ($self, @ids) = @_;
map {
Expand Down Expand Up @@ -280,7 +271,7 @@ around 'clone' => sub {
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = $self->files;
$return->{values} = $self->is_purged ? ["[purged]"] : $self->files;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Datum::File inherit the is_purged method from a parent object? I see that the local is_purged sub has been deleted.

$return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Datum/Integer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ around 'clone' => sub {
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = $self->values;
$return->{values} = $self->is_purged ? ["[purged]"] : $self->values;
$return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Datum/Person.pm
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ sub for_table
}

my $return = $self->for_table_template;
$return->{values} = \@vals;
$return->{values} = $self->is_purged ? ["[purged]"] : \@vals;
$return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Datum/Rag.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ sub as_integer
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = $self->value;
$return->{values} = $self->is_purged ? ["[purged]"] : $self->value;
$return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Datum/Serial.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sub _build_blank {
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = [$self->as_string];
$return->{values} = $self->is_purged ? ["[purged]"] : [$self->as_string];
$return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Datum/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ around 'clone' => sub {
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = $self->text_all;
$return->{values} = $self->is_purged ? ["[purged]"] : $self->text_all;
$return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Datum/Tree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ has text_all => (
sub for_table
{ my $self = shift;
my $return = $self->for_table_template;
$return->{values} = [$self->text_all];
$return->{values} = $self->is_purged ? ["[purged]"] : [$self->text_all];
$return;
}

Expand Down
6 changes: 5 additions & 1 deletion lib/GADS/Role/Presentation/Datum.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sub presentation { shift->presentation_base(@_) } # Default, overridden

sub presentation_base {
my ($self, %options) = @_;
return {
my $return = {
type => $options{type} || ($self->isa('GADS::Datum::Count') ? 'count' : $self->column->type),
value => $self->as_string,
has_value => $self->has_value,
Expand All @@ -18,6 +18,10 @@ sub presentation_base {
column_id => $self->column && $self->column->id,
column_name => $self->column && $self->column->name,
};
if ($self->can('is_purged')) {
$return->{purged} = $self->is_purged;
}
return $return;
}

1;
7 changes: 7 additions & 0 deletions lib/GADS/Role/Presentation/Record.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ sub presentation {
my @presentation_columns = $self->presentation_map_columns(%options, columns => \@columns);
my @topics= $self->get_topics(\@presentation_columns);

my $has_purged = !!(grep {
defined $_->{data}->{purged} && $_->{data}->{purged}
} map {
@{$_->{columns}}
} @topics);

my $version_datetime_col = $self->layout->column_by_name_short('_version_datetime');
my $created_user_col = $self->layout->column_by_name_short('_created_user');
my $created_datetime_col = $self->layout->column_by_name_short('_created');
Expand All @@ -101,6 +107,7 @@ sub presentation {
has_rag_column => !!(grep { $_->type eq 'rag' } @columns),
new_entry => $self->new_entry,
is_draft => $self->is_draft,
has_purged => $has_purged,
};

if ($options{edit})
Expand Down
4 changes: 3 additions & 1 deletion lib/GADS/Role/Purgable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use Moo::Role;
has value_fields => (
is => 'lazy',
isa => ArrayRef,
builder => sub { ['value']; }
builder => sub {
['value'];
}
);

sub is_purged {
Expand Down
1 change: 1 addition & 0 deletions lib/GADS/Schema/Result/Calcval.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ sub sqlt_deploy_hook {
}

sub _build_valuefield { ('value_text','value_numeric','value_int','value_date','value_date_from','value_date_to'); }
sub _build_value_fields { ['value_text','value_numeric','value_int','value_date','value_date_from','value_date_to'] }

1;
8 changes: 7 additions & 1 deletion src/frontend/components/purge/_purge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
.purge--content {
padding: $padding-large-vertical 0;
border-top: solid 2px $gray-extra-dark;
}
}

.purged {
font-style: italic;
color: $danger;
}

15 changes: 12 additions & 3 deletions views/edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
%]

<div class="content-block__main">
[% IF record.has_purged %]
<div class="row">
<div class="col">
<div class="alert alert-info mb-3" role="alert">
This record has been archived. You can view the version history of the record to see its previous values, but you cannot edit or restore the record.
</div>
</div>
</div>
[% END %]
<form
class="[% IF edit_modal %]curval-edit-form[% ELSE %]form-edit[% END %]"
method="post"
Expand Down Expand Up @@ -374,7 +383,7 @@
</span>
</button>
<div class="card__header-right">
[% IF editable AND NOT record.new_entry AND NOT edit_modal AND topic.has_editable %]
[% IF editable AND NOT record.new_entry AND NOT edit_modal AND topic.has_editable AND NOT record.has_purged %]
<button
type="button"
class="btn btn-edit btn-js-edit"
Expand Down Expand Up @@ -436,7 +445,7 @@
}
</style>
[%
editable = record.user_can_edit AND NOT record.deleted AND NOT is_history AND NOT view_modal ? 1 : 0;
editable = NOT record.has_purged AND record.user_can_edit AND NOT record.deleted AND NOT is_history AND NOT view_modal ? 1 : 0;
is_first_topic = 1;

FOREACH topic IN record.topics;
Expand All @@ -457,7 +466,7 @@
NEXT IF !is_history AND col_panel.data.dependent_not_shown;
NEXT IF view_modal AND col.type == "autocur";
%]
<li class="list__item[% IF col_panel.data.blank AND NOT layout.no_hide_blank %] list__item--blank[% END %] list-group-item">
<li class="list__item[% IF col_panel.data.blank AND NOT layout.no_hide_blank AND NOT col_panel.data.purged %] list__item--blank[% END %] list-group-item">
<span class="list__key">[% col_panel.name | html_entity %]</span>
<span class="list__value">[% render_datum(col_panel, 'full') %]</span>
</li>
Expand Down
1 change: 1 addition & 0 deletions views/historic_purge/confirm.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<h3>Confirm Purge</h3>
<p>Below is a list of the fields and their values you have chosen to purge. Please confirm that you wish to proceed.</p>
<p class="text-danger">WARNING: This is a destructive action and cannot be undone. This will remove all field values from all current and historical versions of the records, and chronology in the selected fields from the current view.</p>
<p class="text-danger">Once this action is performed, the record will no longer be editable.</p>
<input type="hidden" name="csrf_token" value="[% csrf_token %]">

[%
Expand Down
1 change: 1 addition & 0 deletions views/historic_purge/initial.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<h3>Purge field values from records in the current view</h3>
<p>Select fields to purge within this view.</p>
<p class="text-danger">WARNING: This is a destructive action and cannot be undone. This will remove all field values from all current and historical versions of the records, and chronology in the selected fields from the current view.</p>
<p class="text-danger">Once this action is performed, the record will no longer be editable.</p>
<input type="hidden" name="csrf_token" value="[% csrf_token %]">
[%
# prepare table config
Expand Down
Loading
Loading