-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New group sync endpoints with separate add/remove lists (#3538)
* New group sync endpoints with separate add/remove lists * Code review changes
- Loading branch information
Showing
6 changed files
with
198 additions
and
1 deletion.
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
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
36 changes: 36 additions & 0 deletions
36
modules/Core/includes/endpoints/SyncMinecraftGroupsEndpoint.php
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,36 @@ | ||
<?php | ||
|
||
class SyncMinecraftGroupsEndpoint extends KeyAuthEndpoint { | ||
|
||
public function __construct() { | ||
$this->_route = 'minecraft/{user}/sync-groups'; | ||
$this->_module = 'Core'; | ||
$this->_description = 'Update a users groups based on added or removed groups from the Minecraft server'; | ||
$this->_method = 'POST'; | ||
} | ||
|
||
public function execute(Nameless2API $api, User $user): void { | ||
$api->validateParams($_POST, ['server_id']); | ||
|
||
$server_id = $_POST['server_id']; | ||
$integration = Integrations::getInstance()->getIntegration('Minecraft'); | ||
|
||
if (!$integration || $server_id != Settings::get('group_sync_mc_server')) { | ||
$api->returnArray(['message' => $api->getLanguage()->get('api', 'groups_updates_ignored')]); | ||
} | ||
|
||
$log = GroupSyncManager::getInstance()->broadcastGroupChange( | ||
$user, | ||
MinecraftGroupSyncInjector::class, | ||
$_POST['add'] ?? [], | ||
$_POST['remove'] ?? [], | ||
); | ||
|
||
Log::getInstance()->log(Log::Action('mc_group_sync/role_set'), json_encode($log), $user->data()->id); | ||
|
||
$api->returnArray([ | ||
'message' => $api->getLanguage()->get('api', 'groups_updates_successfully'), | ||
'log' => $log, | ||
]); | ||
} | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
modules/Discord Integration/includes/endpoints/SyncDiscordRolesEndpoint.php
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,32 @@ | ||
<?php | ||
|
||
class SyncDiscordRolesEndpoint extends KeyAuthEndpoint { | ||
|
||
public function __construct() { | ||
$this->_route = 'discord/{user}/sync-roles'; | ||
$this->_module = 'Discord Integration'; | ||
$this->_description = 'Set a NamelessMC user\'s according to the supplied Discord Role ID list'; | ||
$this->_method = 'POST'; | ||
} | ||
|
||
public function execute(Nameless2API $api, User $user): void { | ||
$api->validateParams($_POST, []); | ||
|
||
if (!Discord::isBotSetup()) { | ||
$api->throwError(DiscordApiErrors::ERROR_DISCORD_INTEGRATION_DISABLED); | ||
} | ||
|
||
$log_array = GroupSyncManager::getInstance()->broadcastGroupChange( | ||
$user, | ||
DiscordGroupSyncInjector::class, | ||
$_POST['add'] ?? [], | ||
$_POST['remove'] ?? [] | ||
); | ||
|
||
if (count($log_array)) { | ||
Log::getInstance()->log(Log::Action('discord/role_set'), json_encode($log_array), $user->data()->id); | ||
} | ||
|
||
$api->returnArray(array_merge(['message' => Discord::getLanguageTerm('group_updated')], $log_array)); | ||
} | ||
} |