Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T12077, T12814: Remove user from groups upon vanish and change their password #100

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions includes/RemovePIIJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\User;
use MWCryptRand;
use UserProfilePage;

class RemovePIIJob extends Job implements GenericParameterJob {
Expand Down Expand Up @@ -38,6 +39,20 @@ public function run() {
// Invalidate cache before we begin
$newCentral->invalidateCache();

// Set a random password to the account and log them out
$randomPassword = MWCryptRand::generateHex( 32 );

$newCentral->setPassword( $randomPassword, true );

// If they're a global rights holder (sounds familiar), remove their groups
$groups = $newCentral->getGlobalGroups();

if ( $groups !== null ) {
foreach ( $groups as $group ) {
$newCentral->removeFromGlobalGroups( $group );
}
}

$userFactory = MediaWikiServices::getInstance()->getUserFactory();
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();

Expand Down Expand Up @@ -68,6 +83,29 @@ public function run() {
// TODO: Migrate to config and add extension hook support for this

$tableDeletions = [
// Core
'block' => [
[
'where' => [
'bl_by_actor' => $userActorId
]
]
],
'block_target' => [
[
'where' => [
'bt_id' => $userId
]
]
],
'user_groups' => [
[
'where' => [
'ug_user' => $userId
]
]
],

// Extensions
'cu_changes' => [
[
Expand Down Expand Up @@ -154,6 +192,17 @@ public function run() {
]
],
],
'cw_requests' => [
[
'fields' => [
'cw_status' => 'declined'
],
'where' => [
'cw_status' => [ 'inreview', 'onhold', 'needsmoredetails' ],
'cw_user' => $userId
]
],
],
'echo_event' => [
[
'fields' => [
Expand Down
Loading