From 22ea81a2e83e5d77e39584f32e9c5cfc29698200 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 4 Jun 2021 09:56:30 +0900 Subject: [PATCH 1/3] Update TheSideBar.vue to hide label and relation menu --- frontend/components/layout/TheSideBar.vue | 73 +++++++++++++++---- frontend/domain/models/project/project.ts | 16 ++++ frontend/layouts/project.vue | 3 +- frontend/layouts/workspace.vue | 3 +- .../application/project/projectData.ts | 4 + 5 files changed, 84 insertions(+), 15 deletions(-) diff --git a/frontend/components/layout/TheSideBar.vue b/frontend/components/layout/TheSideBar.vue index 798b6387..f7996ccf 100644 --- a/frontend/components/layout/TheSideBar.vue +++ b/frontend/components/layout/TheSideBar.vue @@ -46,6 +46,11 @@ export default { type: Object, default: () => {}, required: true + }, + project: { + type: Object, + default: () => {}, + required: true } }, @@ -58,24 +63,66 @@ export default { computed: { filteredItems() { const items = [ - { icon: 'mdi-home', text: this.$t('projectHome.home'), link: '', adminOnly: false }, - { icon: 'mdi-database', text: this.$t('dataset.dataset'), link: 'dataset', adminOnly: true }, - { icon: 'label', text: this.$t('labels.labels'), link: 'labels', adminOnly: true }, - { icon: 'label', text: 'Relations', link: 'links', adminOnly: true }, - { icon: 'person', text: this.$t('members.members'), link: 'members', adminOnly: true }, - { icon: 'mdi-comment-account-outline', text: 'Comments', link: 'comments', adminOnly: true }, - { icon: 'mdi-book-open-outline', text: this.$t('guideline.guideline'), link: 'guideline', adminOnly: true }, - { icon: 'mdi-chart-bar', text: this.$t('statistics.statistics'), link: 'statistics', adminOnly: true }, - { icon: 'mdi-cog', text: this.$t('settings.title'), link: 'settings', adminOnly: true } + { + icon: 'mdi-home', + text: this.$t('projectHome.home'), + link: '', + isVisible: true + }, + { + icon: 'mdi-database', + text: this.$t('dataset.dataset'), + link: 'dataset', + isVisible: this.role.is_project_admin + }, + { + icon: 'label', + text: this.$t('labels.labels'), + link: 'labels', + isVisible: this.role.is_project_admin && this.project.canDefineLabel + }, + { + icon: 'label', + text: 'Relations', + link: 'links', + isVisible: this.role.is_project_admin && this.project.canDefineRelation + }, + { + icon: 'person', + text: this.$t('members.members'), + link: 'members', + isVisible: this.role.is_project_admin + }, + { + icon: 'mdi-comment-account-outline', + text: 'Comments', + link: 'comments', + isVisible: this.role.is_project_admin + }, + { + icon: 'mdi-book-open-outline', + text: this.$t('guideline.guideline'), + link: 'guideline', + isVisible: this.role.is_project_admin + }, + { + icon: 'mdi-chart-bar', + text: this.$t('statistics.statistics'), + link: 'statistics', + isVisible: this.role.is_project_admin + }, + { + icon: 'mdi-cog', + text: this.$t('settings.title'), + link: 'settings', + isVisible: this.role.is_project_admin + } ] - return items.filter(item => this.isVisible(item)) + return items.filter(item => item.isVisible) } }, methods: { - isVisible(item) { - return !item.adminOnly || this.role.is_project_admin - }, toLabeling() { const query = this.$services.option.findOption(this.$route.params.id) this.$router.push({ diff --git a/frontend/domain/models/project/project.ts b/frontend/domain/models/project/project.ts index eab59ef5..a37c5eba 100644 --- a/frontend/domain/models/project/project.ts +++ b/frontend/domain/models/project/project.ts @@ -90,6 +90,22 @@ export class ProjectReadItem { return role && !role.is_annotator } + get canDefineLabel() { + const allowedProjectTypes = [ + 'DocumentClassification', + 'SequenceLabeling', + 'ImageClassification' + ] + return allowedProjectTypes.includes(this.project_type) + } + + get canDefineRelation() { + const allowedProjectTypes = [ + 'SequenceLabeling' + ] + return allowedProjectTypes.includes(this.project_type) + } + get filterOption() { if (this.project_type === 'DocumentClassification') { return 'categories__isnull' diff --git a/frontend/layouts/project.vue b/frontend/layouts/project.vue index b2e298d3..d475f3ba 100644 --- a/frontend/layouts/project.vue +++ b/frontend/layouts/project.vue @@ -15,6 +15,7 @@ @@ -55,7 +56,7 @@ export default { }, computed: { - ...mapGetters('projects', ['getLink', 'getCurrentUserRole']) + ...mapGetters('projects', ['getLink', 'getCurrentUserRole', 'currentProject']) } } diff --git a/frontend/layouts/workspace.vue b/frontend/layouts/workspace.vue index 38d70a43..a2f30bdc 100644 --- a/frontend/layouts/workspace.vue +++ b/frontend/layouts/workspace.vue @@ -14,6 +14,7 @@ @@ -43,7 +44,7 @@ export default { }, computed: { - ...mapGetters('projects', ['getLink', 'getCurrentUserRole']) + ...mapGetters('projects', ['getLink', 'getCurrentUserRole', 'currentProject']) }, watch: { diff --git a/frontend/services/application/project/projectData.ts b/frontend/services/application/project/projectData.ts index fa591ace..d9e8ccab 100644 --- a/frontend/services/application/project/projectData.ts +++ b/frontend/services/application/project/projectData.ts @@ -15,6 +15,8 @@ export class ProjectDTO { permitApprove: Boolean filterOption: String tags: Object[] + canDefineLabel: Boolean + canDefineRelation: Boolean constructor(item: ProjectReadItem) { this.id = item.id @@ -31,6 +33,8 @@ export class ProjectDTO { this.permitApprove = item.permitApprove this.filterOption = item.filterOption this.tags = item.tags + this.canDefineLabel = item.canDefineLabel + this.canDefineRelation = item.canDefineRelation } } From 028caca8f14c487154eb150f1fd493ec257c7577 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 4 Jun 2021 13:24:55 +0900 Subject: [PATCH 2/3] Update label page validation --- frontend/pages/projects/_id/labels/index.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frontend/pages/projects/_id/labels/index.vue b/frontend/pages/projects/_id/labels/index.vue index 3c53946b..07b39af8 100644 --- a/frontend/pages/projects/_id/labels/index.vue +++ b/frontend/pages/projects/_id/labels/index.vue @@ -56,6 +56,7 @@ import FormDelete from '@/components/label/FormDelete.vue' import FormUpload from '@/components/label/FormUpload.vue' import LabelList from '@/components/label/LabelList.vue' import { LabelDTO } from '~/services/application/label/labelData' +import { ProjectDTO } from '~/services/application/project/projectData' export default Vue.extend({ layout: 'project', @@ -183,8 +184,14 @@ export default Vue.extend({ } }, - validate({ params }) { - return /^\d+$/.test(params.id) + validate({ params, app }) { + if (/^\d+$/.test(params.id)) { + return app.$services.project.findById(params.id) + .then((res:ProjectDTO) => { + return res.canDefineLabel + }) + } + return false } }) From d273ca9f979f5e89794e6cf9bca064dac7a78991 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 4 Jun 2021 13:25:05 +0900 Subject: [PATCH 3/3] Update relation page validation --- frontend/pages/projects/_id/links/index.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frontend/pages/projects/_id/links/index.vue b/frontend/pages/projects/_id/links/index.vue index 67572ce8..04c9cd15 100644 --- a/frontend/pages/projects/_id/links/index.vue +++ b/frontend/pages/projects/_id/links/index.vue @@ -46,6 +46,7 @@ import FormCreate from '@/components/links/FormCreate.vue' import FormDelete from '@/components/links/FormDelete.vue' import LinksList from '~/components/links/LinksList.vue' import { LinkTypeDTO } from '~/services/application/links/linkData' +import { ProjectDTO } from '~/services/application/project/projectData' export default Vue.extend({ layout: 'project', @@ -142,8 +143,14 @@ export default Vue.extend({ } }, - validate({ params }) { - return /^\d+$/.test(params.id) + validate({ params, app }) { + if (/^\d+$/.test(params.id)) { + return app.$services.project.findById(params.id) + .then((res:ProjectDTO) => { + return res.canDefineRelation + }) + } + return false } })