Skip to content

Commit

Permalink
web: implementation of wipe account
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reed committed May 4, 2018
1 parent b4f0bae commit bcd853b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 6 deletions.
19 changes: 19 additions & 0 deletions html/inc/boinc_db.inc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ class BoincTeamDelta {
$db = BoincDb::get();
return $db->enum('team_delta', 'BoincTeamDelta', $where_clause);
}
static function delete_for_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('team_delta', "userid=$user_id");
}
}

class BoincHost {
Expand Down Expand Up @@ -339,6 +343,10 @@ class BoincHost {
if (!$ret) return $ret;
return $db->insert_id();
}
static function delete_for_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('host', "userid=$user_id");
}
}

class BoincResult {
Expand Down Expand Up @@ -598,6 +606,10 @@ class BoincHostAppVersion {
$db = BoincDb::get();
return $db->update_aux('host_app_version', $clause);
}
static function delete_for_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('host_app_version', "host_id in (select id from host where userid = $user_id)");
}
}

// DB utility functions
Expand Down Expand Up @@ -813,6 +825,13 @@ class BoincToken {
return $db->affected_rows();
}

static function delete_for_user($user_id) {
$db = BoincDb::get();
$now = time();
$db->delete_aux('token', "userid=$user_id");
return $db->affected_rows();
}

}

class BoincUserDeleted {
Expand Down
52 changes: 47 additions & 5 deletions html/inc/delete_account.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require_once("../inc/user.inc");
require_once("../inc/host.inc");
require_once("../inc/friend.inc");
require_once("../inc/boinc_db.inc");
require_once("../inc/submit_util.inc");
require_once("../project/project.inc");

// Constants for different methods of deleting accounts
Expand All @@ -46,6 +47,17 @@ function check_delete_account_token($userid, $token) {
}
}

/*
* This function saves the minimal information from the user and their hosts
* so that db_dump can provide the information necessary to export the deleted_user
* and deleted_host files. These records are deleted after 60 days by the
* daily ops task "delete_expired_users_and_hosts.php"
*/
function insert_deleted_records($user) {
BoincUserDeleted::insert_user($user);
BoincHostDeleted::insert_hosts_for_user($user);
}

/*
* This method selects which delete method to utilize. Projects can implement their own method
* and make that a third mechanism if they have a need to
Expand Down Expand Up @@ -77,8 +89,7 @@ function delete_account($user) {
// - clear domain_name, last_ip_addr
//
function obfuscate_account($user) {
BoincUserDeleted::insert_user($user);
BoincHostDeleted::insert_hosts_for_user($user);
insert_deleted_records($user);
$x = "deleted_".time()."_".random_string();
$retval = $user->update("email_addr='$x', authenticator='$x', name='deleted', country='', postal_code='', has_profile=0");
if (!$retval) return false;
Expand All @@ -93,7 +104,38 @@ function obfuscate_account($user) {

// This method deletes all rows from the database associated with the user
function wipe_account($user) {
error_page(
tra("Not Implemented Yet")
);
$db = BoincDb::get();

insert_deleted_records($user);

// delete remote submit user
delete_remote_submit_user($user); // from submit_util.inc

// remove user's team records
user_erase_team_owner($user); // from team.inc
user_quit_team($user); // from team.inc
user_erase_team_delta($user); // from team.inc

// Items that do not have logic elsewhere
// and do not have objects in boinc_db.inc
if (!$db) die("no DB connection");
$db->do_query("delete from credited_job where userid = $user->id");
$db->do_query("delete from donation_paypal where userid = $user->id");
$db->do_query("delete from banishment_vote where userid = $user->id");
$db->do_query("delete from post_ratings where post in ( select id from post where user = $user->id )");
$db->do_query("delete from post_ratings where user = $user->id");
$db->do_query("delete from msg_from_host where hostid in (select id from host where userid = $user->id )");
$db->do_query("delete from msg_to_host where hostid in (select id from host where userid = $user->id )");
$db->do_query("delete from sent_email where userid = $user->id");


//It is much faster to update results with single query
$db->do_query("update result set hostid=0,userid=0 where userid = $user->id");

BoincHostAppVersion::delete_for_user($user->id);
BoincHost::delete_for_user($user->id);

// final action
delete_user($user); //from user_util.inc
return true;
}
6 changes: 6 additions & 0 deletions html/inc/submit_db.inc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class BoincUserSubmit {
$db = BoincDb::get();
return $db->update_aux('user_submit', $clause);
}

static function delete_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('user_submit', "user_id = $user_id");
}

}

class BoincUserSubmitApp {
Expand Down
6 changes: 6 additions & 0 deletions html/inc/submit_util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ function authenticate_user($r, $app) {
return array($user, $user_submit);
}

function delete_remote_submit_user($user) {
BoincUserSubmit::delete_user($user->id);
BoincUserSubmitApp::delete_user($user->id);
}


// given its WUs, compute progress of a batch
// (fraction done, est completion time etc.)
// NOTE: this is inefficient because we need all the WUs.
Expand Down
15 changes: 14 additions & 1 deletion html/inc/team.inc
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,27 @@ function user_quit_team($user) {
if (!$user->teamid) return;
$user->update("teamid=0");
$team = BoincTeam::lookup_id($user->teamid);
if ($team && $team->ping_user=$user->id) {
if ($team && $team->ping_user==$user->id) {
$team->update("ping_user=-ping_user");
}
BoincTeamAdmin::delete("teamid=$user->teamid and userid=$user->id");
$now = time();
BoincTeamDelta::insert("(userid, teamid, timestamp, joining, total_credit) values ($user->id, $user->teamid, $now, 0, $user->total_credit)");
}

function user_erase_team_owner($user) {
if ($user->teamid) {
$team = BoincTeam::lookup_id($user->teamid);
if ($team && $team.userid == $user->id) {
$team->update("userid=0");
}
}
}

function user_erase_team_delta($user) {
BoincTeamDelta::delete_for_user($user->id);
}

function team_edit_form($team, $label, $url) {
global $team_types, $recaptcha_public_key;
echo "<form method=post action=$url>\n";
Expand Down
1 change: 1 addition & 0 deletions html/inc/user_util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ function delete_user($user) {
BoincCreditUser::delete_user($user);
BoincBadgeUser::delete("user_id=$user->id");
BoincFriend::delete_aux("user_src=$user->id or user_dest=$user->id");
BoincToken::delete_for_user($user->id);
$user->delete();
}
?>

1 comment on commit bcd853b

@davidpanderson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding style issues:

  • functions should return zero for success, nonzero (an error code) for failure.
  • comments should use //, and should end with an empty comment line
    to separate them from code.

See https://boinc.berkeley.edu/trac/wiki/CodingStyle

Please sign in to comment.