[Bps-public-commit] App-Changeloggr branch, master, updated. 264efd3744485b3c2ba6c156d982006e75540231

sartak at bestpractical.com sartak at bestpractical.com
Wed Apr 1 13:48:48 EDT 2009


The branch, master has been updated
       via  264efd3744485b3c2ba6c156d982006e75540231 (commit)
       via  03b3e44a930d181696e3ec3bce960e4582be86de (commit)
      from  52fdd0ee731928c1d7d786597f8451e266c0dc6f (commit)

Summary of changes:
 lib/App/Changeloggr/Action/AddChanges.pm           |   28 +---------------
 lib/App/Changeloggr/Action/DeleteChangelog.pm      |   14 +-------
 .../Changeloggr/Action/Mixin/RequiresAdminToken.pm |   36 ++++++++++++++++++++
 lib/App/Changeloggr/Action/UpdateChangelog.pm      |   14 +-------
 lib/App/Changeloggr/Model/Changelog.pm             |    2 +-
 5 files changed, 40 insertions(+), 54 deletions(-)
 create mode 100644 lib/App/Changeloggr/Action/Mixin/RequiresAdminToken.pm

- Log -----------------------------------------------------------------
commit 03b3e44a930d181696e3ec3bce960e4582be86de
Author: Shawn M Moore <sartak at gmail.com>
Date:   Wed Apr 1 13:47:18 2009 -0400

    Use a mixin for "requires admin token"

diff --git a/lib/App/Changeloggr/Action/AddChanges.pm b/lib/App/Changeloggr/Action/AddChanges.pm
index d22f8a6..7782f6f 100644
--- a/lib/App/Changeloggr/Action/AddChanges.pm
+++ b/lib/App/Changeloggr/Action/AddChanges.pm
@@ -1,8 +1,7 @@
 package App::Changeloggr::Action::AddChanges;
 use strict;
 use warnings;
-
-use JiftyX::ModelHelpers;
+use base 'App::Changeloggr::Action::Mixin::RequiresAdminToken', 'Jifty::Action';
 
 use Jifty::Param::Schema;
 use Jifty::Action schema {
@@ -16,31 +15,6 @@ use Jifty::Action schema {
         hints is 'Formats we accept: git log --pretty=fuller --stat, svn log, or svn log --xml';
 };
 
-sub get_changelog {
-    my $self = shift;
-
-    my $changelog = Changelog(
-        admin_token => $self->argument_value('admin_token'),
-        { current_user => App::Changeloggr::CurrentUser->superuser },
-    );
-
-    return $changelog;
-}
-
-sub validate_admin_token {
-    my $self        = shift;
-    my $admin_token = shift;
-
-    my $changelog = $self->get_changelog;
-
-    if ($changelog->admin_token eq $admin_token) {
-        return $self->validation_ok('admin_token');
-    }
-    else {
-        return $self->validation_error(admin_token => "You do not have permission to add changes to this changelog.");
-    }
-}
-
 sub take_action {
     my $self = shift;
 
diff --git a/lib/App/Changeloggr/Action/DeleteChangelog.pm b/lib/App/Changeloggr/Action/DeleteChangelog.pm
index 4abdade..a8bd5a9 100644
--- a/lib/App/Changeloggr/Action/DeleteChangelog.pm
+++ b/lib/App/Changeloggr/Action/DeleteChangelog.pm
@@ -1,19 +1,7 @@
 package App::Changeloggr::Action::DeleteChangelog;
 use strict;
 use warnings;
-use base 'Jifty::Action::Record::Delete';
-
-sub validate_admin_token {
-    my $self        = shift;
-    my $admin_token = shift;
-
-    if ($self->record->as_superuser->admin_token eq ($admin_token||'')) {
-        return $self->validation_ok('admin_token');
-    }
-    else {
-        return $self->validation_error(admin_token => "You do not have permission to delete this changelog.");
-    }
-}
+use base 'App::Changeloggr::Action::Mixin::RequiresAdminToken', 'Jifty::Action::Record::Delete';
 
 sub take_action {
     my $self = shift;
diff --git a/lib/App/Changeloggr/Action/Mixin/RequiresAdminToken.pm b/lib/App/Changeloggr/Action/Mixin/RequiresAdminToken.pm
new file mode 100644
index 0000000..a6b91ff
--- /dev/null
+++ b/lib/App/Changeloggr/Action/Mixin/RequiresAdminToken.pm
@@ -0,0 +1,36 @@
+package App::Changeloggr::Action::Mixin::RequiresAdminToken;
+use strict;
+use warnings;
+use JiftyX::ModelHelpers;
+
+sub get_changelog {
+    my $self = shift;
+
+    return $self->record
+        if $self->can('record')
+        && $self->record->isa('App::Changeloggr::Model::Changelog');
+
+    my $changelog = Changelog(
+        admin_token => $self->argument_value('admin_token'),
+        { current_user => App::Changeloggr::CurrentUser->superuser },
+    );
+
+    return $changelog;
+}
+
+sub validate_admin_token {
+    my $self        = shift;
+    my $admin_token = shift;
+
+    my $changelog = $self->get_changelog;
+
+    if ($changelog->admin_token eq $admin_token) {
+        return $self->validation_ok('admin_token');
+    }
+    else {
+        return $self->validation_error(admin_token => "You do not have permission to add changes to this changelog.");
+    }
+}
+
+1;
+
diff --git a/lib/App/Changeloggr/Action/UpdateChangelog.pm b/lib/App/Changeloggr/Action/UpdateChangelog.pm
index 45db386..9d38b44 100644
--- a/lib/App/Changeloggr/Action/UpdateChangelog.pm
+++ b/lib/App/Changeloggr/Action/UpdateChangelog.pm
@@ -1,19 +1,7 @@
 package App::Changeloggr::Action::UpdateChangelog;
 use strict;
 use warnings;
-use base 'Jifty::Action::Record::Update';
-
-sub validate_admin_token {
-    my $self        = shift;
-    my $admin_token = shift;
-
-    if ($self->record->as_superuser->admin_token eq ($admin_token||'')) {
-        return $self->validation_ok('admin_token');
-    }
-    else {
-        return $self->validation_error(admin_token => "You do not have permission to update this changelog.");
-    }
-}
+use base 'App::Changeloggr::Action::Mixin::RequiresAdminToken', 'Jifty::Action::Record::Update';
 
 sub take_action {
     my $self = shift;

commit 264efd3744485b3c2ba6c156d982006e75540231
Author: Shawn M Moore <sartak at gmail.com>
Date:   Wed Apr 1 13:48:33 2009 -0400

    Avoid undef warnings when we're checking the general readability of a changelog

diff --git a/lib/App/Changeloggr/Model/Changelog.pm b/lib/App/Changeloggr/Model/Changelog.pm
index fe66d4e..90c7786 100644
--- a/lib/App/Changeloggr/Model/Changelog.pm
+++ b/lib/App/Changeloggr/Model/Changelog.pm
@@ -37,7 +37,7 @@ sub current_user_can {
 
     # anyone can create and read changelogs (except admin token)
     return 1 if $right eq 'create'
-             || ($right eq 'read' && $args{column} ne 'admin_token');
+             || ($right eq 'read' && ($args{column}||'') ne 'admin_token');
 
     # but not delete or update. those must happen as root
     return $self->SUPER::current_user_can($right, %args);

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



More information about the Bps-public-commit mailing list