Commit 72bd7580 authored by Leigh B Stoller's avatar Leigh B Stoller

Add Copy Profile Support

parent 3866cfb3
......@@ -33,7 +33,9 @@ function (sup)
filter_ignoreCase : true,
// Only one search box.
filter_columnFilters : false,
}
},
headers: { 1: { sorter: false}, 2: {sorter: false} }
});
// Target the $('.search') input using built in functioning
......
......@@ -175,9 +175,9 @@ function SPITFORM($formfields, $errors)
#
$projlist = $this_user->ProjectAccessList($TB_PROJECT_CREATEEXPT);
if (isset($action) && $action == "edit") {
if (isset($action) && ($action == "edit" || $action == "copy")) {
if (!isset($uuid)) {
SPITUSERERROR("Must provide uuid for edit!");
SPITUSERERROR("Must provide uuid!");
}
else {
$profile = Profile::Lookup($uuid);
......@@ -187,7 +187,12 @@ if (isset($action) && $action == "edit") {
else if ($profile->locked()) {
SPITUSERERROR("Profile is currently locked!");
}
else if ($this_idx != $profile->creator_idx() && !ISADMIN()) {
if ($action == "edit") {
if ($this_idx != $profile->creator_idx() && !ISADMIN()) {
SPITUSERERROR("Not enough permission!");
}
}
elseif (!$profile->CanView($this_user) && !ISADMIN()) {
SPITUSERERROR("Not enough permission!");
}
}
......@@ -210,25 +215,27 @@ if (! isset($create)) {
"You do not appear to be a member of any projects in which ".
"you have permission to create new profiles";
}
if ($action == "edit" || $action == "clone") {
if ($action == "clone") {
if (! (isset($snapuuid) && IsValidUUID($snapuuid))) {
$errors["error"] = "No experiment specified for clone!";
}
$instance = Instance::Lookup($snapuuid);
if (!$instance) {
SPITUSERERROR("No such instance to clone!");
}
else if ($this_idx != $instance->creator_idx() && !ISADMIN()) {
SPITUSERERROR("Not enough permission!");
}
$profile = Profile::Lookup($instance->profile_id(),
$instance->profile_version());
if (!$profile) {
SPITUSERERROR("Cannot load profile for instance!");
}
if (!$profile->published()) {
SPITUSERERROR("Not allowed to clone an unpublished profile!");
if ($action == "edit" || $action == "clone" || $action == "copy") {
if ($action == "clone" || $action == "copy") {
if ($action == "clone") {
if (! (isset($snapuuid) && IsValidUUID($snapuuid))) {
$errors["error"] = "No experiment specified for clone!";
}
$instance = Instance::Lookup($snapuuid);
if (!$instance) {
SPITUSERERROR("No such instance to clone!");
}
else if ($this_idx != $instance->creator_idx() && !ISADMIN()) {
SPITUSERERROR("Not enough permission!");
}
$profile = Profile::Lookup($instance->profile_id(),
$instance->profile_version());
if (!$profile) {
SPITUSERERROR("Cannot load profile!");
}
if (!$profile->CanView($this_user)) {
SPITUSERERROR("Not allowed to access this profile!");
}
}
$defaults["profile_rspec"] = $profile->rspec();
$defaults["profile_who"] = "shared";
......
......@@ -59,14 +59,33 @@ SPITHEADER(1);
echo "<link rel='stylesheet'
href='css/tablesorter.css'>\n";
$whereclause = "where v.creator_idx='$target_idx'";
$joinclause = "";
$orderclause = "";
if (isset($all)) {
if (ISADMIN()) {
$whereclause = "";
}
else {
$joinclause =
"left join group_membership as g on ".
" g.uid_idx='$target_idx' and ".
" g.pid_idx=v.pid_idx and g.pid_idx=g.gid_idx";
$whereclause =
"where p.public=1 or p.shared=1 or v.creator_idx='$target_idx' or ".
" g.uid_idx is not null ";
}
}
$query_result =
DBQueryFatal("select i.*,v.*,DATE(v.created) as created ".
" from apt_profiles as i ".
DBQueryFatal("select p.*,v.*,DATE(v.created) as created ".
" from apt_profiles as p ".
"left join apt_profile_versions as v on ".
" v.profileid=i.profileid and ".
" v.version=i.version ".
(isset($all) && ISADMIN() ?
"order by v.creator" : "where v.creator_idx='$target_idx'"));
" v.profileid=p.profileid and ".
" v.version=p.version ".
"$joinclause ".
"$whereclause order by v.creator");
if (mysql_num_rows($query_result) == 0) {
$message = "<b>No profiles to show you. Maybe you want to ".
......@@ -91,13 +110,14 @@ echo "<input class='form-control search' type='search'
echo " <table class='tablesorter'>
<thead>
<tr>
<th>Name</th>\n";
<th>Name</th>
<th>&nbsp</th>
<th>&nbsp</th>\n";
if (isset($all) && ISADMIN()) {
echo " <th>Creator</th>";
}
echo " <th>Project</th>
<th>Description</th>
<th>Show</th>
<th>Created</th>
<th>Listed</th>
<th>Privacy</th>
......@@ -133,19 +153,30 @@ while ($row = mysql_fetch_array($query_result)) {
}
echo " <tr>
<td>
<a href='manage_profile.php?action=edit&uuid=$uuid'>$name</a>
</td>";
<td>$name</td>\n";
if ($creator == $this_user->uid() || ISADMIN()) {
echo " <td style='text-align:center'>
<a class='btn btn-primary btn-xs' type='button'
href='manage_profile.php?action=edit&uuid=$uuid'>Edit</a>
</td>\n";
}
else {
echo " <td style='text-align:center'>
<a class='btn btn-primary btn-xs' type='button'
href='manage_profile.php?action=copy&uuid=$uuid'>Copy</a>
</td>\n";
}
echo "<td style='text-align:center'>
<button class='btn btn-primary btn-xs showtopo_modal_button'
data-profile=$uuid>Topo</button>
</td>\n";
if (isset($all) && ISADMIN()) {
echo "<td>$creator</td>";
}
echo " <td style='white-space:nowrap'>$pid</td>
<td>$desc</td>
<td style='text-align:center'>
<button class='btn btn-primary btn-xs showtopo_modal_button'
data-profile=$uuid>
Show</button>
</td>
<td>$created</td>
<td>$listed</td>
<td>$privacy</td>
......@@ -154,9 +185,15 @@ while ($row = mysql_fetch_array($query_result)) {
echo " </tbody>
</table>\n";
if (ISADMIN() && !isset($all)) {
echo "<img src='images/redball.gif'>
<a href='myprofiles.php?all=1'>Show all user Profiles</a>\n";
if (!isset($all)) {
if (ISADMIN()) {
echo "<img src='images/redball.gif'>
<a href='myprofiles.php?all=1'>Show all user profiles</a>\n";
}
else {
echo "<img src='images/blueball.gif'>
<a href='myprofiles.php?all=1'>Show all profiles you can instantiate</a>\n";
}
}
echo" </div>
</div>\n";
......
......@@ -346,6 +346,12 @@
data-toggle='modal' data-target='#guest_instantiate_modal'
type='button'>Instantiate as Guest
</button>
<a class='btn btn-primary btn-sm pull-left'
style='margin-right: 10px;'
type='button'
href='manage_profile.php?action=copy&uuid=<%= version_uuid %>'>
Copy
</a>
<% if (candelete) { %>
<button class='btn btn-danger btn-sm pull-left' disabled
id='profile_delete_button'
......
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