def fatt_vedtak_action_strategy(soknad, action, data):
    vedtak = VedtakUtils.fatt_vedtak(soknad, data)
    if not data.get('saveOnly'):
        vedtak.vedtaksdato = datetime.now()
        soknad.status = action.get_end_state().id

        current_app.logger.debug("Generating vedtaksbrev...")
        rendered_file, file_size, mimetype, filename = VedtaksbrevGeneratorResource.generate_vedtaksbrev(soknad, vedtak)
        current_app.logger.debug("Saving vedtaksbrev to backend...")
        saved_filename, saved_in_dir = save_file_to_disk(rendered_file, filename,
                                                         relative_path=get_rel_vedtaksmappe_path(soknad, vedtak))
        current_app.logger.debug("Updating vedtaket med vedtaksbrev_file_ref=%s..." % saved_filename)
        vedtak.vedtaksbrev_file_ref = saved_filename

        # Arkivering
        # ###########
        organisation = get_organisation(soknad.organisation_id, request.cookies)
        person = get_person(soknad.person_id, request.cookies)
        save_journalpost_for_vedtaksbrev(soknad, organisation, person, vedtak, is_utgaaende_dokument=True)

        SoknadRepo.save(soknad)

        # Sending mail after save to avoid that mail integration errors make it impossible to perform action.
        # It also makes sense to send mail only when we know that the action is successful
        if action == SoknadStateMachine.t_fatt_vedtak:
            send_email_to_soker_on_action_fatt_vedtak(soknad)
        elif action == SoknadStateMachine.t_fatt_klagevedtak:
            send_email_to_soker_on_action_fatt_klagevedtak(soknad)

    else:
        SoknadRepo.save(soknad)
def save_new_dokument_to_disk(filecontent, filename, dest_dir_rel_path=""):
    document_root_path = os.environ.get('DOCUMENTS_PATH', '/tmp')
    assert (os.path.isdir(document_root_path))

    generated_file_name, target_dir = save_file_to_disk(filecontent, filename,
                                                        relative_path=dest_dir_rel_path,
                                                        use_uuid=False)

    current_app.logger.info("Journalpost file '%s' archived in %s." % (filename, target_dir))

    return "%s/%s" % (target_dir, generated_file_name)