Created
January 22, 2023 19:06
-
-
Save jenswittmann/4b12e71570cea10dd4cd390c58acbd2c to your computer and use it in GitHub Desktop.
MODX CMP User restriction Plugin
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
<?php | |
if ($modx->context->get("key") == "mgr") { | |
if ($modx->user->get("sudo") || $modx->user->isMember("Administrator")) { | |
return; | |
} | |
switch ($modx->event->name) { | |
case "OnMODXInit": | |
$action = $modx->getOption("action", $_REQUEST, ""); | |
// hide users in grid by default | |
if ( | |
$action == "security/user/getList" && | |
empty($_REQUEST["usergroup"]) | |
) { | |
$_POST["usergroup"] = 99999; // empty result | |
} | |
// exclude all other groups from usergroup - selectbox | |
if (strtolower($action) == "security/group/getlist") { | |
$_POST["exclude"] = [1, 2, 5]; // define group ids to hide | |
} | |
// exclude none from roles - selectbox | |
if (strtolower($action) == "security/role/getlist") { | |
$_POST["addNone"] = false; | |
} | |
// restrict edit for users not in group | |
if ($_GET["a"] == "security/user/update") { | |
$user = $modx->getObject("modUser", $_GET["id"]); | |
if (!$user->isMember(["Attendees", "Member"])) { // define group names to edit | |
$_GET["id"] = 99999; | |
} | |
} | |
break; | |
} | |
} | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment