ajout d'un boite de reception et dépot des documents (pour les contrats)
This commit is contained in:
@@ -327,3 +327,57 @@ class MatchParticipant(db.Model):
|
||||
added_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
||||
player = db.relationship('User')
|
||||
|
||||
|
||||
class Contract(db.Model):
|
||||
"""Contract documents for players to sign."""
|
||||
__tablename__ = 'contracts'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
player_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||
team_id = db.Column(db.Integer, db.ForeignKey('org_teams.id'), nullable=True)
|
||||
uploaded_by_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||
|
||||
# File information
|
||||
original_filename = db.Column(db.String(255), nullable=False)
|
||||
stored_filename = db.Column(db.String(255), nullable=False)
|
||||
file_path = db.Column(db.String(500), nullable=False)
|
||||
|
||||
# Signed contract information
|
||||
signed_filename = db.Column(db.String(255), nullable=True)
|
||||
signed_file_path = db.Column(db.String(500), nullable=True)
|
||||
|
||||
# Status and metadata
|
||||
status = db.Column(db.String(20), default='pending') # pending, signed
|
||||
notes = db.Column(db.Text, nullable=True)
|
||||
uploaded_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
signed_at = db.Column(db.DateTime, nullable=True)
|
||||
|
||||
# Relationships
|
||||
player = db.relationship('User', foreign_keys=[player_id], backref='contracts')
|
||||
team = db.relationship('OrgTeam', foreign_keys=[team_id])
|
||||
uploader = db.relationship('User', foreign_keys=[uploaded_by_id])
|
||||
|
||||
def can_view(self, user):
|
||||
"""Check if a user can view this contract."""
|
||||
# Player can always view their own contracts
|
||||
if user.id == self.player_id:
|
||||
return True
|
||||
# President can view all contracts
|
||||
if user.role == 'president':
|
||||
return True
|
||||
# Manager can view contracts for players on their teams
|
||||
if user.role == 'manager':
|
||||
player = User.query.get(self.player_id)
|
||||
if player and player.team_id:
|
||||
return True
|
||||
# Coach can view contracts for players on their team
|
||||
if user.role == 'coach':
|
||||
org_team = OrgTeam.query.filter_by(coach_id=user.id).first()
|
||||
if org_team and (not self.team_id or self.team_id == org_team.id):
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_upload_signed(self, user):
|
||||
"""Check if a user can upload a signed contract."""
|
||||
# Only the player can upload their signed contract
|
||||
return user.id == self.player_id
|
||||
|
||||
Reference in New Issue
Block a user