From 10f4fb86b5e954648b5e7796596e670921380a93 Mon Sep 17 00:00:00 2001 From: axolotle Date: Fri, 29 Dec 2023 17:13:40 +0100 Subject: [PATCH 1/3] fix context evaluation for simple forms (not configpanels) --- app/src/helpers/yunohostArguments.js | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/src/helpers/yunohostArguments.js b/app/src/helpers/yunohostArguments.js index 9325d26a..3c087be8 100644 --- a/app/src/helpers/yunohostArguments.js +++ b/app/src/helpers/yunohostArguments.js @@ -79,16 +79,19 @@ export function adressToFormValue (address) { * @param {Object} forms - A nested form used in config panels. * @return {Boolean} - expression evaluation result. */ -export function evaluateExpression (expression, forms) { +export function evaluateExpression (expression, form, nested = true) { if (!expression) return true if (expression === '"false"') return false - const context = Object.values(forms).reduce((ctx, args) => { - Object.entries(args).forEach(([id, value]) => { - ctx[id] = isObjectLiteral(value) && 'file' in value ? value.content : value - }) - return ctx - }, {}) + const context = nested + ? Object.values(form).reduce((merged, next) => ({ ...merged, ...next })) + : form + + for (const key in context) { + if (isObjectLiteral(context[key]) && 'file' in context[key]) { + context[key] = context[key].content + } + } // Allow to use match(var,regexp) function const matchRe = /match(\s*(\w+)\s*,\s*"([^"]+)"\s*)/g @@ -107,9 +110,9 @@ export function evaluateExpression (expression, forms) { } // Adds a property to an Object that will dynamically returns a expression evaluation result. -function addEvaluationGetter (prop, obj, expr, ctx) { +function addEvaluationGetter (prop, obj, expr, ctx, nested) { Object.defineProperty(obj, prop, { - get: () => evaluateExpression(expr, ctx) + get: () => evaluateExpression(expr, ctx, nested) }) } @@ -357,12 +360,12 @@ export function formatYunoHostArguments (args, forms) { if (validation) validations[arg.id] = validation errors[arg.id] = error - if ('visible' in arg && ![false, '"false"'].includes(arg.visible)) { - addEvaluationGetter('visible', field, arg.visible, forms) + if ('visible' in arg && typeof arg.visible === 'string') { + addEvaluationGetter('visible', field, arg.visible, forms || form, forms !== undefined) } - if ('enabled' in arg) { - addEvaluationGetter('enabled', field.props, arg.enabled, forms) + if ('enabled' in arg && typeof arg.enabled === 'string') { + addEvaluationGetter('enabled', field.props, arg.enabled, forms || form, forms !== undefined) } } From 237b36e2e209df99963f3cabd59d37db9115d8a2 Mon Sep 17 00:00:00 2001 From: axolotle Date: Fri, 9 Feb 2024 04:08:35 +0100 Subject: [PATCH 2/3] centralize a bit moar app init stuff (installed/connected) --- app/src/App.vue | 8 +---- app/src/router/index.js | 4 +++ app/src/store/info.js | 32 +++++++++++++++---- app/src/views/Login.vue | 20 ++++-------- app/src/views/PostInstall.vue | 10 +----- .../views/_partials/ReconnectingDisplay.vue | 2 +- 6 files changed, 39 insertions(+), 37 deletions(-) diff --git a/app/src/App.vue b/app/src/App.vue index b3809363..007ed45e 100644 --- a/app/src/App.vue +++ b/app/src/App.vue @@ -112,13 +112,7 @@ export default { // This hook is only triggered at page first load created () { - // From this hook the value of `connected` always come from the localStorage. - // This state may be `true` but session may have expired, by querying - // yunohost infos, api may respond with `Unauthorized` in which case the `connected` - // state will be automaticly reseted and user will be prompt with the login view. - if (this.connected) { - this.$store.dispatch('GET_YUNOHOST_INFOS') - } + this.$store.dispatch('ON_APP_CREATED') }, mounted () { diff --git a/app/src/router/index.js b/app/src/router/index.js index 163ffd96..21deb68f 100644 --- a/app/src/router/index.js +++ b/app/src/router/index.js @@ -35,6 +35,10 @@ router.beforeEach((to, from, next) => { if (store.getters.error) { store.dispatch('DISMISS_ERROR', true) } + + if (to.name === 'post-install' && store.getters.installed) { + return next('/') + } // Allow if connected or route is not protected if (store.getters.connected || to.meta.noAuth) { next() diff --git a/app/src/store/info.js b/app/src/store/info.js index a34db1a2..dfcd3d20 100644 --- a/app/src/store/info.js +++ b/app/src/store/info.js @@ -7,6 +7,7 @@ import { timeout, isEmptyValue, isObjectLiteral } from '@/helpers/commons' export default { state: { host: window.location.host, // String + installed: null, connected: localStorage.getItem('connected') === 'true', // Boolean yunohost: null, // Object { version, repo } waiting: false, // Boolean @@ -22,6 +23,10 @@ export default { }, mutations: { + 'SET_INSTALLED' (state, boolean) { + state.installed = boolean + }, + 'SET_CONNECTED' (state, boolean) { localStorage.setItem('connected', boolean) state.connected = boolean @@ -106,23 +111,37 @@ export default { }, actions: { - 'CHECK_INSTALL' ({ dispatch }, retry = 2) { + async 'ON_APP_CREATED' ({ dispatch, state }) { + await dispatch('CHECK_INSTALL') + + if (!state.installed) { + router.push({ name: 'post-install' }) + } else { + dispatch('CONNECT') + } + }, + + async 'CHECK_INSTALL' ({ dispatch, commit }, retry = 2) { // this action will try to query the `/installed` route 3 times every 5 s with // a timeout of the same delay. // FIXME need testing with api not responding - return timeout(api.get('installed'), 5000).then(({ installed }) => { + try { + const { installed } = await timeout(api.get('installed'), 5000) + commit('SET_INSTALLED', installed) return installed - }).catch(err => { + } catch (err) { if (retry > 0) { return dispatch('CHECK_INSTALL', --retry) } throw err - }) + } }, - 'CONNECT' ({ commit, dispatch }) { + async 'CONNECT' ({ commit, dispatch }) { + // If the user is not connected, the first action will throw + // and login prompt will be shown automaticly + await dispatch('GET_YUNOHOST_INFOS') commit('SET_CONNECTED', true) - dispatch('GET_YUNOHOST_INFOS') }, 'RESET_CONNECTED' ({ commit }) { @@ -350,6 +369,7 @@ export default { getters: { host: state => state.host, + installed: state => state.installed, connected: state => state.connected, yunohost: state => state.yunohost, error: state => state.error, diff --git a/app/src/views/Login.vue b/app/src/views/Login.vue index f7fdf8db..b5d31f14 100644 --- a/app/src/views/Login.vue +++ b/app/src/views/Login.vue @@ -13,7 +13,7 @@ diff --git a/app/src/views/PostInstall.vue b/app/src/views/PostInstall.vue index 6b1b17af..be54f869 100644 --- a/app/src/views/PostInstall.vue +++ b/app/src/views/PostInstall.vue @@ -75,7 +75,7 @@

{{ $t('installation_complete') }}

- + @@ -201,14 +201,6 @@ export default { confirmation: { required, passwordMatch: sameAs('password') } } } - }, - - created () { - this.$store.dispatch('CHECK_INSTALL').then(installed => { - if (installed) { - this.$router.push({ name: 'home' }) - } - }) } } diff --git a/app/src/views/_partials/ReconnectingDisplay.vue b/app/src/views/_partials/ReconnectingDisplay.vue index 008980fa..45404d63 100644 --- a/app/src/views/_partials/ReconnectingDisplay.vue +++ b/app/src/views/_partials/ReconnectingDisplay.vue @@ -29,7 +29,7 @@ From e5a3f5df2bf27eafd23f01761ddb8b138d881f5f Mon Sep 17 00:00:00 2001 From: axolotle Date: Fri, 9 Feb 2024 04:11:48 +0100 Subject: [PATCH 3/3] header sso link based on main domain or fallback to hostname --- app/src/App.vue | 5 +++-- app/src/store/info.js | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/App.vue b/app/src/App.vue index 007ed45e..c751e218 100644 --- a/app/src/App.vue +++ b/app/src/App.vue @@ -18,7 +18,7 @@