From 5f7ebaad37d4a4c129c942fc2f174375a55b0faa Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Fri, 4 Jun 2010 14:43:28 +0000 Subject: [PATCH] added hide feature for project/jobset --- src/lib/Hydra/Controller/Jobset.pm | 26 ++++++++++++++++++++++++++ src/lib/Hydra/Controller/Project.pm | 26 +++++++++++++++++++++++++- src/lib/Hydra/Controller/Root.pm | 2 +- src/lib/Hydra/Helper/CatalystUtils.pm | 17 ++++++++++++++--- src/lib/Hydra/Schema/Jobsets.pm | 13 +++++++++++-- src/lib/Hydra/Schema/Projects.pm | 13 +++++++++++-- src/root/overview.tt | 11 +++++++++++ src/root/project.tt | 9 ++++++++- src/sql/hydra.sql | 2 ++ 9 files changed, 109 insertions(+), 10 deletions(-) diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index 78145379..5d82ec3b 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -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) = @_; diff --git a/src/lib/Hydra/Controller/Project.pm b/src/lib/Hydra/Controller/Project.pm index 741194b4..e8d6fed6 100644 --- a/src/lib/Hydra/Controller/Project.pm +++ b/src/lib/Hydra/Controller/Project.pm @@ -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) = @_; diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index c0726052..b031da21 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -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 })]; } diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 8569a49d..e258df83 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -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); } diff --git a/src/lib/Hydra/Schema/Jobsets.pm b/src/lib/Hydra/Schema/Jobsets.pm index 65f6448c..97570710 100644 --- a/src/lib/Hydra/Schema/Jobsets.pm +++ b/src/lib/Hydra/Schema/Jobsets.pm @@ -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; diff --git a/src/lib/Hydra/Schema/Projects.pm b/src/lib/Hydra/Schema/Projects.pm index ac152741..682832ae 100644 --- a/src/lib/Hydra/Schema/Projects.pm +++ b/src/lib/Hydra/Schema/Projects.pm @@ -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 diff --git a/src/root/overview.tt b/src/root/overview.tt index 617485f5..71a32933 100644 --- a/src/root/overview.tt +++ b/src/root/overview.tt @@ -20,6 +20,7 @@ Id Name Description + [% IF c.check_user_roles('admin') %]Options[% END %] @@ -29,6 +30,16 @@ [% INCLUDE renderProjectName project = p.name %] [% HTML.escape(p.displayname) %] [% WRAPPER maybeLink uri=p.homepage %][% HTML.escape(p.description) %][% END %] + [% IF c.check_user_roles('admin') %] + + [ [% 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 %] + ] + + [% END %] [% END %] diff --git a/src/root/project.tt b/src/root/project.tt index 8f17852f..214ef148 100644 --- a/src/root/project.tt +++ b/src/root/project.tt @@ -78,7 +78,14 @@
[% j.get_column('nrsucceeded') %]/[% j.get_column('nrtotal') %]
[% IF c.check_user_roles('admin') %] - [ [% 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 _ "?") %] ] + [ [% 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 %] + ] + [% END%] [% END %] diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index e8ceef59..7a09f2d9 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -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