Changeset 297


Ignore:
Timestamp:
04/02/12 17:26:53 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Move action logging for user delete into delUser(). See #35
Tweak log entry/result message for userStatus() for consistency
and clarity

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r296 r297  
    22352235
    22362236## DNSDB::delUser()
    2237 #
     2237# Delete a user.
     2238# Takes a database handle and user ID
     2239# Returns a success/failure code and matching message
    22382240sub delUser {
    22392241  my $dbh = shift;
    2240   return ('FAIL',"Need database handle") if !$dbh;
    22412242  my $userid = shift;
    2242   return ('FAIL',"Missing userid") if !defined($userid);
    2243 
    2244   my $sth = $dbh->prepare("delete from users where user_id=?");
    2245   $sth->execute($userid);
    2246 
    2247   return ('FAIL',"Couldn't remove user: ".$sth->errstr) if $sth->err;
    2248 
    2249   return ('OK','OK');
    2250 
     2243
     2244  return ('FAIL',"Bad userid") if !defined($userid);
     2245
     2246  my $userdata = getUserData($dbh, $userid);
     2247
     2248  # Allow transactions, and raise an exception on errors so we can catch it later.
     2249  # Use local to make sure these get "reset" properly on exiting this block
     2250  local $dbh->{AutoCommit} = 0;
     2251  local $dbh->{RaiseError} = 1;
     2252
     2253  eval {
     2254    $dbh->do("DELETE FROM users WHERE user_id=?", undef, ($userid));
     2255    _log($dbh, (group_id => $userdata->{group_id},
     2256        entry => "Deleted user ID $userid/".$userdata->{username}.
     2257                " (".$userdata->{firstname}." ".$userdata->{lastname}.")") );
     2258    $dbh->commit;
     2259  };
     2260  if ($@) {
     2261    my $msg = $@;
     2262    eval { $dbh->rollback; };
     2263    if ($config{log_failures}) {
     2264      _log($dbh, (group_id => $userdata->{group_id}, entry => "Error deleting user ID ".
     2265        "$userid/".$userdata->{username}.": $msg") );
     2266      $dbh->commit;
     2267    }
     2268    return ('FAIL',"Error deleting user $userid/".$userdata->{username}.": $msg");
     2269  }
     2270
     2271  return ('OK',"Deleted user ".$userdata->{username}." (".$userdata->{firstname}." ".$userdata->{lastname}.")");
    22512272} # end delUser
    22522273
     
    23032324      $dbh->do("UPDATE users SET status=? WHERE user_id=?", undef, ($newstatus, $id));
    23042325
    2305       $resultstr = ($newstatus ? 'Enabled' : 'Disabled')." user ".$userdata->{username};
     2326      $resultstr = ($newstatus ? 'Enabled' : 'Disabled')." user ".$userdata->{username}.
     2327        " (".$userdata->{firstname}." ".$userdata->{lastname}.")";
    23062328
    23072329      my %loghash;
  • trunk/dns.cgi

    r296 r297  
    13831383    $page->param(user => userFullName($dbh,$webvar{id}));
    13841384  } elsif ($webvar{del} eq 'ok') {
    1385 ##fixme: find group id user is in (for logging) *before* we delete the user
    1386 ##fixme: get other user data too for log
    1387     my $userref = getUserData($dbh, $webvar{id});
    13881385    my ($code,$msg) = delUser($dbh, $webvar{id});
    13891386    if ($code eq 'OK') {
    13901387      # success.  go back to the user list, do not pass "GO"
    1391       # actions on users have a domain id of 0, always
    1392       logaction(0, $session->param("username"), $curgroup, "Deleted user $webvar{id}/".$userref->{username}.
    1393         " (".$userref->{lastname}.", ".$userref->{firstname}.")");
    1394       changepage(page => "useradmin", resultmsg => "Deleted user ".$userref->{username}.
    1395         " (".$userref->{lastname}.", ".$userref->{firstname}.")");
     1388      changepage(page => "useradmin", resultmsg => $msg);
    13961389    } else {
    1397 # need to find failure mode
    1398       $page->param(del_failed => 1);
    1399       $page->param(errmsg => $msg);
    1400       list_users($curgroup);
    1401       logaction(0, $session->param("username"), $curgroup, "Failed to delete user ".
    1402         "$webvar{id}/".$userref->{username}.": $msg")
    1403         if $config{log_failures};
     1390      changepage(page => "useradmin", errmsg => $msg);
    14041391    }
    14051392  } else {
Note: See TracChangeset for help on using the changeset viewer.