added hide feature for project/jobset

This commit is contained in:
Rob Vermaas 2010-06-04 14:43:28 +00:00
parent b25761d7b2
commit 5f7ebaad37
9 changed files with 109 additions and 10 deletions

View file

@ -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) = @_;

View file

@ -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) = @_;

View file

@ -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 })];
}

View file

@ -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);
}

View file

@ -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;

View file

@ -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

View file

@ -20,6 +20,7 @@
<th>Id</th>
<th>Name</th>
<th>Description</th>
[% IF c.check_user_roles('admin') %]<th>Options</th>[% END %]
</tr>
</thead>
<tbody>
@ -29,6 +30,16 @@
<td>[% INCLUDE renderProjectName project = p.name %]</td>
<td>[% HTML.escape(p.displayname) %]</td>
<td>[% WRAPPER maybeLink uri=p.homepage %][% HTML.escape(p.description) %][% END %]</td>
[% IF c.check_user_roles('admin') %]
<td>
[ [% IF p.hidden %]
[% INCLUDE maybeLink uri = c.uri_for('/project' p.name 'unhide') content = "Unhide" %]
[% ELSE %]
[% INCLUDE maybeLink uri = c.uri_for('/project' p.name 'hide') content = "Hide" %]
[% END %]
]
</td>
[% END %]
</tr>
[% END %]
</tbody>

View file

@ -78,7 +78,14 @@
<div class="[% class %]">[% j.get_column('nrsucceeded') %]/[% j.get_column('nrtotal') %]</div>
</td>
[% IF c.check_user_roles('admin') %]
<td>[ [% INCLUDE maybeLink uri = c.uri_for(c.controller('Admin').action_for('force_eval'), project.name, j.name) content = "Evaluate" confirmmsg = ("Are you sure you want to force evaluation of jobset " _ project.name _ ":" _ j.name _ "?") %] ]</td>
<td>[ [% INCLUDE maybeLink uri = c.uri_for(c.controller('Admin').action_for('force_eval'), project.name, j.name) content = "Evaluate" confirmmsg = ("Are you sure you want to force evaluation of jobset " _ project.name _ ":" _ j.name _ "?") %]
| [% IF j.hidden %]
[% INCLUDE maybeLink uri = c.uri_for('/jobset' project.name j.name 'unhide') content = "Unhide" %]
[% ELSE %]
[% INCLUDE maybeLink uri = c.uri_for('/jobset' project.name j.name 'hide') content = "Hide" %]
[% END %]
]
</td>
[% END%]
</tr>
[% END %]

View file

@ -20,6 +20,7 @@ create table Projects (
displayName text not null, -- display name (e.g. "PatchELF")
description text,
enabled integer not null default 1,
hidden integer not null default 0,
owner text not null,
homepage text, -- URL for the project
foreign key (owner) references Users(userName) on update cascade
@ -48,6 +49,7 @@ create table Jobsets (
lastCheckedTime integer, -- last time the evaluator looked at this jobset
enabled integer not null default 1,
enableEmail integer not null default 1,
hidden integer not null default 0,
emailOverride text not null,
primary key (project, name),
foreign key (project) references Projects(name) on delete cascade on update cascade