Esempio n. 1
0
 def put(self, request, mapID, nodeID):
     """
     修改节点信息
     :param request:
     :param mapID:
     :param nodeID:
     :return:
     """
     user = getUser(request.session.get('login'))
     mindMap = MindMap.objects.filter(mapId=mapID)
     if not mindMap.exists():
         return JsonResponse({
             'status': False,
             'errMsg': "导图不存在"
         }, status=404)
     mindMap = mindMap[0]
     if not mindMap.shareStatus:
         return JsonResponse({
             'status': False,
             'errMsg': '导图未开启共享功能'
         }, status=401)
     if not mindMap.roomMaster == user:
         coRelation = MindMapCoMember.objects.filter(
             Q(map=mindMap) &
             Q(user=user)
         )
         if not coRelation.exists():
             return JsonResponse({
                 'status': False,
                 'errMsg': '你对该导图没有权限'
             }, status=403)
         elif coRelation[0].auth == 'ro':
             return JsonResponse({
                 'status': False,
                 'errMsg': '你对改导图没有修改权限'
             }, status=403)
     node = MindNode.objects.filter(
         Q(nodeId=nodeID) &
         Q(belong_Map=mindMap)
     )
     if not node.exists():
         return JsonResponse({
             'status': False,
             'errMsg': '该节点不存在'
         }, status=404)
     node = node[0]
     params = request.body
     jsonParams = json.loads(params.decode('utf-8'))
     if jsonParams.get('content') is not None:
         node.content = jsonParams.get('content')
     node.save()
     mindMap.last_mod_date = now()
     mindMap.save()
     return JsonResponse({
         'status': True,
         'nodeID': node.nodeId,
         'parent_node': node.parent_node,
         'content': node.content,
         'mapID': mindMap.mapId
     })
Esempio n. 2
0
 def delete(self, request, shareID):
     """
     删除在线导图
     :param request:
     :param shareID:
     :return:
     """
     mindmap = MindMap.objects.filter(mapId=shareID)
     if not mindmap.exists():
         return JsonResponse({
             'status': False,
             'errMsg': '导图不存在'
         },
                             status=404)
     mindmap = mindmap[0]
     user = getUser(email=request.session.get('login'))
     if mindmap.roomMaster != user:
         return JsonResponse({
             'status': False,
             'errMsg': '你不是导图所有者,不能进行操作'
         },
                             status=401)
     MindNode.objects.filter(belong_Map=mindmap).delete()
     mindmap.delete()
     return JsonResponse({
         'status': True,
         'shareID': shareID,
         'mapName': mindmap.mapName,
         'roomMaster': {
             'name': user.nickname,
             'id': user.id
         }
     })
Esempio n. 3
0
 def post(self, request):
     user = getUser(email=request.session.get('login'))
     params = request.body
     jsonParams = json.loads(params.decode('utf-8'))
     if jsonParams.get('oldPassword') is None:
         return JsonResponse({
             'status': False,
             'errMsg': '旧密码不能为空'
         }, status=401)
     if jsonParams.get('newPassword') is None:
         return JsonResponse({
             'status': False,
             'errMsg': '新密码不能为空'
         }, status=401)
     if not check_password(jsonParams.get('oldPassword'), user.password.password):
         return JsonResponse({
             'status': False,
             'errMsg': '旧密码不匹配'
         }, status=401)
     newPassword = make_password(jsonParams.get('newPassword'))
     user.password.password = newPassword
     user.password.save()
     return JsonResponse({
         'status': True,
         'user': {
             'id': user.id,
             'nickname': user.nickname
         }
     })
Esempio n. 4
0
 def post(self, request, shareID):
     """
     加入导图协作
     :param request:
     :param shareID:
     :return:
     """
     params = request.body
     jsonParams = json.loads(params.decode('utf-8'))
     mindMap = MindMap.objects.filter(mapId=shareID)
     if not mindMap.exists():
         return JsonResponse({
             'status': False,
             'errMsg': '导图不存在'
         },
                             status=404)
     mindMap = mindMap[0]
     user = getUser(email=request.session.get("login"))
     if mindMap.roomMaster == user:
         return JsonResponse({
             'status': False,
             'errMsg': '你是导图所有者'
         },
                             status=401)
     if MindMapCoMember.objects.filter(Q(map=mindMap)
                                       & Q(user=user)).exists():
         return JsonResponse({
             'status': False,
             'errMsg': '你已经是导图协作成员了'
         },
                             status=401)
     if not mindMap.shareStatus:
         return JsonResponse({
             'status': False,
             'errMsg': '导图已经关闭共享了'
         },
                             status=401)
     if not mindMap.roomPassword == jsonParams.get('password', ''):
         return JsonResponse({
             'status': False,
             'errMsg': '密码错误'
         },
                             status=401)
     MindMapCoMember.objects.create(map=mindMap, user=user, auth='rw')
     return JsonResponse({
         'status': True,
         'shareID': shareID,
         'user': {
             'name': user.nickname,
             'id': user.id
         },
         'mapName': mindMap.mapName,
         'roomMaster': {
             'name': mindMap.roomMaster.nickname,
             'id': mindMap.roomMaster.id
         }
     })
Esempio n. 5
0
 def delete(self, request):
     """
     登出
     :param request:
     :return:
     """
     user = getUser(email=request.session.get('login'))
     request.session['login'] = None
     return JsonResponse({'status': True, 'id': user.id})
Esempio n. 6
0
 def get(self, request):
     """
     获取头像base64
     :param request:
     :return:
     """
     user = getUser(email=request.session.get('login'))
     return JsonResponse({
         'status': True,
         'head': user.head
     })
Esempio n. 7
0
 def get(self, request):
     """
     获取个人信息
     :param request:
     :return:
     """
     user = getUser(email=request.session.get('login'))
     userDict = model_to_dict(user, fields=self.FIELDS)
     return JsonResponse({
         'status': True,
         'user': userDict
     })
Esempio n. 8
0
 def get(self, request, shareID):
     """
     获取在线导图详细
     :param request:
     :param shareID:
     :return:
     """
     try:
         mindmap = MindMap.objects.filter(mapId=shareID)
         if not mindmap.exists():
             return JsonResponse({
                 'status': False,
                 'errMsg': '导图不存在'
             },
                                 status=404)
         mindmap = mindmap[0]
         # 获取在线导图节点信息
         mind_node_obj = MindNode.objects.filter(belong_Map=mindmap)
         mind_node_dict = [
             model_to_dict(obj, fields=self.FIELDS) for obj in mind_node_obj
         ]
         # 获取权限信息
         user = getUser(request.session.get('login'))
         if user == mindmap.roomMaster:  # 导图创建者
             auth = 'rw'
         else:
             coMember = MindMapCoMember.objects.filter(
                 Q(map=mindmap) & Q(user=user))
             if not coMember.exists():
                 # 对导图没有权限
                 return JsonResponse({
                     'status': True,
                     'errMsg': '你对该导图没有权限'
                 },
                                     status=401)
             if not mindmap.shareStatus:
                 return JsonResponse({'status': False, 'errMsg': '导图未开启共享'})
             coMember = coMember[0]
             auth = coMember.auth
         return JsonResponse({
             'status': True,
             'shareId': shareID,
             'name': mindmap.mapName,
             'roomMaster': {
                 'name': mindmap.roomMaster.nickname,
                 'id': mindmap.roomMaster.id
             },
             'auth': auth,
             'node': mind_node_dict
         })
     except Exception as e:
         print(e)
Esempio n. 9
0
 def put(self, request):
     user = getUser(email=request.session.get('login'))
     params = request.body
     jsonParams = json.loads(params.decode('utf-8'))
     if jsonParams.get('nickname') is not None:
         user.nickname = jsonParams.get('nickname')
     if jsonParams.get('sex') is not None:
         user.sex = jsonParams.get('sex')
     if jsonParams.get('signature') is not None:
         user.signature = jsonParams.get('signature')
     user.save()
     userDict = model_to_dict(user, fields=self.FIELDS)
     return JsonResponse({
         'status': True,
         'user': userDict
     })
Esempio n. 10
0
 def get(self, request):
     """
     检查是否登录
     :param request:
     :return:
     """
     if request.session.get('login', None):
         return JsonResponse({
             'status': True,
             'id': getUser(request.session.get('login')).id
         })
     else:
         return JsonResponse({
             'status': False,
             'errMsg': '你还未登录'
         },
                             status=401)
Esempio n. 11
0
 def post(self, request):
     """
     创建在线导图/本地首次开启共享
     :param request:
     :return:
     """
     try:
         params = request.body
         print(params.decode('utf8', 'ignore'))
         jsonParams = json.loads(params.decode('utf8', 'ignore'))
         user = getUser(email=request.session.get('login'))
         mapId = self.newShareID()
         newMindMap = MindMap.objects.create(
             mapId=mapId,
             mapName=jsonParams.get('name'),
             roomMaster=user,
             roomPassword=jsonParams.get('password'))
         node_list = jsonParams.get('node')
         for node in node_list:
             if node['parent_node'] == 0:
                 MindNode.objects.create(
                     nodeId=node['nodeId'],
                     content=node['content'],
                     type='root',
                     parent_node=0,
                     belong_Map=newMindMap  # 导图id可以作为唯一
                 )
             else:
                 MindNode.objects.create(nodeId=node['nodeId'],
                                         content=node['content'],
                                         type='seed',
                                         parent_node=node['parent_node'],
                                         belong_Map=newMindMap)
         return JsonResponse({
             'status': True,
             'shareID': newMindMap.mapId,
             'roomMaster': {
                 'name': user.nickname,
                 'id': user.id
             }
         })
     except Exception as e:
         print(e)
Esempio n. 12
0
 def delete(self, request, shareID):
     """
     关闭导图协作
     :param request:
     :param shareID:
     :return:
     """
     mindmap = MindMap.objects.filter(mapId=shareID)
     if not mindmap.exists():
         return JsonResponse({
             'status': False,
             'errMsg': '导图不存在'
         },
                             status=404)
     mindmap = mindmap[0]
     user = getUser(email=request.session.get('login'))
     if mindmap.roomMaster != user:
         return JsonResponse({
             'status': False,
             'errMsg': '你不是导图所有者,不能进行操作'
         },
                             status=401)
     if not mindmap.shareStatus:
         return JsonResponse({
             'status': False,
             'errMsg': '导图还未开启共享'
         },
                             status=401)
     mindmap.shareStatus = False
     mindmap.last_mod_date = now()
     mindmap.save()
     return JsonResponse({
         'status': True,
         'roomMaster': {
             'name': user.nickname,
             'id': user.id
         },
         'mapName': mindmap.mapName,
         'shareID': shareID
     })
Esempio n. 13
0
 def get(self, request):
     """
     获取在线导图列表
     :param request:
     :return:
     """
     user = getUser(request.session.get('login'))
     coMap = MindMapCoMember.objects.filter(user=user)
     coMapList = [co.map_id for co in coMap]
     masterMap = MindMap.objects.filter(roomMaster=user)
     coMap = MindMap.objects.filter(mapId__in=coMapList)
     dict1 = [
         model_to_dict(mapobj, fields=self.FIELDS) for mapobj in masterMap
     ]
     for di in dict1:
         di['auth'] = 'rw'
     dict2 = [model_to_dict(mapobj, fields=self.FIELDS) for mapobj in coMap]
     for di in dict2:
         di['auth'] = MindMapCoMember.objects.get(
             Q(map_id=di['mapId']) & Q(user=user)).auth
     mapDict = dict1 + dict2
     return JsonResponse({'status': True, 'mapList': mapDict})
Esempio n. 14
0
 def put(self, request):
     """
     修改头像
     :param request:
     :return:
     """
     user = getUser(email=request.session.get('login'))
     params = request.body
     jsonParams = json.loads(params.decode('utf-8'))
     if jsonParams.get('head') is None:
         return JsonResponse({
             'status': False,
             'errMsg': '上传头像为空'
         })
     user.head = jsonParams.get('head')
     user.save()
     return JsonResponse({
         'status': True,
         'user': {
             'id': user.id,
             'nickname': user.nickname
         }
     })
Esempio n. 15
0
 def delete(self, request, shareID):
     """
     退出导图协作
     :param request:
     :param shareID:
     :return:
     """
     mindMap = MindMap.objects.filter(mapId=shareID)
     if not mindMap.exists():
         return JsonResponse({
             'status': False,
             'errMsg': '导图不存在'
         },
                             status=404)
     mindMap = mindMap[0]
     user = getUser(email=request.session.get("login"))
     if mindMap.roomMaster == user:
         return JsonResponse({
             'status': False,
             'errMsg': '你是导图所有者'
         },
                             status=401)
     coMember = MindMapCoMember.objects.filter(
         Q(map=mindMap) & Q(user=user))
     if not coMember.exists():
         return JsonResponse({
             'status': False,
             'errMsg': '你还不是导图的协作成员'
         },
                             status=401)
     coMember = coMember[0]
     coMember.delete()
     return JsonResponse({
         'status': False,
         'shareID': shareID,
         'mapName': mindMap.mapName
     })
Esempio n. 16
0
 def put(self, request, shareID):
     """
     再次开启共享
     :param request:
     :param shareID:
     :return:
     """
     mindmap = MindMap.objects.filter(mapId=shareID)
     if not mindmap.exists():
         return JsonResponse({
             'status': False,
             'errMsg': '导图不存在'
         },
                             status=404)
     mindmap = mindmap[0]
     user = getUser(email=request.session.get('login'))
     if mindmap.roomMaster != user:
         return JsonResponse({
             'status': False,
             'errMsg': '你不是导图所有者,不能进行操作'
         },
                             status=401)
     if mindmap.shareStatus:
         return JsonResponse({
             'status': False,
             'errMsg': '导图已经是开启分享'
         },
                             status=401)
     params = request.body
     jsonParams = json.loads(params.decode('utf-8'))
     # 删除原来所有的node
     MindNode.objects.filter(belong_Map=mindmap).delete()
     # 修改导图信息
     mindmap.mapName = jsonParams.get('mapName')
     if jsonParams.get('password') is not None:
         mindmap.roomPassword = jsonParams.get('password')
     mindmap.last_mod_date = now()
     mindmap.shareStatus = True  # 更新状态
     mindmap.last_mod_date = now()
     # 重新更新node
     nodeList = jsonParams.get('node')
     for node in nodeList:
         if node['parent_node'] == 0:
             MindNode.objects.create(
                 nodeId=node['nodeId'],
                 content=node['content'],
                 type='root',
                 parent_node=0,
                 belong_Map=mindmap  # 导图id可以作为唯一
             )
         else:
             MindNode.objects.create(nodeId=node['nodeId'],
                                     content=node['content'],
                                     type='seed',
                                     parent_node=node['parent_node'],
                                     belong_Map=mindmap)
     mindmap.save()
     return JsonResponse({
         'status': True,
         'shareID': mindmap.mapId,
         'roomMaster': {
             'name': user.nickname,
             'id': user.id
         }
     })
Esempio n. 17
0
 def post(self, request, mapID, parent_id):
     """
     新建节点
     :param request:
     :param mapID:
     :param parent_id:
     :return:
     """
     user = getUser(request.session.get('login'))
     mindMap = MindMap.objects.filter(mapId=mapID)
     if not mindMap.exists():
         return JsonResponse({
             'status': False,
             'errMsg': "导图不存在"
         }, status=404)
     mindMap = mindMap[0]
     if not mindMap.shareStatus:
         return JsonResponse({
             'status': False,
             'errMsg': '导图未开启共享功能'
         }, status=401)
     if not mindMap.roomMaster == user:
         coRelation = MindMapCoMember.objects.filter(
             Q(map=mindMap) &
             Q(user=user)
         )
         if not coRelation.exists():
             return JsonResponse({
                 'status': False,
                 'errMsg': '你对该导图没有权限'
             }, status=403)
         elif coRelation[0].auth == 'ro':
             return JsonResponse({
                 'status': False,
                 'errMsg': '你对改导图没有修改权限'
             }, status=403)
     if not MindNode.objects.filter(
         Q(nodeId=parent_id) &
         Q(belong_Map=mindMap)
     ).exists():
         return JsonResponse({
             'status': False,
             'errMsg': '父节点不存在'
         }, status=404)
     params = request.body
     jsonParams = json.loads(params.decode('utf-8'))
     newNode = MindNode.objects.create(
         content=jsonParams.get('content', ''),
         type='seed',
         parent_node=parent_id,
         belong_Map=mindMap,
         nodeId=self.newNodeID()
     )
     mindMap.last_mod_date = now()
     mindMap.save()
     return JsonResponse({
         'status': True,
         'nodeId': newNode.nodeId,
         'parent_node': parent_id,
         'map': mindMap.mapId
     })
Esempio n. 18
0
 def delete(self, request, mapID, nodeID):
     """
     删除节点及其子节点
     :param request:
     :param mapID:
     :param nodeID:
     :return:
     """
     user = getUser(request.session.get('login'))
     mindMap = MindMap.objects.filter(mapId=mapID)
     if not mindMap.exists():
         return JsonResponse({
             'status': False,
             'errMsg': "导图不存在"
         }, status=404)
     mindMap = mindMap[0]
     if not mindMap.shareStatus:
         return JsonResponse({
             'status': False,
             'errMsg': '导图未开启共享功能'
         }, status=401)
     if not mindMap.roomMaster == user:
         coRelation = MindMapCoMember.objects.filter(
             Q(map=mindMap) &
             Q(user=user)
         )
         if not coRelation.exists():
             return JsonResponse({
                 'status': False,
                 'errMsg': '你对该导图没有权限'
             }, status=403)
         elif coRelation[0].auth == 'ro':
             return JsonResponse({
                 'status': False,
                 'errMsg': '你对改导图没有修改权限'
             }, status=403)
     node = MindNode.objects.filter(
         Q(nodeId=nodeID) &
         Q(belong_Map=mindMap)
     )
     if not node.exists():
         return JsonResponse({
             'status': False,
             'errMsg': '该节点不存在'
         }, status=404)
     node = node[0]
     if node.type == 'root':
         return JsonResponse({
             'status': False,
             'errMsg': '不可以删除根节点'
         }, status=401)
     sonNode = MindNode.objects.filter(
         Q(parent_node=node.nodeId) &
         Q(belong_Map=mindMap)
     )
     # 删除所有的子节点
     sonNode.delete()
     node.delete()
     mindMap.last_mod_date = now()
     mindMap.save()
     return JsonResponse({
         'status': True,
         'nodeID': nodeID
     })