2009-02-25 12:03:13 +00:00
|
|
|
package Hydra::Helper::CatalystUtils;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Exporter;
|
2009-03-02 10:23:40 +00:00
|
|
|
use Readonly;
|
2009-02-25 12:03:13 +00:00
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
2009-03-02 10:23:40 +00:00
|
|
|
our @EXPORT = qw(
|
|
|
|
getBuild error notFound
|
2009-03-02 16:03:41 +00:00
|
|
|
requireLogin requireProjectOwner
|
2009-03-02 10:23:40 +00:00
|
|
|
$pathCompRE $relPathRE
|
|
|
|
);
|
2009-02-25 12:03:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub getBuild {
|
|
|
|
my ($c, $id) = @_;
|
|
|
|
my $build = $c->model('DB::Builds')->find($id);
|
|
|
|
return $build;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub error {
|
|
|
|
my ($c, $msg) = @_;
|
|
|
|
$c->error($msg);
|
2009-03-02 16:03:41 +00:00
|
|
|
$c->detach; # doesn't return
|
2009-02-25 12:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-25 14:34:29 +00:00
|
|
|
sub notFound {
|
|
|
|
my ($c, $msg) = @_;
|
|
|
|
$c->response->status(404);
|
|
|
|
error($c, $msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-02 16:03:41 +00:00
|
|
|
sub requireLogin {
|
|
|
|
my ($c) = @_;
|
|
|
|
$c->flash->{afterLogin} = $c->request->uri;
|
|
|
|
$c->response->redirect($c->uri_for('/login'));
|
|
|
|
$c->detach; # doesn't return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub requireProjectOwner {
|
|
|
|
my ($c, $project) = @_;
|
|
|
|
|
|
|
|
requireLogin($c) if !$c->user_exists;
|
|
|
|
|
|
|
|
error($c, "Only the project owner or the administrator can perform this operation.")
|
|
|
|
unless $c->check_user_roles('admin') || $c->user->username eq $project->owner->username;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-02 10:23:40 +00:00
|
|
|
# Security checking of filenames.
|
|
|
|
Readonly::Scalar our $pathCompRE => "(?:[A-Za-z0-9-\+][A-Za-z0-9-\+\._]*)";
|
|
|
|
Readonly::Scalar our $relPathRE => "(?:$pathCompRE(?:\/$pathCompRE)*)";
|
|
|
|
|
|
|
|
|
2009-02-25 12:03:13 +00:00
|
|
|
1;
|