Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>tags/v14.0.0beta1
<script> | <script> | ||||
export default { | export default { | ||||
name: 'App', | name: 'App', | ||||
beforeMount: function () { | |||||
beforeMount: function() { | |||||
// importing server data into the store | // importing server data into the store | ||||
const serverDataElmt = document.getElementById('serverData'); | const serverDataElmt = document.getElementById('serverData'); | ||||
if (serverDataElmt !== null) { | if (serverDataElmt !== null) { |
} | } | ||||
}, | }, | ||||
methods: { | methods: { | ||||
showMenu () { | |||||
showMen() { | |||||
this.openedMenu = true; | this.openedMenu = true; | ||||
}, | }, | ||||
hideMenu () { | |||||
hideMenu() { | |||||
this.openedMenu = false; | this.openedMenu = false; | ||||
}, | }, | ||||
toggleCollapse () { | |||||
toggleCollapse() { | |||||
// if item.opened isn't set, Vue won't trigger view updates https://vuejs.org/v2/api/#Vue-set | // if item.opened isn't set, Vue won't trigger view updates https://vuejs.org/v2/api/#Vue-set | ||||
// ternary is here to detect the undefined state of item.opened | // ternary is here to detect the undefined state of item.opened | ||||
Vue.set(this.item, 'opened', this.item.opened ? !this.item.opened : true); | Vue.set(this.item, 'opened', this.item.opened ? !this.item.opened : true); | ||||
}, | }, | ||||
cancelEdit () { | |||||
cancelEdit() { | |||||
// remove the editing class | // remove the editing class | ||||
if (Array.isArray(this.item.classes)) | if (Array.isArray(this.item.classes)) | ||||
this.item.classes = this.item.classes.filter(item => item !== 'editing'); | this.item.classes = this.item.classes.filter(item => item !== 'editing'); |
}, | }, | ||||
infiniteHandler($state) { | infiniteHandler($state) { | ||||
this.$store.dispatch('getUsers', {offset:this.usersOffset, limit:this.usersLimit, group:this.selectedGroup}) | |||||
this.$store.dispatch('getUsers', { | |||||
offset: this.usersOffset, | |||||
limit: this.usersLimit, | |||||
group: this.selectedGroup !== 'disabled' ? this.selectedGroup : ''}) | |||||
.then((response) => {response?$state.loaded():$state.complete()}); | .then((response) => {response?$state.loaded():$state.complete()}); | ||||
}, | }, | ||||
resetForm () { | |||||
resetForm() { | |||||
// revert form to original state | // revert form to original state | ||||
Object.assign(this.newUser, this.$options.data.call(this).newUser); | Object.assign(this.newUser, this.$options.data.call(this).newUser); | ||||
this.loading = false; | this.loading = false; |
// unify format output | // unify format output | ||||
return this.setUserQuota(OC.Util.humanFileSize(OC.Util.computerFileSize(quota))); | return this.setUserQuota(OC.Util.humanFileSize(OC.Util.computerFileSize(quota))); | ||||
} | } | ||||
// if no valid doo not change | |||||
// if no valid do not change | |||||
return false; | return false; | ||||
}, | }, | ||||
const tokenHeaders = { headers: { requesttoken: requestToken } }; | const tokenHeaders = { headers: { requesttoken: requestToken } }; | ||||
const sanitize = function(url) { | const sanitize = function(url) { | ||||
return url.replace(/\/$/, ''); // Remove last slash of url | |||||
return url.replace(/\/$/, ''); // Remove last url slash | |||||
}; | }; | ||||
export default { | export default { | ||||
return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers }) | return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers }) | ||||
.then((response) => Promise.resolve(response)) | .then((response) => Promise.resolve(response)) | ||||
.catch((error) => Promise.reject(error)); | .catch((error) => Promise.reject(error)); | ||||
}, | |||||
// OCS API entry points | |||||
/** | |||||
* | |||||
* @param {string} app Application name | |||||
* @param {string} key Config key | |||||
* @param {string} [value=''] Value to set | |||||
* @returns{Promise} | |||||
*/ | |||||
setAppConfig(app, key, value = '') { | |||||
return this.requireAdmin().then((response) => { | |||||
return this.post(OC.linkToOCS(`apps/provisioning_api/api/v1/config/apps/${app}/${key}`, 2), {value: value}); | |||||
}); | |||||
} | } | ||||
}; | }; |
getServerData(state) { | getServerData(state) { | ||||
return state.serverData; | return state.serverData; | ||||
} | } | ||||
} | |||||
const actions = {} | |||||
}; | |||||
const actions = {}; | |||||
export default {state, mutations, getters, actions}; | export default {state, mutations, getters, actions}; |
state.userCount = userCount; | state.userCount = userCount; | ||||
state.groups = orderGroups(state.groups, state.orderBy); | state.groups = orderGroups(state.groups, state.orderBy); | ||||
}, | }, | ||||
addGroup(state, groupid) { | |||||
addGroup(state, gid) { | |||||
try { | try { | ||||
state.groups.push({ | state.groups.push({ | ||||
id: groupid, | |||||
name: groupid, | |||||
id: gid, | |||||
name: gid, | |||||
usercount: 0 // user will be added after the creation | usercount: 0 // user will be added after the creation | ||||
}); | }); | ||||
state.groups = orderGroups(state.groups, state.orderBy); | state.groups = orderGroups(state.groups, state.orderBy); | ||||
console.log('Can\'t create group', e); | console.log('Can\'t create group', e); | ||||
} | } | ||||
}, | }, | ||||
removeGroup(state, gid) { | |||||
let groupIndex = state.groups.findIndex(groupSearch => groupSearch.id == gid); | |||||
if (groupIndex >= 0) { | |||||
state.groups.splice(groupIndex, 1); | |||||
} | |||||
}, | |||||
addUserGroup(state, { userid, gid }) { | addUserGroup(state, { userid, gid }) { | ||||
// this should not be needed as it would means the user contains a group | // this should not be needed as it would means the user contains a group | ||||
// the server database doesn't have. | // the server database doesn't have. | ||||
* @param {int} options.limit List number to return from offset | * @param {int} options.limit List number to return from offset | ||||
* @param {string} options.search Search amongst users | * @param {string} options.search Search amongst users | ||||
* @param {string} options.group Get users from group | * @param {string} options.group Get users from group | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
getUsers(context, { offset, limit, search, group }) { | getUsers(context, { offset, limit, search, group }) { | ||||
search = typeof search === 'string' ? search : ''; | search = typeof search === 'string' ? search : ''; | ||||
* @param {Object} options | * @param {Object} options | ||||
* @param {int} options.offset List offset to request | * @param {int} options.offset List offset to request | ||||
* @param {int} options.limit List number to return from offset | * @param {int} options.limit List number to return from offset | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
getUsersFromList(context, { offset, limit, search }) { | getUsersFromList(context, { offset, limit, search }) { | ||||
search = typeof search === 'string' ? search : ''; | search = typeof search === 'string' ? search : ''; | ||||
* @param {Object} options | * @param {Object} options | ||||
* @param {int} options.offset List offset to request | * @param {int} options.offset List offset to request | ||||
* @param {int} options.limit List number to return from offset | * @param {int} options.limit List number to return from offset | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
getUsersFromGroup(context, { groupid, offset, limit }) { | getUsersFromGroup(context, { groupid, offset, limit }) { | ||||
return api.get(OC.linkToOCS(`cloud/users/${groupid}/details?offset=${offset}&limit=${limit}`, 2)) | return api.get(OC.linkToOCS(`cloud/users/${groupid}/details?offset=${offset}&limit=${limit}`, 2)) | ||||
* | * | ||||
* @param {Object} context | * @param {Object} context | ||||
* @param {string} gid Group id | * @param {string} gid Group id | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
addGroup(context, gid) { | addGroup(context, gid) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
* | * | ||||
* @param {Object} context | * @param {Object} context | ||||
* @param {string} gid Group id | * @param {string} gid Group id | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
removeGroup(context, gid) { | removeGroup(context, gid) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
return api.post(OC.linkToOCS(`cloud/groups`, 2), {groupid: gid}) | |||||
return api.delete(OC.linkToOCS(`cloud/groups/${gid}`, 2)) | |||||
.then((response) => context.commit('removeGroup', gid)) | .then((response) => context.commit('removeGroup', gid)) | ||||
.catch((error) => {throw error;}); | .catch((error) => {throw error;}); | ||||
}).catch((error) => context.commit('API_FAILURE', { userid, error })); | |||||
}).catch((error) => context.commit('API_FAILURE', { gid, error })); | |||||
}, | }, | ||||
/** | /** | ||||
* @param {Object} options | * @param {Object} options | ||||
* @param {string} options.userid User id | * @param {string} options.userid User id | ||||
* @param {string} options.gid Group id | * @param {string} options.gid Group id | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
addUserGroup(context, { userid, gid }) { | addUserGroup(context, { userid, gid }) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
* @param {Object} options | * @param {Object} options | ||||
* @param {string} options.userid User id | * @param {string} options.userid User id | ||||
* @param {string} options.gid Group id | * @param {string} options.gid Group id | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
removeUserGroup(context, { userid, gid }) { | removeUserGroup(context, { userid, gid }) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
* @param {Object} options | * @param {Object} options | ||||
* @param {string} options.userid User id | * @param {string} options.userid User id | ||||
* @param {string} options.gid Group id | * @param {string} options.gid Group id | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
addUserSubAdmin(context, { userid, gid }) { | addUserSubAdmin(context, { userid, gid }) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
* @param {Object} options | * @param {Object} options | ||||
* @param {string} options.userid User id | * @param {string} options.userid User id | ||||
* @param {string} options.gid Group id | * @param {string} options.gid Group id | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
removeUserSubAdmin(context, { userid, gid }) { | removeUserSubAdmin(context, { userid, gid }) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
* | * | ||||
* @param {Object} context | * @param {Object} context | ||||
* @param {string} userid User id | * @param {string} userid User id | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
deleteUser(context, { userid }) { | deleteUser(context, { userid }) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
* @param {string} options.groups User groups | * @param {string} options.groups User groups | ||||
* @param {string} options.subadmin User subadmin groups | * @param {string} options.subadmin User subadmin groups | ||||
* @param {string} options.quota User email | * @param {string} options.quota User email | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
addUser({context, dispatch}, { userid, password, email, groups, subadmin, quota, language }) { | addUser({context, dispatch}, { userid, password, email, groups, subadmin, quota, language }) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
* | * | ||||
* @param {Object} context | * @param {Object} context | ||||
* @param {string} userid User id | * @param {string} userid User id | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
addUserData(context, userid) { | addUserData(context, userid) { | ||||
return api.requireAdmin().then((response) => { | return api.requireAdmin().then((response) => { | ||||
* @param {Object} options | * @param {Object} options | ||||
* @param {string} options.userid User id | * @param {string} options.userid User id | ||||
* @param {boolean} options.enabled User enablement status | * @param {boolean} options.enabled User enablement status | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
enableDisableUser(context, { userid, enabled = true }) { | enableDisableUser(context, { userid, enabled = true }) { | ||||
let userStatus = enabled ? 'enable' : 'disable'; | let userStatus = enabled ? 'enable' : 'disable'; | ||||
* @param {string} options.userid User id | * @param {string} options.userid User id | ||||
* @param {string} options.key User field to edit | * @param {string} options.key User field to edit | ||||
* @param {string} options.value Value of the change | * @param {string} options.value Value of the change | ||||
* @returns Promise | |||||
* @returns {Promise} | |||||
*/ | */ | ||||
setUserData(context, { userid, key, value }) { | setUserData(context, { userid, key, value }) { | ||||
let allowedEmpty = ['email', 'displayname']; | let allowedEmpty = ['email', 'displayname']; |
<div id="app"> | <div id="app"> | ||||
<app-navigation :menu="menu"> | <app-navigation :menu="menu"> | ||||
<template slot="settings-content"> | <template slot="settings-content"> | ||||
<div> | |||||
<p>{{t('settings', 'Default quota :')}}</p> | |||||
<multiselect :value="defaultQuota" :options="quotaOptions" | |||||
tag-placeholder="create" :placeholder="t('settings', 'Select default quota')" | |||||
label="label" track-by="id" class="multiselect-vue" | |||||
:allowEmpty="false" :taggable="true" | |||||
@tag="validateQuota" @input="setDefaultQuota"> | |||||
</multiselect> | |||||
</div> | |||||
<div> | <div> | ||||
<input type="checkbox" id="showLanguages" class="checkbox" | <input type="checkbox" id="showLanguages" class="checkbox" | ||||
:checked="showLanguages" v-model="showLanguages"> | :checked="showLanguages" v-model="showLanguages"> | ||||
import userList from '../components/userList'; | import userList from '../components/userList'; | ||||
import Vue from 'vue'; | import Vue from 'vue'; | ||||
import VueLocalStorage from 'vue-localstorage' | import VueLocalStorage from 'vue-localstorage' | ||||
import Multiselect from 'vue-multiselect'; | |||||
import api from '../store/api'; | |||||
Vue.use(VueLocalStorage) | |||||
Vue.use(VueLocalStorage) | Vue.use(VueLocalStorage) | ||||
export default { | export default { | ||||
props: ['selectedGroup'], | props: ['selectedGroup'], | ||||
components: { | components: { | ||||
appNavigation, | appNavigation, | ||||
userList | |||||
userList, | |||||
Multiselect | |||||
}, | }, | ||||
beforeMount() { | beforeMount() { | ||||
this.$store.commit('initGroups', { | this.$store.commit('initGroups', { | ||||
}, | }, | ||||
data() { | data() { | ||||
return { | return { | ||||
// default quota is unlimited | |||||
unlimitedQuota: {id:'default', label:t('settings', 'Unlimited')}, | |||||
showConfig: { | showConfig: { | ||||
showStoragePath: false, | showStoragePath: false, | ||||
showUserBackend: false, | showUserBackend: false, | ||||
this.showConfig[key] = status; | this.showConfig[key] = status; | ||||
this.$localStorage.set(key, status); | this.$localStorage.set(key, status); | ||||
return status; | return status; | ||||
} | |||||
}, | |||||
removeGroup(groupid) { | |||||
let self = this; | |||||
// TODO migrate to a vue js confirm dialog component | |||||
OC.dialogs.confirm( | |||||
t('settings', 'You are about to remove the group {group}. The users will NOT be deleted.', {group: groupid}), | |||||
t('settings','Please confirm the group removal '), | |||||
function (success) { | |||||
if (success) { | |||||
self.$store.dispatch('removeGroup', groupid); | |||||
} | |||||
} | |||||
); | |||||
}, | |||||
/** | |||||
* Dispatch default quota set request | |||||
* | |||||
* @param {string|Object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'} | |||||
* @returns {string} | |||||
*/ | |||||
setDefaultQuota(quota = 'none') { | |||||
// ensure we only send the preset id | |||||
quota = quota.id ? quota.id : quota; | |||||
api.setAppConfig('files', 'default_quota', quota); | |||||
}, | |||||
/** | |||||
* Validate quota string to make sure it's a valid human file size | |||||
* | |||||
* @param {string} quota Quota in readable format '5 GB' | |||||
* @returns {Promise|boolean} | |||||
*/ | |||||
validateQuota(quota) { | |||||
// only used for new presets sent through @Tag | |||||
let validQuota = OC.Util.computerFileSize(quota); | |||||
if (validQuota === 0) { | |||||
return this.setDefaultQuota('none'); | |||||
} else if (validQuota !== null) { | |||||
// unify format output | |||||
return this.setDefaultQuota(OC.Util.humanFileSize(OC.Util.computerFileSize(quota))); | |||||
} | |||||
// if no valid do not change | |||||
return false; | |||||
}, | |||||
}, | }, | ||||
computed: { | computed: { | ||||
route() { | |||||
return this.$store.getters.getRoute; | |||||
}, | |||||
users() { | users() { | ||||
return this.$store.getters.getUsers; | return this.$store.getters.getUsers; | ||||
}, | }, | ||||
userCount() { | userCount() { | ||||
return this.$store.getters.getUserCount; | return this.$store.getters.getUserCount; | ||||
}, | }, | ||||
settings() { | |||||
return this.$store.getters.getServerData; | |||||
}, | |||||
// default quota | |||||
quotaOptions() { | |||||
// convert the preset array into objects | |||||
let quotaPreset = this.settings.quotaPreset.reduce((acc, cur) => acc.concat({id:cur, label:cur}), []); | |||||
// add default presets | |||||
quotaPreset.unshift(this.unlimitedQuota); | |||||
return quotaPreset; | |||||
}, | |||||
// mapping saved values to objects | |||||
defaultQuota() { | |||||
if (OC.Util.computerFileSize(this.settings.defaultQuota) > 0) { | |||||
// if value is valid, let's map the quotaOptions or return custom quota | |||||
return {id:this.settings.defaultQuota, label:this.settings.defaultQuota}; | |||||
} | |||||
return this.unlimitedQuota; // unlimited | |||||
}, | |||||
// BUILD APP NAVIGATION MENU OBJECT | |||||
menu() { | menu() { | ||||
// Data provided php side | // Data provided php side | ||||
let groups = this.$store.getters.getGroups; | let groups = this.$store.getters.getGroups; | ||||
item.utils.actions = [{ | item.utils.actions = [{ | ||||
icon: 'icon-delete', | icon: 'icon-delete', | ||||
text: t('settings', 'Remove group'), | text: t('settings', 'Remove group'), | ||||
action: () => {} | |||||
action: function() {self.removeGroup(item.id)} | |||||
}]; | }]; | ||||
}; | }; | ||||
return item; | return item; | ||||
items: groups | items: groups | ||||
} | } | ||||
}, | }, | ||||
removeGroup(groupid) { | |||||
console.trace(this); | |||||
return this.$store.dispatch('removeGroup', groupid); | |||||
} | |||||
} | } | ||||
} | } | ||||
</script> | </script> |