Author: dom Date: 2008-10-22 13:35:20 +0100 (Wed, 22 Oct 2008) New Revision: 1243
Added: trunk/t/83_show_delete_to_admins_only.t trunk/t/84_navbar_admin.t Modified: trunk/Changes trunk/MANIFEST trunk/t/41_deletion.t trunk/templates/footer.tt trunk/templates/navbar_this_page.tt trunk/templates/node_history.tt Log: Don't add delete links unless the user requests (fixes #159 - thanks bob)
Modified: trunk/Changes =================================================================== --- trunk/Changes 2008-10-22 11:25:56 UTC (rev 1242) +++ trunk/Changes 2008-10-22 12:35:20 UTC (rev 1243) @@ -18,6 +18,7 @@ Move the node image outside the metadata div, to aid styling (#222) Add the ability to whitelist hosts who can change moderated nodes without explicit moderation (#203) + Don't add delete links unless the user requests (#159)
0.63 16 August 2008 Major overhaul of RDF output.
Modified: trunk/MANIFEST =================================================================== --- trunk/MANIFEST 2008-10-22 11:25:56 UTC (rev 1242) +++ trunk/MANIFEST 2008-10-22 12:35:20 UTC (rev 1243) @@ -146,6 +146,8 @@ t/78_about.t t/79_host_blacklist.t t/81_node_moderate_whitelist.t +t/83_show_delete_to_admins_only.t +t/84_navbar_admin.t t/85_universal_edit_link.t t/templates/15_test.tt wiki.cgi
Modified: trunk/t/41_deletion.t =================================================================== --- trunk/t/41_deletion.t 2008-10-22 11:25:56 UTC (rev 1242) +++ trunk/t/41_deletion.t 2008-10-22 12:35:20 UTC (rev 1243) @@ -2,6 +2,7 @@ use OpenGuides; use OpenGuides::Template; use OpenGuides::Test; +use OpenGuides::CGI; use Test::More tests => 3;
my $config = OpenGuides::Test->make_basic_config; @@ -19,13 +20,28 @@ unlike( $output, qr/action=delete/, "doesn't offer page deletion link by default" ); $config->enable_page_deletion( "y" ); + # set is_admin to 1 +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; + $output = OpenGuides::Template->output( wiki => $wiki, config => $config, template => "node.tt", ); like( $output, qr/action=delete/, - "...but does when enable_page_deletion is set to 'y'" ); + "...but does when enable_page_deletion is set to 'y' and is_admin is 1" ); $config->enable_page_deletion( 1 ); $output = OpenGuides::Template->output( wiki => $wiki, @@ -33,4 +49,4 @@ template => "node.tt", ); like( $output, qr/action=delete/, - "...and when enable_page_deletion is set to '1'" ); + "...and when enable_page_deletion is set to '1' and is_admin is 1" );
Added: trunk/t/83_show_delete_to_admins_only.t =================================================================== --- trunk/t/83_show_delete_to_admins_only.t (rev 0) +++ trunk/t/83_show_delete_to_admins_only.t 2008-10-22 12:35:20 UTC (rev 1243) @@ -0,0 +1,122 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::CGI; + + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; + exit 0; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +sub get_recent_changes { + my ($guide) = @_; + + my $output = $guide->display_recent_changes( return_output => 1 ); + $output =~ s/^Content-Type.*[\r\n]+//m; + + return $output; +} + +sub get_preferences { + my ($guide) = @_; + + return OpenGuides::Template->output( + wiki => $guide->wiki, + config => $guide->config, + template => "preferences.tt", + noheaders => 1, + vars => { + not_editable => 1, + show_form => 1 + }, + ); +} + + +plan tests => 4; + +my ( $config, $guide, $wiki, $output ); + +# Clear out the database from any previous runs. +unlink "t/node.db"; +unlink <t/indexes/*>; +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); + + + # Make a guide + $config = OpenGuides::Test->make_basic_config; +$config->enable_page_deletion( 1 ); + $guide = OpenGuides->new( config => $config ); + # set is_admin to 1 +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; +OpenGuides::Test->write_data( + guide => $guide, + node => "Test Page", + ); + + $output = $guide->display_node( + return_output => 1, + id => "Test Page", + ); +# check delete link is shown in footer + Test::HTML::Content::tag_ok( $output, "div", { id => "footer_delete_link" }, + "delete link in footer for admin" ); + + $output = $guide->list_all_versions( + return_output => 1, + id => "Test Page", + ); + like( $output, qr/version=1;action=delete/, + "delete links on history page"); + +# set is_admin to 0 + $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 0, +); +$ENV{HTTP_COOKIE} = $cookie; + + $output = $guide->display_node( + return_output => 1, + id => "Test Page", + ); +# check that the delete link in footer isnt shown + Test::HTML::Content::no_tag( $output, "div", { id => "footer_delete_link" }, + "delete link in footer not shown"); + $output = $guide->list_all_versions( + return_output => 1, + id => "Test Page", + ); + unlike( $output, qr/version=1;action=delete/, + "no delete links on history page");
Added: trunk/t/84_navbar_admin.t =================================================================== --- trunk/t/84_navbar_admin.t (rev 0) +++ trunk/t/84_navbar_admin.t 2008-10-22 12:35:20 UTC (rev 1243) @@ -0,0 +1,107 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::CGI; + + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; + exit 0; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +sub get_recent_changes { + my ($guide) = @_; + + my $output = $guide->display_recent_changes( return_output => 1 ); + $output =~ s/^Content-Type.*[\r\n]+//m; + + return $output; +} + +sub get_preferences { + my ($guide) = @_; + + return OpenGuides::Template->output( + wiki => $guide->wiki, + config => $guide->config, + template => "preferences.tt", + noheaders => 1, + vars => { + not_editable => 1, + show_form => 1 + }, + ); +} + + +plan tests => 2; + +my ( $config, $guide, $wiki, $output ); + +# Clear out the database from any previous runs. +unlink "t/node.db"; +unlink <t/indexes/*>; +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); + + + # Make a guide + $config = OpenGuides::Test->make_basic_config; + $guide = OpenGuides->new( config => $config ); + # set is_admin to 1 +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; +OpenGuides::Test->write_data( + guide => $guide, + node => "Test Page", + ); + + $output = $guide->display_node( + return_output => 1, + id => "Test Page", + ); +# check navbar_admin div is shown. + Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_admin" }, + "admin section displayed in navbar" ); +# set is_admin to 0 + $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 0, +); +$ENV{HTTP_COOKIE} = $cookie; + + $output = $guide->display_node( + return_output => 1, + id => "Test Page", + ); +# check that the navbar_admin div isnt shown + Test::HTML::Content::no_tag( $output, "div", { id => "navbar_admin" }, + "navbar not shown");
Modified: trunk/templates/footer.tt =================================================================== --- trunk/templates/footer.tt 2008-10-22 11:25:56 UTC (rev 1242) +++ trunk/templates/footer.tt 2008-10-22 12:35:20 UTC (rev 1243) @@ -11,7 +11,7 @@
<div id="footer"> [% BLOCK delete_link %] - [% IF enable_page_deletion AND NOT not_deletable %] + [% IF enable_page_deletion AND is_admin AND NOT not_deletable %] <div id="footer_delete_link"> <a href="[% full_cgi_url %]?id=[% node_param %];action=delete">Delete page</a> (admins only) </div>
Modified: trunk/templates/navbar_this_page.tt =================================================================== --- trunk/templates/navbar_this_page.tt 2008-10-22 11:25:56 UTC (rev 1242) +++ trunk/templates/navbar_this_page.tt 2008-10-22 12:35:20 UTC (rev 1243) @@ -8,7 +8,7 @@ <li><a href="[% full_cgi_url %]?action=list_all_versions;id=[% node_param %]">List all revisions</a></li> [% END %] <li><a href="[% full_cgi_url %]?id=[% node_param %];format=rdf">RDF/XML version</a></li> - [% IF enable_page_deletion %] + [% IF enable_page_deletion and is_admin %] <li><a href="[% full_cgi_url %]?id=[% node_param %];action=delete">Delete (admin only)</a></li> [% END %] </ul>
Modified: trunk/templates/node_history.tt =================================================================== --- trunk/templates/node_history.tt 2008-10-22 11:25:56 UTC (rev 1242) +++ trunk/templates/node_history.tt 2008-10-22 12:35:20 UTC (rev 1243) @@ -54,7 +54,7 @@ [% IF revision.comment %] <i>([% revision.comment %])</i> [% END %] - [% IF enable_page_deletion %] + [% IF enable_page_deletion AND is_admin %] <small>[<a href="[% full_cgi_url %]?id=[% node_param %];version=[% revision.version %];action=delete">delete</a>]</small> [% END %] </li>