Skip to content

Commit

Permalink
Adjust how user name and URI are handled (#591)
Browse files Browse the repository at this point in the history
This commit allows the user to choose any name regardless of identity URI.
  • Loading branch information
stefandesu committed Nov 16, 2020
1 parent 196b5e2 commit 4959997
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 53 deletions.
8 changes: 0 additions & 8 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,6 @@ export default {
}
}
},
/**
* Update authorized user's name if creator name changed.
*/
userName() {
if (this.authorized && this.user && this.userName != this.user.name) {
this.setName(this.userName)
}
},
/**
* Unminimize mapping browser if force mapping browser is set to true
*/
Expand Down
29 changes: 24 additions & 5 deletions src/components/TheNavbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@
'navbar-dropdown-selectable': true,
'navbar-dropdown-selectable-selected': uri == creator.uri
}"
@click="$store.commit({
type: 'settings/set',
prop: 'creatorUri',
value: uri
})">
@click="setIdentity(uri)">
<span class="navbar-dropdown-selectable-icon">
<img
v-if="imageForIdentityUri(uri)"
Expand Down Expand Up @@ -403,6 +399,29 @@ export default {
this.settingsTab = index
this.$refs.settings.show()
},
setIdentity(uri) {
this.$store.commit({
type: "settings/set",
prop: "creatorUri",
value: uri,
})
// Find name in identity and set creator
// TODO: Code duplication with TheSettings
if (this.user) {
let name = this.user.name
const identity = Object.values(this.user.identities).find(i => i.uri === uri)
if (identity) {
name = identity.name
}
if (name) {
this.$store.commit({
type: "settings/set",
prop: "creator",
value: name,
})
}
}
},
},
}
</script>
Expand Down
44 changes: 17 additions & 27 deletions src/components/TheSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,10 @@
</p>
<p>
<b>{{ $t("settings.creator") }}</b>
<span v-if="!user || localSettings.creatorUri == user.uri">
<!-- Default or no identity chosen - name changeable -->
<b-form-input
v-model="localSettings.creator"
:placeholder="$t('settings.creatorPlaceholder')"
type="text" />
</span>
<span v-else>
<!-- Specific identity chosen - name is set -->
<div class="d-flex align-items-center">
<div class="flex-grow-1">
<b-form-input
:value="creatorName"
type="text"
disabled />
</div>
<div
v-if="userIdentityProvider"
class="ml-2">
<img
v-if="userIdentityImage"
:src="userIdentityImage"
height="24px">
{{ userIdentityProvider.name }}
</div>
</div>
</span>
<b-form-input
v-model="localSettings.creator"
:placeholder="$t('settings.creatorPlaceholder')"
type="text" />
</p>
<p>
<b>{{ $t("settings.creatorUri") }}</b>
Expand Down Expand Up @@ -540,6 +517,19 @@ export default {
reader.readAsText(this.uploadedFile)
}
},
"localSettings.creatorUri"(uri) {
// Find name in identity and set creator
if (this.user) {
let name = this.user.name
const identity = Object.values(this.user.identities).find(i => i.uri === uri)
if (identity) {
name = identity.name
}
if (name) {
this.localSettings.creator = name
}
}
},
},
methods: {
show() {
Expand Down
14 changes: 1 addition & 13 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,16 @@ const getters = {
*/
creator: (state) => {
let creator = {}
let language = state.settings.settings.locale
if (!(state.config.languages || []).includes(language)) {
language = "en"
}
let name = state.settings.settings.creator
let uri = state.settings.settings.creatorUri
if (!jskos.isValidUri(uri)) {
uri = null
}
if (uri) {
creator.uri = uri
// Override name with name from chosen identity
let user = state.auth.user
if (user) {
let identity = Object.values(user.identities).find(identity => identity.uri === uri)
if (identity && identity.name) {
name = identity.name
}
}
}
if (name) {
creator.prefLabel = { [language]: name }
creator.prefLabel = { "en": name }
}
return creator
},
Expand Down

0 comments on commit 4959997

Please sign in to comment.