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

try to respect MATRIX_AUTO_CREATE_ACCOUNTS setting

parent 9a550aa5
No related branches found
No related tags found
No related merge requests found
[submodule "vendor/libpatrix"]
[submodule "libpatrix"]
path = vendor/libpatrix
url = git@gitlab.data-quest.de:strohm/libpatrix.git
......@@ -40,24 +40,39 @@ class MatrixChatController extends AuthenticatedController
{
Navigation::activateItem('/course/matrix/matrix_chat');
if (!Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
PageLayout::postInfo(
sprintf(
dgettext('matrix', 'Sollten Sie sich noch nie beim Chat angemeldet haben, ' .
'tun Sie dies bitte jetzt und %sladen danach die Seite neu%s.'),
'<a href="" title="' . dgettext('matrix', 'Seite neu laden') . '">',
'</a>'
)
);
}
// Check if current user has a Matrix account.
$this->account = MatrixAccount::find(User::findCurrent()->id);
// If no account is found, try to search in Matrix user directory.
$found = MatrixClient::get()->searchUsers(
MatrixAccount::requireSystemAccount(), '@studip_test1:', 1);
PageLayout::postInfo('<pre>' . print_r($found, 1) . '</pre>');
$this->no_account_wanted = UserConfig::get(User::findCurrent()->id)->MATRIX_NO_ACCOUNT_WANTED;
if ($this->account) {
if (!$this->account && !Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
$this->account = new MatrixAccount();
$this->account->user_id = User::findCurrent()->id;
$this->account->matrix_account_id = '@' . User::findCurrent()->username . ':' . Config::get()->MATRIX_SERVER_HOSTNAME;
$this->account->matrix_password = '';
$this->account->store();
}
$this->hasToCreate = false;
if ($this->account || !Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
if (!($room = MatrixRoom::findOneByRange_id(Course::findCurrent()->id))) {
$this->hasToCreate = true;
} else {
$this->hasToCreate = false;
$room->requireMembership($this->account->getLinkedAccount());
//$room->requireMembership($this->account->getLinkedAccount());
$room->requireInvitation($this->account->getLinkedAccount());
}
}
......
......@@ -77,9 +77,9 @@ class InitMatrixChat extends Migration
'section' => 'matrix',
'description' => 'URL des Chatservers (z.B. Element)'
],
'AUTO_CREATE_ACCOUNTS' => [
'MATRIX_AUTO_CREATE_ACCOUNTS' => [
'value' => false,
'type' => 'bool',
'type' => 'boolean',
'range' => 'global',
'section' => 'matrix',
'description' => 'Soll automatisch versucht werden, Matrixaccounts anzulegen? Andernfalls wird ' .
......
......@@ -36,7 +36,9 @@ class MatrixAccount extends SimpleORMap
public function getLinkedAccount()
{
$account = new \Patrix\Account($this->matrix_account_id, $this->matrix_password);
MatrixClient::get()->login($account);
if (Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) {
MatrixClient::get()->login($account);
}
return $account;
}
......
......@@ -30,8 +30,7 @@ class MatrixClient
{
if (is_null(MatrixClient::$client)) {
MatrixClient::$client = new Patrix\MatrixClient(
Config::get()->MATRIX_SERVER_HOSTNAME,
'https://' . Config::get()->MATRIX_SERVER_HOSTNAME
Config::get()->MATRIX_SERVER_HOSTNAME
);
}
......
......@@ -158,4 +158,32 @@ class MatrixRoom extends SimpleORMap
}
}
public function requireInvitation($account)
{
$sysaccount = MatrixAccount::requireSystemAccount();
$invited = MatrixClient::get()->inviteIntoRoom($sysaccount, $this->getLinkedRoom(), $account->getUserName());
if ($invited) {
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;
}
// Get existing room permissions so that they are not completely overwritten when adding the current user.
$permissions = MatrixClient::get()
->getRoomPermissionLevels($sysaccount, $this->getLinkedRoom())
->getUserPermissions();
$permissions[$account->getUserName()] = $perm;
// Set correct permission for current user.
MatrixClient::get()->setRoomUserPermissionLevels($sysaccount, $this->getLinkedRoom(), $permissions);
}
}
}
\ No newline at end of file
pluginname=Matrix-Chat
pluginclassname=MatrixPlugin
origin=data-quest
version=0.9
version=0.95
screenshot=assets/images/matrix_logo.png
description=Matrix chat for Stud.IP courses
studipMinVersion=4.5
......
<? if (!$account) : ?>
<? if (!$account && Config::get()->MATRIX_AUTO_CREATE_ACCOUNTS) : ?>
<form class="default" action="<?= $controller->link_for('matrix_chat/create_account') ?>" method="post">
<? if ($no_account_wanted) : ?>
<?= MessageBox::info(dgettext('matrix',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment