From 82a7e5dfd2b7e5b3cda2863296f6b95a4c97e8e1 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Sun, 21 Sep 2008 22:56:42 +0000 Subject: [PATCH] fixed problem with showing other assets' edit forms fixed utility skeleton to be more complete and less annoying added warning message when editing default templates --- docs/changelog/7.x.x.txt | 3 + docs/upgrades/upgrade_7.5.21-7.6.0.pl | 122 +++++++++++++++++++ lib/WebGUI/Asset.pm | 7 ++ lib/WebGUI/Asset/Template.pm | 142 +++++++++++++++------- lib/WebGUI/i18n/English/Asset_Template.pm | 13 ++ sbin/_utility.skeleton | 38 ++++-- 6 files changed, 270 insertions(+), 55 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 0176b233b..a67a582e3 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -79,6 +79,9 @@ - added: Thingy view template now has access to field_dateCreated and field_lastUpdated for Things. - added: AssetManager now times out after 30 seconds on the AJAX call to load assets. This will help people realize they are having network issues. - fixed: DatePicker.js can now use different first days of the week. + - added: Default templates now show big warning message. All templates added via upgrade scripts + are set to be a "default" template. + - fixed: Utility script skeleton now more complete and less annoying 7.5.22 - fixed: Layout template now gets prepared correctly diff --git a/docs/upgrades/upgrade_7.5.21-7.6.0.pl b/docs/upgrades/upgrade_7.5.21-7.6.0.pl index 423106df9..8f82f0061 100644 --- a/docs/upgrades/upgrade_7.5.21-7.6.0.pl +++ b/docs/upgrades/upgrade_7.5.21-7.6.0.pl @@ -36,9 +36,113 @@ addLoginTimeStats( $session ); addEMSBadgeTemplate ( $session ); redirectChoice ($session); badgePriceDates ($session); +addIsDefaultTemplates( $session ); finish($session); # this line required +#---------------------------------------------------------------------------- +# Add the "isDefault" flag and set it for the right templates +sub addIsDefaultTemplates { + my $session = shift; + print "\tAdding warning when editing default templates... " unless $quiet; + $session->db->write( "ALTER TABLE template ADD COLUMN isDefault INT(1) DEFAULT 0" ); + print "DONE!\n" unless $quiet; +} + +sub setDefaultTemplates { + my $session = shift; + print "\tUpdating default templates to show warning... " unless $quiet; + my $defaultTemplates =[ + '-ANLpoTEP-n4POAdRxCzRw','05FpjceLYhq4csF1Kww1KQ','0X4Q3tBWUb_thsVbsYz9xQ', + '2gtFt7c0qAFNU3BG_uvNvg','2rC4ErZ3c77OJzJm7O5s3w','3womoo7Teyy2YKFa25-MZg', + '63ix2-hU0FchXGIWkG3tow','6X-7Twabn5KKO_AbgK3PEw','7JCTAiu1U_bT9ldr655Blw', + 'BMybD3cEnmXVk2wQ_qEsRQ','CalendarDay00000000001','CalendarEvent000000001', + 'CalendarEventEdit00001','CalendarMonth000000001','CalendarPrintDay000001', + 'CalendarPrintEvent0001','CalendarPrintMonth0001','CalendarPrintWeek00001', + 'CalendarSearch00000001','CalendarWeek0000000001','DPUROtmpl0000000000001', + 'DashboardViewTmpl00001','EBlxJpZQ9o-8VBOaGQbChA','GNvjCFQWjY2AF2uf0aCM8Q', + 'IOB0000000000000000001','IOB0000000000000000002','KAMdiUdJykjN02CPHpyZOw', + 'MultiSearchTmpl0000001','OOyMH33plAy6oCj_QWrxtg','OkphOEdaSGTXnFGhK4GT5A', + 'OxJWQgnGsgyGohP2L3zJPQ','PBnav00000000000bullet', + 'PBnav00000000indentnav','PBnav000000style01lvl2','PBtmpl0000000000000001', + 'PBtmpl0000000000000002','PBtmpl0000000000000004','PBtmpl0000000000000005', + 'PBtmpl0000000000000006','PBtmpl0000000000000010','PBtmpl0000000000000011', + 'PBtmpl0000000000000012','PBtmpl0000000000000013','PBtmpl0000000000000014', + 'PBtmpl0000000000000020','PBtmpl0000000000000021','PBtmpl0000000000000024', + 'PBtmpl0000000000000026','PBtmpl0000000000000027','PBtmpl0000000000000029', + 'PBtmpl0000000000000031','PBtmpl0000000000000032','PBtmpl0000000000000033', + 'PBtmpl0000000000000034','PBtmpl0000000000000036','PBtmpl0000000000000037', + 'PBtmpl0000000000000038','PBtmpl0000000000000039','PBtmpl0000000000000040', + 'PBtmpl0000000000000041','PBtmpl0000000000000042','PBtmpl0000000000000043', + 'PBtmpl0000000000000044','PBtmpl0000000000000045','PBtmpl0000000000000046', + 'PBtmpl0000000000000047','PBtmpl0000000000000048','PBtmpl0000000000000051', + 'PBtmpl0000000000000052','PBtmpl0000000000000053','PBtmpl0000000000000054', + 'PBtmpl0000000000000055','PBtmpl0000000000000056','PBtmpl0000000000000057', + 'PBtmpl0000000000000059','PBtmpl0000000000000060','PBtmpl0000000000000061', + 'PBtmpl0000000000000062','PBtmpl0000000000000063','PBtmpl0000000000000064', + 'PBtmpl0000000000000065','PBtmpl0000000000000066','PBtmpl0000000000000067', + 'PBtmpl0000000000000068','PBtmpl0000000000000069','PBtmpl0000000000000077', + 'PBtmpl0000000000000078','PBtmpl0000000000000079','PBtmpl0000000000000080', + 'PBtmpl0000000000000081','PBtmpl0000000000000082','PBtmpl0000000000000083', + 'PBtmpl0000000000000084','PBtmpl0000000000000085','PBtmpl0000000000000088', + 'PBtmpl0000000000000090','PBtmpl0000000000000091','PBtmpl0000000000000092', + 'PBtmpl0000000000000093','PBtmpl0000000000000094','PBtmpl0000000000000097', + 'PBtmpl0000000000000098','PBtmpl0000000000000099','PBtmpl0000000000000100', + 'PBtmpl0000000000000101','PBtmpl0000000000000103','PBtmpl0000000000000104', + 'PBtmpl0000000000000107','PBtmpl0000000000000108','PBtmpl0000000000000109', + 'PBtmpl0000000000000111','PBtmpl0000000000000112','PBtmpl0000000000000113', + 'PBtmpl0000000000000114','PBtmpl0000000000000115','PBtmpl0000000000000116', + 'PBtmpl0000000000000117','PBtmpl0000000000000118','PBtmpl0000000000000121', + 'PBtmpl0000000000000122','PBtmpl0000000000000123','PBtmpl0000000000000124', + 'PBtmpl0000000000000125','PBtmpl0000000000000128','PBtmpl0000000000000129', + 'PBtmpl0000000000000130','PBtmpl0000000000000131','PBtmpl0000000000000132', + 'PBtmpl0000000000000133','PBtmpl0000000000000134','PBtmpl0000000000000135', + 'PBtmpl0000000000000136','PBtmpl0000000000000137','PBtmpl0000000000000140', + 'PBtmpl0000000000000141','PBtmpl0000000000000142','PBtmpl0000000000000200', + 'PBtmpl0000000000000205','PBtmpl0000000000000206','PBtmpl0000000000000207', + 'PBtmpl0000000000000208','PBtmpl0000000000000209','PBtmpl0000000000000210', + 'PBtmpl000000000table54','PBtmpl00000000table094','PBtmpl00000000table109', + 'PBtmpl00000000table118','PBtmpl00000000table125','PBtmpl00000000table131', + 'PBtmpl00000000table135','PBtmpl00000userInvite1','PBtmpl0userInviteEmail', + 'PBtmplBlankStyle000001','PBtmplHelp000000000001','PBtmplPrivateMessage01', + 'ProjectManagerTMPL0001','ProjectManagerTMPL0002','ProjectManagerTMPL0003', + 'ProjectManagerTMPL0004','ProjectManagerTMPL0005','ProjectManagerTMPL0006', + 'PsFn7dJt4wMwBa8hiE3hOA','SQLReportDownload0001','StockDataTMPL000000001', + 'StockDataTMPL000000002','TEId5V-jEvUULsZA0wuRuA','ThingyTmpl000000000001', + 'ThingyTmpl000000000002','ThingyTmpl000000000003','ThingyTmpl000000000004', + 'TimeTrackingTMPL000001','TimeTrackingTMPL000002','TimeTrackingTMPL000003', + 'UTNFeV7B_aSCRmmaFCq4Vw','UserListTmpl0000001','UserListTmpl0000002', + 'UserListTmpl0000003','WVtmpl0000000000000001','WeatherDataTmpl0000001', + 'WikiFrontTmpl000000001','WikiKeyword00000000001','WikiMPTmpl000000000001', + 'WikiPHTmpl000000000001','WikiPageEditTmpl000001','WikiPageTmpl0000000001', + 'WikiRCTmpl000000000001','WikiSearchTmpl00000001','XNd7a_g_cTvJVYrVHcx2Mw', + 'ZipArchiveTMPL00000001','aIpCmr9Hi__vgdZnDTz1jw','azCqD0IjdQSlM3ar29k5Sg', + 'bPz1yk6Y9uwMDMBcmMsSCg','eqb9sWjFEVq0yHunGV8IGw','g8W53Pd71uHB9pxaXhWf_A', + 'ilu5BrM-VGaOsec9Lm7M6Q','jME5BEDYVDlBZ8jIQA9-jQ','kj3b-X3i6zRKnhLb4ZiCLw', + 'm3IbBavqzuKDd2PGGhKPlA','mM3bjP_iG9sv5nQb4S17tQ','managefriends_________', + 'matrixtmpl000000000001','matrixtmpl000000000002','matrixtmpl000000000003', + 'matrixtmpl000000000004','matrixtmpl000000000005','nFen0xjkZn8WkpM93C9ceQ', + 'newsletter000000000001','newslettercs0000000001','newslettersubscrip0001', + 'pbtmpl0000000000000220','pbtmpl0000000000000221','q5O62aH4pjUXsrQR3Pq4lw', + 'stevecoolmenu000000001','stevenav00000000000001','stevestyle000000000001', + 'stevestyle000000000002','stevestyle000000000003','uRL9qtk7Rb0YRJ41LmHOJw', + 'vrKXEtluIhbmAS9xmPukDA','yBwydfooiLvhEFawJb0VTQ','zcX-wIUct0S_np14xxOA-A' + ]; + + for my $assetId ( @{ $defaultTemplates } ) { + my $asset = WebGUI::Asset::Template->new( $session, $assetId ); + if ( !$asset ) { + print "\n\t\tCouldn't instanciate default asset '$assetId', skipping..."; + next; + } + else { + $asset->update( { isDefault => 1 } ); + } + } + + print "DONE!\n" unless $quiet; +} + #---------------------------------------------------------------------------- sub badgePriceDates { my $session = shift; @@ -139,6 +243,23 @@ sub addPackage { # Make the package not a package anymore $package->update({ isPackage => 0 }); + + # Set the default flag for templates added + my $assetIds + = $package->getLineage( ['self','descendants'], { + includeOnlyClasses => [ 'WebGUI::Asset::Template' ], + } ); + for my $assetId ( @{ $assetIds } ) { + my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId ); + if ( !$asset ) { + print "Couldn't instantiate asset with ID '$assetId'. Please check package '$file' for corruption.\n"; + next; + } + $asset->update( { isDefault => 1 } ); + print "Updated $assetId\n"; + } + + return; } #------------------------------------------------- @@ -160,6 +281,7 @@ sub start { sub finish { my $session = shift; updateTemplates($session); + setDefaultTemplates( $session ); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->commit; $session->db->write("insert into webguiVersion values (".$session->db->quote($toVersion).",'upgrade',".$session->datetime->time().")"); diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index b2a462f26..c913efccf 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -929,6 +929,13 @@ sub getEditForm { my $uiLevelOverride = $self->get("className"); $uiLevelOverride =~ s/\:\:/_/g; my $tabform = WebGUI::TabForm->new($self->session,undef,undef,$self->getUrl(),$uiLevelOverride); + + # Set the appropriate URL + # If we're adding a new asset, don't set anything + if ( $self->session->form->get( "func" ) ne "add" ) { + $tabform->formHeader( { action => $self->getUrl, method => "POST" } ); + } + if ($self->session->config->get("enableSaveAndCommit")) { $tabform->submitAppend(WebGUI::Form::submit($self->session, { name => "saveAndCommit", diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index d21404f9e..9c79c78e9 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -40,7 +40,6 @@ These methods are available from this class: =cut - #------------------------------------------------------------------- =head2 definition ( session, definition ) @@ -58,45 +57,49 @@ A hash reference passed in from a subclass definition. =cut sub definition { - my $class = shift; - my $session = shift; - my $definition = shift; - my $i18n = WebGUI::International->new($session,"Asset_Template"); - push(@{$definition}, { - assetName=>$i18n->get('assetName'), - icon=>'template.gif', - tableName=>'template', - className=>'WebGUI::Asset::Template', - properties=>{ - template=>{ - fieldType=>'codearea', - defaultValue=>undef - }, - isEditable=>{ - noFormPost=>1, - fieldType=>'hidden', - defaultValue=>1 - }, - showInForms=>{ - fieldType=>'yesNo', - defaultValue=>1 - }, - parser=>{ - noFormPost=>1, - fieldType=>'selectList', - defaultValue=>[$session->config->get("defaultTemplateParser")] - }, - headBlock=>{ - fieldType=>"codearea", - defaultValue=>undef - }, - namespace=>{ - fieldType=>'combo', - defaultValue=>undef - } - } - }); - return $class->SUPER::definition($session,$definition); + my $class = shift; + my $session = shift; + my $definition = shift; + my $i18n = WebGUI::International->new($session,"Asset_Template"); + push @{$definition}, { + assetName => $i18n->get('assetName'), + icon => 'template.gif', + tableName => 'template', + className => 'WebGUI::Asset::Template', + properties => { + template => { + fieldType => 'codearea', + defaultValue => undef, + }, + isEditable => { + noFormPost => 1, + fieldType => 'hidden', + defaultValue => 1, + }, + isDefault => { + fieldType => 'hidden', + defaultValue => 0, + }, + showInForms => { + fieldType => 'yesNo', + defaultValue => 1, + }, + parser => { + noFormPost => 1, + fieldType => 'selectList', + defaultValue => [$session->config->get("defaultTemplateParser")], + }, + headBlock => { + fieldType => "codearea", + defaultValue => undef, + }, + namespace => { + fieldType => 'combo', + defaultValue => undef, + }, + }, + }; + return $class->SUPER::definition($session,$definition); } #------------------------------------------------------------------- @@ -104,6 +107,7 @@ sub definition { sub processPropertiesFromFormPost { my $self = shift; $self->SUPER::processPropertiesFromFormPost; + # TODO: Perhaps add a way to check template syntax before it blows stuff up? if ($self->getValue("parser") ne $self->session->form->process("parser","className") && ($self->session->form->process("parser","className") ne "")) { my %data; if (isIn($self->session->form->process("parser","className"),@{$self->session->config->get("templateParsers")})) { @@ -374,9 +378,48 @@ sub www_edit { my $self = shift; return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->locked() unless $self->canEditIfLocked; - my $i18n = WebGUI::International->new($self->session, "Asset_Template"); + my $session = $self->session; + my $form = $session->form; + my $url = $session->url; + my $i18n = WebGUI::International->new($session, "Asset_Template"); + my $output = ''; + + # Add an unfriendly warning message if this is a default template + if ( $self->get( 'isDefault' ) ) { + # Get a proper URL to make the duplicate + my $duplicateUrl = $self->getUrl( "func=editDuplicate" ); + if ( $form->get( "proceed" ) ) { + $duplicateUrl = $url->append( $duplicateUrl, "proceed=" . $form->get( "proceed" ) ); + if ( $form->get( "returnUrl" ) ) { + $duplicateUrl = $url->append( $duplicateUrl, "returnUrl=" . $form->get( "returnUrl" ) ); + } + } + + $session->style->setRawHeadTags( <<'ENDHTML' ); + +ENDHTML + + $output .= q{

} + . $i18n->get( "warning default template" ) + . q{

} + . sprintf( q{%s}, $i18n->get( "make duplicate label" ) ) + . q{

getEditForm->print; + $self->getAdminConsole->addSubmenuItem($self->getUrl('func=styleWizard'),$i18n->get("style wizard")) if ($self->get("namespace") eq "style"); - return $self->getAdminConsole->render($self->getEditForm->print,$i18n->get('edit template')); + return $self->getAdminConsole->render( $output, $i18n->get('edit template') ); } #------------------------------------------------------------------- @@ -386,6 +429,21 @@ sub www_goBackToPage { return undef; } +#---------------------------------------------------------------------------- + +=head2 www_editDuplicate + +Make a duplicate of this template and edit that instead. + +=cut + +sub www_editDuplicate { + my $self = shift; + return $self->session->privilege->insufficient() unless $self->canEdit; + my $newAsset = $self->duplicate; + $newAsset->update( { isDefault => 0 } ); + return $newAsset->www_edit; +} #------------------------------------------------------------------- sub www_manage { diff --git a/lib/WebGUI/i18n/English/Asset_Template.pm b/lib/WebGUI/i18n/English/Asset_Template.pm index bb94f28e5..620c8a5b5 100644 --- a/lib/WebGUI/i18n/English/Asset_Template.pm +++ b/lib/WebGUI/i18n/English/Asset_Template.pm @@ -297,6 +297,19 @@ Any scratch variables will be available in the template with this syntax:
lastUpdated => 1162088018, }, + 'warning default template' => { + message => q{You are attempting to edit a default template. Any changes you make to this template + may be lost when you next upgrade WebGUI. To be safe, you should make a duplicate of this template.}, + lastUpdated => 0, + context => q{Warning for users attempting to edit a default template}, + }, + + 'make duplicate label' => { + message => q{Duplicate this template and edit}, + lastUpdated => 0, + context => q{Label for URL to make a duplicate and open the duplicate's edit screen}, + }, + }; 1; diff --git a/sbin/_utility.skeleton b/sbin/_utility.skeleton index 648df63d8..00463a20f 100644 --- a/sbin/_utility.skeleton +++ b/sbin/_utility.skeleton @@ -8,7 +8,8 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); +$|++; # disable output buffering +our ($webguiRoot, $configFile, $help, $man); BEGIN { $webguiRoot = ".."; @@ -21,24 +22,27 @@ use Getopt::Long; use WebGUI::Session; # Get parameters here, including $help +GetOptions( + 'configFile=s' => \$configFile, + 'help' => \$help, + 'man' => \$man, +); -pod2usage( verbose => 2 ) if $help; -pod2usage() unless $help; # Change condition! +pod2usage( verbose => 1 ) if $help; +pod2usage( verbose => 2 ) if $man; +pod2usage( msg => "Must specify a config file!" ) unless $configFile; -my $session = start(); +my $session = start( $webguiRoot, $configFile ); # Do your work here finish($session); -#------------------------------------------------- +#---------------------------------------------------------------------------- # Your sub here -#------------------------------------------------- +#---------------------------------------------------------------------------- sub start { - my $configFile; - $| = 1; #disable output buffering - GetOptions( - 'configFile=s' => \$configFile, - ); + my $webguiRoot = shift; + my $configFile = shift; my $session = WebGUI::Session->open($webguiRoot,$configFile); $session->user({userId=>3}); @@ -52,7 +56,7 @@ sub start { return $session; } -#------------------------------------------------- +#---------------------------------------------------------------------------- sub finish { my $session = shift; @@ -83,6 +87,10 @@ utility - A template for WebGUI utility scripts This WebGUI utility script helps you... +=head1 ARGUMENTS + +=head1 OPTIONS + =over =item B<--configFile config.conf> @@ -93,7 +101,11 @@ This parameter is required. =item B<--help> -Shows this documentation, then exits. +Shows a short summary and usage + +=item B<--man> + +Shows this document =back