Add settings for user search (#458)

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/458
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad 2021-04-07 19:31:14 +00:00
parent 7fe0552689
commit 2a56c84e94
5 changed files with 33 additions and 10 deletions

View file

@ -410,7 +410,7 @@ describe('Lists', () => {
.should('contain', `/tasks/${tasks[0].id}`) .should('contain', `/tasks/${tasks[0].id}`)
}) })
it.only('Should remove a task from the kanban board when moving it to another list', () => { it('Should remove a task from the kanban board when moving it to another list', () => {
const lists = ListFactory.create(2) const lists = ListFactory.create(2)
BucketFactory.create(2, { BucketFactory.create(2, {
list_id: '{increment}', list_id: '{increment}',

View file

@ -1,8 +1,14 @@
import AbstractModel from './abstractModel' import AbstractModel from './abstractModel'
import UserSettingsModel from '@/models/userSettings'
export default class UserModel extends AbstractModel { export default class UserModel extends AbstractModel {
constructor(data) { constructor(data) {
super(data) super(data)
if (this.settings !== null) {
this.settings = new UserSettingsModel(this.settings)
}
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
@ -15,6 +21,7 @@ export default class UserModel extends AbstractModel {
name: '', name: '',
created: null, created: null,
updated: null, updated: null,
settings: null,
} }
} }

View file

@ -6,6 +6,8 @@ export default class UserSettingsModel extends AbstractModel {
return { return {
name: '', name: '',
emailRemindersEnabled: true, emailRemindersEnabled: true,
discoverableByName: false,
discoverableByEmail: false,
} }
} }
} }

View file

@ -11,6 +11,7 @@ export default {
needsTotpPasscode: false, needsTotpPasscode: false,
avatarUrl: '', avatarUrl: '',
lastUserInfoRefresh: null, lastUserInfoRefresh: null,
settings: {},
}), }),
mutations: { mutations: {
info(state, info) { info(state, info) {
@ -18,10 +19,15 @@ export default {
if (info !== null) { if (info !== null) {
state.avatarUrl = info.getAvatarUrl() state.avatarUrl = info.getAvatarUrl()
} }
if (info.settings) {
state.settings = info.settings
}
}, },
setUserSettings(state, {name, emailRemindersEnabled}) { setUserSettings(state, settings) {
state.info.name = name state.settings = settings
state.info.emailRemindersEnabled = emailRemindersEnabled const info = state.info !== null ? state.info : {}
info.name = settings.name
state.info = info
}, },
authenticated(state, authenticated) { authenticated(state, authenticated) {
state.authenticated = authenticated state.authenticated = authenticated
@ -176,7 +182,7 @@ export default {
authenticated = info.exp >= ts authenticated = info.exp >= ts
ctx.commit('info', info) ctx.commit('info', info)
if (authenticated ) { if (authenticated) {
const HTTP = HTTPFactory() const HTTP = HTTPFactory()
// We're not returning the promise here to prevent blocking the initial ui render if the user is // We're not returning the promise here to prevent blocking the initial ui render if the user is
// accessing the site with a token in local storage // accessing the site with a token in local storage
@ -190,7 +196,6 @@ export default {
info.type = ctx.state.info.type info.type = ctx.state.info.type
info.email = ctx.state.info.email info.email = ctx.state.info.email
info.exp = ctx.state.info.exp info.exp = ctx.state.info.exp
info.emailRemindersEnabled = ctx.state.info.emailRemindersEnabled
ctx.commit('info', info) ctx.commit('info', info)
ctx.commit('authenticated', authenticated) ctx.commit('authenticated', authenticated)

View file

@ -108,6 +108,18 @@
Send me Reminders for tasks via Email Send me Reminders for tasks via Email
</label> </label>
</div> </div>
<div class="field">
<label class="checkbox">
<input type="checkbox" v-model="settings.discoverableByName"/>
Let other users find me when they search for my name
</label>
</div>
<div class="field">
<label class="checkbox">
<input type="checkbox" v-model="settings.discoverableByEmail"/>
Let other users find me when they search for my full email
</label>
</div>
<div class="field"> <div class="field">
<label class="checkbox"> <label class="checkbox">
<input type="checkbox" v-model="playSoundWhenDone"/> <input type="checkbox" v-model="playSoundWhenDone"/>
@ -276,10 +288,7 @@ export default {
this.totp = new TotpModel() this.totp = new TotpModel()
this.userSettingsService = new UserSettingsService() this.userSettingsService = new UserSettingsService()
this.settings = new UserSettingsModel({ this.settings = this.$store.state.auth.settings
name: this.$store.state.auth.info.name,
emailRemindersEnabled: this.$store.state.auth.info.emailRemindersEnabled ?? false,
})
this.playSoundWhenDone = localStorage.getItem(playSoundWhenDoneKey) === 'true' || localStorage.getItem(playSoundWhenDoneKey) === null this.playSoundWhenDone = localStorage.getItem(playSoundWhenDoneKey) === 'true' || localStorage.getItem(playSoundWhenDoneKey) === null