Fixed tabs and Language support

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-04-09 11:03:21 +02:00
parent 6ada8254c9
commit f33065523d
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
9 changed files with 599 additions and 559 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,3 @@
{ {
"esversion": 6 "esversion": 6
} }

View File

@ -231,7 +231,7 @@ export default {
// 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;
}, },
createUser() { createUser() {
this.loading = true; this.loading = true;
this.$store.dispatch('addUser', { this.$store.dispatch('addUser', {

View File

@ -343,7 +343,7 @@ export default {
let userid = this.user.id; let userid = this.user.id;
let gid = group.id; let gid = group.id;
return this.$store.dispatch('addUserGroup', {userid, gid}) return this.$store.dispatch('addUserGroup', {userid, gid})
.then(() => this.loading.groups = false); .then(() => this.loading.groups = false);
}, },
/** /**
@ -357,7 +357,7 @@ export default {
let userid = this.user.id; let userid = this.user.id;
let gid = group.id; let gid = group.id;
return this.$store.dispatch('removeUserGroup', {userid, gid}) return this.$store.dispatch('removeUserGroup', {userid, gid})
.then(() => this.loading.groups = false); .then(() => this.loading.groups = false);
}, },
/** /**
@ -371,7 +371,7 @@ export default {
let userid = this.user.id; let userid = this.user.id;
let gid = group.id; let gid = group.id;
return this.$store.dispatch('addUserSubAdmin', {userid, gid}) return this.$store.dispatch('addUserSubAdmin', {userid, gid})
.then(() => this.loading.subadmins = false); .then(() => this.loading.subadmins = false);
}, },
/** /**
@ -385,12 +385,11 @@ export default {
let userid = this.user.id; let userid = this.user.id;
let gid = group.id; let gid = group.id;
return this.$store.dispatch('removeUserSubAdmin', {userid, gid}) return this.$store.dispatch('removeUserSubAdmin', {userid, gid})
.then(() => this.loading.subadmins = false); .then(() => this.loading.subadmins = false);
}, },
/** /**
* Validate quota string to make sure it's a valid human file size * Dispatch quota set request
* *
* @param {string|Object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'} * @param {string|Object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'}
* @returns {string} * @returns {string}
@ -407,24 +406,6 @@ export default {
return quota; return quota;
}, },
/**
* Validate quota string to make sure it's a valid human file size
*
* @param {string|Object} quota Quota in readable format '5 GB' or Object {id: '5 GB', label: '5GB'}
* @returns {string}
*/
setUserLanguage(lang) {
this.loading.languages = true;
// ensure we only send the preset id
this.$store.dispatch('setUserData', {
userid: this.user.id,
key: 'language',
value: lang.code
}).then(() => this.loading.languages = false);
return lang;
},
/** /**
* Validate quota string to make sure it's a valid human file size * Validate quota string to make sure it's a valid human file size
* *
@ -442,6 +423,23 @@ export default {
} }
// if no valid doo not change // if no valid doo not change
return false; return false;
},
/**
* Dispatch language set request
*
* @param {Object} lang language object {code:'en', name:'English'}
* @returns {Object}
*/
setUserLanguage(lang) {
this.loading.languages = true;
// ensure we only send the preset id
this.$store.dispatch('setUserData', {
userid: this.user.id,
key: 'language',
value: lang.code
}).then(() => this.loading.languages = false);
return lang;
} }
} }
} }

View File

@ -12,9 +12,9 @@ Vue.prototype.OC = OC;
Vue.prototype.oc_userconfig = oc_userconfig; Vue.prototype.oc_userconfig = oc_userconfig;
const app = new Vue({ const app = new Vue({
router, router,
store, store,
render: h => h(App) render: h => h(App)
}).$mount('#content'); }).$mount('#content');
export { app, router, store }; export { app, router, store };

View File

@ -14,10 +14,10 @@ Vue.use(Router);
*/ */
export default new Router({ export default new Router({
mode: 'history', mode: 'history',
base: window.location.pathName, base: window.location.pathName,
routes: [{ routes: [{
path: '/settings/users', path: '/settings/users',
component: Users component: Users
}] }]
}); });

View File

@ -4,47 +4,94 @@ const requestToken = document.getElementsByTagName('head')[0].getAttribute('data
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 slash of url
} };
export default { export default {
requireAdmin() {
return new Promise(function(resolve, reject) { /**
setTimeout(reject, 5000); // automatically reject 5s if not ok * This Promise is used to chain a request that require an admin password confirmation
function waitForpassword() { * Since chaining Promise have a very precise behavior concerning catch and then,
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { * you'll need to be careful when using it.
setTimeout(waitForpassword, 500); * e.g
return; * // store
} * action(context) {
resolve(); * return api.requireAdmin().then((response) => {
} * return api.get('url')
waitForpassword(); * .then((response) => {API success})
OC.PasswordConfirmation.requirePasswordConfirmation(); * .catch((error) => {API failure});
}).catch((error) => console.log('Required password not entered')); * }).catch((error) => {requireAdmin failure});
}, * }
get(url) { * // vue
return axios.get(sanitize(url), tokenHeaders) * this.$store.dispatch('action').then(() => {always executed})
.then((response) => Promise.resolve(response)) *
.catch((error) => Promise.reject(error)); * Since Promise.then().catch().then() will always execute the last then
}, * this.$store.dispatch('action').then will always be executed
post(url, data) { *
return axios.post(sanitize(url), data, tokenHeaders) * If you want requireAdmin failure to also catch the API request failure
.then((response) => Promise.resolve(response)) * you will need to throw a new error in the api.get.catch()
.catch((error) => Promise.reject(error)); *
}, * e.g
patch(url, data) { * api.requireAdmin().then((response) => {
return axios.patch(sanitize(url), data, tokenHeaders) * api.get('url')
.then((response) => Promise.resolve(response)) * .then((response) => {API success})
.catch((error) => Promise.reject(error)); * .catch((error) => {throw error;});
}, * }).catch((error) => {requireAdmin OR API failure});
put(url, data) { */
return axios.put(sanitize(url), data, tokenHeaders) requireAdmin() {
.then((response) => Promise.resolve(response)) return new Promise(function(resolve, reject) {
.catch((error) => Promise.reject(error)); // TODO: migrate the OC.dialog to Vue and avoid this mess
}, // wait for password confirmation
delete(url, data) { let passwordTimeout;
return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers }) let waitForpassword = function() {
.then((response) => Promise.resolve(response)) if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
.catch((error) => Promise.reject(error)); passwordTimeout = setTimeout(waitForpassword, 500);
} return;
}
clearTimeout(passwordTimeout);
clearTimeout(promiseTimeout);
resolve();
};
// automatically reject after 5s if not resolved
let promiseTimeout = setTimeout(() => {
clearTimeout(passwordTimeout);
// close dialog
if (document.getElementsByClassName('oc-dialog-close').length>0) {
document.getElementsByClassName('oc-dialog-close')[0].click();
}
OC.Notification.showTemporary(t('settings', 'You did not enter the password in time'));
reject('Password request cancelled');
}, 7000);
// request password
OC.PasswordConfirmation.requirePasswordConfirmation();
waitForpassword();
});
},
get(url) {
return axios.get(sanitize(url), tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
post(url, data) {
return axios.post(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
patch(url, data) {
return axios.patch(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
put(url, data) {
return axios.put(sanitize(url), data, tokenHeaders)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
delete(url, data) {
return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers })
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
}
}; };

View File

@ -1,420 +1,420 @@
import api from './api'; import api from './api';
const orderGroups = function(groups, orderBy) { const orderGroups = function(groups, orderBy) {
/* const SORT_USERCOUNT = 1; /* const SORT_USERCOUNT = 1;
* const SORT_GROUPNAME = 2; * const SORT_GROUPNAME = 2;
* https://github.com/nextcloud/server/blob/208e38e84e1a07a49699aa90dc5b7272d24489f0/lib/private/Group/MetaData.php#L34 * https://github.com/nextcloud/server/blob/208e38e84e1a07a49699aa90dc5b7272d24489f0/lib/private/Group/MetaData.php#L34
*/ */
if (orderBy === 1) { if (orderBy === 1) {
return groups.sort((a, b) => a.usercount < b.usercount); return groups.sort((a, b) => a.usercount < b.usercount);
} else { } else {
return groups.sort((a, b) => a.name.localeCompare(b.name)); return groups.sort((a, b) => a.name.localeCompare(b.name));
} }
} }
const state = { const state = {
users: [], users: [],
groups: [], groups: [],
orderBy: 1, orderBy: 1,
minPasswordLength: 0, minPasswordLength: 0,
usersOffset: 0, usersOffset: 0,
usersLimit: 25, usersLimit: 25,
userCount: 0 userCount: 0
}; };
const mutations = { const mutations = {
appendUsers(state, usersObj) { appendUsers(state, usersObj) {
// convert obj to array // convert obj to array
let users = state.users.concat(Object.keys(usersObj).map(userid => usersObj[userid])); let users = state.users.concat(Object.keys(usersObj).map(userid => usersObj[userid]));
state.usersOffset += state.usersLimit; state.usersOffset += state.usersLimit;
state.users = users; state.users = users;
}, },
setPasswordPolicyMinLength(state, length) { setPasswordPolicyMinLength(state, length) {
state.minPasswordLength = length!=='' ? length : 0; state.minPasswordLength = length!=='' ? length : 0;
}, },
initGroups(state, {groups, orderBy, userCount}) { initGroups(state, {groups, orderBy, userCount}) {
state.groups = groups; state.groups = groups;
state.orderBy = orderBy; state.orderBy = orderBy;
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, groupid) {
try { try {
state.groups.push({ state.groups.push({
id: groupid, id: groupid,
name: groupid, name: groupid,
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);
} catch (e) { } catch (e) {
console.log('Can\'t create group', e); console.log('Can\'t create group', e);
} }
}, },
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.
let group = state.groups.find(groupSearch => groupSearch.id == gid); let group = state.groups.find(groupSearch => groupSearch.id == gid);
if (group) { if (group) {
group.usercount++; // increase count group.usercount++; // increase count
} }
let groups = state.users.find(user => user.id == userid).groups; let groups = state.users.find(user => user.id == userid).groups;
groups.push(gid); groups.push(gid);
state.groups = orderGroups(state.groups, state.orderBy); state.groups = orderGroups(state.groups, state.orderBy);
}, },
removeUserGroup(state, { userid, gid }) { removeUserGroup(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.
let group = state.groups.find(groupSearch => groupSearch.id == gid); let group = state.groups.find(groupSearch => groupSearch.id == gid);
if (group) { if (group) {
group.usercount--; // lower count group.usercount--; // lower count
} }
let groups = state.users.find(user => user.id == userid).groups; let groups = state.users.find(user => user.id == userid).groups;
groups.splice(groups.indexOf(gid),1); groups.splice(groups.indexOf(gid),1);
state.groups = orderGroups(state.groups, state.orderBy); state.groups = orderGroups(state.groups, state.orderBy);
}, },
addUserSubAdmin(state, { userid, gid }) { addUserSubAdmin(state, { userid, gid }) {
let groups = state.users.find(user => user.id == userid).subadmin; let groups = state.users.find(user => user.id == userid).subadmin;
groups.push(gid); groups.push(gid);
}, },
removeUserSubAdmin(state, { userid, gid }) { removeUserSubAdmin(state, { userid, gid }) {
let groups = state.users.find(user => user.id == userid).subadmin; let groups = state.users.find(user => user.id == userid).subadmin;
groups.splice(groups.indexOf(gid),1); groups.splice(groups.indexOf(gid),1);
}, },
deleteUser(state, userid) { deleteUser(state, userid) {
let userIndex = state.users.findIndex(user => user.id == userid); let userIndex = state.users.findIndex(user => user.id == userid);
state.users.splice(userIndex, 1); state.users.splice(userIndex, 1);
}, },
addUserData(state, response) { addUserData(state, response) {
state.users.push(response.data.ocs.data); state.users.push(response.data.ocs.data);
}, },
enableDisableUser(state, { userid, enabled }) { enableDisableUser(state, { userid, enabled }) {
state.users.find(user => user.id == userid).enabled = enabled; state.users.find(user => user.id == userid).enabled = enabled;
// increment or not // increment or not
state.groups.find(group => group.id == '_disabled').usercount += enabled ? -1 : 1; state.groups.find(group => group.id == '_disabled').usercount += enabled ? -1 : 1;
state.userCount += enabled ? 1 : -1; state.userCount += enabled ? 1 : -1;
console.log(enabled); console.log(enabled);
}, },
setUserData(state, { userid, key, value }) { setUserData(state, { userid, key, value }) {
if (key === 'quota') { if (key === 'quota') {
let humanValue = OC.Util.computerFileSize(value); let humanValue = OC.Util.computerFileSize(value);
state.users.find(user => user.id == userid)[key][key] = humanValue?humanValue:value; state.users.find(user => user.id == userid)[key][key] = humanValue?humanValue:value;
} else { } else {
state.users.find(user => user.id == userid)[key] = value; state.users.find(user => user.id == userid)[key] = value;
} }
}, },
/** /**
* Reset users list * Reset users list
*/ */
resetUsers(state) { resetUsers(state) {
state.users = []; state.users = [];
state.usersOffset = 0; state.usersOffset = 0;
} }
}; };
const getters = { const getters = {
getUsers(state) { getUsers(state) {
return state.users; return state.users;
}, },
getGroups(state) { getGroups(state) {
return state.groups; return state.groups;
}, },
getPasswordPolicyMinLength(state) { getPasswordPolicyMinLength(state) {
return state.minPasswordLength; return state.minPasswordLength;
}, },
getUsersOffset(state) { getUsersOffset(state) {
return state.usersOffset; return state.usersOffset;
}, },
getUsersLimit(state) { getUsersLimit(state) {
return state.usersLimit; return state.usersLimit;
}, },
getUserCount(state) { getUserCount(state) {
return state.userCount; return state.userCount;
} }
}; };
const actions = { const actions = {
/** /**
* Get all users with full details * Get all users with full details
* *
* @param {Object} context * @param {Object} context
* @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
* @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 : '';
group = typeof group === 'string' ? group : ''; group = typeof group === 'string' ? group : '';
if (group !== '') { if (group !== '') {
return api.get(OC.linkToOCS(`cloud/groups/${group}/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2)) return api.get(OC.linkToOCS(`cloud/groups/${group}/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
.then((response) => { .then((response) => {
if (Object.keys(response.data.ocs.data.users).length > 0) { if (Object.keys(response.data.ocs.data.users).length > 0) {
context.commit('appendUsers', response.data.ocs.data.users); context.commit('appendUsers', response.data.ocs.data.users);
return true; return true;
} }
return false; return false;
}) })
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => context.commit('API_FAILURE', error));
} }
return api.get(OC.linkToOCS(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2)) return api.get(OC.linkToOCS(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
.then((response) => { .then((response) => {
if (Object.keys(response.data.ocs.data.users).length > 0) { if (Object.keys(response.data.ocs.data.users).length > 0) {
context.commit('appendUsers', response.data.ocs.data.users); context.commit('appendUsers', response.data.ocs.data.users);
return true; return true;
} }
return false; return false;
}) })
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => context.commit('API_FAILURE', error));
}, },
/** /**
* Get all users with full details * Get all users with full details
* *
* @param {Object} context * @param {Object} context
* @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 : '';
return api.get(OC.linkToOCS(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2)) return api.get(OC.linkToOCS(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
.then((response) => { .then((response) => {
if (Object.keys(response.data.ocs.data.users).length > 0) { if (Object.keys(response.data.ocs.data.users).length > 0) {
context.commit('appendUsers', response.data.ocs.data.users); context.commit('appendUsers', response.data.ocs.data.users);
return true; return true;
} }
return false; return false;
}) })
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => context.commit('API_FAILURE', error));
}, },
/** /**
* Get all users with full details from a groupid * Get all users with full details from a groupid
* *
* @param {Object} context * @param {Object} context
* @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))
.then((response) => context.commit('getUsersFromList', response.data.ocs.data.users)) .then((response) => context.commit('getUsersFromList', response.data.ocs.data.users))
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => context.commit('API_FAILURE', error));
}, },
getPasswordPolicyMinLength(context) { getPasswordPolicyMinLength(context) {
return api.get(OC.linkToOCS('apps/provisioning_api/api/v1/config/apps/password_policy/minLength', 2)) return api.get(OC.linkToOCS('apps/provisioning_api/api/v1/config/apps/password_policy/minLength', 2))
.then((response) => context.commit('setPasswordPolicyMinLength', response.data.ocs.data.data)) .then((response) => context.commit('setPasswordPolicyMinLength', response.data.ocs.data.data))
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => context.commit('API_FAILURE', error));
}, },
/** /**
* Add group * Add group
* *
* @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) => {
return api.post(OC.linkToOCS(`cloud/groups`, 2), {groupid: gid}) return api.post(OC.linkToOCS(`cloud/groups`, 2), {groupid: gid})
.then((response) => context.commit('addGroup', gid)) .then((response) => context.commit('addGroup', gid))
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Remove group * Remove group
* *
* @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.post(OC.linkToOCS(`cloud/groups`, 2), {groupid: gid})
.then((response) => context.commit('removeGroup', gid)) .then((response) => context.commit('removeGroup', gid))
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Add user to group * Add user to group
* *
* @param {Object} context * @param {Object} context
* @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) => {
return api.post(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid }) return api.post(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid })
.then((response) => context.commit('addUserGroup', { userid, gid })) .then((response) => context.commit('addUserGroup', { userid, gid }))
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Remove user from group * Remove user from group
* *
* @param {Object} context * @param {Object} context
* @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) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid }) return api.delete(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid })
.then((response) => context.commit('removeUserGroup', { userid, gid })) .then((response) => context.commit('removeUserGroup', { userid, gid }))
.catch((error) => context.commit('API_FAILURE', { userid, error })); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Add user to group admin * Add user to group admin
* *
* @param {Object} context * @param {Object} context
* @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) => {
return api.post(OC.linkToOCS(`cloud/users/${userid}/subadmins`, 2), { groupid: gid }) return api.post(OC.linkToOCS(`cloud/users/${userid}/subadmins`, 2), { groupid: gid })
.then((response) => context.commit('addUserSubAdmin', { userid, gid })) .then((response) => context.commit('addUserSubAdmin', { userid, gid }))
.catch((error) => context.commit('API_FAILURE', error)); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Remove user from group admin * Remove user from group admin
* *
* @param {Object} context * @param {Object} context
* @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) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}/subadmins`, 2), { groupid: gid }) return api.delete(OC.linkToOCS(`cloud/users/${userid}/subadmins`, 2), { groupid: gid })
.then((response) => context.commit('removeUserSubAdmin', { userid, gid })) .then((response) => context.commit('removeUserSubAdmin', { userid, gid }))
.catch((error) => context.commit('API_FAILURE', { userid, error })); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Delete a user * Delete a user
* *
* @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) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}`, 2)) return api.delete(OC.linkToOCS(`cloud/users/${userid}`, 2))
.then((response) => context.commit('deleteUser', userid)) .then((response) => context.commit('deleteUser', userid))
.catch((error) => context.commit('API_FAILURE', { userid, error })); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Add a user * Add a user
* *
* @param {Object} context * @param {Object} context
* @param {Object} options * @param {Object} options
* @param {string} options.userid User id * @param {string} options.userid User id
* @param {string} options.password User password * @param {string} options.password User password
* @param {string} options.email User email * @param {string} options.email User email
* @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 }) { addUser({context, dispatch}, { userid, password, email, groups, subadmin, quota }) {
console.log(subadmin, quota); console.log(subadmin, quota);
return api.requireAdmin().then((response) => { return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/users`, 2), { userid, password, email, groups, subadmin, quota }) return api.post(OC.linkToOCS(`cloud/users`, 2), { userid, password, email, groups, subadmin, quota })
.then((response) => { .then((response) => {
//let quotaDis = dispatch('setUserData', { userid, key: 'quota', value:quota }); //let quotaDis = dispatch('setUserData', { userid, key: 'quota', value:quota });
//let subadminDis = dispatch('addUserSubAdmin', userid); //let subadminDis = dispatch('addUserSubAdmin', userid);
}) })
.catch((error) => context.commit('API_FAILURE', { userid, error })); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Get user data and commit addition * Get user data and commit addition
* *
* @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) => {
return api.get(OC.linkToOCS(`cloud/users/${userid}`, 2)) return api.get(OC.linkToOCS(`cloud/users/${userid}`, 2))
.then((response) => context.commit('addUserData', response)) .then((response) => context.commit('addUserData', response))
.catch((error) => context.commit('API_FAILURE', { userid, error })); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** Enable or disable user /** Enable or disable user
* *
* @param {Object} context * @param {Object} context
* @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';
return api.requireAdmin().then((response) => { return api.requireAdmin().then((response) => {
return api.put(OC.linkToOCS(`cloud/users/${userid}/${userStatus}`, 2)) return api.put(OC.linkToOCS(`cloud/users/${userid}/${userStatus}`, 2))
.then((response) => context.commit('enableDisableUser', { userid, enabled })) .then((response) => context.commit('enableDisableUser', { userid, enabled }))
.catch((error) => context.commit('API_FAILURE', { userid, error })); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
}, },
/** /**
* Edit user data * Edit user data
* *
* @param {Object} context * @param {Object} context
* @param {Object} options * @param {Object} options
* @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'];
if (['email', 'language', 'quota', 'displayname', 'password'].indexOf(key) !== -1) { if (['email', 'language', 'quota', 'displayname', 'password'].indexOf(key) !== -1) {
// We allow empty email or displayname // We allow empty email or displayname
if (typeof value === 'string' && if (typeof value === 'string' &&
( (
(allowedEmpty.indexOf(key) === -1 && value.length > 0) || (allowedEmpty.indexOf(key) === -1 && value.length > 0) ||
allowedEmpty.indexOf(key) !== -1 allowedEmpty.indexOf(key) !== -1
) )
) { ) {
return api.requireAdmin().then((response) => { return api.requireAdmin().then((response) => {
return api.put(OC.linkToOCS(`cloud/users/${userid}`, 2), { key: key, value: value }) return api.put(OC.linkToOCS(`cloud/users/${userid}`, 2), { key: key, value: value })
.then((response) => context.commit('setUserData', { userid, key, value })) .then((response) => context.commit('setUserData', { userid, key, value }))
.catch((error) => context.commit('API_FAILURE', { userid, error })); .catch((error) => {throw error;});
}); }).catch((error) => context.commit('API_FAILURE', { userid, error }));
} }
} }
return Promise.reject(new Error('Invalid request data')); return Promise.reject(new Error('Invalid request data'));
} }
}; };
export default { state, mutations, getters, actions }; export default { state, mutations, getters, actions };

View File

@ -138,7 +138,7 @@ export default {
// Adjust data // Adjust data
let adminGroup = groups.find(group => group.id == 'admin'); let adminGroup = groups.find(group => group.id == 'admin');
let disabledGroup = groups.find(group => group.id == '_disabled'); let disabledGroup = groups.find(group => group.id == '_disabled');
if (adminGroup.text) { if (adminGroup.text) {
adminGroup.text = t('settings', 'Admins');} // rename admin group adminGroup.text = t('settings', 'Admins');} // rename admin group
if (disabledGroup.text) { if (disabledGroup.text) {