Skip to content

Commit

Permalink
Filter items in admin panel depending on admin level
Browse files Browse the repository at this point in the history
  • Loading branch information
petterhj committed Nov 21, 2023
1 parent ab7d8fe commit b1a9f98
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ All notable changes to this project will be documented in this file. The format
of parent measurements when switching between items.
- The edit button for key result values is now only visible to users with the
appropriate permissions.
- Organizations, departments, and products in the admin panel are now filtered
based on the admin level of the current user.

### Security

Expand Down
10 changes: 8 additions & 2 deletions src/views/Admin/CreateDepartment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
:label="$t('admin.department.parentOrganisation')"
select-label="name"
rules="required"
:select-options="organizations"
:select-options="organizationOptions"
data-cy="dep-parentOrg"
/>

Expand Down Expand Up @@ -86,7 +86,13 @@ export default {
}),
computed: {
...mapState(['organizations', 'users']),
...mapState(['organizations', 'users', 'user']),
organizationOptions() {
return this.user.superAdmin
? this.organizations
: this.organizations.filter((o) => this.user.admin.includes(o.id));
},
},
methods: {
Expand Down
10 changes: 8 additions & 2 deletions src/views/Admin/CreateProduct.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:label="$t('admin.product.parentDepartment')"
select-label="name"
rules="required"
:select-options="departments"
:select-options="departmentOptions"
/>

<div class="pkt-form-group">
Expand Down Expand Up @@ -82,7 +82,13 @@ export default {
}),
computed: {
...mapState(['departments', 'users']),
...mapState(['departments', 'users', 'user']),
departmentOptions() {
return this.user.superAdmin
? this.departments
: this.departments.filter((d) => this.user.admin.includes(d.organization.id));
},
},
methods: {
Expand Down
56 changes: 29 additions & 27 deletions src/views/Admin/components/AdminItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,53 +171,42 @@ export default {
},
watch: {
showArchived: {
user: {
immediate: true,
handler() {
this.$bind(
'organizations',
db
.collection('organizations')
.where('archived', 'in', [false, this.showArchived])
.orderBy('slug')
);
this.$bind(
'departments',
db
.collection('departments')
.where('archived', 'in', [false, this.showArchived])
.orderBy('slug')
);
this.$bind(
'products',
db
.collection('products')
.where('archived', 'in', [false, this.showArchived])
.orderBy('slug')
);
},
handler: 'bindItems',
},
showArchived: {
immediate: false,
handler: 'bindItems',
},
organizations: {
immediate: true,
handler() {
this.filteredOrgs = this.organizations;
this.filteredOrgs = this.user.superAdmin
? this.organizations
: this.organizations.filter((o) => this.user.admin.includes(o.id));
this.fuseOrgs = new Fuse(this.filteredOrgs, fuseSettings);
},
},
departments: {
immediate: true,
handler() {
this.filteredDeps = this.departments;
this.filteredDeps = this.user.superAdmin
? this.departments
: this.departments.filter((d) => this.user.admin.includes(d.organization.id));
this.fuseDeps = new Fuse(this.filteredDeps, fuseSettings);
},
},
products: {
immediate: true,
handler() {
this.filteredProds = this.products;
this.filteredProds = this.user.superAdmin
? this.products
: this.products.filter((p) => this.user.admin.includes(p.organization.id));
this.fuseProds = new Fuse(this.filteredProds, fuseSettings);
},
},
Expand Down Expand Up @@ -248,6 +237,19 @@ export default {
},
methods: {
bindItems() {
for (const collection of ['organizations', 'departments', 'products']) {
this.$bind(
collection,
db
.collection(collection)
.where('archived', 'in', [false, this.showArchived])
.orderBy('slug'),
{ wait: true }
);
}
},
itemLink(slug) {
return {
name: 'ItemAbout',
Expand Down

0 comments on commit b1a9f98

Please sign in to comment.