Skip to content
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

Merged
merged 7 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/3484-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Change: Make settings available in phoenix
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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


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
5 changes: 5 additions & 0 deletions changelog/unreleased/3484-2
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
6 changes: 6 additions & 0 deletions config.json.sample-ocis
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
"pdf-viewer",
"markdown-editor",
"media-viewer"
],
"external_apps": [
{
"id": "settings",
"path": "http://localhost:9190/settings.js"
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"npm-run-all": "^4.1.5",
"oidc-client": "^1.9.1",
"owncloud-design-system": "^1.5.0",
"owncloud-sdk": "^1.0.0-608",
"owncloud-sdk": "^1.0.0-630",
"p-limit": "^2.2.1",
"p-queue": "^6.1.1",
"parse-json": "^5.0.0",
Expand Down
21 changes: 20 additions & 1 deletion src/Phoenix.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export default {
'activeNotifications',
'activeMessages',
'capabilities',
'apps'
'apps',
'getSettingsValueByIdentifier'
]),
$_applicationsList() {
const list = []
Expand Down Expand Up @@ -154,6 +155,14 @@ export default {
}

return 'fade'
},

selectedLanguage() {
return this.getSettingsValueByIdentifier({
extension: 'ocis-accounts',
bundleKey: 'profile',
settingKey: 'language'
})
}
},
watch: {
Expand All @@ -175,6 +184,16 @@ export default {
this.$_updateNotifications()
}, 30000)
}
},
selectedLanguage: {
handler(language) {
if (language !== null) {
this.$language.current = language.listValue.values[0].stringValue
} else if (this.$language.defaultLanguage) {
LukasHirt marked this conversation as resolved.
Show resolved Hide resolved
this.$language.current = this.$language.defaultLanguage
}
},
immediate: true
}
},

Expand Down
4 changes: 3 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import apps from './apps'
import config from './config'
import user from './user'
import router from './router'
import settings from './settings'

Vue.use(Vuex)

Expand All @@ -34,7 +35,8 @@ export const Store = new Vuex.Store({
apps,
user,
config,
router
router,
settings
},
strict
})
Expand Down
85 changes: 85 additions & 0 deletions src/store/settings.js
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
}
2 changes: 2 additions & 0 deletions src/store/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const actions = {
logout(context) {
const logoutFinalizer = () => {
context.dispatch('cleanUpLoginState')
context.dispatch('loadSettingsValues')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why load the settings during logout?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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' })
}
Expand Down Expand Up @@ -82,6 +83,7 @@ const actions = {
isAuthenticated: true,
groups: groups
})
context.dispatch('loadSettingsValues')

if (payload.autoRedirect) {
router.push({ path: '/' })
Expand Down
13 changes: 7 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2907,9 +2907,9 @@ date-fns@^1.27.2:
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==

"davclient.js@https://github.com/owncloud/davclient.js.git":
"davclient.js@git+https://github.com/owncloud/davclient.js.git":
version "0.2.1"
resolved "https://github.com/owncloud/davclient.js.git#bf19f590451b3c0658913568053ec7f300f7dfc1"
resolved "git+https://github.com/owncloud/davclient.js.git#bf19f590451b3c0658913568053ec7f300f7dfc1"

de-indent@^1.0.2:
version "1.0.2"
Expand Down Expand Up @@ -6944,11 +6944,12 @@ owncloud-design-system@^1.5.0:
webfontloader "^1.6.28"
weekstart "^1.0.0"

owncloud-sdk@^1.0.0-608:
version "1.0.0-608"
resolved "https://registry.yarnpkg.com/owncloud-sdk/-/owncloud-sdk-1.0.0-608.tgz#d5263fd4ce7e804d00d8024373d45191a8714f93"
integrity sha512-iVKUsSq+Lywxncj54bUu/vSD1A98RrrKPG3WgSdoXyGJv5bdoosFMYVo+gSOsWvVBMCIBIwVRUwvnVfRsSEcKg==
owncloud-sdk@^1.0.0-630:
version "1.0.0-630"
resolved "https://registry.yarnpkg.com/owncloud-sdk/-/owncloud-sdk-1.0.0-630.tgz#48ab65a28578ddf2c076b2c9357620cbb95a3581"
integrity sha512-pW039ulDKdZutmL2AU/Sv0STDLRYGbPM2XnY5sehK/IvRDVMhceqy+5c9aN2f2AsBk6Am5OzH/v1lwH9/dWCCw==
dependencies:
axios "^0.19.2"
browser-request "^0.3.3"
davclient.js "https://github.com/owncloud/davclient.js.git"
promise "^8.0.3"
Expand Down