From d0a74b8ee8b16fe0253bfa3f0eccd2da769f7e50 Mon Sep 17 00:00:00 2001 From: itimor Date: Wed, 16 Sep 2020 22:47:46 +0800 Subject: [PATCH] add --- backend/core/settings/base.py | 4 +- backend/systems/permissions.py | 6 +- .../management/commands/init_ticket.py | 5 +- .../migrations/0002_ticket_relation.py | 18 + backend/tickets/models.py | 2 + backend/tickets/serializers.py | 5 + backend/tickets/views.py | 11 +- backend/workflows/models.py | 2 +- frontend/src/lang/en.js | 1 - frontend/src/lang/zh.js | 3 +- frontend/src/store/modules/permission.js | 4 +- frontend/src/views/ticket/all_ticket.vue | 2 +- frontend/src/views/ticket/c_ticket.vue | 419 ------------------ frontend/src/views/ticket/my_ticket.vue | 5 +- frontend/src/views/ticket/s_ticket.vue | 171 ++++--- frontend/src/views/ticket/u_ticket.vue | 78 ++-- 16 files changed, 195 insertions(+), 541 deletions(-) create mode 100644 backend/tickets/migrations/0002_ticket_relation.py delete mode 100644 frontend/src/views/ticket/c_ticket.vue diff --git a/backend/core/settings/base.py b/backend/core/settings/base.py index 75aff1d..733323c 100644 --- a/backend/core/settings/base.py +++ b/backend/core/settings/base.py @@ -118,8 +118,8 @@ 'DEFAULT_PAGINATION_CLASS': 'common.pagination.StandardResultsSetPagination', 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.AllowAny', - # 'rest_framework.permissions.IsAuthenticated', - # 'systems.permissions.IsOwnerRoles', + 'rest_framework.permissions.IsAuthenticated', + 'systems.permissions.IsOwnerRoles', ), 'DEFAULT_FILTER_BACKENDS': ( 'django_filters.rest_framework.DjangoFilterBackend', diff --git a/backend/systems/permissions.py b/backend/systems/permissions.py index 2bba119..8673f53 100644 --- a/backend/systems/permissions.py +++ b/backend/systems/permissions.py @@ -18,6 +18,7 @@ '/api/sys/auth/jwt-token-auth/', '/api/sys/auth/getuserinfo/', '/api/sys/auth/getmenubutons/', + '/api/sys/user/', ] @@ -42,8 +43,9 @@ def check_permission(request, perm): class IsOwnerRoles(BasePermission): def has_permission(self, request, view): - app = view.get_view_name().split()[0].lower() - perm = 'view_' + app + app = view.get_view_name().split() + object = ''.join(app[:-1]).lower() + perm = 'view_{}'.format(object) return check_permission(request, perm) def has_object_permission(self, request, view, obj): diff --git a/backend/tickets/management/commands/init_ticket.py b/backend/tickets/management/commands/init_ticket.py index 980b284..393eb85 100644 --- a/backend/tickets/management/commands/init_ticket.py +++ b/backend/tickets/management/commands/init_ticket.py @@ -20,7 +20,7 @@ def handle(self, *args, **options): menumodel = Menu.objects.create(name='编辑工单', code='u_ticket', curl='/u_ticket/:id', icon='u_ticket', sequence=10, type=2, hidden=True, active_menu='/new_ticket', parent_id=ticketmenu.id) init_menu(menumodel) - menumodel = Menu.objects.create(name='审核工单', code='s_ticket', curl='/s_ticket/:id', icon='s_ticket', sequence=10, type=2, + menumodel = Menu.objects.create(name='审批工单', code='s_ticket', curl='/s_ticket/:id', icon='s_ticket', sequence=10, type=2, hidden=True, active_menu='/todo_ticket', parent_id=ticketmenu.id) init_menu(menumodel) menumodel = Menu.objects.create(name='我的工单', code='my_ticket', curl='/my_ticket', icon='my_ticket', sequence=30, type=2, @@ -32,7 +32,4 @@ def handle(self, *args, **options): menumodel = Menu.objects.create(name='所有工单', code='all_ticket', curl='/all_ticket', icon='all_ticket', sequence=90, type=2, no_cache=True, parent_id=ticketmenu.id) init_menu(menumodel) - menumodel = Menu.objects.create(name='查看工单', code='c_ticket', curl='/c_ticket/:id', icon='list', sequence=100, type=2, - hidden=True, active_menu='/my_ticket', parent_id=ticketmenu.id) - init_menu(menumodel) self.stdout.write(self.style.SUCCESS('初始化完成')) diff --git a/backend/tickets/migrations/0002_ticket_relation.py b/backend/tickets/migrations/0002_ticket_relation.py new file mode 100644 index 0000000..1fda8f7 --- /dev/null +++ b/backend/tickets/migrations/0002_ticket_relation.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.3 on 2020-09-16 13:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tickets', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='ticket', + name='relation', + field=models.TextField(blank=True, default='', help_text='创建人、处理人,用于查询', verbose_name='工单关联人'), + ), + ] diff --git a/backend/tickets/models.py b/backend/tickets/models.py index 87ebd21..3ac1953 100644 --- a/backend/tickets/models.py +++ b/backend/tickets/models.py @@ -19,6 +19,8 @@ class Ticket(BaseModel): state = models.ForeignKey(State, on_delete=models.CASCADE, verbose_name='当前状态') transition = models.ForeignKey(Transition, on_delete=models.SET_NULL, blank=True, null=True, verbose_name='进行状态') customfield = models.TextField('所有表单数据', default=[]) + relation = models.TextField('工单关联人', default='', blank=True, help_text='创建人、处理人,用于查询') + def __str__(self): return self.name diff --git a/backend/tickets/serializers.py b/backend/tickets/serializers.py index bd8d203..f4c1146 100644 --- a/backend/tickets/serializers.py +++ b/backend/tickets/serializers.py @@ -88,6 +88,11 @@ def update(self, instance, validated_data): instance.transition = validated_data.get('transition', instance.transition) instance.customfield = validated_data.get('customfield', instance.customfield) instance.memo = validated_data.get('memo', instance.memo) + + # update relation + relation = instance.relation.split(',') + relation.append(validated_data['relation']) + instance.relation = ','.join(set(relation)) instance.save() # save ticketlog diff --git a/backend/tickets/views.py b/backend/tickets/views.py index a0a171e..255d3ac 100644 --- a/backend/tickets/views.py +++ b/backend/tickets/views.py @@ -19,11 +19,14 @@ def get_serializer_class(self): return TicketSerializer def get_queryset(self): - user = User.objects.get(username=self.request.user) - if user.is_admin: + try: + user = User.objects.get(username=self.request.user) + if user.is_admin: + return Ticket.objects.all() + else: + return Ticket.objects.all().filter(relation__icontains=self.request.user).distinct() + except: return Ticket.objects.all() - else: - return Ticket.objects.all().filter(ticketuser__username=self.request.user).distinct() class TicketFlowLogViewSet(BulkModelMixin): diff --git a/backend/workflows/models.py b/backend/workflows/models.py index a1e1a57..c14d311 100644 --- a/backend/workflows/models.py +++ b/backend/workflows/models.py @@ -16,7 +16,7 @@ def __str__(self): class Meta: ordering = ['order_id'] - verbose_name = '类型' + verbose_name = '工作流类型' verbose_name_plural = verbose_name diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 0e4853e..0afbad7 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -21,7 +21,6 @@ export default { new_ticket: 'new_ticket', u_ticket: 'u_ticket', s_ticket: 's_ticket', - c_ticket: 'c_ticket', my_ticket: 'my_ticket', todo_ticket: 'todo_ticket', all_ticket: 'all_ticket', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 32164a9..72a77a8 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -20,8 +20,7 @@ export default { ticket: '工单系统', new_ticket: '新建工单', u_ticket: '编辑工单', - s_ticket: '审核工单', - c_ticket: '查看工单', + s_ticket: '审批工单', my_ticket: '我创建的', todo_ticket: '我的待办', all_ticket: '所有工单', diff --git a/frontend/src/store/modules/permission.js b/frontend/src/store/modules/permission.js index 435b5b2..e719aec 100644 --- a/frontend/src/store/modules/permission.js +++ b/frontend/src/store/modules/permission.js @@ -184,10 +184,8 @@ export const componentsMap = { // tickets new_ticket: () => import('@/views/ticket/new_ticket'), // 新建工单 - c_ticket: () => import('@/views/ticket/c_ticket'), // 查看工单 u_ticket: () => import('@/views/ticket/u_ticket'), // 编辑工单 - u_ticket: () => import('@/views/ticket/u_ticket'), // 编辑工单 - s_ticket: () => import('@/views/ticket/s_ticket'), // 处理工单 + s_ticket: () => import('@/views/ticket/s_ticket'), // 审批工单 my_ticket: () => import('@/views/ticket/my_ticket'), // 我创建的 todo_ticket: () => import('@/views/ticket/todo_ticket'), // 我的待办 all_ticket: () => import('@/views/ticket/all_ticket'), // 编辑工单 diff --git a/frontend/src/views/ticket/all_ticket.vue b/frontend/src/views/ticket/all_ticket.vue index 481ac4e..bbeb071 100644 --- a/frontend/src/views/ticket/all_ticket.vue +++ b/frontend/src/views/ticket/all_ticket.vue @@ -41,7 +41,7 @@ diff --git a/frontend/src/views/ticket/c_ticket.vue b/frontend/src/views/ticket/c_ticket.vue deleted file mode 100644 index 9690f96..0000000 --- a/frontend/src/views/ticket/c_ticket.vue +++ /dev/null @@ -1,419 +0,0 @@ - - - diff --git a/frontend/src/views/ticket/my_ticket.vue b/frontend/src/views/ticket/my_ticket.vue index 502fda0..9c84753 100644 --- a/frontend/src/views/ticket/my_ticket.vue +++ b/frontend/src/views/ticket/my_ticket.vue @@ -32,7 +32,7 @@ @@ -55,9 +55,6 @@