Add an admin setting to restrict the app to groups

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-02-27 15:25:25 +01:00
Родитель 5605e9ca26
Коммит b2db37ff9e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
11 изменённых файлов: 546 добавлений и 8 удалений

Просмотреть файл

@ -1,4 +1,6 @@
/js/admin/sha1.js
/js/admin/allowed-groups.js
/js/admin/allowed-groups.js.map
/js/admin/commands.js
/js/admin/commands.js.map
/js/tests/*

Просмотреть файл

@ -78,10 +78,11 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
</commands>
<settings>
<admin>OCA\Spreed\Settings\Admin\TurnServer</admin>
<admin>OCA\Spreed\Settings\Admin\StunServer</admin>
<admin>OCA\Spreed\Settings\Admin\SignalingServer</admin>
<admin>OCA\Spreed\Settings\Admin\AllowedGroups</admin>
<admin>OCA\Spreed\Settings\Admin\Commands</admin>
<admin>OCA\Spreed\Settings\Admin\SignalingServer</admin>
<admin>OCA\Spreed\Settings\Admin\StunServer</admin>
<admin>OCA\Spreed\Settings\Admin\TurnServer</admin>
<admin-section>OCA\Spreed\Settings\Admin\Section</admin-section>
</settings>

305
js/admin/allowed-groups.js Normal file

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Spreed\Settings\Admin;
use OCA\Spreed\Config;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IInitialStateService;
use OCP\Settings\ISettings;
class AllowedGroups implements ISettings {
/** @var Config */
private $config;
/** @var IInitialStateService */
private $initialStateService;
public function __construct(Config $config,
IInitialStateService $initialStateService) {
$this->config = $config;
$this->initialStateService = $initialStateService;
}
/**
* @return TemplateResponse
*/
public function getForm(): TemplateResponse {
$this->initialStateService->provideInitialState('talk', 'allowed_groups', $this->config->getAllowedGroupIds());
return new TemplateResponse('spreed', 'settings/admin/allowed-groups', [], '');
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection(): string {
return 'talk';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority(): int {
return 0;
}
}

Просмотреть файл

@ -0,0 +1,13 @@
<?php
/** @var array $_ */
/** @var \OCP\IL10N $l */
script('spreed', ['admin/allowed-groups']);
style('spreed', ['settings-admin']);
?>
<div class="videocalls section" id="allowed_groups">
<h2><?php p($l->t('Limit to groups')) ?></h2>
<p class="settings-hint"><?php p($l->t('When at least one group is selected, only people of the listed groups can be part of conversations.')); ?></p>
<p class="settings-hint"><?php p($l->t('Guests can still join public conversations.')); ?></p>
<p class="settings-hint"><?php p($l->t('Users that can not use Talk anymore will still be listed as participants in their previous conversations and also their chat messages will be kept.')); ?></p>
</div>

111
vue/src/AllowedGroups.vue Normal file
Просмотреть файл

@ -0,0 +1,111 @@
<!--
- @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
-
- @author Joas Schilling <coding@schilljs.com>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<div class="videocalls section" id="allowed_groups">
<h2>{{ t('spreed', 'Limit to groups') }}</h2>
<p class="settings-hint">{{ t('spreed', 'When at least one group is selected, only people of the listed groups can be part of conversations.') }}</p>
<p class="settings-hint">{{ t('spreed', 'Guests can still join public conversations.') }}</p>
<p class="settings-hint">{{ t('spreed', 'Users that can not use Talk anymore will still be listed as participants in their previous conversations and also their chat messages will be kept.') }}</p>
<Multiselect class="allowed-groups"
v-model="allowedGroups"
:options="groups"
:placeholder="t('spreed', 'Limit app usage to groups.')"
:disabled="loading"
:multiple="true"
:searchable="true"
@search-change="searchGroup"
:loading="loadingGroups"
:show-no-options="false"
:close-on-select="false">
</Multiselect>
<p>
<button class="button primary"
@click="saveChanges"
:disabled="loading">
{{ t('spreed', 'Save changes') }}
</button>
</p>
</div>
</template>
<script>
import Axios from 'nextcloud-axios'
import {Multiselect} from 'nextcloud-vue'
import _ from 'lodash'
export default {
name: 'app',
data () {
return {
loading: false,
loadingGroups: false,
groups: [],
allowedGroups: []
}
},
methods: {
searchGroup: _.debounce(function (query) {
this.loadingGroups = true;
Axios.get(OC.linkToOCS(`cloud/groups?offset=0&search=${encodeURIComponent(query)}&limit=20`, 2))
.then(res => res.data.ocs)
.then(ocs => ocs.data.groups)
.then(groups => this.groups = _.sortedUniq(_.uniq(this.groups.concat(groups))))
.catch(err => console.error('could not search groups', err))
.then(() => this.loadingGroups = false)
}, 500),
saveChanges () {
this.loading = true;
OCP.AppConfig.setValue('spreed', 'allowed_groups', JSON.stringify(this.allowedGroups), {
success: function () {
this.loading = false;
}.bind(this)
});
}
},
components: {
Multiselect
},
mounted () {
this.loading = true;
this.allowedGroups = OCP.InitialState.loadState('talk', 'allowed_groups');
this.groups = this.allowedGroups;
this.loading = false;
this.searchGroup('');
}
}
</script>
<style>
.allowed-groups {
width: 300px;
}
</style>

34
vue/src/allowed-groups.js Normal file
Просмотреть файл

@ -0,0 +1,34 @@
/*
* @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import Vue from 'vue';
import AllowedGroups from './AllowedGroups';
Vue.prototype.t = t;
Vue.prototype.n = n;
Vue.prototype.OC = OC;
Vue.prototype.OCA = OCA;
new Vue({
el: '#allowed_groups',
render: h => h(AllowedGroups)
});

Просмотреть файл

@ -4,6 +4,7 @@ const { VueLoaderPlugin } = require('vue-loader');
module.exports = {
entry: {
"admin/commands": path.join(__dirname, 'src', 'commands.js'),
"admin/allowed-groups": path.join(__dirname, 'src', 'allowed-groups.js'),
},
output: {
path: path.resolve(__dirname, '../js'),