Skip to content

Commit

Permalink
VOTE-1987: Add custom module to block site_builders on production. (#975
Browse files Browse the repository at this point in the history
)
  • Loading branch information
daniel-crowder authored Sep 13, 2024
1 parent e69b600 commit d8594ed
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/production/config_split.patch.core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ adding:
s3fs: 0
samlauth: 0
usagov_login: 0
vote_users: 0
externalauth: 10
removing: { }
5 changes: 5 additions & 0 deletions web/modules/custom/vote_users/vote_users.info.yml
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
48 changes: 48 additions & 0 deletions web/modules/custom/vote_users/vote_users.install
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();
}
}
}

0 comments on commit d8594ed

Please sign in to comment.