From f2dbbe91d09e9ec29548c78a3e3b57b695a6a84d Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 30 Nov 2020 10:38:00 +0100 Subject: [PATCH] [enh] Add Import user view --- app/src/api/api.js | 11 +- .../components/globals/formItems/FileItem.vue | 31 +++++ app/src/i18n/locales/en.json | 12 +- app/src/router/routes.js | 10 ++ app/src/views/user/UserImport.vue | 116 ++++++++++++++++++ 5 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 app/src/components/globals/formItems/FileItem.vue create mode 100644 app/src/views/user/UserImport.vue diff --git a/app/src/api/api.js b/app/src/api/api.js index 8ce42438..f95e54d0 100644 --- a/app/src/api/api.js +++ b/app/src/api/api.js @@ -38,8 +38,8 @@ import { openWebSocket, getResponseData, handleError } from './handlers' * @param {Boolean} [options.addLocale=false] - Option to append the locale to the query string. * @return {URLSearchParams} */ -export function objectToParams (obj, { addLocale = false } = {}) { - const urlParams = new URLSearchParams() +export function objectToParams (obj, { addLocale = false } = {}, formData = false) { + const urlParams = (formData) ? new FormData() : new URLSearchParams() for (const [key, value] of Object.entries(obj)) { if (Array.isArray(value)) { value.forEach(v => urlParams.append(key, v)) @@ -96,14 +96,9 @@ export default { if (method === 'GET') { uri += `${uri.includes('?') ? '&' : '?'}locale=${store.getters.locale}` } else { - options = { ...options, method, body: objectToParams(data, { addLocale: true }) } + options = { ...options, method, body: objectToParams(data, { addLocale: true }, true) } } - const response = await fetch('/yunohost/api/' + uri, options) - const responseData = await getResponseData(response) - store.dispatch('END_REQUEST', { request, success: response.ok, wait }) - - return response.ok ? responseData : handleError(request, response, responseData) }, diff --git a/app/src/components/globals/formItems/FileItem.vue b/app/src/components/globals/formItems/FileItem.vue new file mode 100644 index 00000000..1f9502e6 --- /dev/null +++ b/app/src/components/globals/formItems/FileItem.vue @@ -0,0 +1,31 @@ + + + diff --git a/app/src/i18n/locales/en.json b/app/src/i18n/locales/en.json index 71d964dc..9bff7d56 100644 --- a/app/src/i18n/locales/en.json +++ b/app/src/i18n/locales/en.json @@ -293,7 +293,8 @@ "firstname": "John", "lastname": "Doe", "groupname": "My group name", - "domain": "my-domain.com" + "domain": "my-domain.com", + "file": "Browse a file or drag and drop it" }, "logs": "Logs", "logs_suboperations": "Sub-operations", @@ -489,6 +490,15 @@ "users": "Users", "users_new": "New user", "users_no": "No users.", + "users_import": "Import users", + "users_import_csv_file": "CSV File", + "users_import_update": "Update existing users", + "users_import_delete": "Delete non listed users", + "users_import_csv_file_desc": "The CSV file should be in UTF-8 and with columns username, password, groups, email and quota. See example import csv file.", + "users_import_update_desc": "If checked, all existing users contained in the csv file will be updated with the ne new value", + "users_import_delete_desc": "If checked, all existing users that are not in the csv file will be deleted (and purged).", + "users_import_confirm_destructive": "Are you sure you want to delete users that are not present in this file?", + "users_import_delete_others": "Delete unlisted users", "version": "Version", "warnings": "{count} warnings", "words": { diff --git a/app/src/router/routes.js b/app/src/router/routes.js index 59c99865..33843446 100644 --- a/app/src/router/routes.js +++ b/app/src/router/routes.js @@ -60,6 +60,16 @@ const routes = [ breadcrumb: ['user-list', 'user-create'] } }, + { + name: 'user-import', + path: '/users/import', + component: () => import(/* webpackChunkName: "views/user/import" */ '@/views/user/UserImport'), + props: true, + meta: { + args: { param: 'name' }, + breadcrumb: ['user-list', 'user-import'] + } + }, { name: 'user-info', path: '/users/:name', diff --git a/app/src/views/user/UserImport.vue b/app/src/views/user/UserImport.vue new file mode 100644 index 00000000..dea12af0 --- /dev/null +++ b/app/src/views/user/UserImport.vue @@ -0,0 +1,116 @@ + + +