Пример #1
0
 async def get(self, *, did: document.convert_doc_id, page: int=1):
   ddoc = await discussion.inc_views(self.domain_id, did)
   if self.has_priv(builtin.PRIV_USER_PROFILE):
     dsdoc = await discussion.get_status(self.domain_id, ddoc['doc_id'], self.user['_id'])
   else:
     dsdoc = None
   vnode, (drdocs, pcount, drcount) = await asyncio.gather(
       discussion.get_vnode(self.domain_id, discussion.node_id(ddoc)),
       pagination.paginate(discussion.get_multi_reply(self.domain_id, ddoc['doc_id']),
                           page, self.REPLIES_PER_PAGE))
   if not vnode:
     vnode = builtin.VNODE_MISSING
   elif vnode['doc_type'] == document.TYPE_PROBLEM and vnode.get('hidden', False):
     self.check_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN)
   # TODO(twd2): do more visibility check eg. contest
   uids = {ddoc['owner_uid']}
   uids.update(drdoc['owner_uid'] for drdoc in drdocs)
   for drdoc in drdocs:
     if 'reply' in drdoc:
       uids.update(drrdoc['owner_uid'] for drrdoc in drdoc['reply'])
   if 'owner_uid' in vnode:
     uids.add(vnode['owner_uid'])
   udict, dudict = await asyncio.gather(user.get_dict(uids),
                                        domain.get_dict_user_by_uid(self.domain_id, uids))
   path_components = self.build_path(
       (self.translate('discussion_main'), self.reverse_url('discussion_main')),
       (vnode['title'], node_url(self, 'discussion_node', discussion.node_id(ddoc))),
       (ddoc['title'], None))
   self.render('discussion_detail.html', page_title=ddoc['title'], path_components=path_components,
               ddoc=ddoc, dsdoc=dsdoc, drdocs=drdocs, page=page, pcount=pcount, drcount=drcount,
               vnode=vnode, udict=udict, dudict=dudict)
Пример #2
0
 async def get(self, *, did: document.convert_doc_id, page: int=1):
   ddoc = await discussion.inc_views(self.domain_id, did)
   if self.has_priv(builtin.PRIV_USER_PROFILE):
     dsdoc = await discussion.get_status(self.domain_id, ddoc['doc_id'], self.user['_id'])
   else:
     dsdoc = None
   vnode, (drdocs, pcount, drcount) = await asyncio.gather(
       discussion.get_vnode(self.domain_id, discussion.node_id(ddoc)),
       pagination.paginate(discussion.get_multi_reply(self.domain_id, ddoc['doc_id']),
                           page, self.REPLIES_PER_PAGE))
   if not vnode:
     vnode = builtin.VNODE_MISSING
   elif vnode['doc_type'] == document.TYPE_PROBLEM and vnode.get('hidden', False):
     self.check_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN)
   # TODO(twd2): do more visibility check eg. contest
   uids = {ddoc['owner_uid']}
   uids.update(drdoc['owner_uid'] for drdoc in drdocs)
   for drdoc in drdocs:
     if 'reply' in drdoc:
       uids.update(drrdoc['owner_uid'] for drrdoc in drdoc['reply'])
   if 'owner_uid' in vnode:
     uids.add(vnode['owner_uid'])
   udict, dudict = await asyncio.gather(user.get_dict(uids),
                                        domain.get_dict_user_by_uid(self.domain_id, uids))
   path_components = self.build_path(
       (self.translate('discussion_main'), self.reverse_url('discussion_main')),
       (vnode['title'], node_url(self, 'discussion_node', discussion.node_id(ddoc))),
       (ddoc['title'], None))
   self.render('discussion_detail.html', page_title=ddoc['title'], path_components=path_components,
               ddoc=ddoc, dsdoc=dsdoc, drdocs=drdocs, page=page, pcount=pcount, drcount=drcount,
               vnode=vnode, udict=udict, dudict=dudict)
Пример #3
0
 async def post_delete(self, *, did: document.convert_doc_id):
   ddoc = await discussion.get(self.domain_id, did)
   if not ddoc:
     raise error.DiscussionNotFoundError(self.domain_id, did)
   if not self.own(ddoc, builtin.PERM_DELETE_DISCUSSION_SELF):
     self.check_perm(builtin.PERM_DELETE_DISCUSSION)
   await oplog.add(self.user['_id'], oplog.TYPE_DELETE_DOCUMENT, doc=ddoc)
   await discussion.delete(self.domain_id, did)
   self.json_or_redirect(node_url(self, 'discussion_node', discussion.node_id(ddoc)))
Пример #4
0
 async def post_delete(self, *, did: document.convert_doc_id, **kwargs):
     did = document.convert_doc_id(did)
     ddoc = await discussion.get(self.domain_id, did)
     if not ddoc:
         raise error.DiscussionNotFoundError(self.domain_id, did)
     if not self.own(ddoc, builtin.PERM_DELETE_DISCUSSION_SELF):
         self.check_perm(builtin.PERM_DELETE_DISCUSSION)
     await discussion.delete(self.domain_id, did)
     self.json_or_redirect(
         node_url(self, 'discussion_node', discussion.node_id(ddoc)))
Пример #5
0
 async def post_delete(self, *, did: document.convert_doc_id):
     ddoc = await discussion.get(self.domain_id, did)
     if not ddoc:
         raise error.DiscussionNotFoundError(self.domain_id, did)
     if not self.own(ddoc, builtin.PERM_DELETE_DISCUSSION_SELF):
         self.check_perm(builtin.PERM_DELETE_DISCUSSION)
     await oplog.add(self.user['_id'], oplog.TYPE_DELETE_DOCUMENT, doc=ddoc)
     await discussion.delete(self.domain_id, did)
     self.json_or_redirect(
         node_url(self, 'discussion_node', discussion.node_id(ddoc)))
Пример #6
0
 async def get(self, *, did: document.convert_doc_id, page: int = 1):
     ddoc = await discussion.inc_views(self.domain_id, did)
     if self.has_priv(builtin.PRIV_USER_PROFILE):
         dsdoc = await discussion.get_status(self.domain_id, ddoc['doc_id'],
                                             self.user['_id'])
     else:
         dsdoc = None
     vnode, (drdocs, pcount, drcount) = await asyncio.gather(
         discussion.get_vnode(self.domain_id, discussion.node_id(ddoc)),
         pagination.paginate(
             discussion.get_multi_reply(self.domain_id, ddoc['doc_id']),
             page, self.REPLIES_PER_PAGE))
     uids = {ddoc['owner_uid']}
     uids.update(drdoc['owner_uid'] for drdoc in drdocs)
     for drdoc in drdocs:
         if 'reply' in drdoc:
             uids.update(drrdoc['owner_uid'] for drrdoc in drdoc['reply'])
     udict, dudict = await asyncio.gather(
         user.get_dict(uids),
         domain.get_dict_user_by_uid(self.domain_id, uids))
     path_components = self.build_path(
         (self.translate('discussion_main'),
          self.reverse_url('discussion_main')),
         (vnode['title'],
          node_url(self, 'discussion_node', discussion.node_id(ddoc))),
         (ddoc['title'], None))
     self.render('discussion_detail.html',
                 page_title=ddoc['title'],
                 path_components=path_components,
                 ddoc=ddoc,
                 dsdoc=dsdoc,
                 drdocs=drdocs,
                 page=page,
                 pcount=pcount,
                 drcount=drcount,
                 vnode=vnode,
                 udict=udict,
                 dudict=dudict)