Esempio n. 1
0
def manage_pertinence(store, user_id, tip_id, vote):
    """
    Assign in ReceiverTip the expressed vote (checks if already present)
    Roll over all the rTips with a vote
    re-count the Overall Pertinence
    Assign the Overall Pertinence to the InternalTip
    """
    rtip = access_tip(store, user_id, tip_id)

    # expressed_pertinence has these meanings:
    # 0 = unassigned
    # 1 = negative vote
    # 2 = positive vote

    if rtip.expressed_pertinence:
        raise errors.TipPertinenceExpressed

    rtip.expressed_pertinence = 2 if vote else 1

    vote_sum = 0
    for rtip in rtip.internaltip.receivertips:
        if not rtip.expressed_pertinence:
            continue
        if rtip.expressed_pertinence == 1:
            vote_sum -= 1
        else:
            vote_sum += 1

    rtip.internaltip.pertinence_counter = vote_sum
    return vote_sum
Esempio n. 2
0
def db_get_tip_receiver(store, user_id, tip_id, language):
    rtip = access_tip(store, user_id, tip_id)

    # Events related to this tip and for which the email have been sent can be removed
    eventlst = store.find(
        EventLogs,
        And(EventLogs.receivertip_id == tip_id,
            EventLogs.mail_sent == True)).remove()

    tip_desc = receiver_serialize_internal_tip(rtip.internaltip, language)

    # are added here because part of ReceiverTip, not InternalTip
    tip_desc['access_counter'] = rtip.access_counter
    tip_desc['id'] = rtip.id
    tip_desc['receiver_id'] = user_id

    node = store.find(Node).one()

    tip_desc['postpone_superpower'] = (
        node.postpone_superpower
        or rtip.internaltip.context.postpone_superpower
        or rtip.receiver.postpone_superpower)

    tip_desc['can_delete_submission'] = (
        node.can_delete_submission
        or rtip.internaltip.context.can_delete_submission
        or rtip.receiver.can_delete_submission)

    return tip_desc
Esempio n. 3
0
def get_receiver_list_receiver(
        store,
        user_id,
        tip_id,
        language=GLSetting.memory_copy.default_language):

    rtip = access_tip(store, user_id, tip_id)

    receiver_list = []
    for rtip in rtip.internaltip.receivertips:

        receiver_desc = {
            "gpg_key_status": rtip.receiver.gpg_key_status,
            "can_delete_submission": rtip.receiver.can_delete_submission,
            "name": unicode(rtip.receiver.name),
            "receiver_id": unicode(rtip.receiver.id),
            "receiver_level": int(rtip.receiver.receiver_level),
            "tags": rtip.receiver.tags,
            "access_counter": rtip.access_counter,
        }

        mo = Rosetta()
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_translated(
            "description", language)

        receiver_list.append(receiver_desc)

    return receiver_list
Esempio n. 4
0
def manage_pertinence(store, user_id, tip_id, vote):
    """
    Assign in ReceiverTip the expressed vote (checks if already present)
    Roll over all the rTips with a vote
    re-count the Overall Pertinence
    Assign the Overall Pertinence to the InternalTip
    """
    rtip = access_tip(store, user_id, tip_id)

    # expressed_pertinence has these meanings:
    # 0 = unassigned
    # 1 = negative vote
    # 2 = positive vote

    if rtip.expressed_pertinence:
        raise errors.TipPertinenceExpressed

    rtip.expressed_pertinence = 2 if vote else 1

    vote_sum = 0
    for rtip in rtip.internaltip.receivertips:
        if not rtip.expressed_pertinence:
            continue
        if rtip.expressed_pertinence == 1:
            vote_sum -= 1
        else:
            vote_sum += 1

    rtip.internaltip.pertinence_counter = vote_sum
    return vote_sum
Esempio n. 5
0
def get_internaltip_receiver(store,
                             user_id,
                             tip_id,
                             language=GLSetting.memory_copy.default_language):
    rtip = access_tip(store, user_id, tip_id)

    tip_desc = receiver_serialize_internal_tip(rtip.internaltip)

    # are added here because part of ReceiverTip, not InternalTip
    tip_desc['access_counter'] = rtip.access_counter
    tip_desc['expressed_pertinence'] = rtip.expressed_pertinence
    tip_desc['id'] = rtip.id
    tip_desc['receiver_id'] = user_id

    node = store.find(Node).one()

    tip_desc['postpone_superpower'] = (
        node.postpone_superpower
        or rtip.internaltip.context.postpone_superpower
        or rtip.receiver.postpone_superpower)

    tip_desc['can_delete_submission'] = (
        node.can_delete_submission
        or rtip.internaltip.context.can_delete_submission
        or rtip.receiver.can_delete_submission)

    return tip_desc
Esempio n. 6
0
def get_comment_list_receiver(store, user_id, tip_id):
    rtip = access_tip(store, user_id, tip_id)

    comment_list = []
    for comment in rtip.internaltip.comments:
        comment_list.append(receiver_serialize_comment(comment))

    return comment_list
Esempio n. 7
0
def get_comment_list_receiver(store, user_id, tip_id):
    rtip = access_tip(store, user_id, tip_id)

    comment_list = []
    for comment in rtip.internaltip.comments:
        comment_list.append(receiver_serialize_comment(comment))

    return comment_list
Esempio n. 8
0
def download_all_files(store, user_id, tip_id):

    access_tip(store, user_id, tip_id)

    rfiles = store.find(ReceiverFile,
                        ReceiverFile.receiver_tip_id == unicode(tip_id))

    files_list = []
    for sf in rfiles:

        if sf.downloads == sf.internalfile.internaltip.download_limit:
            log.debug(
                "massive file download for %s: skipped %s (limit %d reached)" %
                (sf.receiver.name, sf.internalfile.name, sf.downloads))
            continue

        sf.downloads += 1
        files_list.append(serialize_receiver_file(sf))

    return files_list
Esempio n. 9
0
def get_files_receiver(store, user_id, tip_id):
    rtip = access_tip(store, user_id, tip_id)

    receiver_files = store.find(ReceiverFile,
        (ReceiverFile.internaltip_id == rtip.internaltip_id, ReceiverFile.receiver_id == rtip.receiver_id))

    files_list = []
    for receiverfile in receiver_files:
        internalfile = receiverfile.internalfile
        files_list.append(receiver_serialize_file(internalfile, receiverfile, tip_id))

    return files_list
Esempio n. 10
0
def create_comment_receiver(store, user_id, tip_id, request):
    rtip = access_tip(store, user_id, tip_id)

    comment = Comment()
    comment.content = request['content']
    comment.internaltip_id = rtip.internaltip.id
    comment.author = rtip.receiver.name  # The printed line
    comment.type = u'receiver'
    comment.mark = u'not notified'

    rtip.internaltip.comments.add(comment)

    return receiver_serialize_comment(comment)
Esempio n. 11
0
def create_comment_receiver(store, user_id, tip_id, request):
    rtip = access_tip(store, user_id, tip_id)

    comment = Comment()
    comment.content = request['content']
    comment.internaltip_id = rtip.internaltip.id
    comment.author = rtip.receiver.name # The printed line
    comment.type = Comment._types[0] # Receiver
    comment.mark = Comment._marker[0] # Not notified

    rtip.internaltip.comments.add(comment)

    return receiver_serialize_comment(comment)
Esempio n. 12
0
def download_file(store, user_id, tip_id, file_id):
    """
    Auth temporary disabled, just Tip_id and File_id required
    """

    access_tip(store, user_id, tip_id)

    rfile = store.find(ReceiverFile, ReceiverFile.id == unicode(file_id)).one()

    if not rfile or rfile.receiver_id != user_id:
        raise errors.FileIdNotFound

    log.debug(
        "Download of %s: %d of %d for %s" %
        (rfile.internalfile.name, rfile.downloads,
         rfile.internalfile.internaltip.download_limit, rfile.receiver.name))

    if rfile.downloads == rfile.internalfile.internaltip.download_limit:
        raise errors.DownloadLimitExceeded

    rfile.downloads += 1

    return serialize_receiver_file(rfile)
Esempio n. 13
0
def delete_internal_tip(store, user_id, tip_id):
    """
    Delete internalTip is possible only to Receiver with
    the dedicated property.
    """
    rtip = access_tip(store, user_id, tip_id)

    node = store.find(Node).one()

    if not (node.can_delete_submission
            or rtip.internaltip.context.can_delete_submission
            or rtip.receiver.can_delete_submission):
        raise errors.ForbiddenOperation

    store.remove(rtip.internaltip)
Esempio n. 14
0
def delete_internal_tip(store, user_id, tip_id):
    """
    Delete internalTip is possible only to Receiver with
    the dedicated property.
    """
    rtip = access_tip(store, user_id, tip_id)

    node = store.find(Node).one()

    if not (node.can_delete_submission or
            rtip.internaltip.context.can_delete_submission or
            rtip.receiver.can_delete_submission):
        raise errors.ForbiddenOperation

    store.remove(rtip.internaltip)
Esempio n. 15
0
def db_increment_receiver_access_count(store, user_id, tip_id):
    rtip = access_tip(store, user_id, tip_id)

    rtip.access_counter += 1
    rtip.last_access = datetime_now()

    if rtip.access_counter > rtip.internaltip.access_limit:
        raise errors.AccessLimitExceeded

    log.debug(
        "Tip %s access garanted to user %s access_counter %d on limit %d" %
        (rtip.id, rtip.receiver.name, rtip.access_counter,
         rtip.internaltip.access_limit))

    return rtip.access_counter
Esempio n. 16
0
def db_get_files_receiver(store, user_id, tip_id):
    rtip = access_tip(store, user_id, tip_id)

    receiver_files = store.find(
        ReceiverFile,
        (ReceiverFile.internaltip_id
         == rtip.internaltip_id, ReceiverFile.receiver_id == rtip.receiver_id))

    files_list = []
    for receiverfile in receiver_files:
        internalfile = receiverfile.internalfile
        files_list.append(
            receiver_serialize_file(internalfile, receiverfile, tip_id))

    return files_list
Esempio n. 17
0
def increment_receiver_access_count(store, user_id, tip_id):
    rtip = access_tip(store, user_id, tip_id)

    rtip.access_counter += 1
    rtip.last_access = datetime_now()

    if rtip.access_counter > rtip.internaltip.access_limit:
        raise errors.AccessLimitExceeded

    log.debug(
        "Tip %s access garanted to user %s access_counter %d on limit %d" %
       (rtip.id, rtip.receiver.name, rtip.access_counter, rtip.internaltip.access_limit)
    )

    return rtip.access_counter
Esempio n. 18
0
def get_messages_list(store, user_id, tip_id):

    rtip = access_tip(store, user_id, tip_id)

    msglist = store.find(Message, Message.receivertip_id == rtip.id)
    msglist.order_by(Desc(Message.creation_date))

    content_list = []
    for msg in msglist:
        content_list.append(receiver_serialize_message(msg))

        if not msg.visualized and msg.type == u'whistleblower':
            log.debug("Marking as readed message [%s] from %s" % (msg.content, msg.author))
            msg.visualized = True

    return content_list
Esempio n. 19
0
def create_message_receiver(store, user_id, tip_id, request):

    rtip = access_tip(store, user_id, tip_id)

    msg = Message()
    msg.content = request['content']
    msg.receivertip_id = rtip.id
    msg.author = rtip.receiver.name
    msg.visualized = False

    msg.type = u'receiver'
    msg.mark = u'skipped'

    store.add(msg)

    return receiver_serialize_message(msg)
Esempio n. 20
0
def get_messages_list(store, user_id, tip_id):

    rtip = access_tip(store, user_id, tip_id)

    msglist = store.find(Message, Message.receivertip_id == rtip.id)
    msglist.order_by(Desc(Message.creation_date))

    content_list = []
    for msg in msglist:
        content_list.append(receiver_serialize_message(msg))

        if not msg.visualized and msg.type == u'whistleblower':
            log.debug("Marking as readed message [%s] from %s" %
                      (msg.content, msg.author))
            msg.visualized = True

    return content_list
Esempio n. 21
0
def postpone_expiration_date(store, user_id, tip_id):
    rtip = access_tip(store, user_id, tip_id)

    node = store.find(Node).one()

    if not (node.postpone_superpower
            or rtip.internaltip.context.postpone_superpower
            or rtip.receiver.postpone_superpower):

        raise errors.ExtendTipLifeNotEnabled()
    else:
        log.debug("Postpone check: Node %s, Context %s, Receiver %s" %
                  ("True" if node.postpone_superpower else "False", "True" if
                   rtip.internaltip.context.postpone_superpower else "False",
                   "True" if rtip.receiver.postpone_superpower else "False"))

    rtip.internaltip.expiration_date = \
        utc_future_date(seconds=rtip.internaltip.context.tip_timetolive)

    log.debug(" [%s] in %s has extended expiration time to %s" %
              (rtip.receiver.name, datetime_to_pretty_str(datetime_now()),
               datetime_to_pretty_str(rtip.internaltip.expiration_date)))

    comment = Comment()
    comment.system_content = dict({
        'type':
        "1",  # the first kind of structured system_comments
        'receiver_name':
        rtip.receiver.name,
        'expire_on':
        datetime_to_ISO8601(rtip.internaltip.expiration_date)
    })

    # remind: this is put just for debug, it's never used in the flow
    # and a system comment may have nothing to say except the struct
    comment.content = "%s %s %s (UTC)" % (
        rtip.receiver.name, datetime_to_pretty_str(datetime_now()),
        datetime_to_pretty_str(rtip.internaltip.expiration_date))

    comment.internaltip_id = rtip.internaltip.id
    comment.author = u'System'
    comment.type = u'system'
    comment.mark = u'skipped'

    rtip.internaltip.comments.add(comment)
Esempio n. 22
0
def postpone_expiration_date(store, user_id, tip_id):
    rtip = access_tip(store, user_id, tip_id)

    node = store.find(Node).one()

    if not (node.postpone_superpower or
            rtip.internaltip.context.postpone_superpower or
            rtip.receiver.postpone_superpower):

        raise errors.ExtendTipLifeNotEnabled()
    else:
        log.debug("Postpone check: Node %s, Context %s, Receiver %s" %(
            "True" if node.postpone_superpower else "False",
            "True" if rtip.internaltip.context.postpone_superpower else "False",
            "True" if rtip.receiver.postpone_superpower else "False"
        ))

    rtip.internaltip.expiration_date = \
        utc_future_date(seconds=rtip.internaltip.context.tip_timetolive)

    log.debug(" [%s] in %s has extended expiration time to %s" % (
        rtip.receiver.name,
        datetime_to_pretty_str(datetime_now()),
        datetime_to_pretty_str(rtip.internaltip.expiration_date)))

    comment = Comment()
    comment.system_content = dict({
           'type': "1", # the first kind of structured system_comments
           'receiver_name': rtip.receiver.name,
           'expire_on' : datetime_to_ISO8601(rtip.internaltip.expiration_date)
    })

    # remind: this is put just for debug, it's never used in the flow
    # and a system comment may have nothing to say except the struct
    comment.content = "%s %s %s (UTC)" % (
                   rtip.receiver.name,
                   datetime_to_pretty_str(datetime_now()),
                   datetime_to_pretty_str(rtip.internaltip.expiration_date))

    comment.internaltip_id = rtip.internaltip.id
    comment.author = u'System' # The printed line
    comment.type = Comment._types[2] # System
    comment.mark = Comment._marker[4] # skipped

    rtip.internaltip.comments.add(comment)
Esempio n. 23
0
def create_message_receiver(store, user_id, tip_id, request):

    rtip = access_tip(store, user_id, tip_id)

    msg = Message()
    msg.content = request['content']
    msg.receivertip_id = rtip.id
    msg.author = rtip.receiver.name
    msg.visualized = False

    # remind: is safest use this convention, and probably we've to
    # change in the whole code the usage of Model._type[ndx]
    msg.type = u'receiver'
    msg.mark = u'skipped'

    store.add(msg)

    return receiver_serialize_message(msg)
Esempio n. 24
0
def create_message_receiver(store, user_id, tip_id, request):

    rtip = access_tip(store, user_id, tip_id)

    msg = Message()
    msg.content = request['content']
    msg.receivertip_id = rtip.id
    msg.author = rtip.receiver.name
    msg.visualized = False

    # remind: is safest use this convention, and probably we've to
    # change in the whole code the usage of Model._type[ndx]
    msg.type = u'receiver'
    msg.mark = u'skipped'

    store.add(msg)

    return receiver_serialize_message(msg)
Esempio n. 25
0
def download_all_files(store, user_id, tip_id):

    rtip = access_tip(store, user_id, tip_id)

    rfiles = store.find(ReceiverFile,
                        ReceiverFile.receiver_tip_id == unicode(tip_id))

    files_list = []
    for sf in rfiles:

        if sf.downloads == sf.internalfile.internaltip.download_limit:
            log.debug("massive file download for %s: skipped %s (limit %d reached)" % (
                sf.receiver.name, sf.internalfile.name, sf.downloads
            ))
            continue

        sf.downloads += 1
        files_list.append(serialize_receiver_file(sf))

    return files_list
Esempio n. 26
0
def delete_receiver_tip(store, user_id, tip_id):
    """
    This operation is permitted to every receiver, and trigger
    a System comment on the Tip history.
    """
    rtip = access_tip(store, user_id, tip_id)

    comment = Comment()
    comment.content = "%s personally remove from this Tip" % rtip.receiver.name
    comment.system_content = dict({ "type" : 2,
                                    "receiver_name" : rtip.receiver.name})

    comment.internaltip_id = rtip.internaltip.id
    comment.author = u'System' # The printed line
    comment.type = u'system' # Comment._types[2]
    comment.mark = u'not notified' # Comment._marker[0]

    rtip.internaltip.comments.add(comment)

    store.remove(rtip)
Esempio n. 27
0
def delete_receiver_tip(store, user_id, tip_id):
    """
    This operation is permitted to every receiver, and trigger
    a System comment on the Tip history.
    """
    rtip = access_tip(store, user_id, tip_id)

    comment = Comment()
    comment.content = "%s personally remove from this Tip" % rtip.receiver.name
    comment.system_content = dict({
        "type": 2,
        "receiver_name": rtip.receiver.name
    })

    comment.internaltip_id = rtip.internaltip.id
    comment.author = u'system'  # The printed line
    comment.type = u'system'
    comment.mark = u'not notified'

    rtip.internaltip.comments.add(comment)

    store.remove(rtip)
Esempio n. 28
0
def get_internaltip_receiver(store, user_id, tip_id, language=GLSetting.memory_copy.default_language):
    rtip = access_tip(store, user_id, tip_id)

    tip_desc = receiver_serialize_internal_tip(rtip.internaltip)

    # are added here because part of ReceiverTip, not InternalTip
    tip_desc['access_counter'] = rtip.access_counter
    tip_desc['expressed_pertinence'] = rtip.expressed_pertinence
    tip_desc['id'] = rtip.id
    tip_desc['receiver_id'] = user_id

    node = store.find(Node).one()

    tip_desc['postpone_superpower'] = (node.postpone_superpower or
                                       rtip.internaltip.context.postpone_superpower or
                                       rtip.receiver.postpone_superpower)

    tip_desc['can_delete_submission'] = (node.can_delete_submission or
                                         rtip.internaltip.context.can_delete_submission or
                                         rtip.receiver.can_delete_submission)

    return tip_desc
Esempio n. 29
0
def download_file(store, user_id, tip_id, file_id):
    """
    Auth temporary disabled, just Tip_id and File_id required
    """

    rtip = access_tip(store, user_id, tip_id)

    rfile = store.find(ReceiverFile,
                       ReceiverFile.id == unicode(file_id)).one()

    if not rfile or rfile.receiver_id != user_id:
        raise errors.FileIdNotFound

    log.debug("Download of %s: %d of %d for %s" %
              (rfile.internalfile.name, rfile.downloads,
               rfile.internalfile.internaltip.download_limit, rfile.receiver.name))

    if rfile.downloads == rfile.internalfile.internaltip.download_limit:
        raise errors.DownloadLimitExceeded

    rfile.downloads += 1

    return serialize_receiver_file(rfile)
Esempio n. 30
0
def get_receiver_list_receiver(store, user_id, tip_id, language):

    rtip = access_tip(store, user_id, tip_id)

    receiver_list = []
    for rtip in rtip.internaltip.receivertips:

        receiver_desc = {
            "gpg_key_status": rtip.receiver.gpg_key_status,
            "can_delete_submission": rtip.receiver.can_delete_submission,
            "name": unicode(rtip.receiver.name),
            "receiver_id": unicode(rtip.receiver.id),
            "access_counter": rtip.access_counter,
        }

        mo = Rosetta(rtip.receiver.localized_strings)
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_localized_attr(
            "description", language)

        receiver_list.append(receiver_desc)

    return receiver_list
Esempio n. 31
0
def get_receiver_list_receiver(store, user_id, tip_id, language=GLSetting.memory_copy.default_language):

    rtip = access_tip(store, user_id, tip_id)

    receiver_list = []
    for rtip in rtip.internaltip.receivertips:

        receiver_desc = {
            "gpg_key_status": rtip.receiver.gpg_key_status,
            "can_delete_submission": rtip.receiver.can_delete_submission,
            "name": unicode(rtip.receiver.name),
            "receiver_id": unicode(rtip.receiver.id),
            "receiver_level": int(rtip.receiver.receiver_level),
            "tags": rtip.receiver.tags,
            "access_counter": rtip.access_counter,
        }

        mo = Rosetta()
        mo.acquire_storm_object(rtip.receiver)
        receiver_desc["description"] = mo.dump_translated("description", language)

        receiver_list.append(receiver_desc)

    return receiver_list