Exemplo n.º 1
0
def postpone_expiration_date(store, user_id, rtip_id):
    rtip = db_access_rtip(store, user_id, rtip_id)

    if not (GLSettings.memory_copy.can_postpone_expiration or rtip.receiver.can_postpone_expiration):

        raise errors.ExtendTipLifeNotEnabled

    log.debug(
        "Postpone check: Node %s, Receiver %s"
        % (
            "True" if GLSettings.memory_copy.can_postpone_expiration else "False",
            "True" if rtip.receiver.can_postpone_expiration else "False",
        )
    )

    db_postpone_expiration_date(rtip)

    log.debug(
        " [%s] in %s has postponed expiration time to %s"
        % (
            rtip.receiver.user.name,
            datetime_to_pretty_str(datetime_now()),
            datetime_to_pretty_str(rtip.internaltip.expiration_date),
        )
    )
Exemplo n.º 2
0
    def dump_field_entry(self, output, field, entry, indent_n):

        field_type = field['type']

        if field_type == 'checkbox':
            for k, v in entry.items():
                for option in field['options']:
                    if k == option.get('id', '') and v is True:
                        output += indent(indent_n) + option['label'] + '\n'
        elif field_type in ['multichoice', 'selectbox']:
            for option in field['options']:
                if entry.get('value', '') == option['id']:
                    output += indent(indent_n) + option['label'] + '\n'
        elif field_type == 'date':
            date = entry.get('value')
            if date is not None:
                output += indent(indent_n) + ISO8601_to_pretty_str(date) + '\n'
        elif field_type == 'daterange':
            daterange = entry.get('value')
            if daterange is not None:
                daterange = daterange.split(':')
                output += indent(indent_n) + datetime_to_pretty_str(datetime.fromtimestamp(int(daterange[0])/1000)) + '\n'
                output += indent(indent_n) + datetime_to_pretty_str(datetime.fromtimestamp(int(daterange[1])/1000)) + '\n'
        elif field_type == 'tos':
            answer = '☑' if entry.get('value', '') is True else '☐'
            output += indent(indent_n) + answer + '\n'
        elif field_type == 'fieldgroup':
            output = self.dump_fields(output, field['children'], entry, indent_n)
        else:
            output += indent_text(entry.get('value', ''), indent_n) + '\n'

        return output + '\n'
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def postpone_expiration_date(store, user_id, rtip_id):
    rtip = db_access_rtip(store, user_id, rtip_id)

    if not (GLSettings.memory_copy.can_postpone_expiration
            or rtip.receiver.can_postpone_expiration):

        raise errors.ExtendTipLifeNotEnabled

    log.debug(
        "Postpone check: Node %s, Receiver %s" %
        ("True" if GLSettings.memory_copy.can_postpone_expiration else "False",
         "True" if rtip.receiver.can_postpone_expiration else "False"))

    db_postpone_expiration_date(rtip)

    log.debug(" [%s] in %s has postponed expiration time to %s" %
              (rtip.receiver.user.name, datetime_to_pretty_str(datetime_now()),
               datetime_to_pretty_str(rtip.internaltip.expiration_date)))
Exemplo n.º 6
0
def postpone_expiration_date(store, user_id, tip_id):
    rtip = db_access_tip(store, user_id, tip_id)

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

    if not (node.can_postpone_expiration or
                rtip.receiver.can_postpone_expiration):

        raise errors.ExtendTipLifeNotEnabled

    log.debug("Postpone check: Node %s, Receiver %s" % (
       "True" if node.can_postpone_expiration else "False",
       "True" if rtip.receiver.can_postpone_expiration else "False"
    ))

    db_postpone_expiration_date(rtip)

    log.debug(" [%s] in %s has postponed expiration time to %s" % (
        rtip.receiver.name,
        datetime_to_pretty_str(datetime_now()),
        datetime_to_pretty_str(rtip.internaltip.expiration_date)))
Exemplo n.º 7
0
 def test_datetime_to_pretty_str(self):
     self.assertEqual(utility.datetime_to_pretty_str(None), "Thursday 01 January 1970 00:00 (UTC)")
     self.assertEqual(
         utility.datetime_to_pretty_str(utility.datetime_null()), "Thursday 01 January 1970 00:00 (UTC)"
     )
Exemplo n.º 8
0
 def test_datetime_to_pretty_str(self):
     self.assertEqual(utility.datetime_to_pretty_str(None), 'Thursday 01 January 1970 00:00 (UTC)')
     self.assertEqual(utility.datetime_to_pretty_str(utility.datetime_null()), 'Thursday 01 January 1970 00:00 (UTC)')
Exemplo n.º 9
0
 def ExpirationDate(self):
     date = ISO8601_to_datetime(
         self.data['signup']['registration_date']) + timedelta(days=30)
     return datetime_to_pretty_str(date)
Exemplo n.º 10
0
def get_receiver_list_wb(store, wb_tip_id, language):
    """
    @return:
        This function contain the serialization of the receiver, this function is
        used only by /wbtip/receivers API

        The returned struct contain information on read/unread messages
    """

    wb_tip = store.find(WhistleblowerTip,
                        WhistleblowerTip.id == unicode(wb_tip_id)).one()

    if not wb_tip:
        raise errors.TipReceiptNotFound

    # This part of code is used only in the short time between the first
    # WB access and the delivery schedule. In this moment
    # wb_tip.internaltips.receivertips is EMPTY, therefore we force
    # the Receivers values below
    if not wb_tip.internaltip.receivertips.count():
        receiver_list = []

        log.debug("Early access from the WB to the Tip (creation_date: %s UTC),"\
                  " Receiver not yet present: fallback on receiver list" %
                  datetime_to_pretty_str(wb_tip.creation_date))

        for receiver in wb_tip.internaltip.receivers:

            # This is the reduced version of Receiver serialization
            receiver_desc = {
                "name": receiver.name,
                "id": receiver.id,
                "gpg_key_status": receiver.gpg_key_status,
                "access_counter": 0,
                "unread_messages": 0,
                "read_messages": 0,
                "your_messages": 0,
                "creation_date": datetime_to_ISO8601(datetime_now()),
                # XXX ReceiverTip last activity ?
            }

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

            receiver_list.append(receiver_desc)

        return receiver_list
    else:
        receiver_list = []
        for rtip in wb_tip.internaltip.receivertips:

            your_messages = store.find(
                Message, Message.receivertip_id == rtip.id,
                Message.type == u'whistleblower').count()

            unread_messages = store.find(Message,
                                         Message.receivertip_id == rtip.id,
                                         Message.type == u'receiver',
                                         Message.visualized == False).count()

            read_messages = store.find(Message,
                                       Message.receivertip_id == rtip.id,
                                       Message.type == u'receiver',
                                       Message.visualized == True).count()

            # if you change something here, check also 20 lines before!
            receiver_desc = {
                "name": rtip.receiver.name,
                "id": rtip.receiver.id,
                "access_counter": rtip.access_counter,
                "unread_messages": unread_messages,
                "read_messages": read_messages,
                "your_messages": your_messages,
                "creation_date": datetime_to_ISO8601(datetime_now()),
                # XXX ReceiverTip last activity ?
            }

            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
Exemplo n.º 11
0
 def ExpirationDate(self):
     return datetime_to_pretty_str(self.data['expiration_date'])
Exemplo n.º 12
0
 def EarliestExpirationDate(self):
     return datetime_to_pretty_str(self.data['earliest_expiration_date'])
Exemplo n.º 13
0
 def EventTime(self):
     return datetime_to_pretty_str(self.data['message']['creation_date'])
Exemplo n.º 14
0
 def ExpirationDate(self):
     date = ISO8601_to_datetime(self.data['signup']['registration_date']) + timedelta(days=30)
     return datetime_to_pretty_str(date)
Exemplo n.º 15
0
def get_receiver_list_wb(store, wb_tip_id, language=GLSetting.memory_copy.default_language):
    """
    @return:
        This function contain the serialization of the receiver, this function is
        used only by /wbtip/receivers API

        The returned struct contain information on read/unread messages
    """

    wb_tip = store.find(WhistleblowerTip,
                        WhistleblowerTip.id == unicode(wb_tip_id)).one()

    if not wb_tip:
        raise errors.TipReceiptNotFound

    # This part of code is used only in the short time between the first
    # WB access and the delivery schedule. In this moment
    # wb_tip.internaltips.receivertips is EMPTY, therefore we force
    # the Receivers values below
    if not wb_tip.internaltip.receivertips.count():
        receiver_list = []

        log.debug("Early access from the WB to the Tip (creation_date: %s UTC),"\
                  " Receiver not yet present: fallback on receiver list" %
                  datetime_to_pretty_str(wb_tip.creation_date))

        for receiver in wb_tip.internaltip.receivers:

            # This is the reduced version of Receiver serialization
            receiver_desc = {
                "name": receiver.name,
                "id": receiver.id,
                "gpg_key_status": receiver.gpg_key_status,
                "tags": receiver.tags,
                "access_counter" : 0,
                "unread_messages" : 0,
                "read_messages" : 0,
                "your_messages" : 0,
                "creation_date" : datetime_to_ISO8601(datetime_now()),
                # XXX ReceiverTip last activity ?
            }

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

        return receiver_list
    else:
        receiver_list = []
        for rtip in wb_tip.internaltip.receivertips:


            your_messages = store.find(Message,
                                       Message.receivertip_id == rtip.id,
                                       Message.type == u'whistleblower').count()

            unread_messages = store.find(Message,
                                         Message.receivertip_id == rtip.id,
                                         Message.type == u'receiver',
                                         Message.visualized == False).count()

            read_messages = store.find(Message,
                                       Message.receivertip_id == rtip.id,
                                       Message.type == u'receiver',
                                       Message.visualized == True).count()

            # if you change something here, check also 20 lines before!
            receiver_desc = {
                "name": rtip.receiver.name,
                "id": rtip.receiver.id,
                "tags": rtip.receiver.tags,
                "access_counter" : rtip.access_counter,
                "unread_messages" : unread_messages,
                "read_messages" : read_messages,
                "your_messages" : your_messages,
                "creation_date" : datetime_to_ISO8601(datetime_now()),
                # XXX ReceiverTip last activity ?
            }

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

            receiver_list.append(receiver_desc)

        return receiver_list
Exemplo n.º 16
0
 def ExpirationDate(self):
     date = self.data['signup']['registration_date'] + timedelta(30)
     return datetime_to_pretty_str(date)