Commit 6b7b921e authored by Leigh Stoller's avatar Leigh Stoller

Turn Template (Workbench) permission into a toggle in the project

table. Note that workbench permission implies archive permission too.
Added the toggle to the project page.

Added a "stud" toggle to the user page while I was there.
parent a42ae961
......@@ -120,6 +120,7 @@ sub expt_last($) { return field($_[0], "expt_last"); }
sub approved($) { return field($_[0], "approved"); }
sub wikiname($) { return field($_[0], "wikiname"); }
sub mailman_password($) { return field($_[0], "mailman_password"); }
sub allow_workbench($) { return field($_[0], "allow_workbench"); }
# These come from the group not the project.
sub unix_gid($) { return $_[0]->{'GROUP'}->unix_gid(); }
......
......@@ -2368,6 +2368,7 @@ CREATE TABLE `projects` (
`default_user_interface` enum('emulab','plab') NOT NULL default 'emulab',
`linked_to_us` tinyint(4) NOT NULL default '0',
`cvsrepo_public` tinyint(1) NOT NULL default '0',
`allow_workbench` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`pid_idx`),
UNIQUE KEY `pid` (`pid`),
KEY `unix_gid` (`unix_gid`),
......
......@@ -3937,3 +3937,9 @@ last_net_act,last_cpu_act,last_ext_act);
./step4_newids.pl
4.114: Minor fix to schema file; skip to next entry.
4.115: Add a workbench flag to the project table.
alter table project_stats add
`allow_workbench` tinyint(1) NOT NULL default '0'
after cvsrepo_public;
......@@ -19,6 +19,7 @@ use vars qw(@ISA @EXPORT);
use lib '@prefix@/lib';
use libdb;
use libtestbed;
use Project;
use English;
use File::stat;
use File::Basename;
......@@ -30,8 +31,7 @@ my $TB = "@prefix@";
my $MAINSITE = @TBMAINSITE@;
my $ARCHSUPPORT = @ARCHIVESUPPORT@;
my $USEARCHIVE = ($MAINSITE || $ARCHSUPPORT);
my %ALLOWEDPID = ("testbed" => 1, "compadres" => 1, "tbres" => 1,
"fightfire" => 1, NetX => 1);
my %ALLOWEDPID = ("testbed" => 1);
# XXX
my $ARCHIVEDIR = "/usr/testbed/exparchive";
my $TESTMODE = @TESTMODE@;
......@@ -79,8 +79,13 @@ sub doarchiving($)
{
my ($pid) = @_;
my $project = Project->Lookup($pid);
return 0
if (!defined($project));
return 1
if ($USEARCHIVE && exists($ALLOWEDPID{$pid}));
if ($USEARCHIVE &&
(exists($ALLOWEDPID{$pid}) || $project->allow_workbench()));
return 0;
}
......@@ -2199,7 +2204,7 @@ sub TBCheckoutExperimentArchivebyExptIDX($$;$$)
my ($archive_idx,$pid) = $query_result->fetchrow_array();
return 0
if (! exists($ALLOWEDPID{$pid}));
if (! doarchiving($pid));
# Need to deal with no archive yet!
return 1
......
......@@ -144,6 +144,7 @@ class Project
{ return $this->field("default_user_interface"); }
function linked_to_us() { return $this->field("linked_to_us"); }
function cvsrepo_public(){ return $this->field("cvsrepo_public"); }
function allow_workbench(){ return $this->field("allow_workbench"); }
function unix_gid() {
$group = $this->DefaultGroup();
......@@ -575,6 +576,15 @@ class Project
return 0;
}
function SetAllowWorkbench($onoff) {
$idx = $this->pid_idx();
$onofff = ($onoff ? 1 : 0);
DBQueryFatal("update projects set allow_workbench='$onoff' ".
"where pid_idx='$idx'");
return 0;
}
function Show() {
global $WIKISUPPORT, $CVSSUPPORT, $TBPROJ_DIR, $TBCVSREPO_DIR;
......@@ -603,6 +613,7 @@ class Project
$expt_last = $this->expt_last();
$wikiname = $group->wikiname();
$cvsrepo_public = $this->cvsrepo_public();
$allow_workbench = $this->allow_workbench();
if (! ($head_user = User::Lookup($proj_head_idx))) {
TBERROR("Could not lookup object for user $proj_head_idx", 1);
......@@ -742,7 +753,7 @@ class Project
# Fine-grained Datapository access: show node_ids over all sub-groups.
# Should probably do likewise in individual sub-group pages.
# "dp_projects" node_attributes are lists of group gid_idx's.
# "dp_projects" node_attributes are lists of group gid_idxs.
$query_result =
DBQueryFatal("select distinct g.gid_idx, a.node_id ".
" from groups as g, node_attributes as a ".
......@@ -784,6 +795,17 @@ class Project
<td class=\"left\">$approved</td>
</tr>\n";
if (ISADMIN()) {
$YesNo = YesNo($allow_workbench);
$flip = ($allow_workbench ? 0 : 1);
echo "<tr>
<td>Allow Workbench:</td>
<td><a href=toggle.php?pid=$pid&type=workbench".
"&value=$flip>$YesNo</a> (Click to toggle)</td>
</tr>\n";
}
echo "<tr>
<td colspan='2'>Why?:</td>
</tr>\n";
......
......@@ -226,10 +226,12 @@ function LoginStatus() {
DBQueryFatal("select NOW()>=u.pswd_expires,l.hashkey,l.timeout, ".
" status,admin,cvsweb,g.trust,l.adminon,webonly, " .
" user_interface,n.type,u.stud,u.wikiname, ".
" u.wikionly,g.pid,u.foreign_admin,u.uid_idx " .
" u.wikionly,g.pid,u.foreign_admin,u.uid_idx, " .
" p.allow_workbench ".
" from users as u ".
"left join login as l on l.uid_idx=u.uid_idx ".
"left join group_membership as g on g.uid_idx=u.uid_idx ".
"left join projects as p on p.pid_idx=g.pid_idx ".
"left join nodetypeXpid_permissions as n on g.pid=n.pid ".
"where u.uid_idx='$safe_idx' and ".
(isset($curhash) ?
......@@ -246,8 +248,9 @@ function LoginStatus() {
# Scan the rows. All the info is duplicate, except for the trust
# values and the pid. pid is a hack.
#
$trusted = 0;
$opsguy = 0;
$trusted = 0;
$opsguy = 0;
$workbench = 0;
while ($row = mysql_fetch_array($query_result)) {
$expired = $row[0];
......@@ -279,6 +282,7 @@ function LoginStatus() {
# Set foreign_admin=1 for admins of another Emulab.
$foreign_admin = $row[15];
$uid_idx = $row[16];
$workbench += $row[17];
$CHECKLOGIN_NODETYPES[$type] = 1;
}
......@@ -430,7 +434,9 @@ function LoginStatus() {
# XXX Temporary.
if ($stud) {
$EXPOSEARCHIVE = 1;
$EXPOSETEMPLATES = 1;
}
if ($workbench) {
$EXPOSETEMPLATES = $EXPOSEARCHIVE = 1;
}
return $CHECKLOGIN_STATUS;
}
......
......@@ -23,22 +23,26 @@ $uid = $this_user->uid();
$isadmin = ISADMIN();
# List of valid toggles
$toggles = array("adminon", "webfreeze", "cvsweb", "lockdown",
"cvsrepo_public");
$toggles = array("adminon", "webfreeze", "cvsweb", "lockdown", "stud",
"cvsrepo_public", "workbench");
# list of valid values for each toggle
$values = array("adminon" => array(0,1),
"webfreeze" => array(0,1),
"cvsweb" => array(0,1),
"stud" => array(0,1),
"lockdown" => array(0,1),
"cvsrepo_public" => array(0,1));
"cvsrepo_public" => array(0,1),
"workbench" => array(0,1));
# list of valid extra variables for the each toggle, and mandatory flag.
$optargs = array("adminon" => array(),
"webfreeze" => array("user" => 1),
"cvsweb" => array("user" => 1),
"stud" => array("user" => 1),
"lockdown" => array("pid" => 1, "eid" => 1),
"cvsrepo_public" => array("pid" => 1));
"cvsrepo_public" => array("pid" => 1),
"workbench" => array("pid" => 1));
# Mandatory page arguments.
$reqargs = RequiredPageArguments("type", PAGEARG_STRING,
......@@ -101,6 +105,17 @@ elseif ($type == "cvsweb") {
$zapurl = CreateURL("showuser", $target_user);
$target_user->SetCVSWeb($value);
}
elseif ($type == "stud") {
# must be admin
if (! $isadmin) {
USERERROR("You do not have permission to toggle $type!", 1);
}
if (! ($target_user = User::Lookup($user))) {
PAGEARGERROR("Target user '$user' is not a valid user!");
}
$zapurl = CreateURL("showuser", $target_user);
$target_user->SetStudly($value);
}
elseif ($type == "lockdown") {
# must be admin
if (! $isadmin) {
......@@ -129,6 +144,21 @@ elseif ($type == "cvsrepo_public") {
$project->SetCVSRepoPublic($value);
SUEXEC($uid, $pid, "webcvsrepo_ctrl $pid", SUEXEC_ACTION_DIE);
}
elseif ($type == "workbench") {
# Must validate the pid since we allow non-admins to do this.
if (! TBvalid_pid($pid)) {
PAGEARGERROR("Invalid characters in $pid");
}
if (! ($project = Project::Lookup($pid))) {
PAGEARGERROR("Project $pid is not a valid project!");
}
# Must be admin
if (!$isadmin) {
USERERROR("You do not have permission to toggle $type!", 1);
}
$zapurl = CreateURL("showproject", $project);
$project->SetAllowWorkbench($value);
}
else {
USERERROR("Nobody has permission to toggle $type!", 1);
}
......
......@@ -575,6 +575,7 @@ class User
$wikiname = $user->wikiname();
$cvsweb = $user->cvsweb();
$wikionly = $user->wikionly();
$stud = $user->stud();
if (!strcmp($usr_addr2, ""))
$usr_addr2 = "&nbsp;";
......@@ -740,6 +741,19 @@ class User
$toggle_url = CreateURL("toggle", $user,
"type", "webfreeze", "value", $freezeflip);
$studflip = ($stud ? 0 : 1);
$toggle_url = CreateURL("toggle", $user,
"type", "stud", "value", $studflip);
echo "<tr>
<td>Studly:</td>
<td>$stud (<a href='$toggle_url'>Toggle</a>)
</tr>\n";
$freezeflip = ($frozen ? 0 : 1);
$toggle_url = CreateURL("toggle", $user,
"type", "webfreeze", "value", $freezeflip);
echo "<tr>
<td>Web Freeze:</td>
<td>$frozen (<a href='$toggle_url'>Toggle</a>)
......@@ -900,6 +914,17 @@ class User
$this->user["cvsweb"] = $onoff;
return 0;
}
function SetStudly($onoff) {
$idx = $this->uid_idx();
$onoff = ($onoff ? 1 : 0);
DBQueryFatal("update users set ".
" stud='$onoff' ".
"where uid_idx='$idx'");
$this->user["stud"] = $onoff;
return 0;
}
function UpdateWebLoginFail() {
$idx = $this->uid_idx();
......
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