def setup_step_url(): token: Optional[SSOToken] = current_user.get_a_sso_token_with_scopes( esi_scopes.fleetcomp_scopes) if token is None: return Response( 'You have no api token with the required scopes associated with your account,' ' please take over the fleet again.', status=412) skip_setup = request.form.get('skip-setup') try: fleet_id: int = int(request.form.get('fleet-id')) except ValueError: flask.flash( gettext("fleet-id=%(fleet_id)d was not valid.", fleet_id=request.form.get('fleet-id')), "danger") return redirect(url_for('fleetoptions.fleet')) fleet_type = request.form.get('fleet-type') if skip_setup == "no-setup": skip_setup = True else: skip_setup = False if not skip_setup: fleet_utils.setup(token, fleet_id, fleet_type) return get_select_form(token, fleet_id)
def send_esi_mail(): """ Sends mails to characters. mailRecipients => JSON String recipients=[{"recipient_id": 0, "recipient_type": "character|alliance"}] mailBody => String mailSubject => String """ token: SSOToken = current_user.get_a_sso_token_with_scopes( esi_scopes.mail_scopes) if token is None: return flask.abort(412, 'Not Authenticated for esi-mail.send_mail.v1') body = request.form.get('mailBody') subject = request.form.get('mailSubject') recipients = json.loads(request.form.get('mailRecipients')) target_chars = [] for rec in recipients: if rec['recipient_type'] == 'character': target_chars.append(rec['recipient_id']) target_accs = db.session.query(Account).filter( or_(Account.current_char == charid for charid in target_chars)).all() resp = send_mail(token, recipients, body, subject) if resp.status == 201: history_entry: AccountNote = AccountNote( accountID=current_user.id, byAccountID=current_user.id, type=account_notes.TYPE_SENT_ACCOUNT_MAIL) history_entry.jsonPayload = { 'sender_character_id': current_user.get_eve_id(), 'recipients': recipients, 'body': body, 'subject': subject } db.session.add(history_entry) for acc in target_accs: acc.had_welcome_mail = True history_entry = AccountNote( accountID=acc.id, byAccountID=current_user.id, type=account_notes.TYPE_GOT_ACCOUNT_MAIL) history_entry.jsonPayload = { 'sender_character_id': current_user.get_eve_id(), 'target_character_id': acc.current_char, 'mail_body': body, 'subject': subject } db.session.add(history_entry) db.session.commit() else: esi_resp: ESIResponse = make_error_response(resp) if esi_resp.is_monolith_error(): return make_response(esi_resp.get_monolith_error()['error_label'], resp.status) return make_response( str(resp.data) if resp.data is not None else '', resp.status)
def take_over_fleet(): # lets make sure we got the token we need token: SSOToken = current_user.get_a_sso_token_with_scopes( esi_scopes.fleetcomp_scopes) if token is None: # if not, get it. And then return here return get_sso_redirect('get_fleet_token', ' '.join(esi_scopes.fleetcomp_scopes)) fleet_id = get_character_fleet_id(token, current_user.get_eve_id()) if fleet_id is None: flask.flash( gettext( "You are not in a fleet, or didn't not provide rights to read them." ), "danger") return redirect(url_for("fleetoptions.fleet")) fleet_ep: EveFleetEndpoint = EveFleetEndpoint(token, fleet_id) settings_resp: Union[EveFleet, ESIResponse] = fleet_ep.get_fleet_settings() if settings_resp.is_error(): flask.flash(gettext('You are not the boss of the fleet you are in.'), 'danger') return redirect(url_for("fleetoptions.fleet")) fleet = db.session.query(CrestFleet).get(fleet_id) if fleet is None: # we don't have a setup fleet # this is the fleetsetup page return render_template("fleet/setup/fleet_url.html", fleetID=fleet_id) else: # if we got a fleet # lets remove the current use from a fleet he might be assigned too # and assign him as the new fleets comp if fleet.compID != current_user.id: oldfleet = db.session.query(CrestFleet).filter( (CrestFleet.compID == current_user.id)).first() if oldfleet is not None: oldfleet.compID = None fleet.compID = current_user.id db.session.commit() with open("set_history.log", "a+") as f: f.write('{} - {} is taking a fleet on CREST\n'.format( datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), fleet.comp.username)) return redirect(url_for('fleetoptions.fleet'))
def open_information(target_id: int) -> ESIResponse: """ Tries to open an ingame information window for the given id. :param target_id: id to open ingame information window for :return: ESIResponse :raises APIException if there is something wrong with tokens """ token: Optional[SSOToken] = current_user.get_a_sso_token_with_scopes(esi_scopes.open_ui_window) if token is None: return ESIResponse(datetime.datetime.utcnow(), 403, f"No token with the required scopes:" f" {''.join(esi_scopes.open_ui_window)} exists.") api_v1: App = get_api() client: EsiClient = get_esi_client(token) resp = client.request(api_v1.op['post_ui_openwindow_information'](target_id=target_id)) if resp.status == 204: return ESIResponse(get_expire_time(resp), resp.status, None) return make_error_response(resp)
def post_esi_openwindow_newmail(): token: SSOToken = current_user.get_a_sso_token_with_scopes( esi_scopes.open_ui_window) if token is None: return flask.abort(412, 'Not Authenticated for esi-ui.open_window.v1') recipients_str: str = request.form['mailRecipients'] subject: str = request.form['mailSubject'] body: str = request.form['mailBody'] recipients_json = json.loads(recipients_str) receipients: List[int] = [] alliance_or_corp: int = None mailinglist_id: int = None for rec in recipients_json: if rec['recipient_type'] == 'character': receipients.append(rec['recipient_id']) elif rec['recipient_type'] == 'alliance' or rec[ 'recipient_type'] == 'corporation': if alliance_or_corp is not None or mailinglist_id is not None: raise ValueError( "Only one alliance or corp or mailing list at maximum can be receipient of a mail" ) alliance_or_corp = rec['recipient_id'] elif rec['recipient_type'] == 'mailing_list': if mailinglist_id is not None or alliance_or_corp is not None: raise ValueError( "Only one alliance or corp or mailing list at maximum can be receipient of a mail" ) mailinglist_id = rec['recipient_id'] response = open_mail(token, receipients, body, subject, alliance_or_corp, mailinglist_id) if response.is_error(): flask.abort(response.error(), response.code()) return make_response('', response.code())
def change_setup(fleet_id: int): token: SSOToken = current_user.get_a_sso_token_with_scopes( esi_scopes.fleetcomp_scopes) return get_select_form(token, fleet_id)
def invite(user_id: int, squad_id_list: Sequence[Tuple[int, int]]): token: Optional[SSOToken] = current_user.get_a_sso_token_with_scopes( esi_scopes.fleet_write) if token is None: return { 'status_code': 404, 'text': "You need to go to <a href='" + url_for('fc_sso.login_redirect') + "'>SSO Login</a> and relogin in!" } fleet: CrestFleet = current_user.fleet fleet_api: EveFleetEndpoint = EveFleetEndpoint(token, fleet.fleetID) oldsquad = (0, 0) for idx in range(len(squad_id_list)): squad = squad_id_list[idx] if squad[0] == oldsquad[0] and squad[1] == oldsquad[1]: continue logger.info("Invite %s to wingID %s and squadID %s", str(user_id), str(squad[0]), str(squad[1])) try: response = fleet_api.invite(user_id, 'squad_member', squad[1], squad[0]) except Exception as ex: logger.error("Failed to Invite Member[%d] into squad[%d] wing[%d]", user_id, squad[0], squad[1]) raise ex if response.is_error(): logger.info('Got code[%d] back from invite call', response.code()) if response.is_monolith_error(): mono_error = response.get_monolith_error() if mono_error['error_label'] == 'FleetTooManyMembersInSquad': logger.info( f'Failed to invites because there are to many people in this squad' f' {mono_error["error_dict"]["num"]} ... trying next one' ) continue elif mono_error['error_label'] == 'FleetCandidateOffline': logger.info( 'Failed invite because target player is offline.') return { 'status_code': 520, 'text': 'They player you tried to invite was offline.' } elif mono_error['error_label'] == 'ContactOwnerUnreachable': logger.info( f'Failed to invite {mono_error["error_dict"]["name"]}' f' because he has the invitee blocked') return { 'status_code': 520, 'text': f'Could not invite {mono_error["error_dict"]["name"]}' f' because he has you blocked or is otherwise unreachable.' } else: logger.error( f'Failed invite because of monolith error {response.error()}' ) return { 'status_code': 520, 'text': f'Failed invite because of unhandled Monolith error ' f'{response.error()} please report this to the waitlist ' f'maintainer with the monolith message.' } elif response.code() == 404: return { 'status_code': 404, 'text': "You need to go to <a href='" + url_for('fc_sso.login_redirect') + "'>SSO Login</a> and relogin in!" } else: return { 'status_code': response.code(), 'text': response.error() } return { 'status_code': response.code(), 'text': 'Invite failed for unknown reason' } logger.info("Failed to invite %d to a squad, because all squads are full!", user_id) return { 'status_code': 403, 'text': 'Failed to invite person a squad, all squads are full!' }