Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

33 changes: 12 additions & 21 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

Choose a reason for hiding this comment

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

Is this a 'Need Fixing' reminder, or is that a comment to exclaim a fix has been made?

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
1 change: 1 addition & 0 deletions lib/GADS/Role/Presentation/Datum/Enum.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sub presentation {

$base->{id_hash} = $self->id_hash;
$base->{deleted_values} = $self->deleted_values;
$base->{purged} = $self->is_purged;

return $base;
}
Expand Down
1 change: 1 addition & 0 deletions lib/GADS/Role/Presentation/Datum/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sub presentation {
my $base = $self->presentation_base;

$base->{files} = $self->files;
$base->{purged} = $self->is_purged;

return $base;
}
Expand Down
1 change: 1 addition & 0 deletions lib/GADS/Role/Presentation/Datum/Person.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sub presentation {
$base->{value} = $self->as_string;
$base->{details} = [map $self->_presentation_details($_, %options), @{$self->value_hash}];
$base->{ids} = $self->ids;
$base->{purged} = $self->is_purged;

return $base;
}
Expand Down
1 change: 1 addition & 0 deletions lib/GADS/Role/Presentation/Datum/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sub presentation {

$base->{raw} = $raw;
$base->{html} = $html;
$base->{purged} = $self->is_purged;

return $base;
}
Expand Down
1 change: 1 addition & 0 deletions lib/GADS/Role/Presentation/Datum/Tree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sub presentation {

$base->{ids} = $self->ids;
$base->{ids_as_params} = $self->ids_as_params;
$base->{purged} = $self->is_purged;

return $base;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/GADS/Role/Presentation/Record.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ 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);

Choose a reason for hiding this comment

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

Could this be potentially a multi-line?


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 +103,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
13 changes: 11 additions & 2 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 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
20 changes: 12 additions & 8 deletions views/snippets/datum.tt
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@
[% END %]

[% MACRO render_file_datum(file, full_content) BLOCK %]
[% FOREACH file IN file.files %]
<a href="/file/[% file.id %]">
[% IF full_content AND file.mimetype.match('^image/') %]
<img class="autosize" src="/file/[% file.id %]">
[% ELSE %]
[% file.name | html %]<br>
[% END %]
</a>
[% IF file.purged %]
<p><em>File has been purged.</em></p>
[% ELSE %]
[% FOREACH file IN file.files %]
<a href="/file/[% file.id %]">
[% IF full_content AND file.mimetype.match('^image/') %]
<img class="autosize" src="/file/[% file.id %]">
[% ELSE %]
[% file.name | html %]<br>
[% END %]
</a>
[% END %]
[% END %]
[% END %]

Expand Down
Loading