Added option to define server groups required to use group assigner (#139)
This commit is contained in:
parent
15a00998da
commit
3f015a2623
|
@ -6,10 +6,15 @@ use Wruczek\TSWebsite\Utils\TemplateUtils;
|
||||||
|
|
||||||
require_once __DIR__ . "/private/php/load.php";
|
require_once __DIR__ . "/private/php/load.php";
|
||||||
|
|
||||||
$data = ["isLoggedIn" => Auth::isLoggedIn()];
|
$data = [
|
||||||
|
"isLoggedIn" => Auth::isLoggedIn()
|
||||||
|
];
|
||||||
|
|
||||||
if (Auth::isLoggedIn()) {
|
if (Auth::isLoggedIn()) {
|
||||||
if (isset($_POST["assigner"])) {
|
$canUseAssigner = Assigner::canUseAssigner();
|
||||||
|
$data["canUseAssigner"] = $canUseAssigner;
|
||||||
|
|
||||||
|
if (isset($_POST["assigner"]) && $canUseAssigner) {
|
||||||
$groups = array_keys($_POST["assigner"]); // get all group ids
|
$groups = array_keys($_POST["assigner"]); // get all group ids
|
||||||
$groups = array_filter($groups, "is_int"); // only keep integers
|
$groups = array_filter($groups, "is_int"); // only keep integers
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,8 @@ INSERT INTO `DBPREFIXconfig` (`identifier`, `type`, `value`, `user_editable`) VA
|
||||||
('cache_channelgroups', 'INT', '60', 1),
|
('cache_channelgroups', 'INT', '60', 1),
|
||||||
('adminstatus_offlinehiddenbydefault', 'BOOL', 'false', 1),
|
('adminstatus_offlinehiddenbydefault', 'BOOL', 'false', 1),
|
||||||
('imprint_enabled', 'BOOL', 'false', 1),
|
('imprint_enabled', 'BOOL', 'false', 1),
|
||||||
('imprint_url', 'STRING', 'imprint.php', 1);
|
('imprint_url', 'STRING', 'imprint.php', 1),
|
||||||
|
('assigner_required_sgids', 'JSON', '[]', 1);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `DBPREFIXfaq`;
|
DROP TABLE IF EXISTS `DBPREFIXfaq`;
|
||||||
CREATE TABLE `DBPREFIXfaq` (
|
CREATE TABLE `DBPREFIXfaq` (
|
||||||
|
|
|
@ -133,4 +133,34 @@ class Assigner {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getRequiredSgids() {
|
||||||
|
return Config::get("assigner_required_sgids");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function canUseAssigner() {
|
||||||
|
// if there are no required sgids, the user can use assigner and
|
||||||
|
// we can skip the other, more expensive checks that will require
|
||||||
|
// fetching user groups from TS3
|
||||||
|
if (empty(self::getRequiredSgids())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$userGroups = Auth::getUserServerGroupIds();
|
||||||
|
return self::canUseAssignerSgArray($userGroups);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function canUseAssignerSgArray(array $serverGroups) {
|
||||||
|
// user needs to be in at least one of those groups to be able
|
||||||
|
// to use group assigner
|
||||||
|
$requiredSgid = self::getRequiredSgids();
|
||||||
|
|
||||||
|
foreach ($requiredSgid as $sgid) {
|
||||||
|
if (in_array($sgid, $serverGroups, false)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@
|
||||||
<div class="alert alert-info">
|
<div class="alert alert-info">
|
||||||
<i class="fas fa-info-circle"></i>{_"ASSIGNER_NOT_CONFIGURED"}
|
<i class="fas fa-info-circle"></i>{_"ASSIGNER_NOT_CONFIGURED"}
|
||||||
</div>
|
</div>
|
||||||
|
{elseif !$canUseAssigner}
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<i class="fa fa-exclamation-circle"></i>{_"ASSIGNER_NO_REQUIRED_GROUPS"}
|
||||||
|
</div>
|
||||||
{else}
|
{else}
|
||||||
{ifset $groupChangeStatus}
|
{ifset $groupChangeStatus}
|
||||||
{if $groupChangeStatus === 0} {* saved *}
|
{if $groupChangeStatus === 0} {* saved *}
|
||||||
|
|
Loading…
Reference in New Issue