Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-12-13 17:13:14 +01:00
Родитель 79e27b30df
Коммит 8c9277566b
14 изменённых файлов: 1236 добавлений и 289 удалений

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

@ -11,6 +11,11 @@ jssources=$(wildcard js/*) $(wildcard js/*/*) $(wildcard css/*/*) $(wildcard cs
all: dist/index.js
.PHONY: watch
watch:
node node_modules/.bin/webpack-dev-server --watch --hot --inline --port 3000 --public localcloud.icewind.me:444 --mode development --config webpack.config.js
clean:
rm -rf $(build_dir)
rm -rf node_modules

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

@ -1,38 +0,0 @@
#guests .select2-container-multi .select2-choices .select2-search-choice {
padding-left: 20px;
}
#guests .select2-container-multi .select2-choices .select2-search-choice .select2-search-choice-close {
display: inherit;
top: 7px;
}
#guests .select2-container {
width: calc(100% - 48px);
margin-right: 0;
}
#guests .select2-container ul {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-right: 0;
}
#guests .whitelist {
display: flex;
}
#guests #guestResetWhitelist {
align-items: stretch;
width: 32px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
#guests .msg {
font-size: 14px;
}
#guests .whitelist-toggle {
margin: 1em 0;
}

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

@ -1,14 +0,0 @@
<template>
<h1>{{ message }}</h1>
</template>
<script>
export default {
name: 'app',
data() {
return {
message: 'Hello, Vue!'
};
}
};
</script>

147
js/GuestSettings.vue Normal file
Просмотреть файл

@ -0,0 +1,147 @@
<template>
<div class="section" id="guests">
<h2>Guests <span class="msg" ref="msg"></span></h2>
<div v-if="loaded">
<p>
<span class="user-info-label">
{{ t('guests', 'Guest users are grouped under a virtual group in the user manager') }}
</span>
</p>
<p class="external-storage-toggle">
<input type="checkbox"
id="allowExternalStorage"
class="checkbox"
@change="saveConfig"
v-model="config.allowExternalStorage"/>
<label for="allowExternalStorage">
{{ t('guests', 'Guest users can access mounted external storages') }}
</label>
</p>
<p class="whitelist-toggle">
<input type="checkbox"
id="guestUseWhitelist"
class="checkbox"
@change="saveConfig"
v-model="config.useWhitelist"/>
<label for="guestUseWhitelist">
{{ t('guests', 'Limit guest access to an app whitelist') }}
</label>
</p>
<p class="whitelist" v-if="config.useWhitelist">
<v-select :options="config.whiteListableApps" multiple v-model="config.whitelist"
:on-change="saveConfig"></v-select>
<button :title="t('guests', 'Reset')" type="button" class="icon-history icon" @click="reset"></button>
</p>
</div>
<div v-if="!loaded">
<div class="loading"/>
</div>
</div>
</template>
<script>
export default {
name: 'guest-settings',
data () {
return {
loaded: false,
config: {
useWhitelist: false,
allowExternalStorage: false,
whitelist: [],
whiteListableApps: [],
}
};
},
methods: {
loadConfig () {
$.get(OC.generateUrl('apps/guests/config'))
.then(data => {
this.config = data;
this.$nextTick(() => {
this.loaded = true;
});
});
},
saveConfig () {
if (!this.loaded) {
return;
}
OC.msg.startSaving(this.$refs.msg);
$.ajax({
type: 'PUT',
url: OC.generateUrl('apps/guests/config'),
data: this.config,
dataType: 'json'
})
.success(() => {
const data = {status: 'success', data: {message: t('guests', 'Saved')}};
OC.msg.finishedSaving(this.$refs.msg, data);
})
.fail((result) => {
const data = {status: 'error', data: {message: result.responseJSON.message}};
OC.msg.finishedSaving(this.$refs.msg, data);
});
},
reset () {
OC.msg.startSaving(this.$refs.msg);
$.ajax({
type: 'POST',
url: OC.generateUrl('apps/guests/whitelist/reset')
}).success((response) => {
this.config.whitelist = response.whitelist;
OC.msg.finishedSaving(this.$refs.msg, {
status: 'success',
data: {message: t('guests', 'Reset')}
});
}).fail((response) => {
OC.msg.finishedSaving(this.$refs.msg, {
status: 'error',
data: {message: response.responseJSON.message}
});
});
}
},
beforeMount () {
this.loadConfig();
}
};
</script>
<style>
#guests {
.whitelist {
display: flex;
.dropdown {
width: calc(100% - 48px);
margin-right: 0;
.dropdown-toggle {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-right: 0;
flex-wrap: nowrap;
input {
min-height: auto;
&:hover, &:active, &:focus {
border-color: transparent;
}
}
}
}
button {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.whitelist-toggle {
margin: 1em 0;
}
}
}
</style>

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

@ -1,167 +0,0 @@
/**
* ownCloud
*
* @author Jörn Friedrich Dreyer <jfd@owncloud.com>
* @copyright (C) 2015-2017 ownCloud, Inc.
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
(function() {
$(document).ready(function () {
// variables
var $section = $('#guests');
var $guestsByGroup = $section.find('#guestsByGroup');
var $allowExternalStorage = $section.find('#allowExternalStorage');
var $guestUseWhitelist = $section.find('#guestUseWhitelist');
var $guestWhitelist = $section.find('#guestWhitelist');
var $guestWhitelistContainer = $section.find('.whitelist');
var $resetWhitelist = $section.find('#guestResetWhitelist');
var $msg = $section.find('.msg');
var loading = true;
var config = { conditions: ['quota'], group: 'guests',
useWhitelist: true, whitelist:[
'','core','settings','avatar','files','files_trashbin','files_sharing'
]};
$guestWhitelist.select2();
// functions
var loadConfig = function () {
OC.msg.startAction($msg, t('guests', 'Loading…'));
$.get(
OC.generateUrl('apps/guests/config'),
'',
function (data) {
// update model
config = data;
// update ui
if(config.useWhitelist) {
$guestUseWhitelist.prop('checked', true);
$guestWhitelistContainer.show();
} else {
$guestUseWhitelist.prop('checked', false);
$guestWhitelistContainer.hide();
}
$allowExternalStorage.prop('checked', config.allowExternalStorage);
if ($.isArray(config.whitelist)) {
$guestWhitelist.val(config.whitelist).trigger("change");
}
loading = false;
},
'json'
).then(function() {
var data = { status: 'success', data: {message: t('guests', 'Loaded')} };
OC.msg.finishedAction($msg, data);
}, function(result) {
var data = { status: 'error', data:{message:result.responseJSON.message} };
OC.msg.finishedAction($msg, data);
});
};
var saveConfig = function () {
if (loading) {
return;
}
OC.msg.startSaving($msg);
$.ajax({
type: 'PUT',
url: OC.generateUrl('apps/guests/config'),
data: config,
dataType: 'json'
}).success(function() {
var data = { status:'success', data:{message:t('guests', 'Saved')} };
OC.msg.finishedSaving($msg, data);
}).fail(function(result) {
var data = { status: 'error', data:{message:result.responseJSON.message} };
OC.msg.finishedSaving($msg, data);
});
};
// load initial config
loadConfig();
var updateConditions = function () {
var conditions = [];
if ($guestsByGroup.prop('checked')) {
conditions.push('group');
}
config.conditions = conditions;
};
// listen to ui changes
$guestsByGroup.on('change', function () {
updateConditions();
saveConfig();
});
$guestUseWhitelist.on('change', function () {
config.useWhitelist = $guestUseWhitelist.prop('checked');
if(config.useWhitelist) {
$guestWhitelistContainer.show();
} else {
$guestWhitelistContainer.hide();
}
saveConfig();
});
$guestWhitelist.on('change', function () {
var apps = $guestWhitelist.val();
config.whitelist = [];
$.each(apps, function( index, value ) {
config.whitelist.push(value.trim());
});
saveConfig();
});
$allowExternalStorage.on('change', function () {
config.allowExternalStorage = $allowExternalStorage.prop('checked');
saveConfig();
});
$resetWhitelist.on('click', function () {
OC.msg.startSaving($msg);
$.ajax({
type: 'POST',
url: OC.generateUrl('apps/guests/whitelist/reset')
}).success(function(response) {
config.whitelist = response.whitelist;
// prevent it saving again
loading = true;
//update ui
if ($.isArray(config.whitelist)) {
$guestWhitelist.val(config.whitelist).trigger("change");
} else {
$guestWhitelist.val([]).trigger("change");
}
loading = false;
OC.msg.finishedSaving($msg, {
status:'success',
data: { message:t('guests', 'Reset') }
});
}).fail(function(response) {
OC.msg.finishedSaving($msg, {
status: 'error',
data: { message: response.responseJSON.message }
});
});
});
});
})();

10
js/settings.js Normal file
Просмотреть файл

@ -0,0 +1,10 @@
import Vue from 'vue';
import GuestSettings from './GuestSettings.vue';
import Nextcloud from './mixins/Nextcloud';
import vSelect from 'vue-select';
Vue.component('v-select', vSelect);
Vue.mixin(Nextcloud);
(new Vue(GuestSettings)).$mount('#guest-settings');

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

@ -149,9 +149,9 @@ class AppWhitelist {
}
public function getWhitelistAbleApps() {
return array_diff(
return array_values(array_diff(
$this->appManager->getInstalledApps(),
explode(',', self::WHITELIST_ALWAYS)
);
));
}
}

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

@ -45,10 +45,13 @@ class SettingsController extends Controller {
*/
private $config;
public function __construct($AppName, IRequest $request, $UserId, IConfig $config) {
private $appWhitelist;
public function __construct($AppName, IRequest $request, $UserId, IConfig $config, AppWhitelist $appWhitelist) {
parent::__construct($AppName, $request);
$this->userId = $UserId;
$this->config = $config;
$this->appWhitelist = $appWhitelist;
}
/**
@ -69,7 +72,8 @@ class SettingsController extends Controller {
return new DataResponse([
'useWhitelist' => $useWhitelist,
'whitelist' => $whitelist,
'allowExternalStorage' => $allowExternalStorage
'allowExternalStorage' => $allowExternalStorage,
'whiteListableApps' => $this->appWhitelist->getWhitelistAbleApps()
]);
}
/**

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

@ -36,9 +36,7 @@ class Admin implements \OCP\Settings\ISettings {
* {@inheritdoc}
*/
public function getForm() {
return new TemplateResponse('guests', 'settings/admin', [
'whitelistableApps' => $this->appWhitelist->getWhitelistAbleApps()
]);
return new TemplateResponse('guests', 'settings/admin');
}
/**

1027
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -5,8 +5,14 @@
"babel-loader": "^8.0.4",
"css-loader": "^2.0.0",
"less": "^3.9.0",
"mini-css-extract-plugin": "^0.5.0",
"postcss-cssnext": "^3.1.0",
"postcss-loader": "^3.0.0",
"postcss-nested": "^4.1.0",
"style-loader": "^0.23.1",
"vue": "^2.5.21",
"vue-loader": "^15.4.2",
"vue-select": "^2.5.1",
"vue-template-compiler": "^2.5.21",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",

6
postcss.config.js Normal file
Просмотреть файл

@ -0,0 +1,6 @@
module.exports = {
plugins: [
require("postcss-cssnext")(),
require('postcss-nested')
]
};

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

@ -1,58 +1,3 @@
<?php
/**
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Ilja Neumann <ineumann@butonic.de>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
script('guests', 'guests');
style('guests', 'admin');
/** @var $l OC_L10N */
/** @var $_ array */
?>
<div class="section" id="guests">
<h2>Guests <span class="msg"></span></h2>
<div>
<p>
<span class="inlineblock user-info-label"><?php p($l->t('Guest users are grouped under a virtual group in the user manager')); ?></span><br/><br/>
</p>
<p class="external-storage-toggle">
<input type="checkbox" id="allowExternalStorage" class="checkbox"
value="allowExternalStorage"/>
<label for="allowExternalStorage">
<?php p($l->t('Guest users can access mounted external storages')); ?>
</label>
</p>
<p class="whitelist-toggle">
<input type="checkbox" id="guestUseWhitelist" class="checkbox"
value="useWhitelist"/>
<label for="guestUseWhitelist">
<?php p($l->t('Limit guest access to an app whitelist')); ?>
</label>
</p>
<p class="whitelist" style="display: none">
<select multiple="multiple" id="guestWhitelist">
<?php foreach ($_['whitelistableApps'] as $app): ?>
<option value="<?php p($app); ?>"><?php p($app); ?></option>
<?php endforeach; ?>
</select>
<button title="<?php p($l->t('Reset')) ?>" type="button"
class="icon-history icon"
id="guestResetWhitelist"></button>
</p>
</div>
</div>
<?php script('guests', '../dist/settings'); ?>
<?php style('guests', '../dist/settings'); ?>
<div id="guest-settings"/>

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

@ -1,10 +1,15 @@
const VueLoaderPlugin = require('vue-loader/lib/plugin');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
module.exports = (env, argv) => ({
devtool: 'source-map',
entry: [
'./js/index.js'
],
entry: {
'main': './js/index.js',
'settings': './js/settings.js'
},
output: {
filename: '[name].js'
},
module: {
rules: [
{
@ -18,10 +23,23 @@ module.exports = {
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: [
argv.mode !== 'production'
? 'vue-style-loader'
: MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader'
]
}
],
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css'
})
]
};
});