From 7a79d17a3690c917a982c88be1e5623d7d157586 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Tue, 27 Apr 2010 13:29:08 +0000 Subject: [PATCH] added newsitems, added some admin options to clear various caches. --- src/lib/Hydra/Controller/Admin.pm | 92 ++++++++++++++++ src/lib/Hydra/Controller/Root.pm | 3 +- src/lib/Hydra/Schema/NewsItems.pm | 112 +++++++++++++++++++ src/lib/Hydra/Schema/Projects.pm | 26 ++++- src/lib/Hydra/Schema/Users.pm | 172 ++++++++++++++++++++++++++++++ src/root/admin.tt | 19 ++++ src/root/common.tt | 2 +- src/root/layout.tt | 2 +- src/root/news.tt | 39 +++++++ src/root/overview.tt | 10 +- src/root/static/css/hydra.css | 15 +++ src/root/topbar.tt | 8 +- src/sql/hydra.sql | 12 +++ 13 files changed, 503 insertions(+), 9 deletions(-) create mode 100644 src/lib/Hydra/Controller/Admin.pm create mode 100644 src/lib/Hydra/Schema/NewsItems.pm create mode 100644 src/root/admin.tt create mode 100644 src/root/news.tt diff --git a/src/lib/Hydra/Controller/Admin.pm b/src/lib/Hydra/Controller/Admin.pm new file mode 100644 index 00000000..a6194293 --- /dev/null +++ b/src/lib/Hydra/Controller/Admin.pm @@ -0,0 +1,92 @@ +package Hydra::Controller::Admin; + +use strict; +use warnings; +use base 'Catalyst::Controller'; +use Hydra::Helper::Nix; +use Hydra::Helper::CatalystUtils; + +sub admin : Path('/admin') Args(0) { + my ($self, $c) = @_; + requireAdmin($c); + + $c->stash->{template} = 'admin.tt'; +} + +sub clearfailedcache : Path('/admin/clear-failed-cache') Args(0) { + my ($self, $c) = @_; + requireAdmin($c); + + my $r = `nix-store --clear-failed-paths '*'`; + + $c->res->redirect("/admin"); +} + +sub clearevalcache : Path('/admin/clear-eval-cache') Args(0) { + my ($self, $c) = @_; + requireAdmin($c); + + print "Clearing evaluation cache\n"; + $c->model('DB::JobsetInputHashes')->delete_all; + + $c->res->redirect("/admin"); +} + +sub clearvcscache : Path('/admin/clear-vcs-cache') Args(0) { + my ($self, $c) = @_; + requireAdmin($c); + + print "Clearing path cache\n"; + $c->model('DB::CachedPathInputs')->delete_all; + + print "Clearing git cache\n"; + $c->model('DB::CachedGitInputs')->delete_all; + + print "Clearing subversion cache\n"; + $c->model('DB::CachedSubversionInputs')->delete_all; + + $c->res->redirect("/admin"); +} + +sub managenews : Path('/admin/news') Args(0) { + my ($self, $c) = @_; + requireAdmin($c); + + $c->stash->{newsItems} = [$c->model('DB::NewsItems')->search({}, {order_by => 'createtime DESC'})]; + + $c->stash->{template} = 'news.tt'; +} + +sub news_submit : Path('/admin/news/submit') Args(0) { + my ($self, $c) = @_; + + requireAdmin($c); + requirePost($c); + + my $contents = trim $c->request->params->{"contents"}; + my $createtime = time; + + $c->model('DB::NewsItems')->create({ + createtime => $createtime, + contents => $contents, + author => $c->user->username + }); + + $c->res->redirect("/admin/news"); +} + +sub news_delete : Path('/admin/news/delete') Args(1) { + my ($self, $c, $id) = @_; + + requireAdmin($c); + + txn_do($c->model('DB')->schema, sub { + my $newsItem = $c->model('DB::NewsItems')->find($id) + or notFound($c, "Newsitem with id $id doesn't exist."); + $newsItem->delete; + }); + + $c->res->redirect("/admin/news"); +} + +1; diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index e2b83521..c0726052 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -16,7 +16,7 @@ sub begin :Private { $c->stash->{curUri} = $c->request->uri; $c->stash->{version} = $ENV{"HYDRA_RELEASE"} || ""; $c->stash->{nixVersion} = $ENV{"NIX_RELEASE"} || ""; - + $c->stash->{nrRunningBuilds} = $c->model('DB::BuildSchedulingInfo')->search({ busy => 1 }, {})->count(); $c->stash->{nrQueuedBuilds} = $c->model('DB::BuildSchedulingInfo')->count(); @@ -27,6 +27,7 @@ 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->{newsItems} = [$c->model('DB::NewsItems')->search({}, { order_by => ['createtime DESC'], rows => 5 })]; } diff --git a/src/lib/Hydra/Schema/NewsItems.pm b/src/lib/Hydra/Schema/NewsItems.pm new file mode 100644 index 00000000..e9388423 --- /dev/null +++ b/src/lib/Hydra/Schema/NewsItems.pm @@ -0,0 +1,112 @@ +package Hydra::Schema::NewsItems; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + + +=head1 NAME + +Hydra::Schema::NewsItems + +=cut + +__PACKAGE__->table("NewsItems"); + +=head1 ACCESSORS + +=head2 id + + data_type: integer + default_value: undef + is_auto_increment: 1 + is_nullable: 0 + size: undef + +=head2 contents + + data_type: text + default_value: undef + is_nullable: 0 + size: undef + +=head2 createtime + + data_type: integer + default_value: undef + is_nullable: 0 + size: undef + +=head2 author + + data_type: text + default_value: undef + is_foreign_key: 1 + is_nullable: 0 + size: undef + +=cut + +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + default_value => undef, + is_auto_increment => 1, + is_nullable => 0, + size => undef, + }, + "contents", + { + data_type => "text", + default_value => undef, + is_nullable => 0, + size => undef, + }, + "createtime", + { + data_type => "integer", + default_value => undef, + is_nullable => 0, + size => undef, + }, + "author", + { + data_type => "text", + default_value => undef, + is_foreign_key => 1, + is_nullable => 0, + size => undef, + }, +); +__PACKAGE__->set_primary_key("id"); + +=head1 RELATIONS + +=head2 author + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to("author", "Hydra::Schema::Users", { username => "author" }, {}); + + +# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-04-27 15:13:51 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SX13YZYhf5Uz5KZGphG/+w + +use Hydra::Helper::Nix; + +# !!! Ugly, should be generated. +my $hydradbi = getHydraDBPath; +if ($hydradbi =~ m/^dbi:Pg/) { + __PACKAGE__->sequence('newsitems_id_seq'); +} + +1; diff --git a/src/lib/Hydra/Schema/Projects.pm b/src/lib/Hydra/Schema/Projects.pm index ed8a9448..ac152741 100644 --- a/src/lib/Hydra/Schema/Projects.pm +++ b/src/lib/Hydra/Schema/Projects.pm @@ -118,6 +118,20 @@ Related object: L __PACKAGE__->belongs_to("owner", "Hydra::Schema::Users", { username => "owner" }, {}); +=head2 projectmembers + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "projectmembers", + "Hydra::Schema::ProjectMembers", + { "foreign.project" => "self.name" }, +); + =head2 jobsets Type: has_many @@ -231,7 +245,15 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-03-05 13:07:45 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SXJ+FzgNDad87OKSBH2qrg +# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-04-20 11:21:42 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1VZpwwaEdEJzrrV31ErPzw +# 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 +# this section or remove that file from @INC, this section +# will be repeated redundantly when you re-create this +# file again via Loader! See skip_load_external to disable +# this feature. +# You can replace this text with custom content, and it will be preserved on regeneration 1; diff --git a/src/lib/Hydra/Schema/Users.pm b/src/lib/Hydra/Schema/Users.pm index 30c49c18..5c03d013 100644 --- a/src/lib/Hydra/Schema/Users.pm +++ b/src/lib/Hydra/Schema/Users.pm @@ -120,8 +120,180 @@ __PACKAGE__->has_many( { "foreign.owner" => "self.username" }, ); +=head2 projectmembers + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "projectmembers", + "Hydra::Schema::ProjectMembers", + { "foreign.username" => "self.username" }, +); + +=head2 newsitems + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "newsitems", + "Hydra::Schema::NewsItems", + { "foreign.author" => "self.username" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.05000 @ 2010-04-27 15:13:51 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:C5uoz6EYyYL442zRYmXkyw +# These lines were loaded from '/home/rbvermaa/src/hydra/src/lib/Hydra/Schema/Users.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 +# this section or remove that file from @INC, this section +# will be repeated redundantly when you re-create this +# file again via Loader! See skip_load_external to disable +# this feature. + +package Hydra::Schema::Users; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + + +=head1 NAME + +Hydra::Schema::Users + +=cut + +__PACKAGE__->table("Users"); + +=head1 ACCESSORS + +=head2 username + + data_type: text + default_value: undef + is_nullable: 0 + size: undef + +=head2 fullname + + data_type: text + default_value: undef + is_nullable: 1 + size: undef + +=head2 emailaddress + + data_type: text + default_value: undef + is_nullable: 0 + size: undef + +=head2 password + + data_type: text + default_value: undef + is_nullable: 0 + size: undef + +=head2 emailonerror + + data_type: integer + default_value: 0 + is_nullable: 0 + size: undef + +=cut + +__PACKAGE__->add_columns( + "username", + { + data_type => "text", + default_value => undef, + is_nullable => 0, + size => undef, + }, + "fullname", + { + data_type => "text", + default_value => undef, + is_nullable => 1, + size => undef, + }, + "emailaddress", + { + data_type => "text", + default_value => undef, + is_nullable => 0, + size => undef, + }, + "password", + { + data_type => "text", + default_value => undef, + is_nullable => 0, + size => undef, + }, + "emailonerror", + { data_type => "integer", default_value => 0, is_nullable => 0, size => undef }, +); +__PACKAGE__->set_primary_key("username"); + +=head1 RELATIONS + +=head2 userroles + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "userroles", + "Hydra::Schema::UserRoles", + { "foreign.username" => "self.username" }, +); + +=head2 projects + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "projects", + "Hydra::Schema::Projects", + { "foreign.owner" => "self.username" }, +); + # Created by DBIx::Class::Schema::Loader v0.05003 @ 2010-02-25 10:29:41 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vHluB+s1FkpJBPWmpv+wUQ 1; +# End of lines loaded from '/home/rbvermaa/src/hydra/src/lib/Hydra/Schema/Users.pm' +# These lines were loaded from '/home/rbvermaa/src/hydra/src/lib/Hydra/Schema/Users.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 +# this section or remove that file from @INC, this section +# will be repeated redundantly when you re-create this +# file again via Loader! See skip_load_external to disable +# this feature. + +# You can replace this text with custom content, and it will be preserved on regeneration +1; diff --git a/src/root/admin.tt b/src/root/admin.tt new file mode 100644 index 00000000..b548dc5f --- /dev/null +++ b/src/root/admin.tt @@ -0,0 +1,19 @@ +[% WRAPPER layout.tt title="Admin" %] +[% PROCESS common.tt %] + +

Admin

+ +
    +
  • [% INCLUDE maybeLink uri = c.uri_for(c.controller('Project').action_for('create')) content = "Create project" %]
  • +
  • Caching +
      +
    • [% INCLUDE maybeLink uri = c.uri_for(c.controller('Admin').action_for('clearfailedcache')) content = "Clear failed builds cache" confirmmsg = "Are you sure you want to clear the failed builds cache?" %]
    • +
    • [% INCLUDE maybeLink uri = c.uri_for(c.controller('Admin').action_for('clearevalcache')) content = "Clear evaluation cache" confirmmsg = "Are you sure you want to clear the evaluation cache?" %]
    • +
    • [% INCLUDE maybeLink uri = c.uri_for(c.controller('Admin').action_for('clearvcscache')) content = "Clear VCS caches" confirmmsg = "Are you sure you want to clear the VCS caches?" %]
    • +
    +
  • +
  • [% INCLUDE maybeLink uri = c.uri_for(c.controller('Admin').action_for('managenews')) content = "News" %]
  • +
+ + +[% END %] diff --git a/src/root/common.tt b/src/root/common.tt index 46057cb8..1fb9b539 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -174,7 +174,7 @@ [% BLOCK maybeLink -%] - [% IF uri %] uri) %]>[% content %][% ELSE; content; END -%] + [% IF uri %] uri) %][% IF confirmmsg %]onclick="javascript:return confirm('[% confirmmsg %]')"[% END %]>[% content %][% ELSE; content; END -%] [% END -%] diff --git a/src/root/layout.tt b/src/root/layout.tt index 6d6b6280..ce80a0c3 100644 --- a/src/root/layout.tt +++ b/src/root/layout.tt @@ -90,7 +90,7 @@