debut changement vers google drive
CI - Security, Lint & Tests / validate (push) Failing after 1m14s
CI - Security, Lint & Tests / validate (push) Failing after 1m14s
This commit is contained in:
+4
-3
@@ -8,6 +8,7 @@ import uuid
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request, jsonify, send_file
|
||||
from flask_login import login_required, current_user
|
||||
from app.extensions import db, hash_password, csrf
|
||||
from app.time_utils import utc_now_naive
|
||||
from app.models import (
|
||||
Admin, Manager, Coach, Player, Scout,
|
||||
User, USER_TYPES, ESPORT_GAMES,
|
||||
@@ -625,7 +626,7 @@ def upload_signed_contract(contract_id):
|
||||
contract.signed_filename = signed_filename
|
||||
contract.signed_file_path = contract.file_path.replace(contract.stored_filename, signed_filename)
|
||||
contract.status = 'signed'
|
||||
contract.signed_at = datetime.utcnow()
|
||||
contract.signed_at = utc_now_naive()
|
||||
db.session.commit()
|
||||
flash('Signed contract uploaded successfully!', 'success')
|
||||
return redirect(url_for('users.list_contracts'))
|
||||
@@ -891,7 +892,7 @@ def accept_one_on_one(request_id):
|
||||
|
||||
player = request_obj.player
|
||||
request_obj.status = 'approved'
|
||||
request_obj.responded_at = datetime.utcnow()
|
||||
request_obj.responded_at = utc_now_naive()
|
||||
db.session.commit()
|
||||
|
||||
# Notify player via Discord (same message as if approved through Discord reactions)
|
||||
@@ -934,7 +935,7 @@ def reject_one_on_one(request_id):
|
||||
player = request_obj.player
|
||||
|
||||
request_obj.status = 'rejected'
|
||||
request_obj.responded_at = datetime.utcnow()
|
||||
request_obj.responded_at = utc_now_naive()
|
||||
if rejection_reason:
|
||||
request_obj.coach_rejection_message = rejection_reason
|
||||
db.session.commit()
|
||||
|
||||
@@ -18,7 +18,13 @@ from app.routes.users._shared import (
|
||||
pdf_upload_error,
|
||||
)
|
||||
from app.routes.users.blueprint import users_bp
|
||||
from app.storage import CONTRACTS_DIR, document_path
|
||||
from app.storage import (
|
||||
CONTRACTS_DIR,
|
||||
GoogleDriveStorageError,
|
||||
is_google_drive_path,
|
||||
open_document,
|
||||
store_uploaded_document,
|
||||
)
|
||||
from app.time_utils import utc_now_naive
|
||||
from app.validators import UploadContractSchema
|
||||
|
||||
@@ -126,9 +132,11 @@ def upload_contract():
|
||||
if team:
|
||||
relative_path = os.path.join(CONTRACTS_DIR, secure_filename(team.name), stored_filename)
|
||||
|
||||
absolute_path = document_path(relative_path)
|
||||
os.makedirs(os.path.dirname(absolute_path), exist_ok=True)
|
||||
file.save(absolute_path)
|
||||
try:
|
||||
stored_path = store_uploaded_document(file, relative_path)
|
||||
except GoogleDriveStorageError:
|
||||
flash(_('Contract storage is temporarily unavailable. Please try again later.'), 'danger')
|
||||
return redirect(url_for('users.upload_contract'))
|
||||
|
||||
contract = Contract(
|
||||
player_id=player_id,
|
||||
@@ -136,7 +144,7 @@ def upload_contract():
|
||||
uploaded_by_id=current_user.id,
|
||||
original_filename=original_filename,
|
||||
stored_filename=stored_filename,
|
||||
file_path=relative_path,
|
||||
file_path=stored_path,
|
||||
notes=notes if notes else None,
|
||||
)
|
||||
db.session.add(contract)
|
||||
@@ -166,11 +174,22 @@ def upload_signed_contract(contract_id):
|
||||
return redirect(url_for('users.list_contracts'))
|
||||
|
||||
signed_filename = f"signed_{contract.stored_filename}"
|
||||
signed_path = contract.file_path.replace(contract.stored_filename, signed_filename)
|
||||
file.save(document_path(signed_path))
|
||||
# Legacy local records keep their signed copy beside the original. Drive
|
||||
# identifiers are opaque rather than filenames, so new Drive records use
|
||||
# a fresh logical path and receive a second Drive ID.
|
||||
signed_path = (
|
||||
os.path.join(CONTRACTS_DIR, signed_filename)
|
||||
if is_google_drive_path(contract.file_path)
|
||||
else contract.file_path.replace(contract.stored_filename, signed_filename)
|
||||
)
|
||||
try:
|
||||
stored_signed_path = store_uploaded_document(file, signed_path)
|
||||
except GoogleDriveStorageError:
|
||||
flash(_('Contract storage is temporarily unavailable. Please try again later.'), 'danger')
|
||||
return redirect(url_for('users.list_contracts'))
|
||||
|
||||
contract.signed_filename = signed_filename
|
||||
contract.signed_file_path = signed_path
|
||||
contract.signed_file_path = stored_signed_path
|
||||
contract.status = 'signed'
|
||||
contract.signed_at = utc_now_naive()
|
||||
db.session.commit()
|
||||
@@ -186,11 +205,12 @@ def download_contract(contract_id):
|
||||
if not contract.can_view(current_user):
|
||||
flash(_('You do not have permission to download this contract.'), 'danger')
|
||||
return redirect(url_for('users.list_contracts'))
|
||||
return send_file(
|
||||
document_path(contract.file_path),
|
||||
as_attachment=True,
|
||||
download_name=contract.original_filename,
|
||||
)
|
||||
try:
|
||||
document = open_document(contract.file_path)
|
||||
except GoogleDriveStorageError:
|
||||
flash(_('Contract storage is temporarily unavailable. Please try again later.'), 'danger')
|
||||
return redirect(url_for('users.list_contracts'))
|
||||
return send_file(document, as_attachment=True, download_name=contract.original_filename)
|
||||
|
||||
|
||||
@users_bp.route('/contracts/<int:contract_id>/download_signed')
|
||||
@@ -204,8 +224,9 @@ def download_signed_contract(contract_id):
|
||||
if not contract.signed_file_path:
|
||||
flash(_('No signed contract available.'), 'danger')
|
||||
return redirect(url_for('users.list_contracts'))
|
||||
return send_file(
|
||||
document_path(contract.signed_file_path),
|
||||
as_attachment=True,
|
||||
download_name=contract.signed_filename,
|
||||
)
|
||||
try:
|
||||
document = open_document(contract.signed_file_path)
|
||||
except GoogleDriveStorageError:
|
||||
flash(_('Contract storage is temporarily unavailable. Please try again later.'), 'danger')
|
||||
return redirect(url_for('users.list_contracts'))
|
||||
return send_file(document, as_attachment=True, download_name=contract.signed_filename)
|
||||
|
||||
Reference in New Issue
Block a user