Commit c1d3f663 authored by Leigh B Stoller's avatar Leigh B Stoller

Show experiments belonging to same projects in second table.

parent af6ae4ff
...@@ -63,6 +63,8 @@ class Instance ...@@ -63,6 +63,8 @@ class Instance
function profile_id() { return $this->field('profile_id'); } function profile_id() { return $this->field('profile_id'); }
function profile_version() { return $this->field('profile_version'); } function profile_version() { return $this->field('profile_version'); }
function status() { return $this->field('status'); } function status() { return $this->field('status'); }
function pid() { return $this->field('pid'); }
function pid_idx() { return $this->field('pid_idx'); }
function public_url() { return $this->field('public_url'); } function public_url() { return $this->field('public_url'); }
function manifest() { return $this->field('manifest'); } function manifest() { return $this->field('manifest'); }
function admin_lockdown() { return $this->field('admin_lockdown'); } function admin_lockdown() { return $this->field('admin_lockdown'); }
...@@ -286,5 +288,29 @@ class Instance ...@@ -286,5 +288,29 @@ class Instance
" extension_reason='$safe_reason' ". " extension_reason='$safe_reason' ".
"where uuid='$uuid'"); "where uuid='$uuid'");
} }
#
# Permission check; does user have permission to view instance.
#
function CanView($user) {
if ($this->creator_idx() == $user->uid_idx()) {
return 1;
}
# Otherwise a project membership test.
$project = Project::Lookup($this->pid_idx());
if (!$project) {
return 0;
}
$isapproved = 0;
if ($project->IsMember($user, $isapproved) && $isapproved) {
return 1;
}
return 0;
}
function CanModify($user) {
if ($this->creator_idx() == $user->uid_idx()) {
return 1;
}
return 0;
}
} }
?> ?>
...@@ -16,7 +16,16 @@ function (sup, moment) ...@@ -16,7 +16,16 @@ function (sup, moment)
.format("MMM Do, h:mm a")); .format("MMM Do, h:mm a"));
} }
}); });
var table = $(".tablesorter") InitTable("table1");
InitTable("table2");
}
function InitTable(name)
{
var tablename = "#tablesorter_" + name;
var searchname = "#experiment_search_" + name;
var table = $(tablename)
.tablesorter({ .tablesorter({
theme : 'green', theme : 'green',
...@@ -45,7 +54,7 @@ function (sup, moment) ...@@ -45,7 +54,7 @@ function (sup, moment)
// this binds to the search using "search" and "keyup" // this binds to the search using "search" and "keyup"
// Allows using filter_liveSearch or delayed search & // Allows using filter_liveSearch or delayed search &
// pressing escape to cancel the search // pressing escape to cancel the search
$.tablesorter.filter.bindSearch( table, $('#experiment_search') ); $.tablesorter.filter.bindSearch(table, $(searchname));
} }
$(document).ready(initialize); $(document).ready(initialize);
......
...@@ -36,7 +36,9 @@ $dblink = GetDBLink("sa"); ...@@ -36,7 +36,9 @@ $dblink = GetDBLink("sa");
# #
$optargs = OptionalPageArguments("target_user", PAGEARG_USER, $optargs = OptionalPageArguments("target_user", PAGEARG_USER,
"all", PAGEARG_BOOLEAN); "all", PAGEARG_BOOLEAN);
if (!isset($all)) {
$all = 0;
}
# #
# Get current user. # Get current user.
# #
...@@ -61,105 +63,152 @@ SPITHEADER(1); ...@@ -61,105 +63,152 @@ SPITHEADER(1);
echo "<link rel='stylesheet' echo "<link rel='stylesheet'
href='css/tablesorter.css'>\n"; href='css/tablesorter.css'>\n";
$query_result = $query_result1 = null;
DBQueryFatal("select a.*,s.expires,s.hrn,u.email, ". $query_result2 = null;
" (UNIX_TIMESTAMP(now()) > ".
" UNIX_TIMESTAMP(s.expires)) as expired ". if ($all && ISADMIN()) {
" from apt_instances as a ". $query_result1 =
"left join geni.geni_slices as s on ". DBQueryFatal("select a.*,s.expires,s.hrn,u.email, ".
" s.uuid=a.slice_uuid ". " (UNIX_TIMESTAMP(now()) > ".
"left join geni.geni_users as u on u.uuid=a.creator_uuid ". " UNIX_TIMESTAMP(s.expires)) as expired ".
(isset($all) && ISADMIN() ? " from apt_instances as a ".
"order by a.creator" : "left join geni.geni_slices as s on ".
"where a.creator_uuid='$target_uuid'")); " s.uuid=a.slice_uuid ".
"left join geni.geni_users as u on u.uuid=a.creator_uuid ".
if (mysql_num_rows($query_result) == 0) { "order by a.creator");
$message = "<b>No experiments to show you. Maybe you want to ". }
"<a href='instantiate.php'>start one?</a></b><br><br>"; else {
$query_result1 =
if (ISADMIN()) { DBQueryFatal("select a.*,s.expires,s.hrn,u.email, ".
$message .= "<img src='images/redball.gif'>". " (UNIX_TIMESTAMP(now()) > ".
"<a href='myexperiments.php?all=1'>Show all user Experiments</a>"; " UNIX_TIMESTAMP(s.expires)) as expired ".
} " from apt_instances as a ".
SPITUSERERROR($message); "left join geni.geni_slices as s on ".
exit(); " s.uuid=a.slice_uuid ".
"left join geni.geni_users as u on u.uuid=a.creator_uuid ".
"where a.creator_uuid='$target_uuid'");
$query_result2 =
DBQueryFatal("select distinct a.*,s.expires,s.hrn,u.email, ".
" (UNIX_TIMESTAMP(now()) > ".
" UNIX_TIMESTAMP(s.expires)) as expired ".
" from apt_instances as a ".
"left join geni.geni_slices as s on ".
" s.uuid=a.slice_uuid ".
"left join geni.geni_users as u on u.uuid=a.creator_uuid ".
"left join group_membership as g on ".
" g.uid_idx='$target_idx' and ".
" g.pid_idx=a.pid_idx ".
"where a.creator_uuid='$target_uuid' or ".
" g.uid_idx is not null ".
"order by a.creator");
} }
echo "<div class='row'>
<div class='col-lg-10 col-lg-offset-1
col-md-10 col-md-offset-1
col-sm-12 col-sm-offset-0
col-xs-12 col-xs-offset-0'>\n";
echo "<input class='form-control search' type='search' data-column='all' function SPITROWS($all, $name, $result)
id='experiment_search' placeholder='Search'>\n"; {
echo "<input class='form-control search' type='search' data-column='all'
id='experiment_search_${name}' placeholder='Search'>\n";
echo " <table class='tablesorter'> echo " <table class='tablesorter' id='tablesorter_${name}'>
<thead> <thead>
<tr> <tr>
<th>Profile</th>\n"; <th>Profile</th>\n";
if (isset($all) && ISADMIN()) {
echo " <th>Slice</th>"; if (ISADMIN()) {
echo " <th>Creator</th>"; echo " <th>Slice</th>";
echo " <th>Project</th>";
}
echo " <th>Status</th>
<th>Created</th>
<th>Expires</th>
</tr>
</thead>
<tbody>\n";
while ($row = mysql_fetch_array($query_result)) {
$profile_id = $row["profile_id"];
$version = $row["profile_version"];
$uuid = $row["uuid"];
$status = $row["status"];
$created = DateStringGMT($row["created"]);
$expires = DateStringGMT($row["expires"]);
$creator_idx = $row["creator_idx"];
$profile_name = $profile_id;
$creator_uid = $row["creator"];
$pid = $row["pid"];
list($foo,$hrn) = preg_split("/\./", $row["hrn"]);
$email = $row["email"];
# If a guest user, use email instead.
if (isset($email)) {
$creator = $email;
}
else {
$creator = "<a href='$TBBASE/showuser.php3?user=$creator_idx'>".
"$creator_uid</a>";
}
if ($row["expired"]) {
$status = "expired";
} }
if ($all) {
$profile = Profile::Lookup($profile_id, $version); echo " <th>Creator</th>\n";
if ($profile) {
$profile_name = $profile->name();
} }
echo " <th>Project</th>
echo " <tr> <th>Status</th>
<th>Created</th>
<th>Expires</th>
</tr>
</thead>
<tbody>\n";
while ($row = mysql_fetch_array($result)) {
$profile_id = $row["profile_id"];
$version = $row["profile_version"];
$uuid = $row["uuid"];
$status = $row["status"];
$created = DateStringGMT($row["created"]);
$expires = DateStringGMT($row["expires"]);
$creator_idx = $row["creator_idx"];
$profile_name = $profile_id;
$creator_uid = $row["creator"];
$pid = $row["pid"];
list($foo,$hrn) = preg_split("/\./", $row["hrn"]);
$email = $row["email"];
# If a guest user, use email instead.
if (isset($email)) {
$creator = $email;
}
else {
$creator = "<a href='$TBBASE/showuser.php3?user=$creator_idx'>".
"$creator_uid</a>";
}
if ($row["expired"]) {
$status = "expired";
}
$profile = Profile::Lookup($profile_id, $version);
if ($profile) {
$profile_name = $profile->name();
}
echo " <tr>
<td> <td>
<a href='status.php?uuid=$uuid'>$profile_name</a> <a href='status.php?uuid=$uuid'>$profile_name</a>
</td>"; </td>";
if (isset($all) && ISADMIN()) { if (ISADMIN()) {
echo "<td>$hrn</td>"; echo "<td>$hrn</td>";
echo "<td>$creator</td>"; }
echo "<td>$pid</td>"; if ($all) {
} echo "<td>$creator</td>";
echo " <td>$status</td> }
echo " <td><a href='$TBBASE/showproject.php3?pid=$pid'>$pid</a></td>";
echo " <td>$status</td>
<td class='format-date'>$created</td> <td class='format-date'>$created</td>
<td class='format-date'>$expires</td> <td class='format-date'>$expires</td>
</tr>\n"; </tr>\n";
} }
echo " </tbody> echo " </tbody>
</table>\n"; </table>\n";
}
echo "<div class='row'>
<div class='col-lg-10 col-lg-offset-1
col-md-10 col-md-offset-1
col-sm-12 col-sm-offset-0
col-xs-12 col-xs-offset-0'>\n";
if (ISADMIN() && !isset($all)) { if (mysql_num_rows($query_result1) == 0) {
echo "<img src='images/redball.gif'> $message = "<b>No experiments to show you. Maybe you want to ".
<a href='myexperiments.php?all=1'>Show all user Experiments</a>\n"; "<a href='instantiate.php'>start one?</a></b><br>";
if (ISADMIN()) {
$message .= "<img src='images/redball.gif'>".
"<a href='myexperiments.php?all=1'>";
$message .= "Show all user Experiments</a>";
}
echo $message;
} }
else {
SPITROWS($all, "table1", $query_result1);
if (ISADMIN() && !$all) {
echo "<img src='images/redball.gif'>
<a href='myexperiments.php?all=1'>Show all user Experiments</a>\n";
}
}
if ($query_result2 && mysql_num_rows($query_result2)) {
echo "<br>\n";
echo "Experiments started by all members of projects you belong to\n";
echo "<br>\n";
SPITROWS(1, "table2", $query_result2);
}
echo " </div> echo " </div>
</div>\n"; </div>\n";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment