added hide feature for project/jobset
This commit is contained in:
@ -135,6 +135,32 @@ sub submit : Chained('jobset') PathPart Args(0) {
|
||||
}
|
||||
|
||||
|
||||
sub hide : Chained('jobset') PathPart Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
requireProjectOwner($c, $c->stash->{project});
|
||||
|
||||
txn_do($c->model('DB')->schema, sub {
|
||||
$c->stash->{jobset}->update({ hidden => 1, enabled => 0 });
|
||||
});
|
||||
|
||||
$c->res->redirect($c->uri_for($c->controller('Project')->action_for("view"),
|
||||
[$c->stash->{project}->name]));
|
||||
}
|
||||
|
||||
sub unhide : Chained('jobset') PathPart Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
requireProjectOwner($c, $c->stash->{project});
|
||||
|
||||
txn_do($c->model('DB')->schema, sub {
|
||||
$c->stash->{jobset}->update({ hidden => 0 });
|
||||
});
|
||||
|
||||
$c->res->redirect($c->uri_for($c->controller('Project')->action_for("view"),
|
||||
[$c->stash->{project}->name]));
|
||||
}
|
||||
|
||||
sub delete : Chained('jobset') PathPart Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
|
@ -26,7 +26,7 @@ sub view : Chained('project') PathPart('') Args(0) {
|
||||
#getBuildStats($c, scalar $c->stash->{project}->builds);
|
||||
|
||||
$c->stash->{views} = [$c->stash->{project}->views->all];
|
||||
$c->stash->{jobsets} = [$c->stash->{project}->jobsets->search({},
|
||||
$c->stash->{jobsets} = [$c->stash->{project}->jobsets->search( isProjectOwner($c, $c->stash->{project}->name) ? {} : { hidden => 0 },
|
||||
{ order_by => "name"
|
||||
, "+select" => [
|
||||
"(SELECT COUNT(*) FROM Builds AS a NATURAL JOIN BuildSchedulingInfo WHERE me.project = a.project AND me.name = a.jobset AND a.isCurrent = 1 )"
|
||||
@ -63,6 +63,30 @@ sub submit : Chained('project') PathPart Args(0) {
|
||||
}
|
||||
|
||||
|
||||
sub hide : Chained('project') PathPart Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
requireProjectOwner($c, $c->stash->{project});
|
||||
|
||||
txn_do($c->model('DB')->schema, sub {
|
||||
$c->stash->{project}->update({ hidden => 1, enabled => 0 });
|
||||
});
|
||||
|
||||
$c->res->redirect($c->uri_for("/"));
|
||||
}
|
||||
|
||||
sub unhide : Chained('project') PathPart Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
requireProjectOwner($c, $c->stash->{project});
|
||||
|
||||
txn_do($c->model('DB')->schema, sub {
|
||||
$c->stash->{project}->update({ hidden => 0 });
|
||||
});
|
||||
|
||||
$c->res->redirect($c->uri_for("/"));
|
||||
}
|
||||
|
||||
sub delete : Chained('project') PathPart Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
|
@ -26,7 +26,7 @@ sub begin :Private {
|
||||
sub index :Path :Args(0) {
|
||||
my ($self, $c) = @_;
|
||||
$c->stash->{template} = 'overview.tt';
|
||||
$c->stash->{projects} = [$c->model('DB::Projects')->search({}, {order_by => 'name'})];
|
||||
$c->stash->{projects} = [$c->model('DB::Projects')->search(isAdmin($c) ? {} : {hidden => 0}, {order_by => 'name'})];
|
||||
$c->stash->{newsItems} = [$c->model('DB::NewsItems')->search({}, { order_by => ['createtime DESC'], rows => 5 })];
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
getBuild getPreviousBuild getPreviousSuccessfulBuild getBuildStats joinWithResultInfo getChannelData
|
||||
error notFound
|
||||
requireLogin requireProjectOwner requireAdmin requirePost
|
||||
requireLogin requireProjectOwner requireAdmin requirePost isAdmin isProjectOwner
|
||||
trim
|
||||
$pathCompRE $relPathRE $relNameRE $jobNameRE $systemRE
|
||||
);
|
||||
@ -134,6 +134,11 @@ sub requireLogin {
|
||||
$c->detach; # doesn't return
|
||||
}
|
||||
|
||||
sub isProjectOwner {
|
||||
my ($c, $project) = @_;
|
||||
|
||||
return $c->user_exists && ($c->check_user_roles('admin') || $c->user->username eq $project->owner->username || defined $c->model('DB::ProjectMembers')->find({ project => $project, userName => $c->user->username }));
|
||||
}
|
||||
|
||||
sub requireProjectOwner {
|
||||
my ($c, $project) = @_;
|
||||
@ -141,17 +146,23 @@ sub requireProjectOwner {
|
||||
requireLogin($c) if !$c->user_exists;
|
||||
|
||||
error($c, "Only the project members or administrators can perform this operation.")
|
||||
unless $c->check_user_roles('admin') || $c->user->username eq $project->owner->username || defined $c->model('DB::ProjectMembers')->find({ project => $project, userName => $c->user->username });
|
||||
unless isProjectOwner($c, $project);
|
||||
}
|
||||
|
||||
|
||||
sub isAdmin {
|
||||
my ($c) = @_;
|
||||
|
||||
return $c->user_exists && $c->check_user_roles('admin');
|
||||
}
|
||||
|
||||
sub requireAdmin {
|
||||
my ($c) = @_;
|
||||
|
||||
requireLogin($c) if !$c->user_exists;
|
||||
|
||||
error($c, "Only administrators can perform this operation.")
|
||||
unless $c->check_user_roles('admin');
|
||||
unless isAdmin($c);
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,6 +92,13 @@ __PACKAGE__->table("Jobsets");
|
||||
is_nullable: 0
|
||||
size: undef
|
||||
|
||||
=head2 hidden
|
||||
|
||||
data_type: integer
|
||||
default_value: 0
|
||||
is_nullable: 0
|
||||
size: undef
|
||||
|
||||
=head2 emailoverride
|
||||
|
||||
data_type: text
|
||||
@ -165,6 +172,8 @@ __PACKAGE__->add_columns(
|
||||
{ data_type => "integer", default_value => 1, is_nullable => 0, size => undef },
|
||||
"enableemail",
|
||||
{ data_type => "integer", default_value => 1, is_nullable => 0, size => undef },
|
||||
"hidden",
|
||||
{ data_type => "integer", default_value => 0, is_nullable => 0, size => undef },
|
||||
"emailoverride",
|
||||
{
|
||||
data_type => "text",
|
||||
@ -271,7 +280,7 @@ __PACKAGE__->has_many(
|
||||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-03-05 13:07:46
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Z0HutYxnzYVuQc3W51mq5Q
|
||||
# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-06-04 16:32:43
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:aQ+7TLIXnNDjjulPNqLq7A
|
||||
|
||||
1;
|
||||
|
@ -47,6 +47,13 @@ __PACKAGE__->table("Projects");
|
||||
is_nullable: 0
|
||||
size: undef
|
||||
|
||||
=head2 hidden
|
||||
|
||||
data_type: integer
|
||||
default_value: 0
|
||||
is_nullable: 0
|
||||
size: undef
|
||||
|
||||
=head2 owner
|
||||
|
||||
data_type: text
|
||||
@ -88,6 +95,8 @@ __PACKAGE__->add_columns(
|
||||
},
|
||||
"enabled",
|
||||
{ data_type => "integer", default_value => 1, is_nullable => 0, size => undef },
|
||||
"hidden",
|
||||
{ data_type => "integer", default_value => 0, is_nullable => 0, size => undef },
|
||||
"owner",
|
||||
{
|
||||
data_type => "text",
|
||||
@ -245,8 +254,8 @@ __PACKAGE__->has_many(
|
||||
);
|
||||
|
||||
|
||||
# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-04-20 11:21:42
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1VZpwwaEdEJzrrV31ErPzw
|
||||
# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-06-04 16:32:43
|
||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:b6DRXQBuBX5/tm+3VPO9yA
|
||||
# These lines were loaded from '/home/rbvermaa/src/hydra/src/lib/Hydra/Schema/Projects.pm' found in @INC.
|
||||
# They are now part of the custom portion of this file
|
||||
# for you to hand-edit. If you do not either delete
|
||||
|
Reference in New Issue
Block a user