Skip to content

Commit

Permalink
Merge pull request #4792 from solgenomics/topic/fix_locus_owner
Browse files Browse the repository at this point in the history
Topic/fix locus owner
  • Loading branch information
lukasmueller authored Jan 24, 2024
2 parents 2d8b0eb + cca1b1b commit ccaa368
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 79 deletions.
29 changes: 14 additions & 15 deletions lib/SGN/Controller/AJAX/People.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ backend for the sgn_people schema
=head1 DESCRIPTION
REST interface for searching people, getting user data, etc.
REST interface for searching people, getting user data, etc.
=head1 AUTHOR
Expand Down Expand Up @@ -54,7 +54,7 @@ sub autocomplete_GET :Args(1) {
$person =~ s/(^\s+|\s+)$//g;
$person =~ s/\s+/ /g;
my $q = "SELECT sp_person_id, first_name, last_name FROM sgn_people.sp_person
WHERE lower(first_name) like ? OR lower(last_name) like ? and censor =0 and disable IS NULL
WHERE lower(first_name) like ? OR lower(last_name) like ? and censor =0 and disabled IS NULL
LIMIT 20";

my $sth = $c->dbc->dbh->prepare($q);
Expand Down Expand Up @@ -107,7 +107,7 @@ sub roles :Chained('/') PathPart('ajax/roles') CaptureArgs(0) {
my $c = shift;

print STDERR "ajax/roles...\n";

$c->stash->{message} = "processing";
}

Expand All @@ -128,20 +128,20 @@ sub list_roles :Chained('roles') PathPart('list') Args(0) {
while (my $row = $rs1->next()) {
$roles{$row->sp_role_id} = $row->name();
}

my $rs2 = $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 @data;
my %hash;

my %role_colors = ( curator => 'red', submitter => 'orange', user => 'green' );
my $default_color = "#0275d8";


while (my $row = $rs2->next()) {
my $person_name = $row->first_name." ".$row->last_name();
Expand All @@ -150,17 +150,17 @@ sub list_roles :Chained('roles') PathPart('list') Args(0) {
if ($c->user()->has_role("curator")) {
$delete_link = '<a href="javascript:delete_user_role('.$row->get_column('sp_person_role_id').')"><b>X</b></a>';
}

else {
$delete_link = "X";
}

$hash{$row->sp_person_id}->{userlink} = '<a href="/solpeople/personal-info.pl?sp_person_id='.$row->sp_person_id().'">'.$row->first_name()." ".$row->last_name().'</a>';

my $role_name = $roles{$row->get_column('sp_role_id')};

print STDERR "ROLE : $role_name\n";

if (! $c->user()->has_role("curator")) {
# only show breeding programs
if ($role_name !~ /curator|user|submitter/) {
Expand All @@ -172,14 +172,14 @@ sub list_roles :Chained('roles') PathPart('list') Args(0) {
$hash{$row->sp_person_id}->{userroles} .= '<span style="border-radius:16px;color:white;border-style:solid;border:1px;padding:8px;margin:6px;background-color:'.$color.'"><b>'. $delete_link."&nbsp;&nbsp; ".$role_name."</b></span>";
$hash{$row->sp_person_id}->{add_user_link} = $add_user_link;
}

}

foreach my $k (keys %hash) {
$hash{$k}->{userroles} .= $hash{$k}->{add_user_link};
push @data, [ $hash{$k}->{userlink}, $hash{$k}->{userroles} ];
}

$c->stash->{rest} = { data => \@data };
}

Expand All @@ -206,7 +206,7 @@ sub list_roles :Chained('roles') PathPart('list') Args(0) {
# $c->stash->{rest} = { error => "You don't have the necessary privileges for maintaining user roles." };
# return;
# }


# }

Expand All @@ -215,7 +215,7 @@ sub delete :Chained('roles') PathPart('delete/association') Args(1) {
my $self = shift;
my $c = shift;
my $sp_person_role_id = shift;

if (! $c->user()) {
$c->stash->{rest} = { error => "You must be logged in to use this function." };
return;
Expand All @@ -227,7 +227,7 @@ sub delete :Chained('roles') PathPart('delete/association') Args(1) {
}

my $schema = $c->dbic_schema("CXGN::People::Schema");

my $row = $schema->resultset("SpPersonRole")->find( { sp_person_role_id => $sp_person_role_id } );

if (!$row) {
Expand All @@ -244,4 +244,3 @@ sub delete :Chained('roles') PathPart('delete/association') Args(1) {

###
1;

11 changes: 10 additions & 1 deletion mason/phenome/assign_owner.mas
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,26 @@ Naama Menda <[email protected]>
var error = response.error;
if (error) { alert(error) ; }
display_owners( "<% $owners_div %>" );

}
} );
}

function display_owners(owners_div) {
jQuery.ajax( { url: "/<% $object_type %>/<% $object_id %>/owners" , dataType: "json",
success: function(response) {
jQuery("#"+owners_div).html(response.html);
}
} );
}

</script>


% if ($show_form) {

<&| /page/optional_show.mas, title => "Assign owner" &>

<div id="associate_owner_form">
Notice: 'user' account will be updated to 'submitter'
<div id="person_search" >
Expand Down
63 changes: 0 additions & 63 deletions mason/phenome/display_owners.mas

This file was deleted.

0 comments on commit ccaa368

Please sign in to comment.