Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display personalized homepage when logged in #5287

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e995923
add an index page for logged in users.
lukasmueller Dec 13, 2024
970378a
start adding functions to retrieve recent activities for personalized…
lukasmueller Dec 13, 2024
5774426
provide more info about the user to the personalized homepage.
lukasmueller Dec 13, 2024
5c4bf48
add functions for the personalized homepage.
lukasmueller Dec 19, 2024
fbd5279
add AJAX functions for retrieving recently modified data for personal…
lukasmueller Dec 20, 2024
80709cd
tweak index page for logged in users.
lukasmueller Dec 20, 2024
6d01928
make recently added accessions table work.
lukasmueller Dec 22, 2024
2f6ece9
make recenlty added accessions table work - addl file.
lukasmueller Dec 22, 2024
cac870b
add a config variable to activate personalized homepage.
lukasmueller Jan 6, 2025
173bb54
tweak appearance of personalized homepage. Fix an issue with Stock cr…
lukasmueller Jan 7, 2025
20aacb4
test for personalized homepage.
lukasmueller Jan 7, 2025
3167de1
allow create_date to be undef as not all the stocks have create dates.
lukasmueller Jan 12, 2025
5c82ccc
fix some idents; use the CXGN::People::Roles module with the new corr…
lukasmueller Jan 17, 2025
ebb51b6
Fix accessor for CXGN::People::Roles object - it should be people_sch…
lukasmueller Jan 17, 2025
5340b68
add some POD for new recently_added_* functions.
lukasmueller Jan 17, 2025
b11f4ee
change schema parameter from bcs_schema to people_schema in code that…
lukasmueller Jan 17, 2025
b44ca08
change schema parameter from bcs_schema to people_schema in code that…
lukasmueller Jan 17, 2025
5aa916b
adapt tests to new people_schema parameter in CXGN::Stock::Roles.
lukasmueller Jan 17, 2025
7c9c9eb
add tests for the functions that detect recently modified or added tr…
lukasmueller Jan 17, 2025
8be409e
remove unused package.
lukasmueller Jan 29, 2025
9fdac4b
Merge branch 'master' into topic/personalized_homepage
lukasmueller Jan 29, 2025
408318c
fix suggestions by lint.
lukasmueller Jan 30, 2025
3a0d93f
add missing parameter timestamp.
lukasmueller Jan 31, 2025
f0fb625
add to fixture pod.
lukasmueller Feb 2, 2025
c38901e
call clean_up_db() in a few tests that interfere with new tests in th…
lukasmueller Feb 2, 2025
cd45369
remove role section.
lukasmueller Feb 2, 2025
0b85000
fix lint error (return with explicit undef)
lukasmueller Feb 3, 2025
69b4a5f
also pass highest user role to mason so that it can be displayed and …
lukasmueller Feb 3, 2025
1148289
show highest user status; hide recent activities for status "user".
lukasmueller Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions lib/CXGN/BreedersToolbox/Projects.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,31 @@ use Moose;
use Data::Dumper;
use Try::Tiny;
use SGN::Model::Cvterm;
use CXGN::People::Schema;
use CXGN::People::Roles;
use JSON;
use Encode;
use CXGN::BrAPI::v2::ExternalReferences;
use Try::Tiny;

has 'schema' => (
is => 'rw',
isa => 'DBIx::Class::Schema',
);
is => 'rw',
isa => 'DBIx::Class::Schema',
);

has 'id' => (
isa => 'Maybe[Int]',
is => 'rw',
isa => 'Maybe[Int]',
is => 'rw',
);

has 'name' => (
isa => 'Str',
is => 'rw',
is => 'rw',
);

has 'description' => (
isa => 'Maybe[Str]',
is => 'rw',
is => 'rw',
);

has 'external_references' => (
Expand Down Expand Up @@ -541,7 +542,10 @@ sub store_breeding_program {
# Add new program if no id supplied
if (!$id) {
try {
my $role = CXGN::People::Roles->new({bcs_schema=>$self->schema});
my $dbh = $self->schema()->storage()->dbh();
my $people_schema = CXGN::People::Schema->connect( sub { $dbh->clone() } );

my $role = CXGN::People::Roles->new({ people_schema => $people_schema});
my $error = $role->add_sp_role($name);
if ($error){
die $error;
Expand Down Expand Up @@ -599,7 +603,9 @@ sub store_breeding_program {
my $old_program = $schema->resultset("Project::Project")->search({ project_id => $id });
my $old_name = $old_program->first->name();

my $role = CXGN::People::Roles->new({bcs_schema=>$self->schema});
my $dbh = $self->schema()->storage()->dbh();
my $people_schema = CXGN::People::Schema->connect( sub { $dbh->clone } );
my $role = CXGN::People::Roles->new({ people_schema => $people_schema });
my $error = $role->update_sp_role($name,$old_name);
if ($error){
die $error;
Expand Down
105 changes: 76 additions & 29 deletions lib/CXGN/People/Roles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CXGN::People::Roles - helper class for people's roles

=head1 SYNOPSYS

my $person_roles = CXGN::Person::Roles->new( { bcs_schema => $schema } );
my $person_roles = CXGN::Person::Roles->new( { people_schema => $schema } );

etc.

Expand All @@ -26,15 +26,20 @@ use Data::Dumper;
use Text::Unidecode;
use List::MoreUtils qw /any /;

has 'bcs_schema' => (
isa => 'Bio::Chado::Schema',
is => 'rw',
);
has 'bcs_schema' => ( # deprecated
isa => 'Bio::Chado::Schema',
is => 'rw',
);

has 'people_schema' => (
isa => 'CXGN::People::Schema',
is => 'rw',
);

sub add_sp_role {
my $self = shift;
my $name = shift;
my $dbh = $self->bcs_schema->storage->dbh;
my $dbh = $self->people_schema->storage->dbh;

my $q="SELECT sp_role_id FROM sgn_people.sp_roles where name=?;";
my $sth = $dbh->prepare($q);
Expand All @@ -55,33 +60,75 @@ sub add_sp_role {
}

sub update_sp_role {
my $self = shift;
my $new_name = shift;
my $self = shift;
my $new_name = shift;
my $old_name = shift;
my $dbh = $self->bcs_schema->storage->dbh;

my $q="SELECT sp_role_id FROM sgn_people.sp_roles where name=?;";
my $dbh = $self->people_schema->storage->dbh;

my $q="SELECT sp_role_id FROM sgn_people.sp_roles where name=?;";
my $sth = $dbh->prepare($q);
$sth->execute($old_name);
my $count = $sth->rows;
if ($count < 1){
print STDERR "No role with that name exists.\n";
return;
}
eval {
my $q="UPDATE sgn_people.sp_roles SET name = ? WHERE name = ?;";
my $sth = $dbh->prepare($q);
$sth->execute($old_name);
my $count = $sth->rows;
if ($count < 1){
print STDERR "No role with that name exists.\n";
return;
}
eval {
my $q="UPDATE sgn_people.sp_roles SET name = ? WHERE name = ?;";
my $sth = $dbh->prepare($q);
$sth->execute($new_name,$old_name);
};
if ($@) {
return "An error occurred while updating an existing role. ($@)";
}
$sth->execute($new_name,$old_name);
};
if ($@) {
return "An error occurred while updating an existing role. ($@)";
}
}

sub role_hash {
my $self = shift;
my %roles;
my $rs1 = $self->people_schema()->resultset("SpRole")->search( { } );
while (my $row = $rs1->next()) {
$roles{$row->sp_role_id} = $row->name();
}
return %roles;
}

sub list_roles {
my $self = shift;
my $sp_person_id = shift;

my $rs2;

if ($sp_person_id) {
$rs2 = $self->people_schema->resultset("SpPerson")->search(
{ censor => 0, disabled => undef, 'me.sp_person_id' => $sp_person_id },
{ join => 'sp_person_roles',
'+select' => ['sp_person_roles.sp_role_id', 'sp_person_roles.sp_person_role_id' ],
'+as' => ['sp_role_id', 'sp_person_role_id' ],
order_by => 'sp_role_id' });
}
else {
$rs2 = $self->people_schema->resultset("SpPerson")->search(
{ censor => 0, disabled => undef },
{ join => 'sp_person_roles',
'+select' => ['sp_person_roles.sp_role_id', 'sp_person_roles.sp_person_role_id' ],
'+as' => ['sp_role_id', 'sp_person_role_id' ],
order_by => 'sp_role_id' });
}

my @rows;

while (my $row= $rs2->next()) {
push @rows, $row;
}

return @rows;
}

sub get_breeding_program_roles {
my $self = shift;
my $ascii_chars = shift;
my $dbh = $self->bcs_schema->storage->dbh;
my $dbh = $self->people_schema->storage->dbh;
my @breeding_program_roles;
my $q="SELECT username, sp_person_id, name, censor FROM sgn_people.sp_person
JOIN sgn_people.sp_person_roles using(sp_person_id)
Expand All @@ -104,7 +151,7 @@ sub add_sp_person_role {
my $self = shift;
my $sp_person_id = shift;
my $sp_role_id = shift;
my $dbh = $self->bcs_schema->storage->dbh;
my $dbh = $self->people_schema->storage->dbh;
my $q = "INSERT INTO sgn_people.sp_person_roles (sp_person_id, sp_role_id) VALUES (?,?);";
my $sth = $dbh->prepare($q);
$sth->execute($sp_person_id, $sp_role_id);
Expand All @@ -113,7 +160,7 @@ sub add_sp_person_role {

sub get_sp_persons {
my $self = shift;
my $dbh = $self->bcs_schema->storage->dbh;
my $dbh = $self->people_schema->storage->dbh;
my @sp_persons;
my $q="SELECT username, sp_person_id FROM sgn_people.sp_person WHERE disabled IS NULL and censor = 0 ORDER BY username ASC;";
my $sth = $dbh->prepare($q);
Expand All @@ -126,7 +173,7 @@ sub get_sp_persons {

sub get_sp_roles {
my $self = shift;
my $dbh = $self->bcs_schema->storage->dbh;
my $dbh = $self->people_schema->storage->dbh;
my @sp_roles;
my $q="SELECT name, sp_role_id FROM sgn_people.sp_roles;";
my $sth = $dbh->prepare($q);
Expand Down
Loading