|
6 | 6 | import axios from '@nextcloud/axios' |
7 | 7 | import { showError, showInfo } from '@nextcloud/dialogs' |
8 | 8 | import { loadState } from '@nextcloud/initial-state' |
| 9 | +import { PwdConfirmationMode } from '@nextcloud/password-confirmation' |
9 | 10 | import { generateUrl } from '@nextcloud/router' |
10 | 11 | import Vue from 'vue' |
11 | 12 | import logger from '../logger.ts' |
@@ -180,81 +181,82 @@ const actions = { |
180 | 181 | } else { |
181 | 182 | apps = [appId] |
182 | 183 | } |
183 | | - return api.requireAdmin().then(() => { |
184 | | - context.commit('startLoading', apps) |
185 | | - context.commit('startLoading', 'install') |
186 | | - |
187 | | - const previousState = {} |
188 | | - apps.forEach((_appId) => { |
189 | | - const app = context.state.apps.find((app) => app.id === _appId) |
190 | | - if (app) { |
191 | | - previousState[_appId] = { |
192 | | - active: app.active, |
193 | | - groups: [...(app.groups || [])], |
194 | | - } |
195 | | - context.commit('enableApp', { appId: _appId, groups }) |
| 184 | + context.commit('startLoading', apps) |
| 185 | + context.commit('startLoading', 'install') |
| 186 | + |
| 187 | + const previousState = {} |
| 188 | + apps.forEach((_appId) => { |
| 189 | + const app = context.state.apps.find((app) => app.id === _appId) |
| 190 | + if (app) { |
| 191 | + previousState[_appId] = { |
| 192 | + active: app.active, |
| 193 | + groups: [...(app.groups || [])], |
196 | 194 | } |
197 | | - }) |
198 | | - |
199 | | - return api.post(generateUrl('settings/apps/enable'), { appIds: apps, groups }) |
200 | | - .then((response) => { |
201 | | - context.commit('stopLoading', apps) |
202 | | - context.commit('stopLoading', 'install') |
203 | | - |
204 | | - // check for server health |
205 | | - return axios.get(generateUrl('apps/files/')) |
206 | | - .then(() => { |
207 | | - if (response.data.update_required) { |
208 | | - showInfo( |
209 | | - t( |
210 | | - 'settings', |
211 | | - 'The app has been enabled but needs to be updated. You will be redirected to the update page in 5 seconds.', |
212 | | - ), |
213 | | - { |
214 | | - onClick: () => window.location.reload(), |
215 | | - close: false, |
216 | | - |
217 | | - }, |
218 | | - ) |
219 | | - setTimeout(function() { |
220 | | - location.reload() |
221 | | - }, 5000) |
222 | | - } |
223 | | - }) |
224 | | - .catch(() => { |
225 | | - if (!Array.isArray(appId)) { |
226 | | - showError(t('settings', 'Error: This app cannot be enabled because it makes the server unstable')) |
227 | | - context.commit('setError', { |
228 | | - appId: apps, |
229 | | - error: t('settings', 'Error: This app cannot be enabled because it makes the server unstable'), |
230 | | - }) |
231 | | - context.dispatch('disableApp', { appId }) |
232 | | - } |
233 | | - }) |
234 | | - }) |
235 | | - .catch((error) => { |
236 | | - context.commit('stopLoading', apps) |
237 | | - context.commit('stopLoading', 'install') |
| 195 | + context.commit('enableApp', { appId: _appId, groups }) |
| 196 | + } |
| 197 | + }) |
238 | 198 |
|
239 | | - apps.forEach((_appId) => { |
240 | | - if (previousState[_appId]) { |
241 | | - context.commit('enableApp', { |
242 | | - appId: _appId, |
243 | | - groups: previousState[_appId].groups, |
| 199 | + return api.post(generateUrl('settings/apps/enable'), { appIds: apps, groups }, { confirmPassword: PwdConfirmationMode.Strict }) |
| 200 | + .then((response) => { |
| 201 | + context.commit('stopLoading', apps) |
| 202 | + context.commit('stopLoading', 'install') |
| 203 | + |
| 204 | + // check for server health |
| 205 | + return axios.get(generateUrl('apps/files/')) |
| 206 | + .then(() => { |
| 207 | + if (response.data.update_required) { |
| 208 | + showInfo( |
| 209 | + t( |
| 210 | + 'settings', |
| 211 | + 'The app has been enabled but needs to be updated. You will be redirected to the update page in 5 seconds.', |
| 212 | + ), |
| 213 | + { |
| 214 | + onClick: () => window.location.reload(), |
| 215 | + close: false, |
| 216 | + |
| 217 | + }, |
| 218 | + ) |
| 219 | + setTimeout(function() { |
| 220 | + location.reload() |
| 221 | + }, 5000) |
| 222 | + } |
| 223 | + }) |
| 224 | + .catch(() => { |
| 225 | + if (!Array.isArray(appId)) { |
| 226 | + showError(t('settings', 'Error: This app cannot be enabled because it makes the server unstable')) |
| 227 | + context.commit('setError', { |
| 228 | + appId: apps, |
| 229 | + error: t('settings', 'Error: This app cannot be enabled because it makes the server unstable'), |
244 | 230 | }) |
245 | | - if (!previousState[_appId].active) { |
246 | | - context.commit('disableApp', _appId) |
247 | | - } |
| 231 | + context.dispatch('disableApp', { appId }) |
248 | 232 | } |
249 | 233 | }) |
| 234 | + }) |
| 235 | + .catch((error) => { |
| 236 | + context.commit('stopLoading', apps) |
| 237 | + context.commit('stopLoading', 'install') |
| 238 | + |
| 239 | + apps.forEach((_appId) => { |
| 240 | + if (previousState[_appId]) { |
| 241 | + context.commit('enableApp', { |
| 242 | + appId: _appId, |
| 243 | + groups: previousState[_appId].groups, |
| 244 | + }) |
| 245 | + if (!previousState[_appId].active) { |
| 246 | + context.commit('disableApp', _appId) |
| 247 | + } |
| 248 | + } |
| 249 | + }) |
250 | 250 |
|
| 251 | + const message = error.response?.data?.data?.message |
| 252 | + if (message) { |
251 | 253 | context.commit('setError', { |
252 | 254 | appId: apps, |
253 | | - error: error.response.data.data.message, |
| 255 | + error: message, |
254 | 256 | }) |
255 | 257 | context.commit('APPS_API_FAILURE', { appId, error }) |
256 | | - }) |
257 | | - }).catch((error) => context.commit('API_FAILURE', { appId, error })) |
| 258 | + } |
| 259 | + }) |
258 | 260 | }, |
259 | 261 | forceEnableApp(context, { appId }) { |
260 | 262 | let apps |
|
0 commit comments