mc-cms-namelessmc/modules/Core/includes/endpoints/RemoveGroupsEndpoint.php
tadhgboyle 145c8bc1c2
Remove internal deprecations (#3630)
* Remove internal deprecations

* add convert profile posts task + remove dead lang_charset references

* guard og_image usages

* fix

* add note about mailhog

* revert group sync manager for time being

* review amendments

* fox
2025-05-04 14:08:21 -07:00

39 lines
1 KiB
PHP

<?php
/**
* @param int $user NamelessMC ID of user to view
* @param array $groups ID of group ids
*
* @return string JSON Array
*/
class RemoveGroupsEndpoint extends KeyAuthEndpoint {
public function __construct() {
$this->_route = 'users/{user}/groups/remove';
$this->_module = 'Core';
$this->_description = 'Remove groups from user';
$this->_method = 'POST';
}
public function execute(Nameless2API $api, User $user): void {
$api->validateParams($_POST, ['groups']);
$groups = $_POST['groups'];
if (!count($groups)) {
$api->throwError(Nameless2API::ERROR_INVALID_POST_CONTENTS);
}
foreach ($groups as $group) {
$user->removeGroup($group);
}
GroupSyncManager::getInstance()->broadcastGroupChange(
$user,
NamelessMCGroupSyncInjector::class,
[],
$groups,
);
$api->returnArray(['message' => $api->getLanguage()->get('api', 'group_updated')]);
}
}