Пример #1
0
def self_remove_all():
    # remove your self from all wls
    # sse list
    _events = []

    logger.info("%s removed them selfs from waitlists", current_user.get_eve_name())
    # queue = db.session.query(Waitlist).filter(Waitlist.name == WaitlistNames.xup_queue).first()
    # remove from all lists except queue
    entries = db.session.query(WaitlistEntry).filter(WaitlistEntry.user == current_user.get_eve_id())
    fittings = []
    for entry in entries:
        fittings.extend(entry.fittings)

    h_entry = create_history_object(current_user.get_eve_id(), HistoryEntry.EVENT_SELF_RM_WLS_ALL, None, fittings)
    db.session.add(h_entry)

    for entry in entries:
        logger.info("%s removed own entry with id=%s", current_user.get_eve_name(), entry.id)
        event = EntryRemovedSSE(entry.waitlist.group.groupID, entry.waitlist_id, entry.id)
        _events.append(event)
        db.session.delete(entry)

    db.session.commit()
    for event in _events:
        send_server_sent_event(event)
    return "success"
Пример #2
0
def self_remove_fit(fitid):
    # remove one of your fittings by id
    fit = db.session.query(Shipfit).filter(Shipfit.id == fitid).first()
    # this fit is not on any waitlist
    # if we get this case it means some ones UI did not update
    if fit.waitlist is None:
        logger.info(f"{current_user.get_eve_name()} tried to remove own fit with id={fit.id}"
                    f" while it was not on any waitlist anymore")
        return "This fit is not on a waitlist anymore"

    wlentry = db.session.query(WaitlistEntry).filter(WaitlistEntry.id == fit.waitlist.id).first()

    if wlentry.user == current_user.get_eve_id():
        logger.info("%s removed their fit with id %d from group %s", current_user.get_eve_name(), fitid,
                    wlentry.waitlist.group.groupName)
        event = FitRemovedSSE(wlentry.waitlist.group.groupID, wlentry.waitlist_id, wlentry.id, fit.id, wlentry.user)
        wlentry.fittings.remove(fit)

        # don't delete anymore we need them for history
        # db.session.delete(fit)
        if len(wlentry.fittings) <= 0:
            event = EntryRemovedSSE(wlentry.waitlist.group.groupID, wlentry.waitlist_id, wlentry.id)
            db.session.delete(wlentry)

        send_server_sent_event(event)
        h_entry = create_history_object(current_user.get_eve_id(), HistoryEntry.EVENT_SELF_RM_FIT, None, [fit])
        h_entry.exref = wlentry.waitlist.group.groupID
        db.session.add(h_entry)
        db.session.commit()
    else:
        flask.abort(403)

    return "success"
Пример #3
0
def api_wls_remove_player():
    # sse events
    _events = []

    player_id = int(request.form['playerId'])
    group_id = int(request.form['groupId'])

    if player_id is None:
        logger.error("Tried to remove player with None id from waitlists.")

    group = db.session.query(WaitlistGroup).get(group_id)
    # don't remove from queue
    waitlist_entries = db.session.query(WaitlistEntry).filter(
        (WaitlistEntry.user == player_id) &
        ((WaitlistEntry.waitlist_id == group.logiwlID) |
         (WaitlistEntry.waitlist_id == group.dpswlID) |
         (WaitlistEntry.waitlist_id == group.sniperwlID))).all()

    fittings = []
    for entry in waitlist_entries:
        fittings.extend(entry.fittings)

    # check if there is an other waitlist
    if group.otherwlID is not None:
        entry = db.session.query(WaitlistEntry).filter(
            (WaitlistEntry.user == player_id) & (WaitlistEntry.waitlist_id == group.otherwlID)).one_or_none()
        if entry is not None:
            fittings.extend(entry.fittings)

    waitlist_entries = db.session.query(WaitlistEntry).filter(
        (WaitlistEntry.user == player_id) &
        ((WaitlistEntry.waitlist_id == group.logiwlID) |
         (WaitlistEntry.waitlist_id == group.dpswlID) |
         (WaitlistEntry.waitlist_id == group.sniperwlID))).all()
    for entry in waitlist_entries:
        event = EntryRemovedSSE(entry.waitlist.groupID, entry.waitlist_id, entry.id)
        _events.append(event)

    db.session.query(WaitlistEntry).filter(
        (WaitlistEntry.user == player_id) &
        ((WaitlistEntry.waitlist_id == group.logiwlID) |
         (WaitlistEntry.waitlist_id == group.dpswlID) |
         (WaitlistEntry.waitlist_id == group.sniperwlID))).delete()

    # if other waitlist delete those entries too
    if group.otherwlID is not None:
        db.session.query(WaitlistEntry).filter((WaitlistEntry.user == player_id) &
                                               (WaitlistEntry.waitlist_id == group.otherwlID)).delete()

    h_entry = create_history_object(player_id, HistoryEntry.EVENT_COMP_RM_PL, current_user.id, fittings)
    h_entry.exref = group.groupID
    db.session.add(h_entry)
    db.session.commit()
    character = db.session.query(Character).filter(Character.id == player_id).first()
    logger.info("%s removed %s from %s waitlist.", current_user.username, character.eve_name, group.groupName)

    for event in _events:
        send_server_sent_event(event)

    return "OK"
Пример #4
0
def self_remove_wl_entry(entry_id):
    # remove your self from a wl by wl entry id
    entry = db.session.query(WaitlistEntry).filter(
        (WaitlistEntry.id == entry_id) & (WaitlistEntry.user == current_user.get_eve_id())).first()
    if entry is None:
        flask.abort(404, "This Waitlist Entry does not exist.")
    event = EntryRemovedSSE(entry.waitlist.groupID, entry.waitlist_id, entry.id)
    logger.info("%s removed their own entry with id %d", current_user.get_eve_name(), entry_id)
    h_entry = create_history_object(current_user.get_eve_id(), HistoryEntry.EVENT_SELF_RM_ETR, None, entry.fittings)
    h_entry.exref = entry.waitlist.group.groupID
    db.session.add(h_entry)
    db.session.delete(entry)
    db.session.commit()
    send_server_sent_event(event)
    return "success"
Пример #5
0
def wl_remove_entry():
    entry_id = int(request.form['entryId'])
    entry = db.session.query(WaitlistEntry).get(entry_id)
    if entry is None:
        flask.abort(404, "Waitlist Entry does not exist!")
    h_entry = create_history_object(entry.user_data.get_eve_id(), HistoryEntry.EVENT_COM_RM_ETR, current_user.id,
                                    entry.fittings)
    h_entry.exref = entry.waitlist.group.groupID
    db.session.add(h_entry)
    logger.info("%s removed %s from waitlist %s of group %s", current_user.username, entry.user_data.get_eve_name(),
                entry.waitlist.name, entry.waitlist.group.groupName)
    event = EntryRemovedSSE(entry.waitlist.groupID, entry.waitlist_id, entry.id)
    db.session.query(WaitlistEntry).filter(WaitlistEntry.id == entry_id).delete()
    db.session.commit()
    send_server_sent_event(event)
    return "OK"
Пример #6
0
def check_invite_and_remove_timer(char_id: int, group_id: int, fleet_id: int):
    try:
        logger.info(
            f"Check Invite and remove timer triggered for"
            f" char_id={char_id}, group_id={group_id} and fleet_id={fleet_id}")
        max_runs: int = 4
        current_run: int = 1
        timer_id = (char_id, group_id, fleet_id)
        if timer_id in check_timers:
            current_run = check_timers[timer_id] + 1

        check_timers[timer_id] = current_run
        logger.info(
            f"New Timer count={check_timers[timer_id]} for timer_id={timer_id}"
        )

        # hold SSE till sending
        _events = []
        logger.info(
            "Checking invite for charID[%d] groupID[%d] fleetID[%d] current_run[%d]",
            char_id, group_id, fleet_id, current_run)
        group: WaitlistGroup = db.session.query(WaitlistGroup).get(group_id)
        crest_fleet = db.session.query(CrestFleet).get(fleet_id)
        # the fleet was deleted meanwhile or has no fleetcomp
        if group is None or crest_fleet is None or crest_fleet.comp is None:
            if group is None:
                logger.error("On Invitecheck group is None")
            if crest_fleet is None:
                logger.error("On Invitecheck crestFleet is None")
            elif crest_fleet.comp is None:
                logger.error("On Invitecheck FleetComp is None")
            db.session.remove()
            return
        member = member_info.get_fleet_members(fleet_id, crest_fleet.comp)
        character = db.session.query(Character).filter(
            Character.id == char_id).first()
        waitlist_entries = db.session.query(WaitlistEntry)\
            .filter((WaitlistEntry.user == char_id) &
                    (WaitlistEntry.waitlist_id != group.xuplist.id)
                    ).all()

        if char_id in member:  # he is in the fleet
            logger.info("Member %s found in members", char_id)
            fittings = []
            for entry in waitlist_entries:
                fittings.extend(entry.fittings)

            for entry in waitlist_entries:
                event = EntryRemovedSSE(entry.waitlist.group.groupID,
                                        entry.waitlist_id, entry.id)
                _events.append(event)

            db.session.query(WaitlistEntry).filter(
                (WaitlistEntry.user == char_id)
                & (WaitlistEntry.waitlist_id != group.xuplist.id)).delete()

            h_entry = create_history_object(char_id,
                                            HistoryEntry.EVENT_AUTO_RM_PL,
                                            None, fittings)
            h_entry.exref = group.groupID
            db.session.add(h_entry)
            db.session.commit()

            for event in _events:
                send_server_sent_event(event)

            logger.info("auto removed %s from %s waitlist.",
                        character.eve_name, group.groupName)
            # we are done delete timer entry
            check_timers.pop(timer_id, None)
        else:
            logger.info("Character %d %s not found in fleetmembers", char_id,
                        character.eve_name)
            if current_run == max_runs:  # he reached his invite timeout
                logger.info(
                    "Max Runs reached and Member %s not found in members",
                    str(char_id))
                for entry in waitlist_entries:
                    entry.inviteCount += 1
                h_entry = create_history_object(
                    char_id, HistoryEntry.EVENT_AUTO_CHECK_FAILED, None, None)
                h_entry.exref = group.groupID
                db.session.add(h_entry)
                db.session.commit()
                send_server_sent_event(InviteMissedSSE(group_id, char_id))

                logger.info("%s missed his invite", character.eve_name)
                # we are done delete the timer entry
                check_timers.pop(timer_id, None)
            else:
                # we want to wait some more, set up new timer
                logger.info(
                    'charID[%d] groupID[%d] fleetID[%d] %s was not in fleet this time, checking again in 20s',
                    char_id, group_id, fleet_id, character.eve_name)
                t = Timer(20.0, check_invite_and_remove_timer,
                          [char_id, group_id, fleet_id])
                t.start()

        db.session.remove()
    except Exception as e:
        logger.exception("Some thing went wrong during invite check!")
Пример #7
0
def move_to_waitlists():
    """
    Move a whole entry to a the corresponding waitlists
    """

    # variables for SSE spawning
    _sseEvents = []
    _createdEntriesList = []

    entry_id = int(request.form['entryId'])
    fit_ids = request.form['fitIds']
    fit_ids = [int(x) for x in fit_ids.split(",")]
    entry = db.session.query(WaitlistEntry).filter(
        WaitlistEntry.id == entry_id).first()
    if entry is None or entry.waitlist is None:
        flask.abort(
            404,
            "This entry does not exist or not belong to a waitlist anymore!")
    group: WaitlistGroup = entry.waitlist.group

    if entry is None:
        return "OK"
    logger.info("%s approved %s", current_user.username,
                entry.user_data.get_eve_name())

    # get waitlists in this group
    waitlist_ids = []
    for wl in group.waitlists:
        waitlist_ids.append(wl.id)

    # get all entries that are in one of these waitlists and from the current user
    waitlist_entries = db.session.query(WaitlistEntry) \
        .filter((WaitlistEntry.user == entry.user) & WaitlistEntry.waitlist_id.in_(waitlist_ids)).all()

    logi_entry = None
    sniper_entry = None
    dps_entry = None
    other_entry = None
    if len(waitlist_entries) > 0:  # there are actually existing entries
        # if there are existing wl entries assign them to appropriate variables
        for wl in waitlist_entries:
            if wl.waitlist.name == WaitlistNames.logi:
                logi_entry = wl
                continue
            if wl.waitlist.name == WaitlistNames.dps:
                dps_entry = wl
                continue
            if wl.waitlist.name == WaitlistNames.sniper:
                sniper_entry = wl
            elif wl.waitlist.name == WaitlistNames.other:
                other_entry = wl

    # find out what timestamp a possibly new entry should have
    # rules are: if no wl entry, take timestamp of x-up
    #    if there is a wl entry take the waitlist entry timestamp (a random one since they should all have the same)

    new_entry_timedate = entry.creation
    for entry_t in waitlist_entries:
        if entry_t.creation < new_entry_timedate:
            new_entry_timedate = entry_t.creation

    # sort fittings by ship type
    logi = []
    dps = []
    sniper = []
    other = []
    h_entry = create_history_object(entry.user,
                                    HistoryEntry.EVENT_COMP_MV_XUP_ETR,
                                    current_user.id)
    for fit in entry.fittings:
        if fit.id not in fit_ids:
            continue
        h_entry.fittings.append(fit)

    fits_to_remove = []

    for fit in entry.fittings:
        if fit.id not in fit_ids:
            logger.info("Skipping %s because not in %s", fit, fit_ids)
            continue
        logger.info("Sorting fit %s by type into %s", str(fit), fit.wl_type)

        if fit.wl_type == WaitlistNames.logi:
            logi.append(fit)
        elif fit.wl_type == WaitlistNames.dps:
            dps.append(fit)
        elif fit.wl_type == WaitlistNames.sniper:
            sniper.append(fit)
        elif fit.wl_type == WaitlistNames.other:
            other.append(fit)
        else:
            logger.error("Failed to add %s do a waitlist.", fit)

        fits_to_remove.append(fit)

    for fit in fits_to_remove:
        event = FitRemovedSSE(entry.waitlist.group.groupID, entry.waitlist.id,
                              entry.id, fit.id, entry.user)
        _sseEvents.append(event)
        entry.fittings.remove(fit)

    # we have a logi fit but no logi wl entry, so create one
    if len(logi) and logi_entry is None:
        logi_entry = WaitlistEntry()
        logi_entry.creation = new_entry_timedate  # for sorting entries
        logi_entry.user = entry.user  # associate a user with the entry
        group.logilist.entries.append(logi_entry)
        _createdEntriesList.append(logi_entry)

    # same for dps
    if len(dps) and dps_entry is None:
        dps_entry = WaitlistEntry()
        dps_entry.creation = new_entry_timedate  # for sorting entries
        dps_entry.user = entry.user  # associate a user with the entry
        group.dpslist.entries.append(dps_entry)
        _createdEntriesList.append(dps_entry)

    # and sniper
    if len(sniper) and sniper_entry is None:
        sniper_entry = WaitlistEntry()
        sniper_entry.creation = new_entry_timedate  # for sorting entries
        sniper_entry.user = entry.user  # associate a user with the entry
        group.sniperlist.entries.append(sniper_entry)
        _createdEntriesList.append(sniper_entry)

    # and other if other exists
    if len(other) and other_entry is None and group.otherlist is not None:
        other_entry = WaitlistEntry()
        other_entry.creation = new_entry_timedate  # for sorting entries
        other_entry.user = entry.user  # associate a user with the entry
        group.otherlist.entries.append(other_entry)
        _createdEntriesList.append(other_entry)

    # iterate over sorted fits and add them to their entry
    for logifit in logi:
        logi_entry.fittings.append(logifit)

    if logi_entry not in _createdEntriesList:
        for fit in logi:
            event = FitAddedSSE(group.groupID, logi_entry.waitlist_id,
                                logi_entry.id, fit, False, logi_entry.user)
            _sseEvents.append(event)

    for dpsfit in dps:
        dps_entry.fittings.append(dpsfit)

    if dps_entry not in _createdEntriesList:
        for fit in dps:
            event = FitAddedSSE(group.groupID, dps_entry.waitlist_id,
                                dps_entry.id, fit, False, dps_entry.user)
            _sseEvents.append(event)

    for sniperfit in sniper:
        sniper_entry.fittings.append(sniperfit)

    if sniper_entry not in _createdEntriesList:
        for fit in sniper:
            event = FitAddedSSE(group.groupID, sniper_entry.waitlist_id,
                                sniper_entry.id, fit, False, sniper_entry.user)
            _sseEvents.append(event)

    # if there is no other list sort other fits in dps
    if group.otherlist is not None:
        for otherfit in other:
            other_entry.fittings.append(otherfit)

        if other_entry not in _createdEntriesList:
            for fit in other:
                event = FitAddedSSE(group.groupID, other_entry.waitlist_id,
                                    other_entry.id, fit, False,
                                    other_entry.user)
                _sseEvents.append(event)
    else:
        # it fits should go to dps wl make sure it is there
        if len(other) > 0 and dps_entry is None:
            dps_entry = WaitlistEntry()
            dps_entry.creation = new_entry_timedate  # for sorting entries
            dps_entry.user = entry.user  # associate a user with the entry
            group.dpslist.entries.append(dps_entry)
            _createdEntriesList.append(dps_entry)
        for otherfit in other:
            dps_entry.fittings.append(otherfit)

        if dps_entry not in _createdEntriesList:
            for fit in other:
                event = FitAddedSSE(group.groupID, dps_entry.waitlist_id,
                                    dps_entry.id, fit, False, dps_entry.user)
                _sseEvents.append(event)

    # add history entry to db
    db.session.add(h_entry)

    db.session.commit()

    if len(entry.fittings) <= 0:
        event = EntryRemovedSSE(entry.waitlist.group.groupID,
                                entry.waitlist.id, entry.id)
        send_server_sent_event(event)
        db.session.delete(entry)
        db.session.commit()
    else:
        for fitEvent in _sseEvents:
            if isinstance(fitEvent, FitRemovedSSE):
                send_server_sent_event(fitEvent)

    for fitAddedEvent in _sseEvents:
        if isinstance(fitAddedEvent, FitAddedSSE):
            send_server_sent_event(fitAddedEvent)

    for createdEntry in _createdEntriesList:
        event = EntryAddedSSE(createdEntry, group.groupID,
                              createdEntry.waitlist_id, False)
        send_server_sent_event(event)

    return "OK"
Пример #8
0
def api_move_fit_to_waitlist():
    fit_id = int(request.form['fit_id'])
    fit = db.session.query(Shipfit).filter(Shipfit.id == fit_id).first()
    # fit doesn't exist or is not in a waitlist, probably double trigger when moving some one
    if fit is None or fit.waitlist is None:
        return "OK"

    entry = db.session.query(WaitlistEntry).filter(
        WaitlistEntry.id == fit.waitlist.id).first()

    group: WaitlistGroup = entry.waitlist.group

    logger.info("%s approved fit %s from %s", current_user.username, fit,
                entry.user_data.get_eve_name())

    # get the entry for the wl we need
    waitlist = None
    if fit.wl_type == WaitlistNames.logi:
        waitlist = group.logilist
    elif fit.wl_type == WaitlistNames.dps:
        waitlist = group.dpslist
    elif fit.wl_type == WaitlistNames.sniper:
        waitlist = group.sniperlist
    elif fit.wl_type == WaitlistNames.other:
        if group.otherlist is not None:
            waitlist = group.otherlist
        else:
            waitlist = group.dpslist

    waitlist_ids: List[int] = []
    for wl in group.waitlists:
        waitlist_ids.append(wl.id)

    waitlist_entries = db.session.query(WaitlistEntry) \
        .filter((WaitlistEntry.user == entry.user) & WaitlistEntry.waitlist_id.in_(waitlist_ids)).all()

    creation_time = entry.creation

    for centry in waitlist_entries:
        if centry.creation < creation_time:
            creation_time = centry.creation

    wl_entry = db.session.query(WaitlistEntry).join(Waitlist) \
        .filter((WaitlistEntry.user == entry.user) & (Waitlist.id == waitlist.id)).first()
    new_entry = False
    # if it doesn't exist create it
    if wl_entry is None:
        wl_entry = WaitlistEntry()
        wl_entry.creation = creation_time
        wl_entry.user = entry.user
        new_entry = True

    # remove fit from old entry
    event = FitRemovedSSE(entry.waitlist.group.groupID, entry.waitlist_id,
                          entry.id, fit.id, entry.user)
    entry.fittings.remove(fit)
    send_server_sent_event(event)

    # add the fit to the entry
    wl_entry.fittings.append(fit)
    if not new_entry:
        event = FitAddedSSE(wl_entry.waitlist.group.groupID,
                            wl_entry.waitlist_id, wl_entry.id, fit, False,
                            wl_entry.user)
        send_server_sent_event(event)

    # add a history entry
    h_entry = create_history_object(entry.user,
                                    HistoryEntry.EVENT_COMP_MV_XUP_FIT,
                                    current_user.id, [fit])
    db.session.add(h_entry)

    if new_entry:
        waitlist.entries.append(wl_entry)

    db.session.commit()
    if len(entry.fittings) == 0:
        event = EntryRemovedSSE(entry.waitlist.group.groupID,
                                entry.waitlist_id, entry.id)
        db.session.delete(entry)
        db.session.commit()
        send_server_sent_event(event)

    if new_entry:
        event = EntryAddedSSE(wl_entry, wl_entry.waitlist.group.groupID,
                              wl_entry.waitlist_id, False)
        send_server_sent_event(event)

    return "OK"
Пример #9
0
def move_to_waitlists():
    """
    Move a whole entry to the corresponding waitlists
    """

    # variables for SSE spawning
    _sseEvents = []
    _createdEntriesList = []

    entry_id = int(request.form['entryId'])
    fit_ids = request.form['fitIds']
    fit_ids = [int(x) for x in fit_ids.split(",")]
    entry = db.session.query(WaitlistEntry).filter(
        WaitlistEntry.id == entry_id).first()
    if entry is None or entry.waitlist is None:
        flask.abort(
            404,
            "This entry does not exist or not belong to a waitlist anymore!")
    group: WaitlistGroup = entry.waitlist.group

    if entry is None:
        return "OK"
    logger.info("%s approved %s", current_user.username,
                entry.user_data.get_eve_name())

    # get waitlists in this group
    waitlist_ids = []
    for wl in group.waitlists:
        waitlist_ids.append(wl.id)

    # get all entries that are in one of these waitlists and from the current user
    waitlist_entries = db.session.query(WaitlistEntry) \
        .filter((WaitlistEntry.user == entry.user) & WaitlistEntry.waitlist_id.in_(waitlist_ids)).all()

    # find out what timestamp a possibly new entry should have
    # rules are: if no wl entry, take timestamp of x-up
    #    if there is a wl entry take the waitlist entry timestamp (a random one since they should all have the same)

    new_entry_timedate = entry.creation
    for entry_t in waitlist_entries:
        if entry_t.creation < new_entry_timedate:
            new_entry_timedate = entry_t.creation

    h_entry = create_history_object(entry.user,
                                    HistoryEntry.EVENT_COMP_MV_XUP_ETR,
                                    current_user.id)
    for fit in entry.fittings:
        if fit.id not in fit_ids:
            continue
        h_entry.fittings.append(fit)

    fit_list = [fit for fit in entry.fittings]

    for fit in fit_list:
        event = FitRemovedSSE(entry.waitlist.group.groupID, entry.waitlist.id,
                              entry.id, fit.id, entry.user)
        _sseEvents.append(event)
        entry.fittings.remove(fit)
        is_new, new_entry = get_waitlist_entry_for_list(
            fit.targetWaitlistID, new_entry_timedate, waitlist_entries,
            entry.user)
        new_entry.fittings.append(fit)
        # fits in a created entry will be sent out later a whole entry
        if is_new:
            _createdEntriesList.append(new_entry)
        else:
            event = FitAddedSSE(group.groupID, new_entry.waitlist_id,
                                new_entry.id, fit, False, new_entry.user)
            _sseEvents.append(event)

    # add history entry to db
    db.session.add(h_entry)

    db.session.commit()

    if len(entry.fittings) <= 0:
        event = EntryRemovedSSE(entry.waitlist.group.groupID,
                                entry.waitlist.id, entry.id)
        send_server_sent_event(event)
        db.session.delete(entry)
        db.session.commit()
    else:
        for fitEvent in _sseEvents:
            if isinstance(fitEvent, FitRemovedSSE):
                send_server_sent_event(fitEvent)

    for fitAddedEvent in _sseEvents:
        if isinstance(fitAddedEvent, FitAddedSSE):
            send_server_sent_event(fitAddedEvent)

    for createdEntry in _createdEntriesList:
        event = EntryAddedSSE(createdEntry, group.groupID,
                              createdEntry.waitlist_id, False)
        send_server_sent_event(event)

    return "OK"
Пример #10
0
def api_move_fit_to_waitlist():
    fit_id = int(request.form['fit_id'])
    fit = db.session.query(Shipfit).filter(Shipfit.id == fit_id).first()
    # fit doesn't exist or is not in a waitlist, probably double trigger when moving some one
    if fit is None or fit.waitlist is None:
        flask.abort(
            404,
            "This fit does not exist or not belong to a waitlist anymore!")

    entry = db.session.query(WaitlistEntry).filter(
        WaitlistEntry.id == fit.waitlist.id).first()

    group: WaitlistGroup = entry.waitlist.group

    logger.info("%s approved fit %s from %s", current_user.username, fit,
                entry.user_data.get_eve_name())

    waitlist = fit.targetWaitlist

    waitlist_ids: List[int] = []
    for wl in group.waitlists:
        waitlist_ids.append(wl.id)

    waitlist_entries = db.session.query(WaitlistEntry) \
        .filter((WaitlistEntry.user == entry.user) & WaitlistEntry.waitlist_id.in_(waitlist_ids)).all()

    creation_time = entry.creation

    for centry in waitlist_entries:
        if centry.creation < creation_time:
            creation_time = centry.creation

    wl_entry = db.session.query(WaitlistEntry).join(Waitlist) \
        .filter((WaitlistEntry.user == entry.user) & (Waitlist.id == waitlist.id)).first()

    # is already on target
    if fit.waitlist is not None and wl_entry is not None and fit.waitlist.id == wl_entry.id:
        flask.abort(409, 'This fit was already moved')

    is_entry_new, wl_entry = get_waitlist_entry_for_list(
        fit.targetWaitlistID, creation_time,
        [wl_entry] if wl_entry is not None else [], entry.user)

    # remove fit from old entry
    event = FitRemovedSSE(entry.waitlist.group.groupID, entry.waitlist_id,
                          entry.id, fit.id, entry.user)
    entry.fittings.remove(fit)
    send_server_sent_event(event)

    # add the fit to the entry
    wl_entry.fittings.append(fit)
    if not is_entry_new:
        event = FitAddedSSE(wl_entry.waitlist.group.groupID,
                            wl_entry.waitlist_id, wl_entry.id, fit, False,
                            wl_entry.user)
        send_server_sent_event(event)

    # add a history entry
    h_entry = create_history_object(entry.user,
                                    HistoryEntry.EVENT_COMP_MV_XUP_FIT,
                                    current_user.id, [fit])
    db.session.add(h_entry)

    if is_entry_new:
        waitlist.entries.append(wl_entry)

    db.session.commit()
    if len(entry.fittings) == 0:
        event = EntryRemovedSSE(entry.waitlist.group.groupID,
                                entry.waitlist_id, entry.id)
        db.session.delete(entry)
        db.session.commit()
        send_server_sent_event(event)

    if is_entry_new:
        event = EntryAddedSSE(wl_entry, wl_entry.waitlist.group.groupID,
                              wl_entry.waitlist_id, False)
        send_server_sent_event(event)

    return "OK"