[Bps-public-commit] wifty branch, master, updated. 6fd9227e69c740f31e87a2ca7c2d31affef53fb9

Ruslan Zakirov ruz at bestpractical.com
Fri Oct 29 22:20:04 EDT 2010


The branch, master has been updated
       via  6fd9227e69c740f31e87a2ca7c2d31affef53fb9 (commit)
       via  8606ddefbc7f2004e4603a83c46518686d665a78 (commit)
       via  17f5a103dc0775ca4cb75c8fca65b470aad8b3f8 (commit)
      from  ecac978401766200c9033694bc9e38e9a593a09e (commit)

Summary of changes:
 .gitignore              |    4 ++++
 etc/config.yml          |    3 +++
 lib/Wifty/Dispatcher.pm |    2 +-
 lib/Wifty/Model/Page.pm |    7 +++++++
 lib/Wifty/View.pm       |   35 ++++++++++++++++++++++++++++-------
 5 files changed, 43 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit 17f5a103dc0775ca4cb75c8fca65b470aad8b3f8
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat Oct 30 06:15:21 2010 +0400

    use template_exists from Jifty->web
    
    Looks like it's the right thing to do nowadays

diff --git a/lib/Wifty/Dispatcher.pm b/lib/Wifty/Dispatcher.pm
index 00c2d98..7e4d786 100644
--- a/lib/Wifty/Dispatcher.pm
+++ b/lib/Wifty/Dispatcher.pm
@@ -159,7 +159,7 @@ on 'user/*' => run {
 sub error {
     my ($action, $reason) = @_;
     foreach my $page ( map { "error/$_" } "$action/$reason", "$reason", "$action", "" ) {
-        next unless $Jifty::Dispatcher::Dispatcher->template_exists($page);
+        next unless Jifty->web->template_exists($page);
         show($page);
         return;
     }

commit 8606ddefbc7f2004e4603a83c46518686d665a78
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat Oct 30 06:16:59 2010 +0400

    implement configurable read only mode

diff --git a/etc/config.yml b/etc/config.yml
index 2ff7008..b917d80 100644
--- a/etc/config.yml
+++ b/etc/config.yml
@@ -52,6 +52,9 @@ application:
   # can anonymous users change wiki?
   RequireAuth: 1
 
+  # read only mode, logged in admins still allowed to change
+  ReadOnly: 0
+
   # The formatter options are "Markdown" and "Kwiki"
   Formatter: Markdown
 
diff --git a/lib/Wifty/Model/Page.pm b/lib/Wifty/Model/Page.pm
index 7b45dea..d334f14 100644
--- a/lib/Wifty/Model/Page.pm
+++ b/lib/Wifty/Model/Page.pm
@@ -144,6 +144,13 @@ sub current_user_can {
     my $type = shift;
 
     if ($type eq 'create' || $type eq 'update') {
+        if ( Jifty->config->app('ReadOnly') ) {
+            my $cu = $self->current_user;
+            return wantarray? (0, 'read_only'): 0 if
+                !$cu->is_superuser
+                && !($cu->id && $cu->user_object->admin);
+        }
+
         return wantarray? (0, 'require_auth'): 0 if
          Jifty->config->app('RequireAuth')
            && !$self->current_user->is_superuser
diff --git a/lib/Wifty/View.pm b/lib/Wifty/View.pm
index 130325e..1f12f87 100644
--- a/lib/Wifty/View.pm
+++ b/lib/Wifty/View.pm
@@ -44,20 +44,33 @@ template 'edit' => page {
         ? _('Edit page %1 as of %2', $page->name, $revision->created)
         : _('Edit page %1');
 
-    my $can_edit = $page->current_user_can('update');
+    my ($can_edit, $reason) = $page->current_user_can('update');
 
     show('markup');
 
     form { div { attr { class => 'form_wrapper' };
         div { attr { class => 'inline' };
             unless ( $can_edit ) { p { attr { style => "width: 70%" };
-                outs(_("You don't have permission to edit this page."));
-                outs(' '. _("In the mean time, though, you're welcome to view and copy the source of this page."). ' ');
-                unless ( Jifty->web->current_user->id ) {
-                    outs(' '. _("Perhaps logging in would help."));
-                    tangent(url => '/login', label => _('Login'));
+                my $logged_in = Jifty->web->current_user->id;
+                if ( $reason eq 'read_only' ) {
+                    outs(_("This wiki is in read only mode."));
+                    unless ( $logged_in ) {
+                        outs(' '. _("Logging in with admin credentials would help."));
+                        tangent(url => '/login', label => _('Login'));
+                    }
+                } else {
+                    outs(_("You don't have permission to edit this page."));
+                    unless ( $logged_in ) {
+                        outs(' '. _("Perhaps logging in would help."));
+                        tangent(url => '/login', label => _('Login'));
+                    }
                 }
-            } }
+                }
+            
+                p { attr { style => "width: 70%" };
+                    outs(' '. _("In the mean time, though, you're welcome to view and copy the source of this page."). ' ');
+                }
+            }
             form_next_page url => '/view/'.$page->name;
             render_action $viewer, ['content'];
         };
@@ -375,4 +388,12 @@ template 'error/black_ip' => page {
     }
 };
 
+template 'error/read_only' => page {
+    page_title is _("Read only mode");
+
+    p {
+        q{This wiki is in read only mode.}
+    }
+};
+
 1;

commit 6fd9227e69c740f31e87a2ca7c2d31affef53fb9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sat Oct 30 06:19:25 2010 +0400

    gitignore update

diff --git a/.gitignore b/.gitignore
index f022075..f8cb513 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,7 @@ wifty
 inc
 var
 log
+pm_to_blib
+blib/
+*.old
+*.bak

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list