From fd3346586ecf9de3eccb8fae90274e7b74510911 Mon Sep 17 00:00:00 2001 From: Peter Christiansen Date: Thu, 21 Jul 2011 21:42:17 +0200 Subject: [PATCH 1/3] - added #9668 extension template variable to attachment loops for the following assets: Article,Post,Event,File,Form::Attachments,Folder --- docs/changelog/7.x.x.txt | 97 ++--------------------------- lib/WebGUI/Asset/Event.pm | 1 + lib/WebGUI/Asset/File.pm | 2 + lib/WebGUI/Asset/Post.pm | 1 + lib/WebGUI/Asset/Wobject/Article.pm | 1 + lib/WebGUI/Asset/Wobject/Folder.pm | 1 + lib/WebGUI/Form/Attachments.pm | 1 + 7 files changed, 13 insertions(+), 91 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 4407a3420..784112767 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,95 +1,6 @@ 7.10.21 - - added the optional WebGUI::Content::PDFGenerator, not enabled by default - (see the module's documentation). - -7.10.20 - - fixed: Do not call group methods on an undefined value. - - fixed #12178: random deletion of columns may happen when a schema is saved (Amir Plivatsky) - - fixed #12179: DataTable Field types get reset to "Text" in Edit Schema (Amir Plivatsky) - - added: FormField macro for rendering Form objects directly from templates - - fixed: Generic Tax driver does not like spaces around commas - - fixed: Date formatting with WebGUI::DateTime has extra spaces for single digit months and days. - - fixed #12165: Default date in Thingy doesn't work - - fixed #12188: Thingy broken after upgrade to 7.9.32-stable - - fixed #12184: Apache error in modperl.error.log (William McKee, Knowmad Technologies) - - fixed #12186: keywords template variable not working properly in Article - - fixed #12190: List type form plugins that do not override getOptions show no value when getValueAsHtml is called - - fixed #12135: Geo::Coder::Googlev3 needs common sense - - fixed #12183: Posts do not disqualify themselves when purged - - fixed #12189: installClass ignores preload.custom - - fixed #12197: Default date Thingy disables date - -7.10.19 - - fixed #12169: extras uploads symlink export - - Added ability to pass caller assetId to RenderThingMacro - - Allow specific expirations for groups in userImport.pl - - fixed #12164: Calendar feeds with tons of ;adminId=XXXXXX added - - fixed #12167: Calendar Next/Prev Month/Year confusion - - fixed #12172: Underground User Style template shows up in Style wizard during site creation - - fixed #12157: www_editThingSave - -7.10.18 - - fixed #12138: Version tag gets create by entering and direct leaving - - Added the WebGUI::Event API - - fixed #12141: Macro_RenderThingData (bad tags) nothing to translate - - fixed #12142: Copy fails on imported threads - - canView will now be checked before calling ANY www_ method on account - plugins to fix an Inbox security bug (and other similar potential bugs). - - fixed #12139: break on calander feeds during upgrade - - fixed #12136: Unable to add more than one image in Story - - fixed #12133: RenderThingData macro doesn't accept templateId - - fixed #12152: PayPal Standard ignores shop-credit - - fixed #12119: Locale setting for paypal - - fixed #12156: Asset Manager performance - - fixed #12158: Shop credit cannot be used to pay for Shipping on PayPal - - rfe #12159: Asset Manager sort preferences - - added: new default Collaboration System notification template. - -7.10.17 - - fixed: Forced to use a PayDriver even with a balance of 0 in the cart. - - add #12134: Access metadata for assets inside an AssetReport - - fixed : Thingy CSV import not counting towards maxEntriesPerUser - - fixed : Thingy CSV new records not updated with createdById and dateCreated and ipAddress - - added : Thingy fields can now be set as unique and checked upon insert - - added : Thingy max entries of thingy records added - - fixed #12140: PayPal standard can be used to to purchase items without paying for them - -7.10.16 - - fixed #12121: typ-o Asset_Map.templateIdEditPoint - - rfe #2123: Layouts related for export purposes - - fixed #12125: Recaptcha API url - - rfe #12127: AssetProperty macro - - fixed #12129: AdminBar calls canAdd as an object method - -7.10.15 - - fixed #12117: Thingy - www_searchViaAjax broken - - fixed #12116: JsonTable form control needs i18n - - fixed #12102: User profiling field extras information - - fixed #12106: CalendarUpdateFeeds activity does not handle time zones correctly - - fixed #11213: Gooey on the Go format problem - - mark makeUrlCompliant as deprecated. - - fixed #12059: WebGUI::Asset::Wobject::Map - Set Default Viewing Area button does not work. - - added: Setting MapPoint locations via address. - - added: Make Thing data searchable - - added: AssetProxy like macro for Thing data, ViewThingData - -7.10.14 - - fixed #12094: Cannot enter in Macros in URLs inside TinyMCE. - - rfe #12093: Remotely stored photos for Story assets - - fixed #12088: Organization left out of transaction - - fixed #12095: Shop admin screen has JS errors? - - fixed #12097: GroupManager pop-up not working - - fixed #12098: Missing template breaks WebGUI password recovery by email - - remove extra Underground style templates that were part of the 7.10.13 upgrade. - - fixed #12056: Adding a Thing always creates a table - - fixed #11955: Rich Text Editor for Forums doesn't work on the iPad - - fixed #11992: html source editor - - fixed #12100: Carousel and/or RichEdit - - fixed #12103: PayPalStd driver fails occasionally - - rfe #12105: Make shortcuts related for export purposes - - rfe #12108: Mail to Group preference field - - fixed #12107: Viewing an individual transaction item fails - - fixed #12104: Calendar iCal feed status and lastUPdated fields missing + - added #9668 extension template variable to attachment loops for the following assets: + Article,Post,Event,File,Form::Attachments,Folder 7.10.13 - added #12079: Carousel Auto Play @@ -104,6 +15,10 @@ - fixed #12076: Paginator shows no results with cached page index - fixed #12087: Extend WebGUI tests to check template attachments - fixed #12091: Survey Statistical Overview display + - fixed : Thingy CSV import not counting towards maxEntriesPerUser + - fixed : Thingy CSV new records not updated with createdById and dateCreated and ipAddress + - added : Thingy fields can now be set as unique and checked upon insert + - added : Thingy max entries of thingy records added 7.10.12 - fixed #12072: Product, related and accessory assets diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 9f4bb9184..6a7f7d872 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -1249,6 +1249,7 @@ sub getTemplateVars { url => $storage->getUrl($filename), icon => $storage->getFileIconUrl($filename), filename => $filename, + extension => WebGUI::Storage->getFileExtension($filename), thumbnail => $storage->getThumbnailUrl($filename), isImage => $storage->isImage($filename), }; diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index 85d0451a0..57aef5c45 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -677,6 +677,8 @@ sub view { $var{fileUrl} = $self->getFileUrl; $var{fileIcon} = $self->getFileIconUrl; $var{fileSize} = formatBytes($self->get("assetSize")); + $var{extension} = WebGUI::Storage->getFileExtension( $self->get("filename")); + my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { WebGUI::Cache->new($self->session,"view_".$self->getId)->set($out,$self->get("cacheTimeout")); diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm index a493e2d61..3f58019f7 100644 --- a/lib/WebGUI/Asset/Post.pm +++ b/lib/WebGUI/Asset/Post.pm @@ -813,6 +813,7 @@ sub getTemplateVars { url => $fileUrl, icon => $storage->getFileIconUrl($filename), filename => $filename, + extension => WebGUI::Storage->getFileExtension($filename), thumbnail => $isImage ? $storage->getThumbnailUrl($filename) : '', isImage => $isImage, }); diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm index 512c50c8b..3e55e2c7c 100644 --- a/lib/WebGUI/Asset/Wobject/Article.pm +++ b/lib/WebGUI/Asset/Wobject/Article.pm @@ -369,6 +369,7 @@ sub view { } push(@{$var{attachment_loop}}, { filename => $file, + extension => WebGUI::Storage->getFileExtension($file), isImage => $storage->isImage($file), url=> $storage->getUrl($file), thumbnailUrl => $storage->getThumbnailUrl($file), diff --git a/lib/WebGUI/Asset/Wobject/Folder.pm b/lib/WebGUI/Asset/Wobject/Folder.pm index a25ea1e17..21c11e357 100644 --- a/lib/WebGUI/Asset/Wobject/Folder.pm +++ b/lib/WebGUI/Asset/Wobject/Folder.pm @@ -313,6 +313,7 @@ sub view { "icon.small" => $child->getIcon(1), "icon.big" => $child->getIcon, type => $child->getName, + extension => WebGUI::Storage->getFileExtension( $child->get("filename")), url => $child->getUrl, canEdit => $child->canEdit, controls => $child->getToolbar, diff --git a/lib/WebGUI/Form/Attachments.pm b/lib/WebGUI/Form/Attachments.pm index 7d551f926..6cb31d0b1 100644 --- a/lib/WebGUI/Form/Attachments.pm +++ b/lib/WebGUI/Form/Attachments.pm @@ -302,6 +302,7 @@ sub www_upload { title => $filename, url => "attachments/".$filename, filename => $filename, + extension => WebGUI::Storage->getFileExtension($filename), ownerUserId => $owner, groupIdEdit => "3", groupIdView => "7", From 3128741b4b4d579ce2d7b4d67fbe2782fa3aeb75 Mon Sep 17 00:00:00 2001 From: Peter Christiansen Date: Thu, 21 Jul 2011 23:11:03 +0200 Subject: [PATCH 2/3] Rebased changelog and added changes. - added #9668 extension template variable to attachment loops for the following assets: Article,Post,Event,File,Form::Attachments,Folder --- docs/changelog/7.x.x.txt | 98 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 784112767..16ae28fbb 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,6 +1,97 @@ 7.10.21 - added #9668 extension template variable to attachment loops for the following assets: - Article,Post,Event,File,Form::Attachments,Folder + Article,Post,Event,File,Form::Attachments,Folder + - added the optional WebGUI::Content::PDFGenerator, not enabled by default + (see the module's documentation). + +7.10.20 + - fixed: Do not call group methods on an undefined value. + - fixed #12178: random deletion of columns may happen when a schema is saved (Amir Plivatsky) + - fixed #12179: DataTable Field types get reset to "Text" in Edit Schema (Amir Plivatsky) + - added: FormField macro for rendering Form objects directly from templates + - fixed: Generic Tax driver does not like spaces around commas + - fixed: Date formatting with WebGUI::DateTime has extra spaces for single digit months and days. + - fixed #12165: Default date in Thingy doesn't work + - fixed #12188: Thingy broken after upgrade to 7.9.32-stable + - fixed #12184: Apache error in modperl.error.log (William McKee, Knowmad Technologies) + - fixed #12186: keywords template variable not working properly in Article + - fixed #12190: List type form plugins that do not override getOptions show no value when getValueAsHtml is called + - fixed #12135: Geo::Coder::Googlev3 needs common sense + - fixed #12183: Posts do not disqualify themselves when purged + - fixed #12189: installClass ignores preload.custom + - fixed #12197: Default date Thingy disables date + +7.10.19 + - fixed #12169: extras uploads symlink export + - Added ability to pass caller assetId to RenderThingMacro + - Allow specific expirations for groups in userImport.pl + - fixed #12164: Calendar feeds with tons of ;adminId=XXXXXX added + - fixed #12167: Calendar Next/Prev Month/Year confusion + - fixed #12172: Underground User Style template shows up in Style wizard during site creation + - fixed #12157: www_editThingSave + +7.10.18 + - fixed #12138: Version tag gets create by entering and direct leaving + - Added the WebGUI::Event API + - fixed #12141: Macro_RenderThingData (bad tags) nothing to translate + - fixed #12142: Copy fails on imported threads + - canView will now be checked before calling ANY www_ method on account + plugins to fix an Inbox security bug (and other similar potential bugs). + - fixed #12139: break on calander feeds during upgrade + - fixed #12136: Unable to add more than one image in Story + - fixed #12133: RenderThingData macro doesn't accept templateId + - fixed #12152: PayPal Standard ignores shop-credit + - fixed #12119: Locale setting for paypal + - fixed #12156: Asset Manager performance + - fixed #12158: Shop credit cannot be used to pay for Shipping on PayPal + - rfe #12159: Asset Manager sort preferences + - added: new default Collaboration System notification template. + +7.10.17 + - fixed: Forced to use a PayDriver even with a balance of 0 in the cart. + - add #12134: Access metadata for assets inside an AssetReport + - fixed : Thingy CSV import not counting towards maxEntriesPerUser + - fixed : Thingy CSV new records not updated with createdById and dateCreated and ipAddress + - added : Thingy fields can now be set as unique and checked upon insert + - added : Thingy max entries of thingy records added + - fixed #12140: PayPal standard can be used to to purchase items without paying for them + +7.10.16 + - fixed #12121: typ-o Asset_Map.templateIdEditPoint + - rfe #2123: Layouts related for export purposes + - fixed #12125: Recaptcha API url + - rfe #12127: AssetProperty macro + - fixed #12129: AdminBar calls canAdd as an object method + +7.10.15 + - fixed #12117: Thingy - www_searchViaAjax broken + - fixed #12116: JsonTable form control needs i18n + - fixed #12102: User profiling field extras information + - fixed #12106: CalendarUpdateFeeds activity does not handle time zones correctly + - fixed #11213: Gooey on the Go format problem + - mark makeUrlCompliant as deprecated. + - fixed #12059: WebGUI::Asset::Wobject::Map - Set Default Viewing Area button does not work. + - added: Setting MapPoint locations via address. + - added: Make Thing data searchable + - added: AssetProxy like macro for Thing data, ViewThingData + +7.10.14 + - fixed #12094: Cannot enter in Macros in URLs inside TinyMCE. + - rfe #12093: Remotely stored photos for Story assets + - fixed #12088: Organization left out of transaction + - fixed #12095: Shop admin screen has JS errors? + - fixed #12097: GroupManager pop-up not working + - fixed #12098: Missing template breaks WebGUI password recovery by email + - remove extra Underground style templates that were part of the 7.10.13 upgrade. + - fixed #12056: Adding a Thing always creates a table + - fixed #11955: Rich Text Editor for Forums doesn't work on the iPad + - fixed #11992: html source editor + - fixed #12100: Carousel and/or RichEdit + - fixed #12103: PayPalStd driver fails occasionally + - rfe #12105: Make shortcuts related for export purposes + - rfe #12108: Mail to Group preference field + - fixed #12107: Viewing an individual transaction item fails + - fixed #12104: Calendar iCal feed status and lastUPdated fields missing 7.10.13 - added #12079: Carousel Auto Play @@ -15,10 +106,6 @@ - fixed #12076: Paginator shows no results with cached page index - fixed #12087: Extend WebGUI tests to check template attachments - fixed #12091: Survey Statistical Overview display - - fixed : Thingy CSV import not counting towards maxEntriesPerUser - - fixed : Thingy CSV new records not updated with createdById and dateCreated and ipAddress - - added : Thingy fields can now be set as unique and checked upon insert - - added : Thingy max entries of thingy records added 7.10.12 - fixed #12072: Product, related and accessory assets @@ -4144,3 +4231,4 @@ - Made the Include macro more secure. - Added Len's patch to fix some caching problems. + From a9ac52aee3a6a8a5aa1247250e7d262aa4a66102 Mon Sep 17 00:00:00 2001 From: Peter Christiansen Date: Sat, 23 Jul 2011 01:58:48 +0200 Subject: [PATCH 3/3] Added tests to Article.t and Post.t for checking that the template variables contain the new extension variable. --- t/Asset/Post.t | 12 ++++++++- t/Asset/Wobject/Article.t | 53 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/t/Asset/Post.t b/t/Asset/Post.t index d03d54276..039b1ea28 100644 --- a/t/Asset/Post.t +++ b/t/Asset/Post.t @@ -19,7 +19,7 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 20; # increment this value for each test you create +use Test::More tests => 23; # increment this value for each test you create use Test::Deep; use WebGUI::Asset::Wobject::Collaboration; use WebGUI::Asset::Post; @@ -175,6 +175,13 @@ $storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')) $storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('littleTextFile')); my $attachment_loop = $post1->getTemplateVars()->{attachment_loop}; + +ok ( $attachment_loop->[0]->{'extension'} eq 'jpg','Yup, extension template variable in attachment loop working for jpg'); +ok ( $attachment_loop->[1]->{'extension'} eq 'jpg','Yup, extension template variable in attachment loop working for jpg'); +ok ( $attachment_loop->[2]->{'extension'} eq '','Yup, extension template variable in attachment loop working for file with no extension'); + + + cmp_bag( $attachment_loop, [ @@ -183,6 +190,7 @@ cmp_bag( url => $storage->getUrl('gooey.jpg'), icon => $session->url->extras('fileIcons/jpg.gif'), thumbnail => $storage->getThumbnailUrl('gooey.jpg'), + extension => 'jpg', isImage => bool(1), }, { @@ -190,6 +198,7 @@ cmp_bag( url => $storage->getUrl('lamp.jpg'), icon => $session->url->extras('fileIcons/jpg.gif'), thumbnail => $storage->getThumbnailUrl('lamp.jpg'), + extension => 'jpg', isImage => bool(1), }, { @@ -197,6 +206,7 @@ cmp_bag( url => $storage->getUrl('littleTextFile'), icon => $session->url->extras('fileIcons/unknown.gif'), thumbnail => '', + extension => '', isImage => bool(0), }, ], diff --git a/t/Asset/Wobject/Article.t b/t/Asset/Wobject/Article.t index defaae2e2..acc778845 100644 --- a/t/Asset/Wobject/Article.t +++ b/t/Asset/Wobject/Article.t @@ -17,7 +17,7 @@ use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 23; # increment this value for each test you create +use Test::More tests => 28; # increment this value for each test you create use WebGUI::Asset::Wobject::Article; my $session = WebGUI::Test->session; @@ -66,9 +66,10 @@ foreach my $newSetting (keys %{$newArticleSettings}) { } # Test the duplicate method... not for assets, just the extended duplicate functionality of the article wobject -my $filename = "page_title.jpg"; +my $filename = "extensions.tar"; my $pathedFile = WebGUI::Test->getTestCollateralPath($filename); + # Use some test collateral to create a storage location and assign it to our article my $storage = WebGUI::Storage->create($session); WebGUI::Test->addToCleanup($storage); @@ -80,6 +81,10 @@ diag(join("\n", @{ $storage->getErrors })) unless $filenameOK; $article->update({storageId=>$storage->getId}); my $storageOK = is($article->get('storageId'), $storage->getId, 'correct storage id stored'); + + + + SKIP: { skip 'storage test setup problem', 3 unless $filenameOK and $storageOK; @@ -122,6 +127,46 @@ $cachedOutput = WebGUI::Cache->new($session, 'view_'.$article->getId)->get; # C isnt ($output, $cachedOutput, 'purgeCache method deletes cache'); +# lets test that our new template variable for the fileloop in the main view method returns the +# right values for the new field in the attached files loop: +# first we create a new template with only the field in it +# -------------------------------------------------------------------------------------------------- + +my $viewTemplate = $node->addChild({className=>'WebGUI::Asset::Template'}); + +my $tmplContent = "|"; + +my $newTemplateSettings = { + namespace => 'Article', + template => $tmplContent, +}; + + +my @extTestFiles = ("rotation_test.png","littleTextFile","jquery.js","tooWide.gif"); + +foreach my $f (@extTestFiles) { + my $pathedFile = WebGUI::Test->getTestCollateralPath($f); + my $storedFilename = $storage->addFileFromFilesystem($pathedFile); +} + +$viewTemplate->update($newTemplateSettings); +$article->update({templateId=>$viewTemplate->getId}); +$article->prepareView; + +my $newFieldoutput = $article->view; +$newFieldoutput =~ s/\|$//; + +my @tmplExtensions = split /\|/,$newFieldoutput; + + +# rememer there is a tar file already stored from earlier test, we reuse this. +ok ( $tmplExtensions[0] eq "tar", 'Yup, extension template variable in fileLoop working for tar'); +ok ( $tmplExtensions[1] eq "png", 'Yup, extension template variable in fileLoop working for png'); +ok ( $tmplExtensions[2] eq "", 'Yup, extension template variable in fileLoop working for file with no extension'); +ok ( $tmplExtensions[3] eq "js", 'Yup, extension template variable in fileLoop working for js'); +ok ( $tmplExtensions[4] eq "gif", 'Yup, extension template variable in fileLoop working for gif'); + + TODO: { local $TODO = "Tests to make later"; ok(0, 'Test exportAssetData method'); @@ -131,3 +176,7 @@ TODO: { ok(0, 'Test www_deleteFile method'); ok(0, 'Test www_view method... maybe?'); } + + + +