Skip to content

Commit

Permalink
fix(backend): api return of aquifer notes (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunamoonmoon authored Dec 3, 2024
1 parent 61758c6 commit 29e7dc2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
12 changes: 11 additions & 1 deletion backend/aquifers/views_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
AQUIFER_CHUNK_SIZE,
GeoJSONIterator
)
from gwells.roles import AQUIFERS_EDIT_ROLE
from gwells.roles import (
AQUIFERS_EDIT_ROLE,
AQUIFERS_VIEWER_ROLE
)
from aquifers import serializers, serializers_v2
from aquifers.models import Aquifer
from wells.models import Well, AquiferParameters
Expand Down Expand Up @@ -89,6 +92,13 @@ def get_queryset(self):
qs = qs.filter(effective_date__lte=now, expiry_date__gt=now)
return qs

def get(self, request, *args, **kwargs):
""" Removes notes field for users without the aquifer view role """
response = super().get(self, request, *args, **kwargs)
if not request.user.groups.filter(name=AQUIFERS_VIEWER_ROLE).exists():
response.data.pop('notes', None)
return response


def _aquifer_qs(request):
"""
Expand Down
63 changes: 35 additions & 28 deletions frontend/tests/unit/specs/aquifers/components/View.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,44 +156,51 @@ describe('View Component', () => {
expect(fetch).toHaveBeenCalled()
})

describe('View comments', () => {
it('auth users can view comments', () => {
mockKeycloak.authenticated = true;

const wrapper = component({
propsData: { edit: false }
}, {
aquiferStore: {
view: {
record: aquiferFixture
}
}
const localVue = createLocalVue()
localVue.use(Vuex)

describe('Comments', () => {
let getters
let store

it('auth users can view comments', async () => {
getters = {
config: () => ({ enable_aquifers_search: false }),
userRoles: () => ({ aquifers: { view: true }})
}

store = new Vuex.Store({
modules: { auth, aquiferStore, documentState },
getters
})

const internalCommentsTitle = wrapper.find('#internal-comments-title');
expect(internalCommentsTitle.exists()).toBe(true);
expect(internalCommentsTitle.text()).toBe('Internal Comments');
const wrapper = component({ store, localVue })

await Vue.nextTick()

const internalCommentsTitle = wrapper.find('#internal-comments-title')
expect(internalCommentsTitle.exists()).toBe(true)
expect(internalCommentsTitle.text()).toBe('Internal Comments')
})

it('unauth users can\'t view comments', () => {
mockKeycloak.authenticated = false;

const wrapper = component({
propsData: { edit: false }
}, {
aquiferStore: {
view: {
record: aquiferFixture
}
}
getters = {
config: () => ({ enable_aquifers_search: false }),
userRoles: () => ({ aquifers: { view: false }})
}
store = new Vuex.Store({
modules: { auth, aquiferStore, documentState },
getters
})

const titles = wrapper.findAll('h5.main-title');
const internalCommentsTitle = titles.filter(title => title.text() === 'Internal Comments');
expect(internalCommentsTitle.exists()).toBe(false);
const wrapper = component({ store, localVue })

const internalCommentsTitleExists = wrapper.find('#internal-comments-title');
expect(internalCommentsTitleExists.exists()).toBe(false);
})
})


describe('View mode', () => {
it('matches the snapshot', () => {
const wrapper = component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,7 @@ exports[`WellDetail.vue should match snapshot 1`] = `
Aquifer Number:
</span>
<router-link-stub
to="[object Object]"
>
</router-link-stub>
<!---->
</b-col-stub>
<b-col-stub
Expand Down Expand Up @@ -457,6 +451,8 @@ exports[`WellDetail.vue should match snapshot 1`] = `
<!---->
<!---->
<div>
<a
class="jump_link"
Expand Down Expand Up @@ -1860,7 +1856,7 @@ exports[`WellDetail.vue should match snapshot 1`] = `
currentpage="1"
emptyfilteredtext="There are no records matching your request"
emptytext="There are no records to show"
fields="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
fields="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
filterdebounce="0"
filterfunction="function bvConfigurablePropDefault() {
var value = getComponentConfig(componentKey, key, prop.default);
Expand Down Expand Up @@ -1904,6 +1900,8 @@ exports[`WellDetail.vue should match snapshot 1`] = `
</p>
</fieldset>
<!---->
<fieldset
class="detail-section my-3"
id="documents_fieldset"
Expand Down

0 comments on commit 29e7dc2

Please sign in to comment.