Skip to content

Commit

Permalink
ACQUI-148: Fix parameters for filterUsersByPermissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mblenk committed Jul 16, 2024
1 parent 227d001 commit 21b88ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default {
this.permittedUsers = patrons
const { permission } = this.$route.meta.self
const permissionRequired = permission ? permission : null
this.owners = this.filterUsersByPermissions(permissionRequired, false)
this.owners = this.filterUsersByPermissions(permissionRequired)
this.visibleGroups = this.filterLibGroupsByUsersBranchcode()
},
error => {}
Expand Down
12 changes: 6 additions & 6 deletions src/stores/acquisitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const useAcquisitionsStore = defineStore("acquisitions", {
})
return codes
},
filterUsersByPermissions(operation, returnAll, branchcodes) {
filterUsersByPermissions(operation, branchcodes = null, returnAll = false) {
const filteredUsers = []
this.permittedUsers.forEach(user => {
user.displayName = user.firstname + ' ' + user.surname
Expand Down Expand Up @@ -123,7 +123,7 @@ export const useAcquisitionsStore = defineStore("acquisitions", {
},
filterGroupsBasedOnOwner(e, data, groups) {
const libGroups = this.filterLibGroupsByUsersBranchcode(null, groups)
const permittedUsers = this.filterUsersByPermissions(this.currentPermission, false)
const permittedUsers = this.filterUsersByPermissions(this.currentPermission)
if (!e) {
this.visibleGroups = libGroups
this.owners = permittedUsers
Expand All @@ -135,24 +135,24 @@ export const useAcquisitionsStore = defineStore("acquisitions", {
},
filterOwnersBasedOnGroup(e, data, groups) {
const libGroups = this.filterLibGroupsByUsersBranchcode(null, groups)
const permittedUsers = this.filterUsersByPermissions(this.currentPermission, false, null)
const permittedUsers = this.filterUsersByPermissions(this.currentPermission)
if (!e.length) {
this.visibleGroups = libGroups
this.owners = permittedUsers
data.owner = null
} else {
const filteredGroups = libGroups.filter(group => e.includes(group.id))
const branchcodes = this._findBranchCodesInGroup(filteredGroups)
this.owners = this.filterUsersByPermissions(this.currentPermission, false, branchcodes)
this.owners = this.filterUsersByPermissions(this.currentPermission, branchcodes)
}
},
setOwnersBasedOnPermission(permission) {
if(this.permittedUsers) {
this.owners = this.filterUsersByPermissions(permission, false, null)
this.owners = this.filterUsersByPermissions(permission)
}
},
resetOwnersAndVisibleGroups(groups) {
this.owners = this.filterUsersByPermissions(this.currentPermission, false)
this.owners = this.filterUsersByPermissions(this.currentPermission)
this.visibleGroups = this.filterLibGroupsByUsersBranchcode(null, groups)
},
getSetting(input) {
Expand Down
8 changes: 4 additions & 4 deletions tests/cypress/specs/unit/AcquisitionsStore_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ describe("AcquisitionsStore", () => {
testPermission: ['something']
}

let filteredUsers = store.filterUsersByPermissions(null, false, null)
let filteredUsers = store.filterUsersByPermissions(null)
expect(filteredUsers).to.have.length(2)
expect(filteredUsers[0].displayName).to.eq('Test Patron')
expect(filteredUsers[1].displayName).to.eq('Another Patron')

filteredUsers = store.filterUsersByPermissions('testPermission', false, null)
filteredUsers = store.filterUsersByPermissions('testPermission')
expect(filteredUsers).to.have.length(1)
expect(filteredUsers[0].displayName).to.eq('Test Patron')

Expand All @@ -92,12 +92,12 @@ describe("AcquisitionsStore", () => {
"surname": "Patron",
})

filteredUsers = store.filterUsersByPermissions('testPermission', false, null)
filteredUsers = store.filterUsersByPermissions('testPermission')
expect(filteredUsers).to.have.length(2)
expect(filteredUsers[0].displayName).to.eq('Test Patron')
expect(filteredUsers[1].displayName).to.eq('Permitted Patron')

filteredUsers = store.filterUsersByPermissions('testPermission', false, ['XYZ'])
filteredUsers = store.filterUsersByPermissions('testPermission', ['XYZ'])
expect(filteredUsers).to.have.length(1)
expect(filteredUsers[0].displayName).to.eq('Permitted Patron')
})
Expand Down

0 comments on commit 21b88ba

Please sign in to comment.