Fix user permissions restricted by tag #421

This commit is contained in:
advplyr 2022-04-21 19:29:15 -05:00
parent 6f7d2ef4cd
commit 2276228531
4 changed files with 15 additions and 7 deletions

View File

@ -88,7 +88,7 @@
</div> </div>
<div v-if="!newUser.permissions.accessAllTags" class="my-4"> <div v-if="!newUser.permissions.accessAllTags" class="my-4">
<ui-multi-select-dropdown v-model="newUser.itemsTagsAccessible" :items="itemTags" label="Tags Accessible to User" /> <ui-multi-select-dropdown v-model="newUser.itemTagsAccessible" :items="itemTags" label="Tags Accessible to User" />
</div> </div>
</div> </div>
@ -162,9 +162,6 @@ export default {
}, },
methods: { methods: {
accessAllTagsToggled(val) { accessAllTagsToggled(val) {
if (!val) {
this.fetchAllTags()
}
if (!val && !this.newUser.itemTagsAccessible.length) { if (!val && !this.newUser.itemTagsAccessible.length) {
this.newUser.itemTagsAccessible = this.libraries.map((l) => l.id) this.newUser.itemTagsAccessible = this.libraries.map((l) => l.id)
} else if (val && this.newUser.itemTagsAccessible.length) { } else if (val && this.newUser.itemTagsAccessible.length) {
@ -275,8 +272,11 @@ export default {
} }
}, },
init() { init() {
this.fetchAllTags()
this.isNew = !this.account this.isNew = !this.account
if (this.account) { if (this.account) {
console.log(this.account)
this.newUser = { this.newUser = {
username: this.account.username, username: this.account.username,
password: this.account.password, password: this.account.password,

View File

@ -62,7 +62,7 @@ export default {
}, },
selectedItems() { selectedItems() {
return (this.value || []).map((v) => { return (this.value || []).map((v) => {
return this.items.find((i) => i.value === v) || {} return this.items.find((i) => i.value === v) || { text: v, value: v }
}) })
} }
}, },
@ -113,6 +113,7 @@ export default {
removeItem(itemValue) { removeItem(itemValue) {
var remaining = this.selected.filter((i) => i !== itemValue) var remaining = this.selected.filter((i) => i !== itemValue)
this.$emit('input', remaining) this.$emit('input', remaining)
this.$nextTick(() => { this.$nextTick(() => {
this.recalcMenuPos() this.recalcMenuPos()
}) })

View File

@ -253,7 +253,13 @@ class LibraryController {
minified: req.query.minified === '1' minified: req.query.minified === '1'
} }
var collections = this.db.collections.filter(c => c.libraryId === req.library.id).map(c => c.toJSONExpanded(libraryItems, payload.minified)) var collections = this.db.collections.filter(c => c.libraryId === req.library.id).map(c => {
var expanded = c.toJSONExpanded(libraryItems, payload.minified)
// If all books restricted to user in this collection then hide this collection
if (!expanded.books.length && c.books.length) return null
return expanded
}).filter(c => !!c)
payload.total = collections.length payload.total = collections.length
if (payload.limit) { if (payload.limit) {

View File

@ -308,7 +308,8 @@ class User {
} }
checkCanAccessLibraryItemWithTags(tags) { checkCanAccessLibraryItemWithTags(tags) {
if (this.permissions.accessAllTags || !tags || !tags.length) return true if (!tags || !tags.length) return false
if (this.permissions.accessAllTags) return true
return this.itemTagsAccessible.some(tag => tags.includes(tag)) return this.itemTagsAccessible.some(tag => tags.includes(tag))
} }