Commit 30b53ed2 authored by Leigh Stoller's avatar Leigh Stoller

Move email generation for user approval and trust changes to the

backend so that it is contained with the code that does the actual
work.
parent f65758ae
......@@ -324,6 +324,12 @@ sub AddMemberShip($$;$)
return -1
if (! (ref($self) && ref($user)));
my $membership = $self->LookupUser($user);
if (defined($membership)) {
print "*** AddMemberShip: $user is already a member of $self!\n";
return -1;
}
return Group::MemberShip->NewMemberShip($self, $user, $trust);
}
......@@ -417,6 +423,86 @@ sub SendJoinEmail($$)
return 0;
}
#
# Send email notifying of initial approval testbed approval in a group.
#
sub SendApprovalEmail($$$)
{
my ($self, $this_user, $target_user) = @_;
# Must be a real reference.
return -1
if (! (ref($self) && ref($this_user) && ref($target_user)));
my $usr_email = $target_user->email();
my $usr_name = $target_user->name();
my $usr_uid = $target_user->uid();
my $this_name = $this_user->name();
my $this_email = $this_user->email();
my $pid = $self->pid();
my $gid = $self->gid();
my $allleaders = $self->LeaderMailList();
my $membership = $self->LookupUser($target_user);
return -1
if (!defined($membership));
my $trust = $membership->trust();
SENDMAIL("$usr_name '$usr_uid' <$usr_email>",
"Membership Approved in '$pid/$gid' ",
"\n".
"This message is to notify you that you have been approved as\n".
"a member of $pid/$gid with '$trust' permission.\n".
"\n\n".
"Thanks,\n".
"Testbed Operations\n",
"$this_name <$this_email>",
"CC: $allleaders\n".
"Bcc: $TBAUDIT");
return 0;
}
sub SendTrustChangeEmail($$$)
{
my ($self, $this_user, $target_user) = @_;
# Must be a real reference.
return -1
if (! (ref($self) && ref($this_user) && ref($target_user)));
my $usr_email = $target_user->email();
my $usr_name = $target_user->name();
my $usr_uid = $target_user->uid();
my $this_name = $this_user->name();
my $this_email = $this_user->email();
my $pid = $self->pid();
my $gid = $self->gid();
my $allleaders = $self->LeaderMailList();
my $membership = $self->LookupUser($target_user);
return -1
if (!defined($membership));
my $trust = $membership->trust();
SENDMAIL("$usr_name '$usr_uid' <$usr_email>",
"Membership Change in '$pid/$gid' ",
"\n".
"This message is to notify you that your permission in $pid/$gid".
"\n".
"has been changed to '$trust'\n".
"\n\n".
"Thanks,\n".
"Testbed Operations\n",
"$this_name <$this_email>",
"CC: $allleaders\n".
"Bcc: $TBAUDIT");
return 0;
}
#
# Lookup user membership in this group
#
......
#!/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.
#
use English;
use Getopt::Std;
use strict;
#
# Modify groups (add and subtract in DB) for a user, and then call
......@@ -49,9 +50,6 @@ my $SETGROUPS = "$TB/sbin/setgroups";
my $SSH = "$TB/bin/sshtb";
my $SAVEUID = $UID;
# Locals
my $dbuid;
#
# Untaint the path
#
......@@ -70,6 +68,7 @@ use lib "@prefix@/lib";
use libaudit;
use libdb;
use libtestbed;
use User;
# Protos
sub fatal($);
......@@ -86,7 +85,7 @@ if ($UID == 0) {
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
......@@ -151,18 +150,16 @@ else {
die("Bad user name: $user.");
}
#
# Lookup current user (person running this command).
#
if (! ($dbuid = User->LookupByUnixId($UID))) {
die("*** $0:\n".
" You do not exist in the Emulab Database!\n");
# Map invoking user to object.
my $this_user = User->ThisUser();
if (! defined($this_user)) {
fatal("You ($UID) do not exist!");
}
# And the target user ...
if (! ($target_user = User->LookupByUid($user))) {
die("*** $0:\n".
" $user does not exist in the Emulab Database!\n");
# Map target user to object.
my $target_user = User->Lookup($user);
if (! defined($target_user)) {
fatal("$user does not exist!");
}
#
......@@ -208,13 +205,13 @@ foreach my $token (@addlist) {
if ($curtrust ne "none" && $curtrust ne $trust && !$ELABINELAB);
$membership->ModifyTrust($trust) == 0
or fatal("Could not modify $membership to '$trust'");
or fatal("Could not modify $membership to $trust");
}
else {
$group->AddMemberShip($target_user, $trust) == 0
or fatal("Could not add $user to $pid/$gid with trust $trust");
or fatal("Could not add $user to $group with trust $trust");
}
#
# Tell chat subsystem to change groups ...
#
......@@ -228,6 +225,9 @@ foreach my $token (@addlist) {
fatal("$SETCHATMEMBERS '-g $gid $pid' failed!");
}
}
$group->SendApprovalEmail($this_user, $target_user) == 0
or fatal("Could not send approval email to $target_user in $group");
}
#
......@@ -246,6 +246,9 @@ foreach my $token (@modlist) {
}
$membership->ModifyTrust($trust) == 0
or fatal("Could not modify $membership to '$trust'");
$group->SendTrustChangeEmail($this_user, $target_user) == 0
or fatal("Could not send trust change email to $target_user");
}
#
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003, 2005, 2006 University of Utah and the Flux Group.
# Copyright (c) 2000-2003, 2005, 2006, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
......@@ -433,25 +433,18 @@ while (list ($header, $value) = each ($POST_VARS_COPY)) {
# users being added to their first project. After this, the status is
# going to be "active", and we just leave it that way.
#
if (strcmp($curstatus, "active")) {
if (strcmp($curstatus, "newuser") == 0) {
$newstatus = "unverified";
}
elseif (strcmp($curstatus, "unapproved") == 0) {
$newstatus = "active";
}
elseif (strcmp($curstatus, "unverified") == 0) {
$newstatus = "unverified";
if ($curstatus != TBDB_USERSTATUS_ACTIVE) {
if ($curstatus == TBDB_USERSTATUS_UNAPPROVED) {
$target_user->SetStatus(TBDB_USERSTATUS_ACTIVE);
}
else {
TBERROR("Invalid $user status $curstatus in approveuser.php3",
1);
TBERROR("Invalid $user status $curstatus", 1);
}
if (!($user_interface = TBGetDefaultProjectUserInterface($project)))
if (!($user_interface =
$target_project->default_user_interface())) {
$user_interface = TBDB_USER_INTERFACE_EMULAB;
}
$target_user->SetUserInterface($user_interface);
$target_user->SetStatus($newstatus);
#
# Create user account on control node.
......@@ -464,20 +457,6 @@ while (list ($header, $value) = each ($POST_VARS_COPY)) {
SUEXEC($uid, $TBADMINGROUP,
"webmodgroups -a $project:$group:$newtrust $user", 1);
TBMAIL("$user_name '$user' <$user_email>",
"Membership Approved in '$project/$group' ",
"\n".
"This message is to notify you that you have been approved\n".
"as a member of project/group $project/$group with\n".
"$newtrust permissions.\n".
"\n\n".
"Thanks,\n".
"Testbed Operations\n",
"From: $uid_name <$uid_email>\n".
"Cc: $leaders\n".
"Bcc: $TBMAIL_AUDIT\n".
"Errors-To: $TBMAIL_WWW");
echo "<p>
User $user was <b>granted</b> membership in $project/$group
with $newtrust permissions.\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