Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 47 additions & 10 deletions 57 src/MGRAST/lib/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,68 @@ sub authenticate {
$key =~ s/^mggo4711//;

use MIME::Base64;
use LWP::UserAgent;
use Conf;
my ($u,$p) = split(/\:/, decode_base64($key));
my $us = $master->User->init( { login => $u } );
if (ref $us and crypt($p, $us->password) eq $us->password) {
my $pref = $master->Preferences->get_objects( { name => 'WebServiceKeyTdate', user => $us } );
if (scalar(@$pref)) {
if (scalar(@$pref)) {
if ($pref->[0]->value < time) {
$pref->[0]->value(time + 1209600);
}
$pref = $master->Preferences->get_objects( { name => 'WebServicesKey', user => $us } );
my $cgi = new CGI;
my $verbose = "";
if ($cgi->param('verbosity') && $cgi->param('verbosity') eq 'verbose') {
$verbose = ', "login": "'.$us->{login}.'", "firstname": "'.$us->{firstname}.'", "lastname": "'.$us->{lastname}.'", "email": "'.$us->{email}.'"';
}
my $cgi = new CGI;
my $verbose = "";
if ($cgi->param('verbosity') && $cgi->param('verbosity') eq 'verbose') {
$verbose = ', "login": "'.$us->{login}.'", "firstname": "'.$us->{firstname}.'", "lastname": "'.$us->{lastname}.'", "email": "'.$us->{email}.'"';

# SHOCK preferences
my $prefs = $master->Preferences->get_objects({ user => $us, name => "shock_pref_node" });
if (scalar(@$prefs)) {
my $nodeid = $prefs->[0]->{value};
my $response = undef;
my $json = new JSON;
$json = $json->utf8();
$json->max_size(0);
$json->allow_nonref;
my $agent = LWP::UserAgent->new;
eval {
my @args = ('Authorization', "mgrast ".$pref->[0]->{value});
my $url = $Conf::shock_url.'/node/'.$nodeid;
my $get = $agent->get($url, @args);
$response = $json->decode( $get->content );
};
if ($@ || (! ref($response))) {
print $cgi->header(-type => 'application/json',
-status => 500,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode({"ERROR" => "Unable to GET node $nodeid from Shock: ".$response->{error}[0]}, $response->{status} );
exit;
} elsif (exists($response->{error}) && $response->{error}) {
print $cgi->header(-type => 'application/json',
-status => 500,
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print $json->encode({"ERROR" => "Unable to GET node $nodeid from Shock: ".$response->{error}[0]}, $response->{status} );
exit;
} else {
$verbose.=', "preferences": '.$json->encode($response->{data}->{attributes}->{pref});
}
}
}
print $cgi->header(-type => 'application/json',
-status => 200,
-charset => 'UTF-8',
-charset => 'UTF-8',
-Access_Control_Allow_Origin => '*' );
print '{ "token": "'.$pref->[0]->value.'"'.$verbose.' }';
exit;
} else {
return (undef, "api access not enabled for this user");
}
return (undef, "api access not enabled for this user");
}
} else {
return (undef, "invalid MG-RAST credentials");
return (undef, "invalid MG-RAST credentials");
}
}

Expand Down
10 changes: 5 additions & 5 deletions 10 src/MGRAST/lib/WebPage/Analysis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ sub single_data {
if ($mg_grp_sel eq 'groups') {
my $joined_data = {};
foreach my $row (@$result) {
my $id_string = join("|", @$row[1..8]);
$row->[0] = $collections->{$row->[0]};
my $id_string = join("|", @$row[0..8]);
if (exists($joined_data->{$id_string})) {
$row->[10] = sprintf("%.2f", (($joined_data->{$id_string}->[9] * $joined_data->{$id_string}->[10]) + ($row->[9] * $row->[10])) / ($joined_data->{$id_string}->[9] + $row->[9]));
$row->[11] = sprintf("%.2f", (($joined_data->{$id_string}->[9] * $joined_data->{$id_string}->[11]) + ($row->[9] * $row->[11])) / ($joined_data->{$id_string}->[9] + $row->[9]));
Expand Down Expand Up @@ -715,8 +715,8 @@ sub phylogenetic_data {
if ($mg_grp_sel eq 'groups') {
my $joined_data = {};
foreach my $row (@$result) {
my $id_string = join("|", @$row[1..9]);
$row->[0] = $collections->{$row->[0]};
my $id_string = join("|", @$row[0..9]);
if (exists($joined_data->{$id_string})) {
$row->[12] = sprintf("%.2f", (($joined_data->{$id_string}->[10] * $joined_data->{$id_string}->[12]) + ($row->[10] * $row->[12])) / ($joined_data->{$id_string}->[10] + $row->[10]));
$row->[13] = sprintf("%.2f", (($joined_data->{$id_string}->[10] * $joined_data->{$id_string}->[13]) + ($row->[10] * $row->[13])) / ($joined_data->{$id_string}->[10] + $row->[10]));
Expand Down Expand Up @@ -861,8 +861,8 @@ sub metabolic_data {
if ($mg_grp_sel eq 'groups') {
my $joined_data = {};
foreach my $row (@$all) {
my $id_string = join("|", @$row[1..4]);
$row->[0] = $collections->{$row->[0]};
my $id_string = join("|", @$row[0..4]);
if (exists($joined_data->{$id_string})) {
$row->[8] = sprintf("%.2f", (($joined_data->{$id_string}->[6] * $joined_data->{$id_string}->[8]) + ($row->[6] * $row->[8])) / ($joined_data->{$id_string}->[6] + $row->[6]));
$row->[9] = sprintf("%.2f", (($joined_data->{$id_string}->[6] * $joined_data->{$id_string}->[9]) + ($row->[6] * $row->[9])) / ($joined_data->{$id_string}->[6] + $row->[6]));
Expand Down Expand Up @@ -966,8 +966,8 @@ sub annotation_data {
if ($mg_grp_sel eq 'groups') {
my $joined_data = {};
foreach my $row (@$result) {
my $id_string = join("|", @$row[1..2]);
$row->[0] = $collections->{$row->[0]};
my $id_string = join("|", @$row[0..2]);
if (exists($joined_data->{$id_string})) {
$row->[5] = sprintf("%.2f", (($joined_data->{$id_string}->[3] * $joined_data->{$id_string}->[5]) + ($row->[3] * $row->[5])) / ($joined_data->{$id_string}->[3] + $row->[3]));
$row->[6] = sprintf("%.2f", (($joined_data->{$id_string}->[3] * $joined_data->{$id_string}->[6]) + ($row->[3] * $row->[6])) / ($joined_data->{$id_string}->[3] + $row->[3]));
Expand Down Expand Up @@ -1053,8 +1053,8 @@ sub lca_data {
if ($mg_grp_sel eq 'groups') {
my $joined_data = {};
foreach my $row (@$result) {
my $id_string = join("|", @$row[1..8]);
$row->[0] = $collections->{$row->[0]};
my $id_string = join("|", @$row[0..8]);
if (exists($joined_data->{$id_string})) {
$row->[10] = sprintf("%.2f", (($joined_data->{$id_string}->[9] * $joined_data->{$id_string}->[10]) + ($row->[9] * $row->[10])) / ($joined_data->{$id_string}->[9] + $row->[9]));
$row->[11] = sprintf("%.2f", (($joined_data->{$id_string}->[9] * $joined_data->{$id_string}->[11]) + ($row->[9] * $row->[11])) / ($joined_data->{$id_string}->[9] + $row->[9]));
Expand Down
2 changes: 1 addition & 1 deletion 2 src/MGRAST/lib/resources/job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ sub job_action {
my $attr = $n->{attributes};
$attr->{status} = 'public';
$self->update_shock_node($n->{id}, $attr, $self->mgrast_token);
$self->edit_shock_acl($n->{id}, $self->mgrast_token, 'mgrast', 'delete', 'read');
$self->edit_shock_public_acl($n->{id}, $self->mgrast_token, 'put', 'read');
}
# update db
$job->public(1);
Expand Down
4 changes: 2 additions & 2 deletions 4 src/MGRAST/lib/resources/metagenome.pm
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ sub query {
if ($self->user->has_star_right('view', 'metagenome')) {
$solr_query_str .= "(status:private)";
} else {
if (scalar(%{$self->rights}) > 0) {
if (scalar(keys %{$self->rights}) > 0) {
$solr_query_str .= "(status:private AND (".join(" OR ", map {'id:mgm'.$_} keys %{$self->rights})."))";
} else {
$return_empty_set = 1;
Expand All @@ -316,7 +316,7 @@ sub query {
if ($self->user->has_star_right('view', 'metagenome')) {
$solr_query_str .= "(status:*)";
} else {
if (scalar(%{$self->rights}) > 0) {
if (scalar(keys %{$self->rights}) > 0) {
$solr_query_str .= "((status:public) OR (status:private AND (".join(" OR ", map {'id:mgm'.$_} keys %{$self->rights}).")))";
} else {
$solr_query_str .= '(status:public)';
Expand Down
2 changes: 1 addition & 1 deletion 2 src/MGRAST/lib/resources/notebook.pm
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ sub shock_post_acl {
map { $self->edit_shock_acl($id, $self->{nb_token}, $_, 'put', 'read') } @$access;
} elsif ($self->{nb_token} && $self->{nb_info} && (@$access == 0)) {
# public
$self->edit_shock_acl($id, $self->{nb_token}, $self->{nb_info}{username}, 'delete', 'read');
$self->edit_shock_public_acl($id, $self->{nb_token}, 'put', 'read');
} else {
# missing config
print STDERR "Missing notebook config options\n";
Expand Down
44 changes: 41 additions & 3 deletions 44 src/MGRAST/lib/resources/project.pm
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,27 @@ sub query {
if ($limit == 0) {
$limit = 18446744073709551615;
}

# check if we just want the private projects
if ($self->cgi->param('private')) {
unless ($self->user) {
$self->return_data({"ERROR" => "private option requires authentication"}, 400);
}
my $ids = [];
if ($self->cgi->param('edit')) {
$ids = $self->user->has_right_to(undef, 'edit', 'project');
} else {
$ids = $self->user->has_right_to(undef, 'view', 'project');
}
if (scalar(@$ids) && $ids->[0] eq '*') {
shift @$ids;
}
my $list = join(",", @$ids);
$total = scalar(@$ids);
$projects = $master->Project->get_objects( {$order => [undef, "id IN ($list) ORDER BY $order LIMIT $limit OFFSET $offset"]} );
}
# get all items the user has access to
if (exists $self->rights->{'*'}) {
elsif (exists $self->rights->{'*'}) {
$total = $master->Project->count_all();
$projects = $master->Project->get_objects( {$order => [undef, "_id IS NOT NULL ORDER BY $order LIMIT $limit OFFSET $offset"]} );
} else {
Expand Down Expand Up @@ -239,13 +258,32 @@ sub prepare_data {
$obj->{samples} = \@samples;
$obj->{libraries} = \@libraries;
}
if (($self->cgi->param('verbosity') eq 'verbose') || ($self->cgi->param('verbosity') eq 'full')) {
if (($self->cgi->param('verbosity') eq 'verbose') || ($self->cgi->param('verbosity') eq 'full') || ($self->cgi->param('verbosity') eq 'summary')) {
my $metadata = $project->data();
my $desc = $metadata->{project_description} || $metadata->{study_abstract} || " - ";
my $fund = $metadata->{project_funding} || " - ";
$obj->{metadata} = $metadata;
$obj->{description} = $desc;
$obj->{funding_source} = $fund;
$obj->{funding_source} = $fund;

if ($self->cgi->param('verbosity') eq 'summary') {
my $jdata = $project->metagenomes_summary();
$obj->{metagenomes} = [];
foreach my $row (@$jdata) {
push(@{$obj->{metagenomes}}, { metagenome_id => $row->[0],
name => $row->[1],
basepairs => $row->[2],
sequences => $row->[3],
biome => $row->[4],
feature => $row->[5],
material => $row->[6],
location => $row->[7],
country => $row->[8],
coordinates => $row->[9],
sequence_type => $row->[10],
sequencing_method => $row->[11] });
}
}
} elsif ($self->cgi->param('verbosity') ne 'minimal') {
$self->return_data( {"ERROR" => "invalid value for option verbosity"}, 400 );
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.