Skip to content

Commit

Permalink
增加工单变更记录
Browse files Browse the repository at this point in the history
  • Loading branch information
welliamcao committed Apr 6, 2020
1 parent 6889485 commit 2bd1bf2
Show file tree
Hide file tree
Showing 34 changed files with 2,390 additions and 1,011 deletions.
1 change: 0 additions & 1 deletion OpsManage/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
'deploy',
'orders',
'wiki',
'filemanage',
'cicd',
'sched',
'django_celery_beat',
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
## QQ交流群
![image](https://github.com/welliamcao/OpsManage/blob/master/demo_imgs/qq_group.png)

## Docker构建OpsManage
[传送门](https://github.com/welliamcao/OpsManage/wiki/Docker%E6%9E%84%E5%BB%BAOpsManage)
<!--## Docker构建OpsManage
[传送门](https://github.com/welliamcao/OpsManage/wiki/Docker%E6%9E%84%E5%BB%BAOpsManage)-->

## 安装环境配置
一、安装Python
Expand Down Expand Up @@ -101,7 +101,6 @@ mysql>\q
# /usr/local/python3/bin/python3 manage.py makemigrations account
# /usr/local/python3/bin/python3 manage.py makemigrations wiki
# /usr/local/python3/bin/python3 manage.py makemigrations orders
# /usr/local/python3/bin/python3 manage.py makemigrations filemanage
# /usr/local/python3/bin/python3 manage.py makemigrations navbar
# /usr/local/python3/bin/python3 manage.py makemigrations databases
# /usr/local/python3/bin/python3 manage.py makemigrations asset
Expand Down
2 changes: 1 addition & 1 deletion apps/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def to_json(self):
"username":self.username,
"is_staff":self.is_staff,
"is_active":self.is_active,
"date_joined":self.date_joined,
"date_joined":self.date_joined.strftime('%Y-%m-%d %H:%M:%S'),
"name":self.name,
"mobile":self.mobile,
"email":self.email,
Expand Down
20 changes: 17 additions & 3 deletions apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,31 @@ def create(self, data):
class OrderSerializer(serializers.ModelSerializer):
create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S",required=False)
modify_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S",required=False)
start_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S",required=False)
end_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S",required=False)
expire = serializers.SerializerMethodField(read_only=True,required=False)
class Meta:
model = Order_System
fields = ('id','order_subject','order_user','order_status','order_cancel',
'order_type','order_level','create_time','modify_time','order_executor')
fields = ('id','order_subject','order_user','order_audit_status','order_mark',
'order_type','order_level','create_time','modify_time','order_executor',
'end_time','start_time',"expire","order_execute_status")
extra_kwargs = {
'order_subject': {'required': False},
'order_user':{'required': False},
'order_cancel':{'required': False},
'order_type':{'required': False},
'order_executor':{'required': False},
}

def get_expire(self,obj):
if obj.is_expired() and obj.is_unexpired():#未到期
return 1

elif obj.is_unexpired() == 0 and obj.is_expired(): #还未到期,而且还未到工单执行时间
return 2

elif obj.is_expired() == 0: #过期
return 0

class DataBaseServerSerializer(serializers.ModelSerializer):
detail = serializers.SerializerMethodField(read_only=True,required=False)
Expand Down Expand Up @@ -529,7 +543,7 @@ class Meta:
class OrdersNoticeConfigSerializer(serializers.ModelSerializer):
class Meta:
model = Order_Notice_Config
fields = ('id','order_type','grant_group','mode','number')
fields = ('id','order_type','mode')

class IPVSSerializer(serializers.ModelSerializer):
sip = serializers.CharField(source='ipvs_assets.server_assets.ip', read_only=True)
Expand Down
8 changes: 6 additions & 2 deletions apps/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
url(r'^assets/tags/(?P<id>[0-9]+)/$',assets_api.assets_tags),

url(r'^account/user/$', account_api.user_list),
url(r'^account/user/(?P<id>[0-9]+)/$',account_api.user_detail),
url(r'^account/user/(?P<id>[0-9]+)/$',account_api.user_detail),
url(r'^account/user/superior/$',account_api.UserSuperior.as_view()),
url(r'^account/group/$',account_api.GROUP_LIST.as_view()),
url(r'^account/role/$', account_api.role_list),
url(r'^account/role/(?P<id>[0-9]+)/$',account_api.role_detail),
Expand Down Expand Up @@ -86,11 +87,14 @@
url(r'^db/user/(?P<uid>[0-9]+)/server/(?P<sid>[0-9]+)/db/$', db_api.DB_USER_SERVER_DBLIST.as_view()),
url(r'^db/user/(?P<uid>[0-9]+)/db/(?P<did>[0-9]+)/table/$', db_api.db_user_db_table_list),
url(r'^db/user/(?P<uid>[0-9]+)/db/(?P<did>[0-9]+)/sql/$', db_api.DB_USER_SERVER_DBSQL.as_view()),

url(r'^orders/list/$', orders_api.OrdersPaginator.as_view()),
url(r'^orders/(?P<id>[0-9]+)/$', orders_api.order_detail),
url(r'^orders/(?P<pk>[0-9]+)/$', orders_api.OrderDetail.as_view()),
url(r'^orders/logs/(?P<pk>[0-9]+)/$', orders_api.OrderLogsDetail.as_view()),
url(r'^orders/count/$', orders_api.order_count),
url(r'^orders/notice/$', orders_api.notice_config),
url(r'^orders/notice/(?P<id>[0-9]+)/$', orders_api.notice_config_detail),

url(r'^sql/custom/$', db_api.DB_CUSTOM_SQL.as_view()),
url(r'^sql/custom/(?P<id>[0-9]+)/$', db_api.sql_custom_detail),
url(r'^apps/list/$', cicd_api.project_list),
Expand Down
8 changes: 7 additions & 1 deletion apps/api/views/account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rest_framework.response import Response
from rest_framework.decorators import api_view
from utils.logger import logger
from dao.account import StructureManage
from dao.account import StructureManage,UsersManage
from mptt.templatetags.mptt_tags import cache_tree_children
from django.http import Http404
from django.contrib.auth.decorators import permission_required
Expand Down Expand Up @@ -64,6 +64,12 @@ def user_detail(request, id,format=None):
snippet.delete()
return Response(status=status.HTTP_204_NO_CONTENT)


class UserSuperior(APIView,UsersManage):

def get(self,request,*args,**kwargs):
return Response(self.get_user_superior(request.user))

@api_view(['GET', 'POST' ])
def role_list(request,format=None):
"""
Expand Down
109 changes: 85 additions & 24 deletions apps/api/views/orders_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# _#_ coding:utf-8 _*_
import json
from django.db.models import Q
from rest_framework import viewsets,permissions
from api import serializers
from orders.models import *
from rest_framework import status
Expand All @@ -11,34 +11,95 @@
from rest_framework.decorators import api_view
from django.contrib.auth.decorators import permission_required
from orders.models import Order_System
from dao.orders import ORDERS_COUNT_RBT
from dao.orders import ORDERS_COUNT_RBT,OrderBase
from django.http import JsonResponse
from django.core.exceptions import PermissionDenied


@api_view(['PUT', 'DELETE'])
@permission_required('orders.orders_change_order_system',raise_exception=True)
def order_detail(request, id,format=None):
"""
Retrieve, update or delete a server assets instance.
"""
try:
snippet = Order_System.objects.get(id=id)
except Order_System.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
class OrderDetail(APIView,OrderBase):

if request.method == 'PUT':
serializer = serializers.OrderSerializer(snippet, data=request.data)
if request.user.is_superuser or request.user.id == serializer.order_executor:
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
def get_object(self, pk):
try:
return Order_System.objects.get(id=pk)
except Order_System.DoesNotExist:
raise Http404

def check_perms(self, request, pk):
order = self.get_object(pk)

if request.user.is_superuser:
return order

# if order.is_expired() and order.is_unexpired():

if request.user.id == order.order_user or request.user.id == order.order_executor:
return order

raise PermissionDenied()

def get(self, request, pk, *args, **kwargs):

order = self.check_perms(request, pk)

return Response(self.order_detail(order))

def put(self, request, pk, *args, **kwargs):

order_mark = None

snippet = self.get_object(pk)

data = request.data.copy()

if "order_audit_status" in data.keys():
data = self.update_order_progress(data)

if "order_mark" in data.keys():
order_mark = data.get("order_mark")

if "order_content" in data.keys():#更新工单内容

if snippet.order_execute_status in [0,1]:

if hasattr(snippet, 'service_audit_order'):

snippet.service_audit_order.order_content = data.get("order_content")
snippet.service_audit_order.save()

self.record_order_operation(snippet.id, snippet.order_audit_status, snippet.order_execute_status, request.user, data.get("order_content"))

return Response(snippet.to_json())
else:

return Response(status=status.HTTP_400_BAD_REQUEST)
else:#更新工单审核状体或者工单进度

serializer = serializers.OrderSerializer(snippet, data=data)

if request.user.is_superuser or request.user.id == serializer.order_executor:
if serializer.is_valid():
serializer.save()
self.record_order_operation(snippet.id, snippet.order_audit_status, snippet.order_execute_status, request.user, order_mark)
return Response(serializer.data)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

elif request.method == 'DELETE':
if not request.user.has_perm('orders.orders_delete_order_system'):
return Response(status=status.HTTP_403_FORBIDDEN)
snippet.delete()
return Response(status=status.HTTP_204_NO_CONTENT)


class OrderLogsDetail(APIView):

def get_object(self, pk):
try:
return Order_System.objects.get(id=pk)
except Order_System.DoesNotExist:
raise Http404

def get(self, request, pk, *args, **kwargs):
order = self.get_object(pk)

if request.user.is_superuser or request.user.id == order.order_user or request.user.id == order.order_executor:
return Response([ ds.to_json() for ds in OrderLog.objects.filter(order=order.id).order_by("-id") ])

return Response(status=status.HTTP_403_FORBIDDEN)

@api_view(['GET'])
def order_count(request,format=None):
Expand Down
Empty file removed apps/filemanage/__init__.py
Empty file.
6 changes: 0 additions & 6 deletions apps/filemanage/admin.py

This file was deleted.

51 changes: 0 additions & 51 deletions apps/filemanage/models.py

This file was deleted.

Loading

0 comments on commit 2bd1bf2

Please sign in to comment.