Commit 63b87a12 authored by Leigh Stoller's avatar Leigh Stoller

Add a few more routines, to be used from mkproj.

parent 4960367f
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005, 2006 University of Utah and the Flux Group.
# Copyright (c) 2005, 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
package Group;
......@@ -53,7 +53,7 @@ sub Lookup($$)
if (exists($groups{"$gid_idx"}));
my $query_result =
DBQueryWarn("select * from groups where gid_idx=$gid_idx");
DBQueryWarn("select * from groups where gid_idx='$gid_idx'");
return undef
if (!$query_result || !$query_result->numrows);
......@@ -165,6 +165,23 @@ sub Update($$)
return Refresh($self);
}
#
# Change the leader for a group.
#
sub ChangeLeader($$)
{
my ($self, $leader) = @_;
# Must be a real reference.
return -1
if (! (ref($self) && ref($leader)));
my %args = ();
$args{'leader'} = $leader->uid();
$args{'leader_idx'} = $leader->uid_idx();
return $self->Update(\%args);
}
#
# Add a user to the group
#
......
......@@ -17,6 +17,7 @@ use vars qw(@ISA @EXPORT);
use lib '@prefix@/lib';
use libdb;
use libtestbed;
use User;
use Group;
use English;
use Data::Dumper;
......@@ -99,6 +100,7 @@ sub created($) { return field($_[0], "created"); }
sub description($) { return field($_[0], "description"); }
sub expt_count($) { return field($_[0], "expt_count"); }
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"); }
......@@ -144,7 +146,7 @@ sub Refresh($)
$self->{'PROJECT'} = $query_result->fetchrow_hashref();
return 0;
return $self->{'GROUP'}->Refresh();
}
#
......@@ -184,6 +186,57 @@ sub Update($$)
return Refresh($self);
}
#
# Return user object for leader.
#
sub GetLeader($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
return User->Lookup($self->head_idx());
}
#
# Change the leader for a project. Done *only* before project is approved.
#
sub ChangeLeader($$)
{
my ($self, $leader) = @_;
# Must be a real reference.
return -1
if (! (ref($self) && ref($leader)));
# Default group fits.
$self->{'GROUP'}->ChangeLeader($leader) == 0
or return -1;
# Then the project
my %args = ();
$args{'head_uid'} = $leader->uid();
$args{'head_idx'} = $leader->uid_idx();
return $self->Update(\%args);
}
#
# Set the approval bit,
#
sub SetApproved($$)
{
my ($self, $approved) = @_;
# Must be a real reference.
return -1
if (! (ref($self)));
my %args = ("approved" => ($approved ? 1 : 0));
return $self->Update(\%args);
}
#
# Delete a user from the project (and all subgroups of course). No checks
# are made; that should be done higher up. Optionally return list of groups
......
......@@ -171,6 +171,14 @@ sub LookupByUnixId($$)
return User->Lookup($uid_idx);
}
#
# Wrap above function so I do not forget to use it for the current user.
#
sub ThisUser($)
{
return User->LookupByUnixId($UID);
}
#
# Refresh a class instance by reloading from the DB.
#
......@@ -265,7 +273,7 @@ sub FirstApprovedProject($$)
"order by date_approved asc limit 1");
if (! $query_result || !$query_result->numrows) {
$pptr = undef;
$$pptr = undef;
return 0;
}
......@@ -281,6 +289,22 @@ sub FirstApprovedProject($$)
return 0;
}
#
# Change the status of a user in the DB.
#
sub SetStatus($$)
{
my ($self, $status) = @_;
# Must be a real reference.
return -1
if (! ref($self));
my %args = ("status" => $status);
return $self->Update(\%args);
}
#
# Set password for user.
#
......
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