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

9 changes: 0 additions & 9 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
9 changes: 0 additions & 9 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
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
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
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
6 changes: 5 additions & 1 deletion lib/GADS/Role/Purgable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package GADS::Role::Purgable;
use strict;
use warnings;

use Log::Report;

use MooX::Types::MooseLike::Base qw(ArrayRef);

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