Esempio n. 1
0
 async def post_update(self,
                       *,
                       did: document.convert_doc_id,
                       title: str,
                       content: str,
                       highlight: str = None):
     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_EDIT_DISCUSSION_SELF):
         self.check_perm(builtin.PERM_EDIT_DISCUSSION)
     flags = {}
     if highlight:
         if not ddoc.get('highlight'):
             self.check_perm(builtin.PERM_HIGHLIGHT_DISCUSSION)
         flags['highlight'] = True
     else:
         flags['highlight'] = False
     ddoc = await discussion.edit(self.domain_id,
                                  did,
                                  title=title,
                                  content=content,
                                  **flags)
     self.json_or_redirect(
         self.reverse_url('discussion_detail', did=ddoc['doc_id']))
Esempio n. 2
0
 async def get(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_EDIT_DISCUSSION_SELF):
         self.check_perm(builtin.PERM_EDIT_DISCUSSION)
     self.render('discussion_edit.html', ddoc=ddoc)
Esempio n. 3
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)))
Esempio n. 4
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)))
Esempio n. 5
0
 async def get(self, *, pid: document.convert_doc_id):
     pdoc = await problem.get(self.domain_id, pid)
     if not pdoc:
         raise error.DiscussionNotFoundError(self.domain_id, pid)
     path_components = self.build_path(
         (self.translate('problem_main'), self.reverse_url('problem_main')),
         (pdoc['title'],
          self.reverse_url('problem_detail', pid=pdoc['doc_id'])),
         (self.translate('problem_edit'), None))
     self.render('problem_edit.html',
                 pdoc=pdoc,
                 page_title=pdoc['title'],
                 path_components=path_components)
Esempio n. 6
0
async def inc_views(domain_id: str, did: document.convert_doc_id):
    doc = await document.inc(domain_id, document.TYPE_DISCUSSION, did, 'views',
                             1)
    if not doc:
        raise error.DiscussionNotFoundError(domain_id, did)
    return doc