Skip to content
Snippets Groups Projects
Commit fc4fa970 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

Merge branch 'add-analysis-permission-endpoint' into 'dev'

fetch list analysis in fetch hook in order to not block page display while...

See merge request !97
parents 585a8f4c 9401067b
No related branches found
No related tags found
1 merge request!97fetch list analysis in fetch hook in order to not block page display while...
Pipeline #78508 passed
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
:sort-desc="sortDesc" :sort-desc="sortDesc"
:search="search" :search="search"
:item-class="getRowClass" :item-class="getRowClass"
:loading="loading"
multi-sort multi-sort
@click:row="goToItemPage" @click:row="goToItemPage"
> >
...@@ -105,6 +106,7 @@ export default { ...@@ -105,6 +106,7 @@ export default {
itemType: { type: String, required: true, default: 'object' }, itemType: { type: String, required: true, default: 'object' },
addRoute: { type: Object, default: () => null }, addRoute: { type: Object, default: () => null },
selectedItem: { type: Number, default: null }, selectedItem: { type: Number, default: null },
loading: { type: Boolean, default: false },
}, },
data() { data() {
return { return {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
:headers="headers" :headers="headers"
:add-route="addAnalysisRoute" :add-route="addAnalysisRoute"
:selected-item="selectedItem" :selected-item="selectedItem"
:loading="$fetchState.pending"
@delete="deleteAnalysis" @delete="deleteAnalysis"
></data-table-actions> ></data-table-actions>
<ProgressBar :waiting="waiting" message="Deleting Analysis" /> <ProgressBar :waiting="waiting" message="Deleting Analysis" />
...@@ -21,18 +22,6 @@ import ProgressBar from '@/components/ProgressBar' ...@@ -21,18 +22,6 @@ import ProgressBar from '@/components/ProgressBar'
import ErrorAlert from '@/components/ErrorAlert' import ErrorAlert from '@/components/ErrorAlert'
import DataTableActions from '~/components/DataTableActions.vue' import DataTableActions from '~/components/DataTableActions.vue'
function fetchAnalysis($axios, params) {
try {
return $axios.$get(`/api/projects/${params.id}/analysis/`)
} catch (error) {
if (error.response.status === 403) {
return []
} else {
throw error
}
}
}
export default { export default {
components: { components: {
ErrorAlert, ErrorAlert,
...@@ -42,8 +31,25 @@ export default { ...@@ -42,8 +31,25 @@ export default {
loading: { loading: {
continuous: true, continuous: true,
}, },
async fetch() {
try {
this.analysis = await this.$axios.$get(
`/api/projects/${this.$route.params.id}/analysis/`
)
} catch (error) {
if (error.response.status === 403) {
return []
} else {
throw error
}
}
},
async asyncData({ params, $axios }) { async asyncData({ params, $axios }) {
return { analysis: await fetchAnalysis($axios, params) } return {
permissions: await $axios.$get(
`/api/projects/${params.id}/analysis/permissions/`
),
}
}, },
data() { data() {
return { return {
...@@ -72,10 +78,17 @@ export default { ...@@ -72,10 +78,17 @@ export default {
} }
}, },
computed: { computed: {
permissionsSet() {
return new Set(this.permissions)
},
addAnalysisRoute() { addAnalysisRoute() {
return { if (this.permissionsSet.has('add')) {
name: 'projects-id-analysis-add', return {
params: this.$route.params, name: 'projects-id-analysis-add',
params: this.$route.params,
}
} else {
return null
} }
}, },
sanitizedAnalysis() { sanitizedAnalysis() {
...@@ -89,6 +102,10 @@ export default { ...@@ -89,6 +102,10 @@ export default {
return parseInt(this.$route.params?.analysisId) return parseInt(this.$route.params?.analysisId)
}, },
}, },
mounted() {
this.$fetch()
},
methods: { methods: {
getItemRoute({ id: analysisId }) { getItemRoute({ id: analysisId }) {
return { return {
...@@ -107,7 +124,7 @@ export default { ...@@ -107,7 +124,7 @@ export default {
await this.$axios.$delete( await this.$axios.$delete(
`/api/projects/${params.id}/analysis/${analysisId}` `/api/projects/${params.id}/analysis/${analysisId}`
) )
this.analysis = await fetchAnalysis(this.$axios, params) this.$fetch()
this.updateAnalysisCount() this.updateAnalysisCount()
this.$emit('update-analysis') this.$emit('update-analysis')
} catch (error) { } catch (error) {
......
...@@ -931,6 +931,17 @@ class ProjectAnalysisViewSet(viewsets.ModelViewSet): ...@@ -931,6 +931,17 @@ class ProjectAnalysisViewSet(viewsets.ModelViewSet):
def perform_destroy(self, instance): def perform_destroy(self, instance):
instance.delete() instance.delete()
@action(detail=False)
def permissions(self, request, pk=None, project_pk=None):
current_user = request.user
return Response(
[
perm.split(".")[1].split("_")[0]
for perm in current_user.get_all_permissions()
if perm.endswith("analysis")
]
)
@action(detail=True) @action(detail=True)
def lodscores(self, request, pk=None, project_pk=None): def lodscores(self, request, pk=None, project_pk=None):
# Get the lodscores # Get the lodscores
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment