Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-09-25 19:19:42 +0300
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-10-01 18:16:09 +0300
commitb9bc2417e7a8dc81feb0abe20359bedaf864f790 (patch)
tree61b47fbf37c1d168da8625224debde9e6a985348 /apps/settings/src/store/users.js
parent7fb651235128dcbca8a6683b5cdafdf835f46300 (diff)
Comply to eslint
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/settings/src/store/users.js')
-rw-r--r--apps/settings/src/store/users.js376
1 files changed, 188 insertions, 188 deletions
diff --git a/apps/settings/src/store/users.js b/apps/settings/src/store/users.js
index 1b174b21bf4..e2eb94610af 100644
--- a/apps/settings/src/store/users.js
+++ b/apps/settings/src/store/users.js
@@ -1,4 +1,4 @@
-/*
+/**
* @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
@@ -20,7 +20,7 @@
*
*/
-import api from './api';
+import api from './api'
const orderGroups = function(groups, orderBy) {
/* const SORT_USERCOUNT = 1;
@@ -28,11 +28,11 @@ const orderGroups = function(groups, orderBy) {
* https://github.com/nextcloud/server/blob/208e38e84e1a07a49699aa90dc5b7272d24489f0/lib/private/Group/MetaData.php#L34
*/
if (orderBy === 1) {
- return groups.sort((a, b) => a.usercount-a.disabled < b.usercount - b.disabled);
+ return groups.sort((a, b) => a.usercount - a.disabled < b.usercount - b.disabled)
} else {
- return groups.sort((a, b) => a.name.localeCompare(b.name));
+ return groups.sort((a, b) => a.name.localeCompare(b.name))
}
-};
+}
const defaults = {
group: {
@@ -43,7 +43,7 @@ const defaults = {
canAdd: true,
canRemove: true
}
-};
+}
const state = {
users: [],
@@ -53,145 +53,146 @@ const state = {
usersOffset: 0,
usersLimit: 25,
userCount: 0
-};
+}
const mutations = {
appendUsers(state, usersObj) {
// convert obj to array
- let users = state.users.concat(Object.keys(usersObj).map(userid => usersObj[userid]));
- state.usersOffset += state.usersLimit;
- state.users = users;
+ let users = state.users.concat(Object.keys(usersObj).map(userid => usersObj[userid]))
+ state.usersOffset += state.usersLimit
+ state.users = users
},
setPasswordPolicyMinLength(state, length) {
- state.minPasswordLength = length!=='' ? length : 0;
+ state.minPasswordLength = length !== '' ? length : 0
},
- initGroups(state, {groups, orderBy, userCount}) {
- state.groups = groups.map(group => Object.assign({}, defaults.group, group));
- state.orderBy = orderBy;
- state.userCount = userCount;
- state.groups = orderGroups(state.groups, state.orderBy);
-
+ initGroups(state, { groups, orderBy, userCount }) {
+ state.groups = groups.map(group => Object.assign({}, defaults.group, group))
+ state.orderBy = orderBy
+ state.userCount = userCount
+ state.groups = orderGroups(state.groups, state.orderBy)
+
},
- addGroup(state, {gid, displayName}) {
+ addGroup(state, { gid, displayName }) {
try {
if (typeof state.groups.find((group) => group.id === gid) !== 'undefined') {
- return;
+ return
}
// extend group to default values
let group = Object.assign({}, defaults.group, {
id: gid,
- name: displayName,
- });
- state.groups.push(group);
- state.groups = orderGroups(state.groups, state.orderBy);
+ name: displayName
+ })
+ state.groups.push(group)
+ state.groups = orderGroups(state.groups, state.orderBy)
} catch (e) {
- console.log('Can\'t create group', e);
+ console.error('Can\'t create group', e)
}
},
removeGroup(state, gid) {
- let groupIndex = state.groups.findIndex(groupSearch => groupSearch.id == gid);
+ let groupIndex = state.groups.findIndex(groupSearch => groupSearch.id === gid)
if (groupIndex >= 0) {
- state.groups.splice(groupIndex, 1);
+ state.groups.splice(groupIndex, 1)
}
},
addUserGroup(state, { userid, gid }) {
- let group = state.groups.find(groupSearch => groupSearch.id == gid);
- let user = state.users.find(user => user.id == userid);
+ let group = state.groups.find(groupSearch => groupSearch.id === gid)
+ let user = state.users.find(user => user.id === userid)
// increase count if user is enabled
if (group && user.enabled) {
- group.usercount++;
+ group.usercount++
}
- let groups = user.groups;
- groups.push(gid);
- state.groups = orderGroups(state.groups, state.orderBy);
+ let groups = user.groups
+ groups.push(gid)
+ state.groups = orderGroups(state.groups, state.orderBy)
},
removeUserGroup(state, { userid, gid }) {
- let group = state.groups.find(groupSearch => groupSearch.id == gid);
- let user = state.users.find(user => user.id == userid);
+ let group = state.groups.find(groupSearch => groupSearch.id === gid)
+ let user = state.users.find(user => user.id === userid)
// lower count if user is enabled
if (group && user.enabled) {
- group.usercount--;
+ group.usercount--
}
- let groups = user.groups;
- groups.splice(groups.indexOf(gid),1);
- state.groups = orderGroups(state.groups, state.orderBy);
+ let groups = user.groups
+ groups.splice(groups.indexOf(gid), 1)
+ state.groups = orderGroups(state.groups, state.orderBy)
},
addUserSubAdmin(state, { userid, gid }) {
- let groups = state.users.find(user => user.id == userid).subadmin;
- groups.push(gid);
+ let groups = state.users.find(user => user.id === userid).subadmin
+ groups.push(gid)
},
removeUserSubAdmin(state, { userid, gid }) {
- let groups = state.users.find(user => user.id == userid).subadmin;
- groups.splice(groups.indexOf(gid),1);
+ let groups = state.users.find(user => user.id === userid).subadmin
+ groups.splice(groups.indexOf(gid), 1)
},
deleteUser(state, userid) {
- let userIndex = state.users.findIndex(user => user.id == userid);
- state.users.splice(userIndex, 1);
+ let userIndex = state.users.findIndex(user => user.id === userid)
+ state.users.splice(userIndex, 1)
},
addUserData(state, response) {
- state.users.push(response.data.ocs.data);
+ state.users.push(response.data.ocs.data)
},
enableDisableUser(state, { userid, enabled }) {
- let user = state.users.find(user => user.id == userid);
- user.enabled = enabled;
+ let user = state.users.find(user => user.id === userid)
+ user.enabled = enabled
// increment or not
- state.groups.find(group => group.id == 'disabled').usercount += enabled ? -1 : 1;
- state.userCount += enabled ? 1 : -1;
+ state.groups.find(group => group.id === 'disabled').usercount += enabled ? -1 : 1
+ state.userCount += enabled ? 1 : -1
user.groups.forEach(group => {
// Increment disabled count
- state.groups.find(groupSearch => groupSearch.id == group).disabled += enabled ? -1 : 1;
- });
+ state.groups.find(groupSearch => groupSearch.id === group).disabled += enabled ? -1 : 1
+ })
},
setUserData(state, { userid, key, value }) {
if (key === 'quota') {
- let humanValue = OC.Util.computerFileSize(value);
- state.users.find(user => user.id == userid)[key][key] = humanValue!==null ? humanValue : value;
+ let humanValue = OC.Util.computerFileSize(value)
+ state.users.find(user => user.id === userid)[key][key] = humanValue !== null ? humanValue : value
} else {
- state.users.find(user => user.id == userid)[key] = value;
+ state.users.find(user => user.id === userid)[key] = value
}
},
/**
* Reset users list
+ * @param {Object} state the store state
*/
resetUsers(state) {
- state.users = [];
- state.usersOffset = 0;
+ state.users = []
+ state.usersOffset = 0
}
-};
+}
const getters = {
getUsers(state) {
- return state.users;
+ return state.users
},
getGroups(state) {
- return state.groups;
+ return state.groups
},
getSubadminGroups(state) {
// Can't be subadmin of admin or disabled
- return state.groups.filter(group => group.id !== 'admin' && group.id !== 'disabled');
+ return state.groups.filter(group => group.id !== 'admin' && group.id !== 'disabled')
},
getPasswordPolicyMinLength(state) {
- return state.minPasswordLength;
+ return state.minPasswordLength
},
getUsersOffset(state) {
- return state.usersOffset;
+ return state.usersOffset
},
getUsersLimit(state) {
- return state.usersLimit;
+ return state.usersLimit
},
getUserCount(state) {
- return state.userCount;
+ return state.userCount
}
-};
+}
const actions = {
/**
* Get all users with full details
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {int} options.offset List offset to request
* @param {int} options.limit List number to return from offset
* @param {string} options.search Search amongst users
@@ -199,74 +200,74 @@ const actions = {
* @returns {Promise}
*/
getUsers(context, { offset, limit, search, group }) {
- search = typeof search === 'string' ? search : '';
- group = typeof group === 'string' ? group : '';
+ search = typeof search === 'string' ? search : ''
+ group = typeof group === 'string' ? group : ''
if (group !== '') {
return api.get(OC.linkToOCS(`cloud/groups/${group}/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
- .then((response) => {
- if (Object.keys(response.data.ocs.data.users).length > 0) {
- context.commit('appendUsers', response.data.ocs.data.users);
- return true;
- }
- return false;
- })
- .catch((error) => context.commit('API_FAILURE', error));
+ .then((response) => {
+ if (Object.keys(response.data.ocs.data.users).length > 0) {
+ context.commit('appendUsers', response.data.ocs.data.users)
+ return true
+ }
+ return false
+ })
+ .catch((error) => context.commit('API_FAILURE', error))
}
return api.get(OC.linkToOCS(`cloud/users/details?offset=${offset}&limit=${limit}&search=${search}`, 2))
.then((response) => {
if (Object.keys(response.data.ocs.data.users).length > 0) {
- context.commit('appendUsers', response.data.ocs.data.users);
- return true;
+ context.commit('appendUsers', response.data.ocs.data.users)
+ return true
}
- return false;
+ return false
})
- .catch((error) => context.commit('API_FAILURE', error));
+ .catch((error) => context.commit('API_FAILURE', error))
},
getGroups(context, { offset, limit, search }) {
- search = typeof search === 'string' ? search : '';
- let limitParam = limit === -1 ? '' : `&limit=${limit}`;
+ search = typeof search === 'string' ? search : ''
+ let limitParam = limit === -1 ? '' : `&limit=${limit}`
return api.get(OC.linkToOCS(`cloud/groups?offset=${offset}&search=${search}${limitParam}`, 2))
.then((response) => {
if (Object.keys(response.data.ocs.data.groups).length > 0) {
response.data.ocs.data.groups.forEach(function(group) {
- context.commit('addGroup', {gid: group, displayName: group});
- });
- return true;
+ context.commit('addGroup', { gid: group, displayName: group })
+ })
+ 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
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {int} options.offset List offset to request
* @param {int} options.limit List number to return from offset
* @returns {Promise}
*/
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))
.then((response) => {
if (Object.keys(response.data.ocs.data.users).length > 0) {
- context.commit('appendUsers', response.data.ocs.data.users);
- return true;
+ context.commit('appendUsers', response.data.ocs.data.users)
+ 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
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {int} options.offset List offset to request
* @param {int} options.limit List number to return from offset
* @returns {Promise}
@@ -274,45 +275,44 @@ const actions = {
getUsersFromGroup(context, { groupid, offset, limit }) {
return api.get(OC.linkToOCS(`cloud/users/${groupid}/details?offset=${offset}&limit=${limit}`, 2))
.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) {
- if(OC.getCapabilities().password_policy && OC.getCapabilities().password_policy.minLength) {
- context.commit('setPasswordPolicyMinLength', OC.getCapabilities().password_policy.minLength);
- return OC.getCapabilities().password_policy.minLength;
+ if (OC.getCapabilities().password_policy && OC.getCapabilities().password_policy.minLength) {
+ context.commit('setPasswordPolicyMinLength', OC.getCapabilities().password_policy.minLength)
+ return OC.getCapabilities().password_policy.minLength
}
- return false;
+ return false
},
/**
* Add group
- *
- * @param {Object} context
+ *
+ * @param {Object} context store context
* @param {string} gid Group id
* @returns {Promise}
*/
addGroup(context, gid) {
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: gid, displayName: gid})
- return {gid: gid, displayName: gid}
+ context.commit('addGroup', { gid: gid, displayName: gid })
+ return { gid: gid, displayName: gid }
})
- .catch((error) => {throw error;});
+ .catch((error) => { throw error })
}).catch((error) => {
- context.commit('API_FAILURE', { gid, error });
+ context.commit('API_FAILURE', { gid, error })
// let's throw one more time to prevent the view
// from adding the user to a group that doesn't exists
- throw error;
- });
+ throw error
+ })
},
/**
* Remove group
- *
- * @param {Object} context
+ *
+ * @param {Object} context store context
* @param {string} gid Group id
* @returns {Promise}
*/
@@ -320,15 +320,15 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.delete(OC.linkToOCS(`cloud/groups/${gid}`, 2))
.then((response) => context.commit('removeGroup', gid))
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { gid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { gid, error }))
},
/**
* Add user to group
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {string} options.userid User id
* @param {string} options.gid Group id
* @returns {Promise}
@@ -337,15 +337,15 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid })
.then((response) => context.commit('addUserGroup', { userid, gid }))
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { userid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { userid, error }))
},
/**
* Remove user from group
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {string} options.userid User id
* @param {string} options.gid Group id
* @returns {Promise}
@@ -354,37 +354,37 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}/groups`, 2), { groupid: gid })
.then((response) => context.commit('removeUserGroup', { userid, gid }))
- .catch((error) => {throw error;});
+ .catch((error) => { throw error })
}).catch((error) => {
- context.commit('API_FAILURE', { userid, error });
+ context.commit('API_FAILURE', { userid, error })
// let's throw one more time to prevent
// the view from removing the user row on failure
- throw error;
- });
+ throw error
+ })
},
/**
* Add user to group admin
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {string} options.userid User id
* @param {string} options.gid Group id
* @returns {Promise}
*/
addUserSubAdmin(context, { userid, gid }) {
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 }))
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { userid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { userid, error }))
},
/**
* Remove user from group admin
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {string} options.userid User id
* @param {string} options.gid Group id
* @returns {Promise}
@@ -393,44 +393,44 @@ const actions = {
return api.requireAdmin().then((response) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}/subadmins`, 2), { groupid: gid })
.then((response) => context.commit('removeUserSubAdmin', { userid, gid }))
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { userid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { userid, error }))
},
/**
* Mark all user devices for remote wipe
*
- * @param {Object} context
+ * @param {Object} context store context
* @param {string} userid User id
* @returns {Promise}
*/
wipeUserDevices(context, userid) {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/users/${userid}/wipe`, 2))
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { userid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { userid, error }))
},
/**
* Delete a user
- *
- * @param {Object} context
- * @param {string} userid User id
+ *
+ * @param {Object} context store context
+ * @param {string} userid User id
* @returns {Promise}
*/
deleteUser(context, userid) {
return api.requireAdmin().then((response) => {
return api.delete(OC.linkToOCS(`cloud/users/${userid}`, 2))
.then((response) => context.commit('deleteUser', userid))
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { userid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { userid, error }))
},
/**
* Add a user
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {string} options.userid User id
* @param {string} options.password User password
* @param {string} options.displayName User display name
@@ -440,93 +440,93 @@ const actions = {
* @param {string} options.quota User email
* @returns {Promise}
*/
- addUser({commit, dispatch}, { userid, password, displayName, email, groups, subadmin, quota, language }) {
+ addUser({ commit, dispatch }, { userid, password, displayName, email, groups, subadmin, quota, language }) {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/users`, 2), { userid, password, displayName, email, groups, subadmin, quota, language })
.then((response) => dispatch('addUserData', userid || response.data.ocs.data.id))
- .catch((error) => {throw error;});
+ .catch((error) => { throw error })
}).catch((error) => {
- commit('API_FAILURE', { userid, error });
- throw error;
- });
+ commit('API_FAILURE', { userid, error })
+ throw error
+ })
},
/**
* Get user data and commit addition
- *
- * @param {Object} context
- * @param {string} userid User id
+ *
+ * @param {Object} context store context
+ * @param {string} userid User id
* @returns {Promise}
*/
addUserData(context, userid) {
return api.requireAdmin().then((response) => {
return api.get(OC.linkToOCS(`cloud/users/${userid}`, 2))
.then((response) => context.commit('addUserData', response))
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { userid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { userid, error }))
},
- /** Enable or disable user
- *
- * @param {Object} context
- * @param {Object} options
+ /** Enable or disable user
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {string} options.userid User id
* @param {boolean} options.enabled User enablement status
* @returns {Promise}
*/
enableDisableUser(context, { userid, enabled = true }) {
- let userStatus = enabled ? 'enable' : 'disable';
+ let userStatus = enabled ? 'enable' : 'disable'
return api.requireAdmin().then((response) => {
return api.put(OC.linkToOCS(`cloud/users/${userid}/${userStatus}`, 2))
.then((response) => context.commit('enableDisableUser', { userid, enabled }))
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { userid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { userid, error }))
},
/**
* Edit user data
- *
- * @param {Object} context
- * @param {Object} options
+ *
+ * @param {Object} context store context
+ * @param {Object} options destructuring object
* @param {string} options.userid User id
* @param {string} options.key User field to edit
* @param {string} options.value Value of the change
* @returns {Promise}
*/
setUserData(context, { userid, key, value }) {
- let allowedEmpty = ['email', 'displayname'];
+ let allowedEmpty = ['email', 'displayname']
if (['email', 'language', 'quota', 'displayname', 'password'].indexOf(key) !== -1) {
// We allow empty email or displayname
- if (typeof value === 'string' &&
- (
- (allowedEmpty.indexOf(key) === -1 && value.length > 0) ||
- allowedEmpty.indexOf(key) !== -1
+ if (typeof value === 'string'
+ && (
+ (allowedEmpty.indexOf(key) === -1 && value.length > 0)
+ || allowedEmpty.indexOf(key) !== -1
)
) {
return api.requireAdmin().then((response) => {
return api.put(OC.linkToOCS(`cloud/users/${userid}`, 2), { key: key, value: value })
.then((response) => context.commit('setUserData', { userid, key, value }))
- .catch((error) => {throw error;});
- }).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'))
},
/**
* Send welcome mail
- *
- * @param {Object} context
- * @param {string} userid User id
+ *
+ * @param {Object} context store context
+ * @param {string} userid User id
* @returns {Promise}
*/
sendWelcomeMail(context, userid) {
return api.requireAdmin().then((response) => {
return api.post(OC.linkToOCS(`cloud/users/${userid}/welcome`, 2))
.then(response => true)
- .catch((error) => {throw error;});
- }).catch((error) => context.commit('API_FAILURE', { userid, error }));
+ .catch((error) => { throw error })
+ }).catch((error) => context.commit('API_FAILURE', { userid, error }))
}
-};
+}
-export default { state, mutations, getters, actions };
+export default { state, mutations, getters, actions }