Skip to content
Draft
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
8 changes: 2 additions & 6 deletions lib/GADS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ post '/api/file/?' => require_login sub {
config => config
)->column($column_id);

my $mimetype = $filecheck->check_upload($upload, check_name => 0, extra_types => $column->override_types); # Borks on invalid file type
my $mimetype = $filecheck->check_upload($upload, check_name => 0, extra_types => $column->override_types, col_filesize => $column->filesize); # Borks on invalid file type
my $filename = $upload->filename;

# Remove any invalid characters from the new name - this will possibly be changed to an error going forward
Expand Down Expand Up @@ -3746,11 +3746,7 @@ prefix '/:layout_name' => sub {
$column->notes(body_parameters->get('notes'));

my $no_alerts;
if ($column->type eq "file")
{
$column->filesize(param('filesize') || undef) if $column->type eq "file";
}
elsif ($column->type eq "rag")
if ($column->type eq "rag")
{
$column->code(param 'code_rag');
$no_alerts = param('no_alerts_rag');
Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Column.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ has from_id => (
'me.instance_id' => $self->instance_id,
},{
order_by => ['me.position', 'enumvals.id'],
prefetch => ['enumvals', 'calcs', 'rags', 'file_options' ],
prefetch => ['enumvals', 'calcs', 'rags' ],
});

$cols_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
Expand Down
46 changes: 16 additions & 30 deletions lib/GADS/Column/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ has '+option_names' => (
[+{
name => 'override_types',
user_configurable => 0,
},
+{
name => 'filesize',
user_configurable => 1,
}]
}
);
Expand All @@ -50,6 +54,16 @@ has override_types => (
has filesize => (
is => 'rw',
isa => Maybe[Int],
lazy => 1,
builder => sub {
my $self = shift;
return undef unless $self->has_options;
$self->options->{filesize} || undef;
},
trigger => sub { $_[0]->reset_options },
coerce => sub {
$_[0] eq '' ? undef : $_[0]
},
);

has '+can_multivalue' => (
Expand All @@ -66,15 +80,9 @@ sub value_field_as_index
}

after build_values => sub {
my ($self, $original) = @_;

my ($self) = @_;
$self->string_storage(1);
$self->value_field('name');
my ($file_option) = $original->{file_options}->[0];
if ($file_option)
{
$self->filesize($file_option->{filesize});
}
};

sub _build_retrieve_fields
Expand Down Expand Up @@ -103,28 +111,7 @@ sub validate
# Any value is valid for a search, as it can include begins_with etc
sub validate_search {1};

sub write_special
{ my ($self, %options) = @_;

my $id = $options{id};

my $foption = {
filesize => $self->filesize,
};
my ($file_option) = $self->schema->resultset('FileOption')->search({
layout_id => $id,
})->all;
if ($file_option)
{
$file_option->update($foption);
}
else {
$foption->{layout_id} = $id;
$self->schema->resultset('FileOption')->create($foption);
}

return ();
};
sub write_special {1};

sub tjoin
{ my $self = shift;
Expand All @@ -134,7 +121,6 @@ sub tjoin
sub cleanup
{ my ($class, $schema, $id) = @_;
$schema->resultset('File')->search({ layout_id => $id })->delete;
$schema->resultset('FileOption')->search({ layout_id => $id })->delete;
};

sub resultset_for_values
Expand Down
10 changes: 0 additions & 10 deletions lib/GADS/Column/Person.pm
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,6 @@ sub id_to_hash
return $prs->next;
}

after build_values => sub {
my ($self, $original) = @_;

my ($file_option) = $original->{file_options}->[0];
if ($file_option)
{
$self->file_options({ filesize => $file_option->{filesize} });
}
};

sub tjoin
{ my $self = shift;
+{$self->field => 'value'};
Expand Down
4 changes: 2 additions & 2 deletions lib/GADS/Filecheck.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ sub check_upload
{
my ($self, $upload, %options) = @_;

error __"Maximum file size is 50 MB"
if $upload->size > 50 * 1024 * 1024;
error __"Maximum file size is $options{col_filesize} KB"
if $upload->size > (int($options{col_filesize} ? $options{col_filesize} : 50 * 1024) * 1024);

return $self->_check_file($upload->filename, $upload->tempname, %options);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use base 'DBIx::Class::Schema';

__PACKAGE__->load_namespaces;

our $VERSION = 110;
our $VERSION = 111;

our $IGNORE_PERMISSIONS;
our $IGNORE_PERMISSIONS_SEARCH;
Expand Down
31 changes: 0 additions & 31 deletions lib/GADS/Schema/Result/FileOption.pm

This file was deleted.

7 changes: 0 additions & 7 deletions lib/GADS/Schema/Result/Layout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,6 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);

__PACKAGE__->has_many(
"file_options",
"GADS::Schema::Result::FileOption",
{ "foreign.layout_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);

__PACKAGE__->has_many(
"files",
"GADS::Schema::Result::File",
Expand Down
Loading