Allow public dashboards

Dashboards can now be marked as publically visible in the user
preferences. The dashboard URL has changed from /user/<name>/dashboard
to /dashboard/<name> because /user/<name> requires being logged in as
<name> or as an admin.
This commit is contained in:
Eelco Dolstra 2016-05-27 12:00:20 +02:00
parent f3a3f8de46
commit f70946efca
5 changed files with 43 additions and 6 deletions

View file

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

View file

@ -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</projectmembers> -> 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 => [

View file

@ -65,6 +65,14 @@
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="publicdashboard" [% IF !create && user.publicdashboard; 'checked="checked"'; END %]/>Public dashboard
</label>
</div>
</div>
[% IF !create || c.check_user_roles('admin') %]
<div class="control-group">
<label class="control-label">Roles</label>

View file

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

1
src/sql/upgrade-49.sql Normal file
View file

@ -0,0 +1 @@
alter table Users add column publicDashboard boolean not null default false;