示例#1
0
 def get_document(self):
     response = dict()
     response['type'] = 'document_data'
     response['document'] = dict()
     response['document']['id']=self.document.id
     response['document']['title']=self.document.title
     response['document']['contents']=self.document.contents
     response['document']['metadata']=self.document.metadata
     response['document']['settings']=self.document.settings
     response['document']['access_rights'] = get_accessrights(AccessRight.objects.filter(document__owner=self.document.owner))
     response['document']['owner'] = dict()
     response['document']['owner']['id']=self.document.owner.id
     response['document']['owner']['name']=self.document.owner.readable_name
     response['document']['owner']['avatar']=avatar_url(self.document.owner,80)            
     response['document']['owner']['team_members']=[]
     for team_member in self.document.owner.leader.all():
         tm_object = dict()
         tm_object['id'] = team_member.member.id
         tm_object['name'] = team_member.member.readable_name
         tm_object['avatar'] = avatar_url(team_member.member,80)
         response['document']['owner']['team_members'].append(tm_object)
     response['document_values'] = dict()    
     response['document_values']['is_owner']=self.is_owner
     response['document_values']['rights'] = self.access_rights
     if self.is_new:
         response['document_values']['is_new'] = True
     if not self.is_owner:
         response['user']=dict()
         response['user']['id']=self.user.id
         response['user']['name']=self.user.readable_name
         response['user']['avatar']=avatar_url(self.user,80)
     if self.in_control:
         response['document_values']['control']=True
     response['document_values']['session_id']= self.id
     self.write_message(response)
示例#2
0
 def get_document(self):
     response = dict()
     response['type'] = 'document_data'
     response['document'] = dict()
     response['document']['id'] = self.document.id
     response['document']['title'] = self.document.title
     response['document']['contents'] = self.document.contents
     response['document']['metadata'] = self.document.metadata
     response['document']['settings'] = self.document.settings
     response['document']['access_rights'] = get_accessrights(
         AccessRight.objects.filter(document__owner=self.document.owner))
     response['document']['owner'] = dict()
     response['document']['owner']['id'] = self.document.owner.id
     response['document']['owner'][
         'name'] = self.document.owner.readable_name
     response['document']['owner']['avatar'] = avatar_url(
         self.document.owner, 80)
     response['document']['owner']['team_members'] = []
     for team_member in self.document.owner.leader.all():
         tm_object = dict()
         tm_object['id'] = team_member.member.id
         tm_object['name'] = team_member.member.readable_name
         tm_object['avatar'] = avatar_url(team_member.member, 80)
         response['document']['owner']['team_members'].append(tm_object)
     response['document_values'] = dict()
     response['document_values']['is_owner'] = self.is_owner
     response['document_values']['rights'] = self.access_rights
     if self.is_new:
         response['document_values']['is_new'] = True
     if not self.is_owner:
         response['user'] = dict()
         response['user']['id'] = self.user.id
         response['user']['name'] = self.user.readable_name
         response['user']['avatar'] = avatar_url(self.user, 80)
     if self.in_control:
         response['document_values']['control'] = True
     response['document_values']['session_id'] = self.id
     self.write_message(response)
示例#3
0
    def send_document(self):
        response = dict()
        response['type'] = 'document_data'
        response['document'] = dict()
        response['document']['id'] = self.doc['id']
        response['document']['version'] = self.doc['version']
        if self.doc['diff_version'] < self.doc['version']:
            print('!!!diff version issue!!!')
            self.doc['diff_version'] = self.doc['version']
            self.doc["last_diffs"] = []
        response['document']['title'] = self.doc['title']
        response['document']['contents'] = self.doc['contents']
        response['document']['metadata'] = self.doc['metadata']
        response['document']['settings'] = self.doc['settings']
        document_owner = self.doc['db'].owner
        access_rights = get_accessrights(
            AccessRight.objects.filter(
                document__owner=document_owner))
        response['document']['access_rights'] = access_rights

        # TODO: switch on filtering when choose workflow and have UI for
        # assigning roles to users
        # filtered_comments = filter_comments_by_role(
        #     DocumentWS.sessions[self.user_info.document_id]["comments"],
        #     access_rights,
        #     'editing',
        #     self.user_info
        # )
        response['document']['comments'] = self.doc["comments"]
        # response['document']['comments'] = filtered_comments
        response['document']['comment_version'] = self.doc["comment_version"]
        response['document']['access_rights'] = get_accessrights(
            AccessRight.objects.filter(document__owner=document_owner))
        response['document']['owner'] = dict()
        response['document']['owner']['id'] = document_owner.id
        response['document']['owner']['name'] = document_owner.readable_name
        response['document']['owner'][
            'avatar'] = avatar_url(document_owner, 80)
        response['document']['owner']['team_members'] = []

        for team_member in document_owner.leader.all():
            tm_object = dict()
            tm_object['id'] = team_member.member.id
            tm_object['name'] = team_member.member.readable_name
            tm_object['avatar'] = avatar_url(team_member.member, 80)
            response['document']['owner']['team_members'].append(tm_object)
        response['document_values'] = dict()
        response['document_values']['is_owner'] = self.user_info.is_owner
        response['document_values']['rights'] = self.user_info.access_rights
        if self.doc['version'] > self.doc['diff_version']:
            print('!!!diff version issue!!!')
            self.doc['diff_version'] = self.doc['version']
            self.doc["last_diffs"] = []
        elif self.doc['diff_version'] > self.doc['version']:
            needed_diffs = self.doc['diff_version'] - self.doc['version']
            response['document_values']['last_diffs'] = self.doc[
                "last_diffs"][-needed_diffs:]
        else:
            response['document_values']['last_diffs'] = []
        if self.user_info.is_new:
            response['document_values']['is_new'] = True
        if not self.user_info.is_owner:
            response['user'] = dict()
            response['user']['id'] = self.user_info.user.id
            response['user']['name'] = self.user_info.user.readable_name
            response['user']['avatar'] = avatar_url(self.user_info.user, 80)
#        if self.doc['in_control'] == self.id:
#            response['document_values']['control']=True
        response['document_values']['session_id'] = self.id
        self.write_message(response)
示例#4
0
    def send_document(self):
        response = dict()
        response['type'] = 'document_data'
        response['document'] = dict()
        response['document']['id'] = self.doc['id']
        response['document']['version'] = self.doc['version']
        if self.doc['diff_version'] < self.doc['version']:
            print('!!!diff version issue!!!')
            self.doc['diff_version'] = self.doc['version']
            self.doc["last_diffs"] = []
        response['document']['title'] = self.doc['title']
        response['document']['contents'] = self.doc['contents']
        response['document']['metadata'] = self.doc['metadata']
        response['document']['settings'] = self.doc['settings']
        document_owner = self.doc['db'].owner
        access_rights = get_accessrights(
            AccessRight.objects.filter(document__owner=document_owner))
        response['document']['access_rights'] = access_rights

        # TODO: switch on filtering when choose workflow and have UI for
        # assigning roles to users
        # filtered_comments = filter_comments_by_role(
        #     DocumentWS.sessions[self.user_info.document_id]["comments"],
        #     access_rights,
        #     'editing',
        #     self.user_info
        # )
        response['document']['comments'] = self.doc["comments"]
        # response['document']['comments'] = filtered_comments
        response['document']['comment_version'] = self.doc["comment_version"]
        response['document']['access_rights'] = get_accessrights(
            AccessRight.objects.filter(document__owner=document_owner))
        response['document']['owner'] = dict()
        response['document']['owner']['id'] = document_owner.id
        response['document']['owner']['name'] = document_owner.readable_name
        response['document']['owner']['avatar'] = avatar_url(
            document_owner, 80)
        response['document']['owner']['team_members'] = []

        for team_member in document_owner.leader.all():
            tm_object = dict()
            tm_object['id'] = team_member.member.id
            tm_object['name'] = team_member.member.readable_name
            tm_object['avatar'] = avatar_url(team_member.member, 80)
            response['document']['owner']['team_members'].append(tm_object)
        response['document_values'] = dict()
        response['document_values']['is_owner'] = self.user_info.is_owner
        response['document_values']['rights'] = self.user_info.access_rights
        if self.doc['version'] > self.doc['diff_version']:
            print('!!!diff version issue!!!')
            self.doc['diff_version'] = self.doc['version']
            self.doc["last_diffs"] = []
        elif self.doc['diff_version'] > self.doc['version']:
            needed_diffs = self.doc['diff_version'] - self.doc['version']
            response['document_values']['last_diffs'] = self.doc["last_diffs"][
                -needed_diffs:]
        else:
            response['document_values']['last_diffs'] = []
        if self.user_info.is_new:
            response['document_values']['is_new'] = True
        if not self.user_info.is_owner:
            response['user'] = dict()
            response['user']['id'] = self.user_info.user.id
            response['user']['name'] = self.user_info.user.readable_name
            response['user']['avatar'] = avatar_url(self.user_info.user, 80)


#        if self.doc['in_control'] == self.id:
#            response['document_values']['control']=True
        response['document_values']['session_id'] = self.id
        self.write_message(response)
示例#5
0
 def send_document(self):
     response = dict()
     response['type'] = 'doc_data'
     doc_owner = self.doc['db'].owner
     response['doc_info'] = {
         'id': self.doc['id'],
         'is_owner': self.user_info.is_owner,
         'access_rights': self.user_info.access_rights,
         'owner': {
             'id': doc_owner.id,
             'name': doc_owner.readable_name,
             'avatar': avatar_url(doc_owner, 80),
             'team_members': []
         }
     }
     response['doc'] = {
         'v': self.doc['version'],
         'contents': self.doc['contents'],
         'bibliography': self.doc['bibliography'],
         'images': {}
     }
     for dimage in DocumentImage.objects.filter(document_id=self.doc['id']):
         image = dimage.image
         field_obj = {
             'id': image.id,
             'title': dimage.title,
             'image': image.image.url,
             'file_type': image.file_type,
             'added': mktime(image.added.timetuple()) * 1000,
             'checksum': image.checksum,
             'cats': []
         }
         if image.thumbnail:
             field_obj['thumbnail'] = image.thumbnail.url
             field_obj['height'] = image.height
             field_obj['width'] = image.width
         response['doc']['images'][image.id] = field_obj
     if self.user_info.access_rights == 'read-without-comments':
         response['doc']['comments'] = []
     elif self.user_info.access_rights == 'review':
         # Reviewer should only get his/her own comments
         filtered_comments = {}
         for key, value in self.doc["comments"].items():
             if value["user"] == self.user_info.user.id:
                 filtered_comments[key] = value
         response['doc']['comments'] = filtered_comments
     else:
         response['doc']['comments'] = self.doc["comments"]
     for team_member in doc_owner.leader.all():
         tm_object = dict()
         tm_object['id'] = team_member.member.id
         tm_object['name'] = team_member.member.readable_name
         tm_object['avatar'] = avatar_url(team_member.member, 80)
         response['doc_info']['owner']['team_members'].append(tm_object)
     collaborators = get_accessrights(
         AccessRight.objects.filter(document__owner=doc_owner))
     response['doc_info']['collaborators'] = collaborators
     if self.user_info.is_owner:
         the_user = self.user_info.user
         response['doc_info']['owner']['email'] = the_user.email
         response['doc_info']['owner']['username'] = the_user.username
         response['doc_info']['owner']['first_name'] = the_user.first_name
         response['doc_info']['owner']['last_name'] = the_user.last_name
     else:
         the_user = self.user_info.user
         response['user'] = dict()
         response['user']['id'] = the_user.id
         response['user']['name'] = the_user.readable_name
         response['user']['avatar'] = avatar_url(the_user, 80)
         response['user']['email'] = the_user.email
         response['user']['username'] = the_user.username
         response['user']['first_name'] = the_user.first_name
         response['user']['last_name'] = the_user.last_name
     response['doc_info']['session_id'] = self.id
     self.send_message(response)
示例#6
0
    def send_document(self):
        response = dict()
        response['type'] = 'doc_data'
        response['doc'] = dict()
        response['doc']['id'] = self.doc['id']
        response['doc']['version'] = self.doc['version']
        if self.doc['diff_version'] < self.doc['version']:
            print('!!!diff version issue!!!')
            self.doc['diff_version'] = self.doc['version']
            self.doc["last_diffs"] = []
        response['doc']['title'] = self.doc['title']
        response['doc']['contents'] = self.doc['contents']
        response['doc']['metadata'] = self.doc['metadata']
        response['doc']['settings'] = self.doc['settings']
        document_owner = self.doc['db'].owner
        access_rights = get_accessrights(
            AccessRight.objects.filter(
                document__owner=document_owner))
        response['doc']['access_rights'] = access_rights

        if (self.user_info.access_rights == 'read-without-comments'):
            response['doc']['comments'] = []
        elif (self.user_info.access_rights == 'review'):
            # Reviewer should only get his/her own comments
            filtered_comments = {}
            for key, value in self.doc["comments"].items():
                if value["user"] == self.user_info.user.id:
                    filtered_comments[key] = value
            response['doc']['comments'] = filtered_comments
        else:
            response['doc']['comments'] = self.doc["comments"]
        response['doc']['comment_version'] = self.doc["comment_version"]
        response['doc']['access_rights'] = get_accessrights(
            AccessRight.objects.filter(document__owner=document_owner))
        response['doc']['owner'] = dict()
        response['doc']['owner']['id'] = document_owner.id
        response['doc']['owner']['name'] = document_owner.readable_name
        response['doc']['owner'][
            'avatar'] = avatar_url(document_owner, 80)
        response['doc']['owner']['team_members'] = []

        for team_member in document_owner.leader.all():
            tm_object = dict()
            tm_object['id'] = team_member.member.id
            tm_object['name'] = team_member.member.readable_name
            tm_object['avatar'] = avatar_url(team_member.member, 80)
            response['doc']['owner']['team_members'].append(tm_object)
        response['doc_info'] = dict()
        response['doc_info']['is_owner'] = self.user_info.is_owner
        response['doc_info']['rights'] = self.user_info.access_rights
        if self.doc['version'] > self.doc['diff_version']:
            print('!!!diff version issue!!!')
            self.doc['diff_version'] = self.doc['version']
            self.doc["last_diffs"] = []
        elif self.doc['diff_version'] > self.doc['version']:
            needed_diffs = self.doc['diff_version'] - self.doc['version']
            # We only send those diffs needed by the receiver.
            response['doc_info']['unapplied_diffs'] = self.doc[
                "last_diffs"][-needed_diffs:]
        else:
            response['doc_info']['unapplied_diffs'] = []
        if not self.user_info.is_owner:
            response['user'] = dict()
            response['user']['id'] = self.user_info.user.id
            response['user']['name'] = self.user_info.user.readable_name
            response['user']['avatar'] = avatar_url(self.user_info.user, 80)
        response['doc_info']['session_id'] = self.id
        self.write_message(response)
示例#7
0
    def send_document(self):
        response = dict()
        response['type'] = 'doc_data'
        response['doc'] = dict()
        response['doc']['id'] = self.doc['id']
        response['doc']['version'] = self.doc['version']
        if self.doc['diff_version'] < self.doc['version']:
            print('!!!diff version issue!!!')
            self.doc['diff_version'] = self.doc['version']
            self.doc["last_diffs"] = []
        response['doc']['title'] = self.doc['title']
        response['doc']['contents'] = self.doc['contents']
        response['doc']['metadata'] = self.doc['metadata']
        response['doc']['settings'] = self.doc['settings']
        doc_owner = self.doc['db'].owner
        access_rights = get_accessrights(
            AccessRight.objects.filter(
                document__owner=doc_owner))
        response['doc']['access_rights'] = access_rights

        if self.user_info.access_rights == 'read-without-comments':
            response['doc']['comments'] = []
        elif self.user_info.access_rights == 'review':
            # Reviewer should only get his/her own comments
            filtered_comments = {}
            for key, value in self.doc["comments"].items():
                if value["user"] == self.user_info.user.id:
                    filtered_comments[key] = value
            response['doc']['comments'] = filtered_comments
        else:
            response['doc']['comments'] = self.doc["comments"]
        response['doc']['comment_version'] = self.doc["comment_version"]
        response['doc']['access_rights'] = get_accessrights(
            AccessRight.objects.filter(document__owner=doc_owner))
        response['doc']['owner'] = dict()
        response['doc']['owner']['id'] = doc_owner.id
        response['doc']['owner']['name'] = doc_owner.readable_name
        response['doc']['owner'][
            'avatar'] = avatar_url(doc_owner, 80)
        response['doc']['owner']['team_members'] = []

        for team_member in doc_owner.leader.all():
            tm_object = dict()
            tm_object['id'] = team_member.member.id
            tm_object['name'] = team_member.member.readable_name
            tm_object['avatar'] = avatar_url(team_member.member, 80)
            response['doc']['owner']['team_members'].append(tm_object)
        response['doc_info'] = dict()
        response['doc_info']['is_owner'] = self.user_info.is_owner
        response['doc_info']['rights'] = self.user_info.access_rights
        if self.doc['version'] > self.doc['diff_version']:
            print('!!!diff version issue!!!')
            self.doc['diff_version'] = self.doc['version']
            self.doc["last_diffs"] = []
        elif self.doc['diff_version'] > self.doc['version']:
            needed_diffs = self.doc['diff_version'] - self.doc['version']
            # We only send those diffs needed by the receiver.
            response['doc_info']['unapplied_diffs'] = self.doc[
                "last_diffs"][-needed_diffs:]
        else:
            response['doc_info']['unapplied_diffs'] = []
        if self.user_info.is_owner:
            the_user = self.user_info.user
            response['doc']['owner']['email'] = the_user.email
            response['doc']['owner']['username'] = the_user.username
            response['doc']['owner']['first_name'] = the_user.first_name
            response['doc']['owner']['last_name'] = the_user.last_name
            response['doc']['owner']['email'] = the_user.email
        else:
            the_user = self.user_info.user
            response['user'] = dict()
            response['user']['id'] = the_user.id
            response['user']['name'] = the_user.readable_name
            response['user']['avatar'] = avatar_url(the_user, 80)
            response['user']['email'] = the_user.email
            response['user']['username'] = the_user.username
            response['user']['first_name'] = the_user.first_name
            response['user']['last_name'] = the_user.last_name
            response['user']['email'] = the_user.email
        response['doc_info']['session_id'] = self.id
        self.write_message(response)
示例#8
0
 def send_document(self):
     response = dict()
     response['type'] = 'doc_data'
     doc_owner = self.doc['db'].owner
     response['doc_info'] = {
         'id': self.doc['id'],
         'is_owner': self.user_info.is_owner,
         'access_rights': self.user_info.access_rights,
         'owner': {
             'id': doc_owner.id,
             'name': doc_owner.readable_name,
             'username': doc_owner.username,
             'avatar': get_user_avatar_url(doc_owner)['url'],
             'team_members': []
         }
     }
     response['doc'] = {
         'v': self.doc['version'],
         'contents': self.doc['contents'],
         'bibliography': self.doc['bibliography'],
         'template': self.doc['template'],
         'images': {}
     }
     response['time'] = int(time()) * 1000
     for dimage in DocumentImage.objects.filter(document_id=self.doc['id']):
         image = dimage.image
         field_obj = {
             'id': image.id,
             'title': dimage.title,
             'image': image.image.url,
             'file_type': image.file_type,
             'added': mktime(image.added.timetuple()) * 1000,
             'checksum': image.checksum,
             'cats': []
         }
         if image.thumbnail:
             field_obj['thumbnail'] = image.thumbnail.url
             field_obj['height'] = image.height
             field_obj['width'] = image.width
         response['doc']['images'][image.id] = field_obj
     if self.user_info.access_rights == 'read-without-comments':
         response['doc']['comments'] = []
     elif self.user_info.access_rights == 'review':
         # Reviewer should only get his/her own comments
         filtered_comments = {}
         for key, value in list(self.doc["comments"].items()):
             if value["user"] == self.user_info.user.id:
                 filtered_comments[key] = value
         response['doc']['comments'] = filtered_comments
     else:
         response['doc']['comments'] = self.doc["comments"]
     for team_member in doc_owner.leader.all():
         tm_object = dict()
         tm_object['id'] = team_member.member.id
         tm_object['name'] = team_member.member.readable_name
         tm_object['username'] = team_member.member.get_username()
         tm_object['avatar'] = get_user_avatar_url(
             team_member.member
         )['url']
         response['doc_info']['owner']['team_members'].append(tm_object)
     collaborators = get_accessrights(
         AccessRight.objects.filter(document__owner=doc_owner)
     )
     response['doc_info']['collaborators'] = collaborators
     response['doc_info']['session_id'] = self.id
     self.send_message(response)