Commit c95e4f90 authored by Audrey Tang's avatar Audrey Tang
Browse files

file OCVF upload works.

it is now possible to download OCFVs.

git-svn-id: svn+ssh://svn.bestpractical.com/svn/bps-public/rt/branches/autrijus-3.1@488 e417ac7c-1bcc-0310-8ffa-8f5827389a85
parent 37312e01
......@@ -31,7 +31,7 @@
<FORM ACTION="<%$RT::WebPath%>/Admin/Groups/Modify.html" METHOD=POST>
<FORM ACTION="<%$RT::WebPath%>/Admin/Groups/Modify.html" METHOD=POST ENCTYPE="multipart/form-data">
%unless ($Group->Id) {
<INPUT TYPE=HIDDEN NAME=id VALUE="new">
......
......@@ -30,7 +30,7 @@
<& /Elements/ListActions, actions => \@results &>
<FORM ACTION="<%$RT::WebPath%>/Admin/Users/Modify.html" METHOD=POST>
<FORM ACTION="<%$RT::WebPath%>/Admin/Users/Modify.html" METHOD=POST ENCTYPE="multipart/form-data">
%if ($Create) {
<INPUT TYPE=HIDDEN NAME=id VALUE="new">
% } else {
......
%# BEGIN LICENSE BLOCK
%#
%# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
%#
%# (Except where explictly superceded by other copyright notices)
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%# General Public License for more details.
%#
%# Unless otherwise specified, all modifications, corrections or
%# extensions to this work which alter its source code become the
%# property of Best Practical Solutions, LLC when submitted for
%# inclusion in the work.
%#
%#
%# END LICENSE BLOCK
<%perl>
my $id;
my $arg = $m->dhandler_arg; # get rest of path
if ($arg =~ /^(\d+)\//) {
$id = $1;
}
else {
Abort("Corrupted customfieldvalue URL.");
}
my $OCFV = RT::ObjectCustomFieldValue->new($session{'CurrentUser'});
$OCFV->Load($id) || Abort("OCFV '$id' could not be loaded");
unless ($OCFV->id) {
Abort("Bad OCFV id. Couldn't find OCFV '$id'\n");
}
my $content_type = $OCFV->ContentType || 'text/plain';
unless ($RT::TrustHTMLAttachments) {
$content_type = 'text/plain' if ($content_type =~ /^text\/html/i);
}
$r->content_type( $content_type );
$m->clear_buffer();
$m->out($OCFV->LargeContent);
$m->abort;
</%perl>
<%attr>
AutoFlush => 0
</%attr>
......@@ -23,10 +23,10 @@
%# END LICENSE BLOCK
% while (my $value = $Values->Next ) {
%# XXX - let user download the file(s) here?
<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValues" value="<% $value->Id %>"><% $value->Content %><br>
<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" value="<% $value->Id %>"><a href="/CustomFieldValue/<% $value->Id %>/<% $value->Content %>"><% $value->Content %></a><br>
% }
% if (!$MaxValues or $Values->Count >= $MaxValues) {
<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Value">
% if (!$MaxValues or $Values->Count < $MaxValues) {
<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Upload">
% }
<%ARGS>
$Object => undef
......
......@@ -22,11 +22,11 @@
%#
%# END LICENSE BLOCK
% while (my $value = $Values->Next ) {
%# XXX - display thumbnails or full images?
<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValues" value="<% $value->Id %>"><% $value->Content %><br>
%# XXX - let user download the file(s) here?
<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" value="<% $value->Id %>"><a href="/CustomFieldValue/<% $value->Id %>/<% $value->Content %>"><% $value->Content %></a><br>
% }
% if (!$MaxValues or $Values->Count < $MaxValues) {
<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Value">
<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Upload">
% }
<%ARGS>
$Object => undef
......
......@@ -773,6 +773,8 @@ sub AddValueForObject {
my $self = shift;
my %args = ( Object => undef,
Content => undef,
LargeContent => undef,
ContentType => undef,
@_ );
my $obj = $args{'Object'} or return;
......@@ -780,6 +782,8 @@ sub AddValueForObject {
my $val = $newval->Create(ObjectType => ref($obj),
ObjectId => $obj->Id,
Content => $args{'Content'},
LargeContent => $args{'LargeContent'},
ContentType => $args{'ContentType'},
CustomField => $self->Id);
return($val);
......@@ -798,15 +802,25 @@ Adds a custom field value for a ticket. Takes a param hash of Object and Content
=cut
sub DeleteValueForObject {
my $self = shift;
my %args = ( Object => undef,
my $self = shift;
my %args = ( Object => undef,
Content => undef,
Id => undef,
@_ );
my $oldval = RT::ObjectCustomFieldValue->new($self->CurrentUser);
$oldval->LoadByObjectContentAndCustomField (Object => $args{'Object'},
Content => $args{'Content'},
CustomField => $self->Id );
my $oldval = RT::ObjectCustomFieldValue->new($self->CurrentUser);
if (my $id = $args{'Id'}) {
$oldval->Load($id);
}
else {
$oldval->LoadByObjectContentAndCustomField(
Object => $args{'Object'},
Content => $args{'Content'},
CustomField => $self->Id
);
}
# check ot make sure we found it
unless ($oldval->Id) {
return(0, $self->loc("Custom field value [_1] could not be found for custom field [_2]", $args{'Content'}, $self->Name));
......
......@@ -1166,6 +1166,19 @@ sub ProcessObjectCustomFieldUpdates {
push ( @results, $msg );
}
}
elsif ( $arg =~ /-Upload$/ ) {
my $cgi_object = $m->cgi_object;
my $fh = $cgi_object->upload($arg) or next;
my $upload_info = $cgi_object->uploadInfo($fh);
my $filename = "$fh";
$filename =~ s#^.*[\\/]##;
my ( $val, $msg ) = $Object->AddCustomFieldValue(
Field => $cf,
Value => $filename,
LargeContent => do { local $/; scalar <$fh> },
ContentType => $upload_info->{'Content-Type'},
);
}
elsif ( $arg =~ /-DeleteValues$/ ) {
foreach my $value (@values) {
next unless length($value);
......@@ -1176,6 +1189,16 @@ sub ProcessObjectCustomFieldUpdates {
push ( @results, $msg );
}
}
elsif ( $arg =~ /-DeleteValueIds$/ ) {
foreach my $value (@values) {
next unless length($value);
my ( $val, $msg ) = $Object->DeleteCustomFieldValue(
Field => $cf,
ValueId => $value,
);
push ( @results, $msg );
}
}
elsif ( $arg =~ /-Values$/ and !$CustomFieldObj->Repeated) {
my $cf_values = $Object->CustomFieldValues($cf);
......
......@@ -68,4 +68,9 @@ sub LoadByObjectContentAndCustomField {
}
sub Delete {
my $self = shift;
$self->SetCurrent(0);
}
1;
......@@ -791,7 +791,9 @@ sub _AddCustomFieldValue {
my ( $new_value_id, $value_msg ) = $cf->AddValueForObject(
Object => $self,
Content => $args{'Value'}
Content => $args{'Value'},
LargeContent => $args{'LargeContent'},
ContentType => $args{'ContenType'},
);
unless ($new_value_id) {
......@@ -836,7 +838,9 @@ sub _AddCustomFieldValue {
else {
my ( $new_value_id ) = $cf->AddValueForObject(
Object => $self,
Content => $args{'Value'}
Content => $args{'Value'},
LargeContent => $args{'LargeContent'},
ContentType => $args{'ContenType'},
);
unless ($new_value_id) {
......@@ -879,6 +883,7 @@ sub DeleteCustomFieldValue {
my %args = (
Field => undef,
Value => undef,
ValueId => undef,
@_);
# XXX - normalise CF related ACLs... ask obra!
......@@ -898,7 +903,11 @@ sub DeleteCustomFieldValue {
}
my ($val, $msg) = $cf->DeleteValueForObject(Object => $self, Content => $args{'Value'});
my ($val, $msg) = $cf->DeleteValueForObject(
Object => $self,
Id => $args{'ValueId'},
Content => $args{'Value'},
);
unless ($val) {
return (0,$msg);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment