-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch settings values from sdk and use language code #3484
Changes from 6 commits
1bd4adb
a32c579
5c2072f
0872d41
ae140bc
847e8b4
f11d884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Change: Make settings available in phoenix | ||
|
||
We upgraded to a new owncloud-sdk version which provides loading settings from the | ||
settings service, if available. The settings values are available throughout phoenix | ||
and all extensions. | ||
|
||
https://github.com/owncloud/phoenix/pull/3484 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Change: Use language setting | ||
|
||
We've changed phoenix to make use of the language the authenticated user has chosen in the settings. | ||
|
||
https://github.com/owncloud/phoenix/pull/3484 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const state = { | ||
settingsValues: null | ||
} | ||
|
||
const actions = { | ||
async loadSettingsValues({ commit, state, dispatch }) { | ||
const oldSettingsValues = state.settingsValues | ||
commit('SET_SETTINGS_VALUES', null) | ||
try { | ||
const values = await this._vm.$client.settings.getSettingsValues() | ||
commit('SET_SETTINGS_VALUES', values) | ||
} catch (error) { | ||
commit('SET_SETTINGS_VALUES', oldSettingsValues) | ||
dispatch('showMessage', { | ||
title: 'Failed to load settings values.', | ||
desc: error.response.statusText, | ||
status: 'danger' | ||
}) | ||
} | ||
} | ||
} | ||
|
||
const mutations = { | ||
SET_SETTINGS_VALUES(state, settingsValues) { | ||
if (settingsValues === null) { | ||
state.settingsValues = null | ||
} else { | ||
const map = new Map() | ||
Array.from(settingsValues).forEach(value => applySettingsValueToMap(value, map)) | ||
state.settingsValues = map | ||
} | ||
}, | ||
SET_SETTINGS_VALUE(state, settingsValue) { | ||
const map = new Map(state.settingsValues) | ||
applySettingsValueToMap(settingsValue, map) | ||
state.settingsValues = map | ||
} | ||
} | ||
|
||
const getters = { | ||
settingsValuesLoaded: state => { | ||
return state.settingsValues !== null | ||
}, | ||
hasSettingsValue: (state, getters) => ({ extension, bundleKey, settingKey }) => { | ||
return getters.getSettingsValueByIdentifier({ extension, bundleKey, settingKey }) !== null | ||
}, | ||
getSettingsValueByIdentifier: (state, getters) => ({ extension, bundleKey, settingKey }) => { | ||
if ( | ||
getters.settingsValuesLoaded && | ||
state.settingsValues.has(extension) && | ||
state.settingsValues.get(extension).has(bundleKey) && | ||
state.settingsValues | ||
.get(extension) | ||
.get(bundleKey) | ||
.has(settingKey) | ||
) { | ||
return state.settingsValues | ||
.get(extension) | ||
.get(bundleKey) | ||
.get(settingKey) | ||
} | ||
return null | ||
} | ||
} | ||
|
||
export default { | ||
state, | ||
actions, | ||
mutations, | ||
getters | ||
} | ||
|
||
function applySettingsValueToMap(settingsValue, map) { | ||
if (!map.has(settingsValue.identifier.extension)) { | ||
map.set(settingsValue.identifier.extension, new Map()) | ||
} | ||
if (!map.get(settingsValue.identifier.extension).has(settingsValue.identifier.bundleKey)) { | ||
map.get(settingsValue.identifier.extension).set(settingsValue.identifier.bundleKey, new Map()) | ||
} | ||
map | ||
.get(settingsValue.identifier.extension) | ||
.get(settingsValue.identifier.bundleKey) | ||
.set(settingsValue.identifier.settingKey, settingsValue) | ||
return map | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ const actions = { | |
logout(context) { | ||
const logoutFinalizer = () => { | ||
context.dispatch('cleanUpLoginState') | ||
context.dispatch('loadSettingsValues') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why load the settings during logout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there will be settings that exist without user context. For example, when we provide multiple themes in the future, an admin could set a default theme in settings. That has to be available even if you don't have a user context. So as a result, all changes to the authenticated user (changing to another one or signing out) need to trigger a settings reload. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I am just a bit afraid of relying on authentication in this case because of the public link's context. |
||
// force redirect to login page after logout | ||
router.push({ name: 'login' }) | ||
} | ||
|
@@ -82,6 +83,7 @@ const actions = { | |
isAuthenticated: true, | ||
groups: groups | ||
}) | ||
context.dispatch('loadSettingsValues') | ||
|
||
if (payload.autoRedirect) { | ||
router.push({ path: '/' }) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Enhancement" might be better in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it's a change. ;-) Introduces settings to phoenix => entirely new feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, a new feature which doesn't change any existing functionality