Skip to content
Snippets Groups Projects
Commit 2d41fc70 authored by Thomas Hackl's avatar Thomas Hackl
Browse files

kick users from rooms if authentication via token is active

parent 0a926122
No related branches found
No related tags found
No related merge requests found
...@@ -157,12 +157,32 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin ...@@ -157,12 +157,32 @@ class MatrixPlugin extends StudIPPlugin implements StandardPlugin
$matrix = MatrixAccount::findOneByUser_id($membership->user_id); $matrix = MatrixAccount::findOneByUser_id($membership->user_id);
$room = MatrixRoom::findOneByRange_id($membership->seminar_id); $room = MatrixRoom::findOneByRange_id($membership->seminar_id);
if (is_a($matrix, MatrixAccount::class) && is_a($room, MatrixRoom::class)) { if (is_a($matrix, MatrixAccount::class) && is_a($room, MatrixRoom::class)) {
/*
* leaveRoom can only be used if we don't authorize our Matrix users with SSO and login token stuff.
* Otherwise we use the Stud.IP system account to kick the user from the room.
*/
if (Config::get()->MATRIX_SYSTEM_ACCOUNT_ACCESS_TOKEN) {
// POST body.
$data = [
'user_id' => $matrix->matrix_account_id,
'reason' => sprintf('Not a member of course "%s" anymore.', $membership->course->getFullname())
];
MatrixClient::get()->requestServer(
sprintf('/_matrix/client/r0/rooms/%s/kick', $room->matrix_room_id),
'POST',
$data,
[],
MatrixAccount::requireSystemAccount()
);
} else {
MatrixClient::get()->leaveRoom( MatrixClient::get()->leaveRoom(
$matrix->getLinkedAccount(), $matrix->getLinkedAccount(),
$room->getLinkedRoom() $room->getLinkedRoom()
); );
} }
} }
}
/** /**
* User has been deleted, remove assigned Matrix account * User has been deleted, remove assigned Matrix account
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment