示例#1
0
def fix_ceo_clearance():
    """
    Raises CEOs of corporations to clearance level 2, and CEOs of alliances to
    level 4. If their clearance level was higher, doesn't modify it.
    """
    for corporation in Corporation.objects(corporation_id__gte=2000000):
        ceo = ensure_user(corporation.ceo_character_id)
        if ceo.clearance_level < 2:
            logging.info(
                "Raising %s (%d), ceo of corporation %s (%d), to level 2",
                ceo.character_name,
                ceo.character_id,
                corporation.corporation_name,
                corporation.corporation_id,
            )
            ceo.update(set__clearance_level=2)
    for alliance in Alliance.objects():
        executor: Corporation = ensure_corporation(
            alliance.executor_corporation_id
        )
        ceo: User = ensure_user(executor.ceo_character_id)
        if ceo.clearance_level < 4:
            logging.info(
                "Raising %s (%d), ceo of alliance %s (%d), to level 4",
                ceo.character_name,
                ceo.character_id,
                alliance.alliance_name,
                alliance.alliance_id,
            )
            ceo.update(set__clearance_level=4)
示例#2
0
def get_corporation(
    corporation_id: int,
    tkn: Token = Depends(from_authotization_header_nondyn),
):
    """
    Get informations about a corporation. Note that this corporation must be
    registered on SNI
    """
    assert_has_clearance(tkn.owner, "sni.read_corporation")
    corporation = Corporation.objects(corporation_id=corporation_id).get()
    return GetCorporationOut.from_record(corporation)
示例#3
0
def get_corporations(tkn: Token = Depends(from_authotization_header_nondyn),):
    """
    Gets the list of corporations registered in this instance. Requires a
    clearance level of 0 or more.
    """
    assert_has_clearance(tkn.owner, "sni.read_corporation")
    return [
        GetCorporationShortOut.from_record(corporation)
        for corporation in Corporation.objects(
            corporation_id__gte=2000000
        ).order_by("corporation_name")
    ]
示例#4
0
def get_corporation_tracking(
    corporation_id: int,
    tkn: Token = Depends(from_authotization_header_nondyn),
):
    """
    Reports which member (of a given corporation) have a valid refresh token
    attacked to them, and which do not. Requires a clearance level of 1 and
    having authority over this corporation.
    """
    corporation: Corporation = Corporation.objects(
        corporation_id=corporation_id
    ).get()
    assert_has_clearance(tkn.owner, "sni.track_corporation", corporation.ceo)
    return GetTrackingOut.from_user_iterator(corporation.user_iterator())
示例#5
0
def get_corporation_guests(
    corporation_id: int,
    tkn: Token = Depends(from_authotization_header_nondyn),
):
    """
    Returns the list of guests in this corporation.
    """
    corporation: Corporation = Corporation.objects(
        corporation_id=corporation_id
    ).get()
    assert_has_clearance(
        tkn.owner, "sni.read_corporation_guests", corporation.ceo
    )
    return [
        GetUserShortOut.from_record(guest)
        for guest in corporation.guest_iterator()
    ]
示例#6
0
def put_corporation(
    corporation_id: int,
    data: PutCorporationIn,
    tkn: Token = Depends(from_authotization_header_nondyn),
):
    """
    Modify a corporation registered on SNI. Note that it does not modify it on
    an ESI level. Requires a clearance level of 2 or more.
    """
    corporation: Corporation = Corporation.objects(
        corporation_id=corporation_id
    ).get()
    assert_has_clearance(tkn.owner, "sni.update_corporation", corporation.ceo)
    corporation.authorized_to_login = data.authorized_to_login
    if data.mandatory_esi_scopes is not None:
        corporation.mandatory_esi_scopes = data.mandatory_esi_scopes
    corporation.save()
    return GetCorporationOut.from_record(corporation)
示例#7
0
def delete_corporation_guest(
    corporation_id: int,
    character_id: int,
    tkn: Token = Depends(from_authotization_header_nondyn),
):
    """
    Deletes a corporation guest
    """
    corporation: Corporation = Corporation.objects(
        corporation_id=corporation_id
    ).get()
    assert_has_clearance(
        tkn.owner, "sni.delete_corporation_guest", corporation.ceo
    )
    guest: User = User.objects(
        character_id=character_id,
        clearance_level__lt=0,
        corporation=corporation,
    ).get()
    guest.delete()
示例#8
0
def post_corporation_guest(
    corporation_id: int,
    tkn: Token = Depends(from_authotization_header_nondyn),
):
    """
    Creates a state code for a new guest to this corporation. The user then has
    to login with this state code to be considered a guest.
    """
    corporation: Corporation = Corporation.objects(
        corporation_id=corporation_id
    ).get()
    assert_has_clearance(
        tkn.owner, "sni.create_corporation_guest", corporation.ceo
    )
    state_code = create_state_code(
        tkn.parent,
        inviting_corporation=corporation,
        code_prefix=esi_scope_set_to_hex(
            corporation.cumulated_mandatory_esi_scopes()
        ),
    )
    return PostCorporationGuestOut(state_code=str(state_code.uuid))