-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VOTE-1987: Add custom module to block site_builders on production. (#975
- Loading branch information
1 parent
e69b600
commit d8594ed
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ adding: | |
s3fs: 0 | ||
samlauth: 0 | ||
usagov_login: 0 | ||
vote_users: 0 | ||
externalauth: 10 | ||
removing: { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: 'Vote Users' | ||
type: module | ||
description: 'Provides custom handling of user accounts.' | ||
core_version_requirement: ^10 || ^11 | ||
package: Custom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Install and update hooks for Vote Users module. | ||
*/ | ||
|
||
use Drupal\user\Entity\User; | ||
|
||
/** | ||
* Implements hook_install(). | ||
*/ | ||
function vote_users_install() { | ||
// Get all users who have the site_builder role. | ||
$users = \Drupal::entityQuery('user') | ||
->accessCheck(FALSE) | ||
->condition('roles', 'site_builder') | ||
->execute(); | ||
|
||
// Block all users who match the criteria above. | ||
foreach ($users as $user_id) { | ||
$user = User::load($user_id); | ||
if ($user) { | ||
$user->block(); | ||
$user->save(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Implements hook_uninstall(). | ||
*/ | ||
function vote_users_uninstall() { | ||
// Get all users who have the site_builder role. | ||
$users = \Drupal::entityQuery('user') | ||
->accessCheck(FALSE) | ||
->condition('roles', 'site_builder') | ||
->execute(); | ||
|
||
// Enable all users who match the criteria above. | ||
foreach ($users as $user_id) { | ||
$user = User::load($user_id); | ||
if ($user) { | ||
$user->activate(); | ||
$user->save(); | ||
} | ||
} | ||
} |