From f70946efca93fedfbc20d3dd5115695bc0e11504 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 27 May 2016 12:00:20 +0200 Subject: [PATCH] Allow public dashboards Dashboards can now be marked as publically visible in the user preferences. The dashboard URL has changed from /user//dashboard to /dashboard/ because /user/ requires being logged in as or as an admin. --- src/lib/Hydra/Controller/User.pm | 25 ++++++++++++++++++++++--- src/lib/Hydra/Schema/Users.pm | 12 ++++++++++-- src/root/user.tt | 8 ++++++++ src/sql/hydra.sql | 3 ++- src/sql/upgrade-49.sql | 1 + 5 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 src/sql/upgrade-49.sql diff --git a/src/lib/Hydra/Controller/User.pm b/src/lib/Hydra/Controller/User.pm index 95d38599..4f28be28 100644 --- a/src/lib/Hydra/Controller/User.pm +++ b/src/lib/Hydra/Controller/User.pm @@ -229,6 +229,7 @@ sub updatePreferences { $user->update( { fullname => $fullName , emailonerror => $c->stash->{params}->{"emailonerror"} ? 1 : 0 + , publicdashboard => $c->stash->{params}->{"publicdashboard"} ? 1 : 0 }); if (isAdmin($c)) { @@ -336,7 +337,25 @@ sub reset_password :Chained('user') :PathPart('reset-password') :Args(0) { } -sub dashboard :Chained('user') :Args(0) { +sub dashboard_old :Chained('user') :PathPart('dashboard') :Args(0) { + my ($self, $c) = @_; + $c->res->redirect($c->uri_for($self->action_for("dashboard"), $c->req->captures)); +} + + +sub dashboard_base :Chained('/') PathPart('dashboard') CaptureArgs(1) { + my ($self, $c, $userName) = @_; + + $c->stash->{user} = $c->model('DB::Users')->find($userName) + or notFound($c, "User $userName doesn't exist."); + + accessDenied($c, "You do not have permission to view this dashboard.") + unless $c->stash->{user}->publicdashboard || + (defined $c->user && ($userName eq $c->user->username || !isAdmin($c))); +} + + +sub dashboard :Chained('dashboard_base') :PathPart('') :Args(0) { my ($self, $c) = @_; $c->stash->{template} = 'dashboard.tt'; @@ -351,7 +370,7 @@ sub dashboard :Chained('user') :Args(0) { } -sub my_jobs_tab :Chained('user') :PathPart('my-jobs-tab') :Args(0) { +sub my_jobs_tab :Chained('dashboard_base') :PathPart('my-jobs-tab') :Args(0) { my ($self, $c) = @_; $c->stash->{template} = 'dashboard-my-jobs-tab.tt'; @@ -370,7 +389,7 @@ sub my_jobs_tab :Chained('user') :PathPart('my-jobs-tab') :Args(0) { } -sub my_jobsets_tab :Chained('user') :PathPart('my-jobsets-tab') :Args(0) { +sub my_jobsets_tab :Chained('dashboard_base') :PathPart('my-jobsets-tab') :Args(0) { my ($self, $c) = @_; $c->stash->{template} = 'dashboard-my-jobsets-tab.tt'; diff --git a/src/lib/Hydra/Schema/Users.pm b/src/lib/Hydra/Schema/Users.pm index a16370d3..43842fb9 100644 --- a/src/lib/Hydra/Schema/Users.pm +++ b/src/lib/Hydra/Schema/Users.pm @@ -67,6 +67,12 @@ __PACKAGE__->table("Users"); default_value: 'hydra' is_nullable: 0 +=head2 publicdashboard + + data_type: 'boolean' + default_value: false + is_nullable: 0 + =cut __PACKAGE__->add_columns( @@ -82,6 +88,8 @@ __PACKAGE__->add_columns( { data_type => "integer", default_value => 0, is_nullable => 0 }, "type", { data_type => "text", default_value => "hydra", is_nullable => 0 }, + "publicdashboard", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); =head1 PRIMARY KEY @@ -184,8 +192,8 @@ Composing rels: L -> project __PACKAGE__->many_to_many("projects", "projectmembers", "project"); -# Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-11-05 10:22:03 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Gd8KwFcnVShZ/WihvwfgQw +# Created by DBIx::Class::Schema::Loader v0.07043 @ 2016-05-27 11:32:14 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Az1+V+ztJoWUt50NLQR3xg my %hint = ( columns => [ diff --git a/src/root/user.tt b/src/root/user.tt index 3b7e8a73..ba765983 100644 --- a/src/root/user.tt +++ b/src/root/user.tt @@ -65,6 +65,14 @@ +
+
+ +
+
+ [% IF !create || c.check_user_roles('admin') %]
diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 78fcfc79..db5bb80b 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -10,7 +10,8 @@ create table Users ( emailAddress text not null, password text not null, -- sha256 hash emailOnError integer not null default 0, - type text not null default 'hydra' -- either "hydra" or "persona" + type text not null default 'hydra', -- either "hydra" or "persona" + publicDashboard boolean not null default false ); diff --git a/src/sql/upgrade-49.sql b/src/sql/upgrade-49.sql new file mode 100644 index 00000000..16b17715 --- /dev/null +++ b/src/sql/upgrade-49.sql @@ -0,0 +1 @@ +alter table Users add column publicDashboard boolean not null default false;