Browse Source

Remove currentUserRole from Project item

pull/1627/head
Hironsan 2 years ago
parent
commit
9f1c8b8de2
11 changed files with 54 additions and 62 deletions
  1. 20
      frontend/components/layout/TheSideBar.vue
  2. 19
      frontend/components/project/FormDelete.vue
  3. 4
      frontend/domain/models/member/member.ts
  4. 11
      frontend/domain/models/project/project.ts
  5. 12
      frontend/layouts/project.vue
  6. 12
      frontend/layouts/workspace.vue
  7. 5
      frontend/middleware/check-admin.js
  8. 6
      frontend/pages/projects/_id/dataset/index.vue
  9. 12
      frontend/repositories/member/apiMemberRepository.ts
  10. 11
      frontend/services/application/member/memberApplicationService.ts
  11. 4
      frontend/services/application/project/projectData.ts

20
frontend/components/layout/TheSideBar.vue

@ -44,9 +44,9 @@ export default {
default: '',
required: true
},
role: {
type: Object,
default: () => {},
isProjectAdmin: {
type: Boolean,
default: false,
required: true
},
project: {
@ -82,43 +82,43 @@ export default {
icon: mdiLabel,
text: this.$t('labels.labels'),
link: 'labels',
isVisible: this.role.is_project_admin && this.project.canDefineLabel
isVisible: this.isProjectAdmin && this.project.canDefineLabel
},
{
icon: mdiLabel,
text: 'Relations',
link: 'links',
isVisible: this.role.is_project_admin && this.project.canDefineRelation
isVisible: this.isProjectAdmin && this.project.canDefineRelation
},
{
icon: mdiAccount,
text: this.$t('members.members'),
link: 'members',
isVisible: this.role.is_project_admin
isVisible: this.isProjectAdmin
},
{
icon: mdiCommentAccountOutline,
text: 'Comments',
link: 'comments',
isVisible: this.role.is_project_admin
isVisible: this.isProjectAdmin
},
{
icon: mdiBookOpenOutline,
text: this.$t('guideline.guideline'),
link: 'guideline',
isVisible: this.role.is_project_admin
isVisible: this.isProjectAdmin
},
{
icon: mdiChartBar,
text: this.$t('statistics.statistics'),
link: 'statistics',
isVisible: this.role.is_project_admin
isVisible: this.isProjectAdmin
},
{
icon: mdiCog,
text: this.$t('settings.title'),
link: 'settings',
isVisible: this.role.is_project_admin
isVisible: this.isProjectAdmin
}
]
return items.filter(item => item.isVisible)

19
frontend/components/project/FormDelete.vue

@ -15,16 +15,6 @@
</v-list-item-content>
</v-list-item>
</v-list>
<span v-show="hasNonDeletableProjects" class="font-weight-bold">
You don't have permission to delete the following projects. We try to delete the projects except for the following.
</span>
<v-list dense>
<v-list-item v-for="(item, i) in nonDeletableProjects" :key="i">
<v-list-item-content>
<v-list-item-title>{{ item.name }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</template>
</base-card>
</template>
@ -44,15 +34,6 @@ export default Vue.extend({
type: Array as PropType<ProjectDTO[]>,
default: () => []
}
},
computed: {
nonDeletableProjects(): ProjectDTO[] {
return this.selected.filter(item => !item.current_users_role.is_project_admin)
},
hasNonDeletableProjects(): boolean {
return this.nonDeletableProjects.length > 0
}
}
})
</script>

4
frontend/domain/models/member/member.ts

@ -14,6 +14,10 @@ export class MemberItem {
return new MemberItem(id, user, role, username, rolename)
}
get isProjectAdmin(): boolean {
return this.rolename === 'project_admin'
}
toObject(): Object {
return {
id: this.id,

11
frontend/domain/models/project/project.ts

@ -1,9 +1,3 @@
export interface CurrentUsersRole {
is_project_admin: boolean;
is_annotator: boolean;
is_annotation_approver: boolean;
}
export type ProjectType = 'DocumentClassification' | 'SequenceLabeling' | 'Seq2seq' | 'IntentDetectionAndSlotFilling' | 'ImageClassification' | 'Speech2text'
@ -14,7 +8,6 @@ export class ProjectReadItem {
public description: string,
public guideline: string,
public users: number[],
public current_users_role: CurrentUsersRole,
public project_type: ProjectType,
public updated_at: string,
public random_order: boolean,
@ -33,7 +26,6 @@ export class ProjectReadItem {
description,
guideline,
users,
current_users_role,
project_type,
updated_at,
random_order,
@ -50,7 +42,6 @@ export class ProjectReadItem {
description: string,
guideline: string,
users: number[],
current_users_role: CurrentUsersRole,
project_type: ProjectType,
updated_at: string,
random_order: boolean,
@ -68,7 +59,6 @@ export class ProjectReadItem {
description,
guideline,
users,
current_users_role,
project_type,
updated_at,
random_order,
@ -145,7 +135,6 @@ export class ProjectReadItem {
description: this.description,
guideline: this.guideline,
users: this.users,
current_users_role: this.current_users_role,
project_type: this.project_type,
updated_at: this.updated_at,
random_order: this.random_order,

12
frontend/layouts/project.vue

@ -14,7 +14,7 @@
>
<the-side-bar
:link="getLink"
:role="getCurrentUserRole"
:is-project-admin="isProjectAdmin"
:project="currentProject"
/>
</v-navigation-drawer>
@ -51,12 +51,18 @@ export default {
data() {
return {
drawerLeft: null
drawerLeft: null,
isProjectAdmin: false,
}
},
computed: {
...mapGetters('projects', ['getLink', 'getCurrentUserRole', 'currentProject'])
...mapGetters('projects', ['getLink', 'currentProject']),
...mapGetters('auth', ['getUserId'])
},
async created() {
this.isProjectAdmin = await this.$services.member.isProjectAdmin(this.$route.params.id, this.getUserId)
}
}
</script>

12
frontend/layouts/workspace.vue

@ -13,7 +13,7 @@
>
<the-side-bar
:link="getLink"
:role="getCurrentUserRole"
:is-project-admin="isProjectAdmin"
:project="currentProject"
/>
</v-navigation-drawer>
@ -39,18 +39,24 @@ export default {
data() {
return {
drawerLeft: null
drawerLeft: null,
isProjectAdmin: false
}
},
computed: {
...mapGetters('projects', ['getLink', 'getCurrentUserRole', 'currentProject'])
...mapGetters('projects', ['getLink', 'currentProject']),
...mapGetters('auth', ['getUserId'])
},
watch: {
'$route.query'() {
this.$services.option.save(this.$route.params.id, this.$route.query)
}
},
async created() {
this.isProjectAdmin = await this.$services.member.isProjectAdmin(this.$route.params.id, this.getUserId)
}
}
</script>

5
frontend/middleware/check-admin.js

@ -6,11 +6,12 @@ export default _.debounce(async function({ app, store, route, redirect }) {
} catch(e) {
redirect('/projects')
}
const role = store.getters['projects/getCurrentUserRole']
const userId = store.getters['auth/getUserId']
const isProjectAdmin = await app.$services.member.isProjectAdmin(route.params.id, userId)
const projectRoot = app.localePath('/projects/' + route.params.id)
const path = route.fullPath.replace(/\/$/g, '')
if (role.is_project_admin || path === projectRoot || path.startsWith(projectRoot + '/dataset')) {
if (isProjectAdmin || path === projectRoot || path.startsWith(projectRoot + '/dataset')) {
return
}

6
frontend/pages/projects/_id/dataset/index.vue

@ -74,6 +74,7 @@
<script lang="ts">
import Vue from 'vue'
import { mapGetters } from 'vuex'
import _ from 'lodash'
import DocumentList from '@/components/example/DocumentList.vue'
import FormDelete from '@/components/example/FormDelete.vue'
@ -142,7 +143,8 @@ export default Vue.extend({
} else {
return 'text'
}
}
},
...mapGetters('auth', ['getUserId'])
},
watch: {
@ -155,7 +157,7 @@ export default Vue.extend({
async created() {
this.project = await this.$services.project.findById(this.projectId)
this.isProjectAdmin = this.project.current_users_role.is_project_admin
this.isProjectAdmin = await this.$services.member.isProjectAdmin(this.projectId, this.getUserId)
},
methods: {

12
frontend/repositories/member/apiMemberRepository.ts

@ -9,28 +9,28 @@ export class APIMemberRepository implements MemberRepository {
) {}
async list(projectId: string): Promise<MemberItem[]> {
const url = `/projects/${projectId}/roles`
const url = `/projects/${projectId}/members`
const response = await this.request.get(url)
const responseItems: MemberItemResponse[] = response.data
return responseItems.map(item => MemberItem.valueOf(item))
}
async create(projectId: string, item: MemberItem): Promise<MemberItem> {
const url = `/projects/${projectId}/roles`
const url = `/projects/${projectId}/members`
const response = await this.request.post(url, item.toObject())
const responseItem: MemberItemResponse = response.data
return MemberItem.valueOf(responseItem)
}
async update(projectId: string, item: MemberItem): Promise<MemberItem> {
const url = `/projects/${projectId}/roles/${item.id}`
const url = `/projects/${projectId}/members/${item.id}`
const response = await this.request.patch(url, item.toObject())
const responseItem: MemberItemResponse = response.data
return MemberItem.valueOf(responseItem)
}
async bulkDelete(projectId: string, labelIds: number[]): Promise<void> {
const url = `/projects/${projectId}/roles`
await this.request.delete(url, { ids: labelIds })
async bulkDelete(projectId: string, memberIds: number[]): Promise<void> {
const url = `/projects/${projectId}/members`
await this.request.delete(url, { ids: memberIds })
}
}

11
frontend/services/application/member/memberApplicationService.ts

@ -11,7 +11,7 @@ export class MemberApplicationService {
try {
const items = await this.repository.list(id)
return items.map(item => new MemberDTO(item))
} catch(e) {
} catch(e: any) {
throw new Error(e.response.data.detail)
}
}
@ -20,7 +20,7 @@ export class MemberApplicationService {
try {
const member = new MemberItem(0, item.user, item.role, item.username, item.rolename)
await this.repository.create(projectId, member)
} catch(e) {
} catch(e: any) {
throw new Error(e.response.data.detail)
}
}
@ -29,7 +29,7 @@ export class MemberApplicationService {
try {
const member = new MemberItem(item.id, item.user, item.role, item.username, item.rolename)
await this.repository.update(projectId, member)
} catch(e) {
} catch(e: any) {
throw new Error(e.response.data.detail)
}
}
@ -38,4 +38,9 @@ export class MemberApplicationService {
const ids = items.map(item => item.id)
return this.repository.bulkDelete(projectId, ids)
}
public async isProjectAdmin(projectId: string, userId: number): Promise<boolean> {
const items = await this.repository.list(projectId)
return items.some((item) => item.id === userId && item.isProjectAdmin)
}
}

4
frontend/services/application/project/projectData.ts

@ -1,11 +1,10 @@
import { ProjectReadItem, CurrentUsersRole, ProjectType } from '~/domain/models/project/project'
import { ProjectReadItem, ProjectType } from '~/domain/models/project/project'
export class ProjectDTO {
id: number
name: string
description: string
guideline: string
current_users_role: CurrentUsersRole
projectType: ProjectType
updatedAt: string
enableRandomOrder: boolean
@ -26,7 +25,6 @@ export class ProjectDTO {
this.name = item.name
this.description = item.description
this.guideline = item.guideline
this.current_users_role = item.current_users_role
this.projectType = item.project_type
this.updatedAt = item.updated_at
this.enableRandomOrder = item.random_order

Loading…
Cancel
Save