Billing Stripe, link regia mobile e staff solo trasmissione.

Aggiunge fatturazione club, pagina regia condivisibile senza account, roster squadre e rimuove la modalità controller dall'app (v1.1.0).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-29 07:23:13 +02:00
parent 4083bc5dee
commit f4b7be0f80
156 changed files with 5033 additions and 2033 deletions

View File

@@ -9,77 +9,55 @@ module Teams
end
class StaffAssignment
def self.call(team:, user:, staff_kind:, membership: nil)
def self.call(team:, user:, staff_kind: "transmission", membership: nil)
new(team: team, user: user, staff_kind: staff_kind, membership: membership).call
end
def initialize(team:, user:, staff_kind:, membership: nil)
def initialize(team:, user:, staff_kind: "transmission", membership: nil)
@team = team
@user = user
@staff_kind = staff_kind.to_s
@staff_kind = "transmission"
@membership = membership
end
def call
unless TeamInvitation::STAFF_KINDS.include?(@staff_kind)
raise StaffAssignmentError, "Ruolo staff non valido"
end
StaffEmailValidator.assert_available!(team: @team, email: @user.email, staff_kind: @staff_kind, except_user: @user)
StaffEmailValidator.assert_available!(
team: @team, email: @user.email, except_user: @user
)
ut = @membership || @user.user_teams.find_by!(team: @team)
return ut if ut.staff_kind == @staff_kind
return ut if ut.staff_kind == "transmission"
ent = Entitlements.new(@team)
ent.assert_can_invite!(staff_kind: @staff_kind)
ut.update!(staff_kind: @staff_kind)
Entitlements.new(@team).assert_can_invite!
ut.update!(staff_kind: "transmission")
ut
end
end
class StaffEmailValidator
def self.assert_available!(team:, email:, staff_kind:, except_user: nil)
new(team: team, email: email, staff_kind: staff_kind, except_user: except_user).assert_available!
def self.assert_available!(team:, email:, except_user: nil, staff_kind: nil)
new(team: team, email: email, except_user: except_user).assert_available!
end
def initialize(team:, email:, staff_kind:, except_user: nil)
def initialize(team:, email:, except_user: nil)
@team = team
@email = email.to_s.downcase.strip
@staff_kind = staff_kind.to_s
@except_user = except_user
end
def assert_available!
if @except_user
ut = @team.user_teams.find_by(user: @except_user)
if ut&.staff_kind.present? && ut.staff_kind != @staff_kind
other_label = ut.staff_kind == "regia" ? "regia" : "trasmissione"
raise StaffAssignmentError,
"Questo account è già staff #{other_label}. Trasmissione e regia devono essere email diverse."
end
user_scope = @team.user_teams.joins(:user).where(users: { email: @email }).where.not(staff_kind: nil)
user_scope = user_scope.where.not(user_id: @except_user.id) if @except_user
if user_scope.exists?
raise StaffAssignmentError,
"L'email #{@email} è già assegnata come responsabile trasmissione per questa squadra."
end
conflict = conflicting_assignment
return unless conflict
inv = @team.team_invitations.pending.where("LOWER(email) = ?", @email)
return unless inv.exists?
other_label = conflict[:kind] == "regia" ? "regia" : "trasmissione"
raise StaffAssignmentError,
"L'email #{@email} è già assegnata come staff #{other_label}. Trasmissione e regia devono essere persone (email) diverse."
end
def conflicting_assignment
other_kind = @staff_kind == "transmission" ? "regia" : "transmission"
user_scope = @team.user_teams.joins(:user).where(users: { email: @email }).where(staff_kind: other_kind)
user_scope = user_scope.where.not(user_id: @except_user.id) if @except_user
return { kind: other_kind, source: :member } if user_scope.exists?
inv = @team.team_invitations.pending.where("LOWER(email) = ?", @email).where(staff_kind: other_kind)
return { kind: other_kind, source: :invitation } if inv.exists?
nil
"Esiste già un invito in sospeso per #{@email}."
end
end
end