Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): api return of aquifer notes #205

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -107,7 +107,7 @@ const aquiferFixture = {
}

describe('View Component', () => {
let fetch = null
let fetch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was fetch changed to uninitialized instead of null?


const component = (options, storeState = {}) => {
const store = new Vuex.Store({
Expand Down 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 localVue = createLocalVue()
localVue.use(Vuex)

const wrapper = component({
propsData: { edit: false }
}, {
aquiferStore: {
view: {
record: aquiferFixture
}
}
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>
<!---->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What were the changes made to this file?

</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
Loading