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

don't invite all users and get permissions on room creation but on actually...

don't invite all users and get permissions on room creation but on actually calling the Stud.IP page and opening Matrix chat.
parent 95c42b13
No related branches found
No related tags found
No related merge requests found
...@@ -45,11 +45,12 @@ class MatrixChatController extends AuthenticatedController ...@@ -45,11 +45,12 @@ class MatrixChatController extends AuthenticatedController
$this->no_account_wanted = UserConfig::get(User::findCurrent()->id)->MATRIX_NO_ACCOUNT_WANTED; $this->no_account_wanted = UserConfig::get(User::findCurrent()->id)->MATRIX_NO_ACCOUNT_WANTED;
if ($this->account) { if ($this->account) {
if (!MatrixRoom::hasRoom(Course::findCurrent()->id)) if (!($room = MatrixRoom::findOneByRange_id(Course::findCurrent()->id))) {
{
$this->hasToCreate = true; $this->hasToCreate = true;
} else { } else {
$this->hasToCreate = false; $this->hasToCreate = false;
$room->requireMembership($this->account->getLinkedAccount());
} }
} }
} }
...@@ -86,9 +87,6 @@ class MatrixChatController extends AuthenticatedController ...@@ -86,9 +87,6 @@ class MatrixChatController extends AuthenticatedController
PageLayout::postSuccess(dgettext('matrix', 'Ihre Kennung wurde erfolgreich angelegt.')); PageLayout::postSuccess(dgettext('matrix', 'Ihre Kennung wurde erfolgreich angelegt.'));
// Create invitations to all relevant rooms.
MatrixClient::addToRooms(User::findCurrent()->id, $mapping->matrix_account_id);
} else { } else {
PageLayout::postError( PageLayout::postError(
dgettext('matrix', 'Ihre Kennung konnte nicht im Matrixchat angelegt werden.')); dgettext('matrix', 'Ihre Kennung konnte nicht im Matrixchat angelegt werden.'));
......
...@@ -59,7 +59,8 @@ class MatrixAccount extends SimpleORMap ...@@ -59,7 +59,8 @@ class MatrixAccount extends SimpleORMap
MatrixClient::get()->login($account); MatrixClient::get()->login($account);
return $account; return $account;
} else { } else {
$username = 'studip-' . Config::get()->STUDIP_INSTALLATION_ID; //$username = 'studip-' . Config::get()->STUDIP_INSTALLATION_ID;
$username = 'studip';
$password = self::randomPassword(); $password = self::randomPassword();
$sysaccount = new \Patrix\Account($username, $password); $sysaccount = new \Patrix\Account($username, $password);
if (MatrixClient::get()->registerAccount($sysaccount)) { if (MatrixClient::get()->registerAccount($sysaccount)) {
......
...@@ -24,7 +24,7 @@ class MatrixRoom extends SimpleORMap ...@@ -24,7 +24,7 @@ class MatrixRoom extends SimpleORMap
const POWER_LEVEL_AUTOR = 0; const POWER_LEVEL_AUTOR = 0;
const POWER_LEVEL_TUTOR = 50; const POWER_LEVEL_TUTOR = 50;
const POWER_LEVEL_DOZENT = 75; const POWER_LEVEL_DOZENT = 50;
const EVENT_POWER_LEVELS = [ const EVENT_POWER_LEVELS = [
'events' => [ 'events' => [
'ban' => self::POWER_LEVEL_TUTOR, 'ban' => self::POWER_LEVEL_TUTOR,
...@@ -67,7 +67,7 @@ class MatrixRoom extends SimpleORMap ...@@ -67,7 +67,7 @@ class MatrixRoom extends SimpleORMap
// Invite all members with existing Matrix account to newly created room. // Invite all members with existing Matrix account to newly created room.
$invites = []; $invites = [];
// Permission levels in the room to create. // Permission levels in the room to create.
$permissions = [ /*$permissions = [
$sysaccount->getUserId() => 100 $sysaccount->getUserId() => 100
]; ];
$accounts = []; $accounts = [];
...@@ -96,18 +96,16 @@ class MatrixRoom extends SimpleORMap ...@@ -96,18 +96,16 @@ class MatrixRoom extends SimpleORMap
} }
$power_levels = self::EVENT_POWER_LEVELS; $power_levels = self::EVENT_POWER_LEVELS;
$power_levels['users'] = $permissions; $power_levels['users'] = $permissions;*/
$newRoom = MatrixClient::get()->createRoom($sysaccount, Context::getHeaderLine(), false, '', $newRoom = MatrixClient::get()->createRoom($sysaccount, Context::getHeaderLine(), false, '',
$invites, $power_levels); [], self::EVENT_POWER_LEVELS);
$mapping = new self(); $mapping = new self();
$mapping->range_id = $context->getId(); $mapping->range_id = $context->getId();
$mapping->matrix_room_id = $newRoom->getId(); $mapping->matrix_room_id = $newRoom->getId();
$mapping->store(); $mapping->store();
//MatrixClient::get()->setRoomUserPermissionLevels($sysaccount, $newRoom, $permissions);
return $newRoom; return $newRoom;
} else { } else {
...@@ -125,4 +123,30 @@ class MatrixRoom extends SimpleORMap ...@@ -125,4 +123,30 @@ class MatrixRoom extends SimpleORMap
return new Patrix\Room($this->matrix_room_id, Context::getHeaderLine()); return new Patrix\Room($this->matrix_room_id, Context::getHeaderLine());
} }
public function requireMembership($account)
{
$sysaccount = MatrixAccount::requireSystemAccount();
$invited = MatrixClient::get()->inviteIntoRoom($sysaccount, $this->getLinkedRoom(), $account->getUserName());
if ($invited) {
MatrixClient::get()->login($account);
MatrixClient::get()->joinRoom($account, $this->getLinkedRoom());
if ($GLOBALS['perm']->have_studip_perm('dozent', $this->range_id)) {
$perm = self::POWER_LEVEL_DOZENT;
} else if ($GLOBALS['perm']->have_studip_perm('tutor', $this->range_id)) {
$perm = self::POWER_LEVEL_TUTOR;
} else {
$perm = self::POWER_LEVEL_AUTOR;
}
}
$permission = [
$account->getUserName() => $perm
];
//MatrixClient::get()->setRoomUserPermissionLevels($sysaccount, $this->getLinkedRoom(), $permission);
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment