Esempio n. 1
0
def create_comment(session, tid, wbtip_id, user_key, content):
    wbtip, itip = session.query(models.WhistleblowerTip, models.InternalTip)\
                         .filter(models.WhistleblowerTip.id == wbtip_id,
                                 models.InternalTip.id == models.WhistleblowerTip.id,
                                 models.InternalTip.tid == tid).one_or_none()

    if wbtip is None:
        raise errors.ModelNotFound(models.WhistleblowerTip)

    itip.update_date = itip.wb_last_access = datetime_now()

    comment = models.Comment()
    comment.internaltip_id = wbtip_id
    comment.type = u'whistleblower'

    if itip.crypto_tip_pub_key:
        comment.content = base64.b64encode(GCE.asymmetric_encrypt(itip.crypto_tip_pub_key, content)).decode()
    else:
        comment.content = content

    session.add(comment)
    session.flush()

    ret = serialize_comment(session, comment)
    ret['content'] = content

    return ret
Esempio n. 2
0
def create_comment(session, tid, wbtip_id, content):
    wbtip, itip = db_get(session,
                         (models.WhistleblowerTip, models.InternalTip),
                         (models.WhistleblowerTip.id == wbtip_id,
                          models.InternalTip.id == models.WhistleblowerTip.id,
                          models.InternalTip.enable_two_way_comments.is_(True),
                          models.InternalTip.status != 'closed',
                          models.InternalTip.tid == tid))

    itip.update_date = itip.wb_last_access = datetime_now()

    _content = content
    if itip.crypto_tip_pub_key:
        _content = base64.b64encode(GCE.asymmetric_encrypt(itip.crypto_tip_pub_key, content)).decode()

    comment = models.Comment()
    comment.internaltip_id = wbtip_id
    comment.type = 'whistleblower'
    comment.content = _content
    session.add(comment)
    session.flush()

    ret = serialize_comment(session, comment)
    ret['content'] = content

    return ret
Esempio n. 3
0
def create_comment(session, tid, user_id, rtip_id, content):
    """
    Transaction for registering a new comment
    :param session: An ORM session
    :param tid: A tenant ID
    :param user_id: The user id of the user creating the comment
    :param rtip_id: The rtip associated to the comment to be created
    :param content: The content of the comment
    :return: A serialized descriptor of the comment
    """
    rtip, itip = db_access_rtip(session, tid, user_id, rtip_id)

    itip.update_date = rtip.last_access = datetime_now()

    _content = content
    if itip.crypto_tip_pub_key:
        _content = base64.b64encode(
            GCE.asymmetric_encrypt(itip.crypto_tip_pub_key, content)).decode()

    comment = models.Comment()
    comment.internaltip_id = itip.id
    comment.type = 'receiver'
    comment.author_id = rtip.receiver_id
    comment.content = _content
    session.add(comment)
    session.flush()

    ret = serialize_comment(session, comment)
    ret['content'] = content

    return ret
Esempio n. 4
0
def create_comment(store, wbtip_id, request):
    internaltip = models.db_get(store, models.InternalTip, id=wbtip_id)

    internaltip.update_date = internaltip.wb_last_access = datetime_now()

    comment = models.Comment()
    comment.content = request['content']
    comment.internaltip_id = wbtip_id
    comment.type = u'whistleblower'
    store.add(comment)

    return serialize_comment(store, comment)
Esempio n. 5
0
def create_comment(session, tid, wbtip_id, request):
    internaltip = session.query(models.InternalTip).filter(models.InternalTip.id == wbtip_id, models.InternalTip.tid == tid)

    internaltip.update_date = internaltip.wb_last_access = datetime_now()

    comment = models.Comment()
    comment.content = request['content']
    comment.internaltip_id = wbtip_id
    comment.type = u'whistleblower'
    session.add(comment)
    session.flush()

    return serialize_comment(session, comment)
Esempio n. 6
0
def create_comment(store, user_id, rtip_id, request):
    rtip, itip = db_access_rtip(store, user_id, rtip_id)

    itip.update_date = rtip.last_access = datetime_now()

    comment = models.Comment()
    comment.content = request['content']
    comment.internaltip_id = itip.id
    comment.type = u'receiver'
    comment.author_id = rtip.receiver_id
    store.add(comment)

    return serialize_comment(store, comment)
Esempio n. 7
0
def create_comment(session, tid, user_id, user_key, rtip_id, content):
    rtip, itip = db_access_rtip(session, tid, user_id, rtip_id)

    itip.update_date = rtip.last_access = datetime_now()

    comment = models.Comment()
    comment.internaltip_id = itip.id
    comment.type = u'receiver'
    comment.author_id = rtip.receiver_id

    if itip.crypto_tip_pub_key:
        comment.content = base64.b64encode(GCE.asymmetric_encrypt(itip.crypto_tip_pub_key, content)).decode()
    else:
        comment.content = content

    session.add(comment)
    session.flush()

    ret = serialize_comment(session, comment)
    ret['content'] = content

    return ret