Example #1
0
def host_edit(host, owner, room, name, processor):
    if host.name != name:
        message = deferred_gettext(
            u"Changed name of host '{}' to '{}'.".format(host.name,
                                                         name))
        host.name = name

        log_user_event(author=processor,
                       user=owner,
                       message=message.to_json())
        
    if host.owner_id != owner.id:
        message = deferred_gettext(
            u"Transferred Host '{}' to {}.".format(host.name,
                                                   owner.id))
        log_user_event(author=processor,
                       user=host.owner,
                       message=message.to_json())

        message = deferred_gettext(
            u"Transferred Host '{}' from {}.".format(host.name,
                                                     host.owner.id))
        log_user_event(author=processor,
                       user=owner,
                       message=message.to_json())

        host.owner = owner

    if host.room != room:
        migrate_user_host(host, room, processor)
Example #2
0
def edit_room(room, number, inhabitable, vo_suchname: str, address: Address,
              processor: User):
    if room.number != number:
        if Room.q.filter_by(number=number,
                            level=room.level,
                            building=room.building).filter(
                                Room.id != room.id).first() is not None:
            raise RoomAlreadyExistsException()

        log_room_event(f"Renamed room from {room.number} to {number}.",
                       processor, room)

        room.number = number

    if room.inhabitable != inhabitable:
        log_room_event(f"Changed inhabitable status to {str(inhabitable)}.",
                       processor, room)

        room.inhabitable = inhabitable

    if room.swdd_vo_suchname != vo_suchname:
        log_room_event(
            deferred_gettext("Changed VO id from {} to {}.").format(
                room.swdd_vo_suchname, vo_suchname).to_json(), processor, room)
        room.swdd_vo_suchname = vo_suchname

    if room.address != address:
        room.address = address
        log_room_event(
            deferred_gettext("Changed address to {}").format(
                str(address)).to_json(), processor, room)
        for user in room.users_sharing_address:
            user.address = room.address

    return room
Example #3
0
def edit_email(user: User,
               email: str | None,
               email_forwarded: bool,
               processor: User,
               is_confirmed: bool = False):
    """
    Changes the email address of a user and creates a log entry.
    :param user: User object to change
    :param email: New email address (empty interpreted as ``None``)
    :param email_forwarded: Boolean if emails should be forwarded
    :param processor: User object of the processor, which issues the change
    :param is_confirmed: If the email address is already confirmed
    :return:Changed user object
    """

    if not can_target(user, processor):
        raise PermissionError("cannot change email of a user with a"
                              " greater or equal permission level.")

    if not email:
        email = None
    else:
        email = email.lower()

    if email_forwarded != user.email_forwarded:
        user.email_forwarded = email_forwarded

        log_user_event(
            author=processor,
            user=user,
            message=deferred_gettext("Set e-mail forwarding to {}.").format(
                email_forwarded).to_json())

    if is_confirmed:
        user.email_confirmed = True
        user.email_confirmation_key = None

    if email == user.email:
        # email wasn't changed, do nothing
        return user

    old_email = user.email
    user.email = email

    if email is not None:
        if not is_confirmed:
            send_confirmation_email(user)
    else:
        user.email_confirmed = False
        user.email_confirmation_key = None

    message = deferred_gettext("Changed e-mail from {} to {}.")
    log_user_event(author=processor,
                   user=user,
                   message=message.format(old_email, email).to_json())
    return user
Example #4
0
def edit_switch_port(switch_port, name,  default_vlans, processor):
    if switch_port.name != name:
        message = deferred_gettext("Changed name of switch-port {} to {}.")\
            .format(switch_port.name, name)
        log_room_event(message.to_json(), processor, switch_port.switch.host.room)

        switch_port.name = name

    if switch_port.default_vlans != default_vlans:
        switch_port.default_vlans = default_vlans

        new_default_vlans_str = ', '.join(str(vlan.vid) for vlan in switch_port.default_vlans)
        message = deferred_gettext("Changed default VLANs of switch-port {} to {}.")\
            .format(switch_port.name, new_default_vlans_str)
        log_room_event(message.to_json(), processor, switch_port.switch.host.room)
Example #5
0
File: user.py Project: JuKu/pycroft
def move_out(user, comment, processor, when, end_membership=True):
    """Move out a user and may terminate relevant memberships.

    The user's room is set to ``None`` and all hosts are deleted.
    Memberships in :py:obj:`config.member_group` and
    :py:obj:`config.member_group` are terminated.  A log message is
    created including the number of deleted hosts.

    :param User user: The user to move out.
    :param unicode|None comment: An optional comment
    :param User processor: The admin who is going to move out the
        user.
    :param datetime when: The time the user is going to move out.
    :param bool end_membership: Ends membership if true

    :return: The user that moved out.
    """
    if when > session.utcnow():
        raise NotImplementedError(
            "Moving out in the future is not supported yet.")

    if end_membership:
        for group in ({
                config.member_group, config.network_access_group,
                config.external_group
        }
                      | set(user.traffic_groups)):
            remove_member_of(user, group, processor, closedopen(when, None))

        user.birthdate = None

    num_hosts = 0  # In case the chain is empty
    for num_hosts, h in enumerate(user.hosts, 1):
        session.session.delete(h)

    user.room = None

    if comment:
        message = deferred_gettext(
            u"Moved out: ({} hosts deleted). Comment: {}").format(
                num_hosts, comment)
    else:
        message = deferred_gettext(u"Moved out: ({} hosts deleted).").format(
            num_hosts)

    log_user_event(message=message.to_json(), author=processor, user=user)

    return user
Example #6
0
def remove_member_of(user, group, processor, during=UnboundedInterval):
    """Remove a user from a group in a given interval.

    The interval defaults to the unbounded interval, so that the user
    will be removed from the group at any point in time, **removing
    all memberships** in this group retroactively.

    However, a common use case is terminating a membership by setting
    ``during=closedopen(now, None)``.

    :param User user: the user
    :param Group group: the group
    :param User processor: User issuing the removal
    :param Interval during:
    """
    memberships = session.session.query(Membership).filter(
        Membership.user == user, Membership.group == group,
        Membership.active(during)).all()
    intervals = IntervalSet(
        closed(m.begins_at, m.ends_at) for m in memberships).difference(during)
    for m in memberships:
        session.session.delete(m)
    session.session.add_all(
        Membership(begins_at=i.begin, ends_at=i.end, user=user, group=group)
        for i in intervals)
    message = deferred_gettext(u"Removed from group {group} during {during}.")
    log_user_event(message=message.format(group=group.name,
                                          during=during).to_json(),
                   user=user,
                   author=processor)
Example #7
0
def remove_member_of(user, group, processor, during=UnboundedInterval):
    """Remove a user from a group in a given interval.

    The interval defaults to the unbounded interval, so that the user
    will be removed from the group at any point in time, **removing
    all memberships** in this group retroactively.

    However, a common use case is terminating a membership by setting
    ``during=closedopen(now, None)``.

    :param User user: the user
    :param Group group: the group
    :param User processor: User issuing the removal
    :param Interval during:
    """
    memberships = session.session.query(Membership).filter(
        Membership.user == user, Membership.group == group,
        Membership.active(during)).all()
    intervals = IntervalSet(
        closed(m.begins_at, m.ends_at) for m in memberships
    ).difference(during)
    for m in memberships:
        session.session.delete(m)
    session.session.add_all(
        Membership(begins_at=i.begin, ends_at=i.end, user=user, group=group)
        for i in intervals)
    message = deferred_gettext(u"Removed from group {group} during {during}.")
    log_user_event(message=message.format(group=group.name,
                                          during=during).to_json(),
                   user=user, author=processor)
Example #8
0
def make_member_of(user, group, processor, during=UnboundedInterval):
    """
    Makes a user member of a group in a given interval. If the given interval
    overlaps with an existing membership, this method will join the overlapping
    intervals together, so that there will be at most one membership for
    particular user in particular group at any given point in time.

    :param User user: the user
    :param Group group: the group
    :param User processor: User issuing the addition
    :param Interval during:
    """
    memberships = session.session.query(Membership).filter(
        Membership.user == user, Membership.group == group,
        Membership.active(during)).all()
    intervals = IntervalSet(
        closed(m.begins_at, m.ends_at) for m in memberships
    ).union(during)
    for m in memberships:
        session.session.delete(m)
    session.session.add_all(
        Membership(begins_at=i.begin, ends_at=i.end, user=user, group=group)
        for i in intervals)
    message = deferred_gettext(u"Added to group {group} during {during}.")
    log_user_event(message=message.format(group=group.name,
                                          during=during).to_json(),
                   user=user, author=processor)
Example #9
0
def block(user, reason, processor, during=None, violation=True):
    """Suspend a user during a given interval.

    The user is added to violation_group or blocked_group in a given
    interval.  A reason needs to be provided.

    :param User user: The user to be suspended.
    :param unicode reason: The reason for suspending.
    :param User processor: The admin who suspended the user.
    :param Interval|None during: The interval in which the user is
        suspended.  If None the user will be suspendeded from now on
        without an upper bound.
    :param Boolean violation: If the user should be added to the violation group

    :return: The suspended user.
    """
    if during is None:
        during = closedopen(session.utcnow(), None)

    if violation:
        make_member_of(user, config.violation_group, processor, during)
    else:
        make_member_of(user, config.blocked_group, processor, during)

    message = deferred_gettext(u"Suspended during {during}. Reason: {reason}.")
    log_user_event(message=message.format(during=during, reason=reason)
                   .to_json(), author=processor, user=user)
    return user
Example #10
0
def make_member_of(user, group, processor, during=UnboundedInterval):
    """
    Makes a user member of a group in a given interval. If the given interval
    overlaps with an existing membership, this method will join the overlapping
    intervals together, so that there will be at most one membership for
    particular user in particular group at any given point in time.

    :param User user: the user
    :param Group group: the group
    :param User processor: User issuing the addition
    :param Interval during:
    """
    memberships = session.session.query(Membership).filter(
        Membership.user == user, Membership.group == group,
        Membership.active(during)).all()
    intervals = IntervalSet(
        closed(m.begins_at, m.ends_at) for m in memberships).union(during)
    for m in memberships:
        session.session.delete(m)
    session.session.add_all(
        Membership(begins_at=i.begin, ends_at=i.end, user=user, group=group)
        for i in intervals)
    message = deferred_gettext(u"Added to group {group} during {during}.")
    log_user_event(message=message.format(group=group.name,
                                          during=during).to_json(),
                   user=user,
                   author=processor)
Example #11
0
def interface_create(host, name, mac, ips, processor):
    interface = Interface(host=host, mac=mac, name=name)

    session.add(interface)

    subnets = get_subnets_for_room(interface.host.room)

    if ips is None:
        ip, _ = get_free_ip(subnets)
        ips = {ip}

    # IP added
    for ip in ips:
        subnet = next(
            iter([subnet for subnet in subnets if (ip in subnet.address)]),
            None)

        if subnet is not None:
            session.add(IP(interface=interface, address=ip, subnet=subnet))

    message = deferred_gettext(
        u"Created interface ({}, {}) with name '{}' for host '{}'.".format(
            interface.mac, ', '.join(str(ip.address) for ip in interface.ips),
            interface.name, interface.host.name))
    log_user_event(author=processor,
                   user=host.owner,
                   message=message.to_json())

    return interface
Example #12
0
def host_delete(host, processor):
    message = deferred_gettext("Deleted host '{}'.".format(host.name))
    log_user_event(author=processor,
                   user=host.owner,
                   message=message.to_json())

    session.delete(host)\
Example #13
0
File: user.py Project: JuKu/pycroft
def unblock(user, processor, when=None):
    """Unblocks a user.

    This removes his membership of the ``config.violation`` group.

    Note that for unblocking, no further asynchronous action has to be
    triggered, as opposed to e.g. membership termination.

    :param User user: The user to be unblocked.
    :param User processor: The admin who unblocked the user.
    :param datetime when: The time of membership termination.  Note
        that in comparison to :py:func:`suspend`, you don't provide an
        _interval_, but a point in time, defaulting to the current
        time.  Will be converted to ``closedopen(when, None)``.

    :return: The unblocked user.
    """
    if when is None:
        when = session.utcnow()

    remove_member_of(user=user,
                     group=config.violation_group,
                     processor=processor,
                     during=closedopen(when, None))
    message = deferred_gettext(u"User has been unblocked.")
    log_user_event(message=message.to_json(), author=processor, user=user)
    return user
Example #14
0
File: user.py Project: JuKu/pycroft
def migrate_user_host(host, new_room, processor):
    """
    Migrate a UserHost to a new room and if necessary to a new subnet.
    If the host changes subnet, it will get a new IP address.
    :param Host host: Host to be migrated
    :param Room new_room: new room of the host
    :param User processor: User processing the migration
    :return:
    """
    old_room = host.room
    host.room = new_room
    subnets = [
        subnet for p in new_room.connected_patch_ports
        for vlan in p.switch_port.default_vlans for subnet in vlan.subnets
    ]
    if old_room.building_id == new_room.building_id:
        return
    for interface in host.interfaces:
        old_ips = tuple(ip for ip in interface.ips)
        for old_ip in old_ips:
            ip_address, subnet = get_free_ip(subnets)
            new_ip = IP(interface=interface, address=ip_address, subnet=subnet)
            session.session.add(new_ip)

            old_address = old_ip.address
            session.session.delete(old_ip)

            message = deferred_gettext(
                u"Changed IP from {old_ip} to {new_ip}.").format(
                    old_ip=str(old_address), new_ip=str(new_ip))
            log_user_event(author=processor,
                           user=host.owner,
                           message=message.to_json())
Example #15
0
def make_member_of(user, group, processor, during=UnboundedInterval):
    """
    Makes a user member of a group in a given interval. If the given interval
    overlaps with an existing membership, this method will join the overlapping
    intervals together, so that there will be at most one membership for
    particular user in particular group at any given point in time.

    :param User user: the user
    :param Group group: the group
    :param User processor: User issuing the addition
    :param Interval during:
    """

    if group.permission_level > processor.permission_level:
        raise PermissionError("cannot create a membership for a group with a"
                              " higher permission level")

    memberships: list[Membership] = [
        m for m in user.active_memberships(when=during) if m.group == group
    ]
    intervals = IntervalSet(m.active_during.closure
                            for m in memberships).union(during)
    for m in memberships:
        session.session.delete(m)
    session.session.flush()
    session.session.add_all(
        Membership(active_during=i, user=user, group=group) for i in intervals)
    message = deferred_gettext("Added to group {group} during {during}.")
    log_user_event(message=message.format(group=group.name,
                                          during=during).to_json(),
                   user=user,
                   author=processor)
Example #16
0
def edit_property_group(group, name, permission_level, processor):
    message = deferred_gettext("Edited property group {} -> {}.")\
        .format((group.name, group.permission_level), (name, permission_level))
    log_event(message.to_json(), processor)

    group.name = name
    group.permission_level = permission_level
Example #17
0
def create_user(name, login, email, birthdate, groups, processor, address):
    """Create a new member

    Create a new user with a generated password, finance- and unix account, and make him member
    of the `config.member_group` and `config.network_access_group`.

    :param str name: The full name of the user (e.g. Max Mustermann)
    :param str login: The unix login for the user
    :param str email: E-Mail address of the user
    :param Date birthdate: Date of birth
    :param PropertyGroup groups: The initial groups of the new user
    :param User processor: The processor
    :param Address address: Where the user lives. May or may not come from a room.
    :return:
    """

    now = session.utcnow()
    plain_password = user_helper.generate_password(12)
    # create a new user
    new_user = User(
        login=login,
        name=name,
        email=email,
        registered_at=now,
        account=Account(name="", type="USER_ASSET"),
        password=plain_password,
        birthdate=birthdate,
        address=address
    )

    account = UnixAccount(home_directory="/home/{}".format(login))
    new_user.unix_account = account

    with session.session.begin(subtransactions=True):
        session.session.add(new_user)
        session.session.add(account)
    new_user.account.name = deferred_gettext(u"User {id}").format(
        id=new_user.id).to_json()

    for group in groups:
        make_member_of(new_user, group, processor, closed(now, None))

    log_user_event(author=processor,
                   message=deferred_gettext(u"User created.").to_json(),
                   user=new_user)

    return new_user, plain_password
Example #18
0
 def test_simple_format_args(self):
     message = "test {} at {}"
     arg1 = "arg1"
     arg2 = datetime.datetime.utcnow()
     m = deferred_gettext(message).format(arg1, arg2)
     expected_result = message.format(arg1, format_datetime(arg2))
     self.assertSimpleMessageCorrect(m, message, None, (arg1, arg2), {},
                                     expected_result)
Example #19
0
def test_missing_keyword_argument():
    message = "{foo}"
    args = (1, )
    kwargs = {}
    error = get_format_error_message(message, args, kwargs)
    m = deferred_gettext(message).format(*args)
    text = f'Could not format message "{message}" (args={args}, kwargs={kwargs}): {error}'
    assertSimpleMessageCorrect(m, message, None, args, kwargs, text)
Example #20
0
File: user.py Project: JuKu/pycroft
def reset_password(user, processor):
    plain_password = user_helper.generate_password(12)
    user.password = plain_password

    message = deferred_gettext(u"Password was reset")
    log_user_event(author=processor, user=user, message=message.to_json())

    return plain_password
Example #21
0
def transaction_confirm(transaction, processor):
    if transaction.confirmed:
        raise ValueError("transaction already confirmed")

    transaction.confirmed = True

    message = deferred_gettext(u"Confirmed transaction {}.").format(transaction.id)
    log_event(message.to_json(), author=processor)
Example #22
0
def reset_wifi_password(user: User, processor: User) -> str:
    plain_password = generate_wifi_password()
    user.wifi_password = plain_password

    message = deferred_gettext(u"WIFI-Password was reset")
    log_user_event(author=processor, user=user, message=message.to_json())

    return plain_password
Example #23
0
def migrate_user_host(host, new_room, processor):
    """
    Migrate a UserHost to a new room and if necessary to a new subnet.
    If the host changes subnet, it will get a new IP address.
    :param Host host: Host to be migrated
    :param Room new_room: new room of the host
    :param User processor: User processing the migration
    :return:
    """
    old_room = host.room
    host.room = new_room

    subnets_old = get_subnets_for_room(old_room)
    subnets = get_subnets_for_room(new_room)

    if subnets_old != subnets:
        for interface in host.interfaces:
            old_ips = tuple(ip for ip in interface.ips)
            for old_ip in old_ips:
                ip_address, subnet = get_free_ip(subnets)
                new_ip = IP(interface=interface,
                            address=ip_address,
                            subnet=subnet)
                session.session.add(new_ip)

                old_address = old_ip.address
                session.session.delete(old_ip)

                message = deferred_gettext(
                    u"Changed IP of {mac} from {old_ip} to {new_ip}.").format(
                        old_ip=str(old_address),
                        new_ip=str(new_ip.address),
                        mac=interface.mac)
                log_user_event(author=processor,
                               user=host.owner,
                               message=message.to_json())

    message = deferred_gettext(
        u"Moved host '{name}' from {room_old} to {room_new}.".format(
            name=host.name,
            room_old=old_room.short_name,
            room_new=new_room.short_name))

    log_user_event(author=processor,
                   user=host.owner,
                   message=message.to_json())
Example #24
0
def change_password(user, password):
    # TODO: verify password complexity
    user.password = password

    message = deferred_gettext(u"Password was changed")
    log_user_event(author=user,
                   user=user,
                   message=message.to_json())
Example #25
0
def interface_delete(interface, processor):
    message = deferred_gettext(u"Deleted interface {} of host {}.".format(
        interface.mac, interface.host.name))
    log_user_event(author=processor,
                   user=interface.host.owner,
                   message=message.to_json())

    session.delete(interface)
Example #26
0
def transaction_delete(transaction, processor):
    if transaction.confirmed:
        raise ValueError("transaction already confirmed")

    session.session.delete(transaction)

    message = deferred_gettext(u"Deleted transaction {}.").format(transaction.id)
    log_event(message.to_json(), author=processor)
Example #27
0
def test_simple_format_kwargs():
    message = "test {arg1} at {arg2}"
    arg1 = "arg1"
    arg2 = datetime.datetime.utcnow()
    m = deferred_gettext(message).format(arg1=arg1, arg2=arg2)
    expected_result = message.format(arg1=arg1, arg2=format_datetime(arg2))
    assertSimpleMessageCorrect(m, message,
                               None, (), {"arg1": arg1, "arg2": arg2}, expected_result)
Example #28
0
 def test_simple_format_args(self):
     message = "test {} at {}"
     arg1 = "arg1"
     arg2 = datetime.datetime.utcnow()
     m = deferred_gettext(message).format(arg1, arg2)
     expected_result = message.format(arg1, format_datetime(arg2))
     self.assertSimpleMessageCorrect(m, message, None, (arg1, arg2), {},
                                     expected_result)
Example #29
0
 def test_missing_keyword_argument(self):
     message = u"{foo}"
     args = (1,)
     kwargs = {}
     error = self.get_format_error_message(message, args, kwargs)
     m = deferred_gettext(message).format(*args)
     text = (u'Could not format message "{}" (args={}, kwargs={}): {}'
             .format(message, args, kwargs, error))
     self.assertSimpleMessageCorrect(m, message, None, args, kwargs, text)
Example #30
0
 def test_missing_keyword_argument(self):
     message = u"{foo}"
     args = (1, )
     kwargs = {}
     error = self.get_format_error_message(message, args, kwargs)
     m = deferred_gettext(message).format(*args)
     text = (
         u'Could not format message "{}" (args={}, kwargs={}): {}'.format(
             message, args, kwargs, error))
     self.assertSimpleMessageCorrect(m, message, None, args, kwargs, text)
Example #31
0
def create_switch_port(switch, name, default_vlans, processor):
    switch_port = SwitchPort(name=name, switch=switch, default_vlans=default_vlans)
    session.add(switch_port)

    default_vlans_str = ', '.join(str(vlan.vid) for vlan in switch_port.default_vlans)
    message = deferred_gettext("Created switch-port {} on {} with default VLANs {}.")\
        .format(switch_port.name, switch_port.switch.host.name, default_vlans_str)
    log_room_event(message.to_json(), processor, switch_port.switch.host.room)

    return switch_port
Example #32
0
def reschedule_task(task: Task, due: datetime, processor: User):
    if task.status != TaskStatus.OPEN:
        raise ValueError("Cannot execute a task that is not open")

    task.due = due
    log_task_event(
        deferred_gettext("Rescheduled task {task_id} to {new_due}").format(
            task_id=task.id, new_due=due).to_json(),
        author=processor,
        task=task)
Example #33
0
def create_switch(name, management_ip, room, processor):
    switch = Switch(management_ip=management_ip, host=Host(room=room, owner=User.get(0), name=name))

    session.add(switch)

    message = deferred_gettext("Created switch '{}' with management IP {}.")\
        .format(switch.host.name, switch.management_ip)
    log_room_event(message.to_json(),
                   processor, switch.host.room)

    return switch
Example #34
0
def edit_patch_port(patch_port, name, room, processor):
    if patch_port.name != name:
        # This check can be removed as soon as the unique constraint exists
        if PatchPort.q.filter_by(name=name, switch_room=patch_port.switch_room).first():
            raise PatchPortAlreadyExistsException()

        message = deferred_gettext("Changed name of patch-port {patch_port_name} to {name}.")\
            .format(patch_port_name=patch_port.name, name=name)
        log_room_event(message.to_json(), processor, patch_port.switch_room)

        patch_port.name = name

    if patch_port.room != room:
        message = deferred_gettext("Changed room of patch-port {pp}"
                                   " from {old_room} to {new_room}.")\
            .format(pp=patch_port.name, old_room=patch_port.room.short_name,
                    new_room=room.short_name)
        log_room_event(message.to_json(), processor, patch_port.switch_room)

        patch_port.room = room
Example #35
0
def change_mac(interface, mac, processor):
    """
    This method will change the mac address of the given interface to the new
    mac address.

    :param interface: the interface which should become a new mac address.
    :param mac: the new mac address.
    :param processor: the user who initiated the mac address change.
    :return: the changed interface with the new mac address.
    """
    old_mac = interface.mac
    interface.mac = mac
    message = deferred_gettext(u"Changed MAC address from {} to {}.").format(
        old_mac, mac)
    log_user_event(message.to_json(), processor, interface.host.owner)
    return interface
Example #36
0
def reset_credit(user, processor, target_amount=1*1024**3):
    """Compensate a user's traffic credit to a target amount

    :param User user:
    :param User processor:
    :param int target_amount: The target amount to reach, in bytes.
        Defaults to 1GiB.

    :raises ValueError: if the user's current credit is greater than
        or equal to the given target amount.
    """
    now = session.utcnow()
    difference = target_amount - user.current_credit
    if difference <= 0:
        raise ValueError("The current credit surpasses the target amount."
                         " Only an upwards correction is possible.")

    session.session.add(TrafficCredit(user=user, timestamp=now, amount=difference))
    log_user_event(deferred_gettext("Traffic has ben compensated to 1GiB").to_json(),
                   author=processor,
                   user=user)
Example #37
0
        split1.account == from_account,
        split2.account == to_account,
        sign(split1.amount) != sign(split2.amount)
    )
    if not when.unbounded:
        query = query.filter(
            between(Transaction.valid_on, when.begin, when.end)
        )
    elif when.begin is not None:
        query = query.filter(Transaction.valid_on >= when.begin)
    elif when.end is not None:
        query = query.filter(Transaction.valid_on <= when.end)
    return query.scalar()


membership_fee_description = deferred_gettext("Mitgliedsbeitrag {fee_name}")
@with_transaction
def post_transactions_for_membership_fee(membership_fee, processor):
    """
    Posts transactions (and splits) for users where the specified membership fee
    was not posted yet.

    User select: User -> Split (user account) -> Transaction -> Split (fee account)
                 Conditions: User has `membership_fee` property on
                             begins_on + 1 day and begins_on + grace - 1 day

    :param membership_fee: The membership fee which should be posted
    :param processor:
    :return: A list of name of all affected users
    """
Example #38
0
 def test_simple(self):
     message = "test"
     m = deferred_gettext(message)
     self.assertSimpleMessageCorrect(m, message, None, (), {}, message)