Club come entità principale, branding e fix infrastruttura streaming.
Introduce clubs con abbonamento, branding Active Storage e flusso registrazione società; corregge healthcheck MediaMTX (immagine distroless) e allinea dominio produzione matchlivetv.it. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,10 +4,11 @@ module Teams
|
||||
|
||||
def initialize(team)
|
||||
@team = team
|
||||
@club = team.club
|
||||
end
|
||||
|
||||
def subscription
|
||||
@subscription ||= @team.subscription || ensure_free_subscription!
|
||||
@subscription ||= @club.subscription || ensure_free_subscription!
|
||||
end
|
||||
|
||||
def plan
|
||||
@@ -59,7 +60,7 @@ module Teams
|
||||
end
|
||||
|
||||
def members_count_for(kind)
|
||||
@team.user_teams.where(role: "member", staff_kind: kind).count
|
||||
@team.user_teams.where(staff_kind: kind).count
|
||||
end
|
||||
|
||||
def pending_invitations_count
|
||||
@@ -75,8 +76,8 @@ module Teams
|
||||
end
|
||||
|
||||
def concurrent_streams_used
|
||||
StreamSession.joins(:match)
|
||||
.where(matches: { team_id: @team.id })
|
||||
StreamSession.joins(match: :team)
|
||||
.where(teams: { club_id: @club.id })
|
||||
.where(status: ACTIVE_STREAM_STATUSES)
|
||||
.count
|
||||
end
|
||||
@@ -101,7 +102,7 @@ module Teams
|
||||
platform = platform.to_s
|
||||
unless active?
|
||||
raise EntitlementError.new(
|
||||
"Abbonamento non attivo per questa squadra",
|
||||
"Abbonamento non attivo per la società",
|
||||
code: "subscription_inactive",
|
||||
billing_url: billing_url
|
||||
)
|
||||
@@ -196,7 +197,7 @@ module Teams
|
||||
end
|
||||
|
||||
def billing_url
|
||||
"#{MatchLiveTv.app_public_url.chomp('/')}/teams/#{@team.id}/billing"
|
||||
"#{MatchLiveTv.app_public_url.chomp('/')}/clubs/#{@club.id}/billing"
|
||||
end
|
||||
|
||||
def staff_manage_url
|
||||
@@ -232,8 +233,8 @@ module Teams
|
||||
private
|
||||
|
||||
def ensure_free_subscription!
|
||||
Billing::AssignPlan.call(team: @team, plan_slug: "free")
|
||||
@team.reload.subscription
|
||||
Billing::AssignPlan.call(club: @club, plan_slug: "free")
|
||||
@club.reload.subscription
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
85
backend/app/services/teams/staff_assignment.rb
Normal file
85
backend/app/services/teams/staff_assignment.rb
Normal file
@@ -0,0 +1,85 @@
|
||||
module Teams
|
||||
class StaffAssignmentError < StandardError
|
||||
attr_reader :message
|
||||
|
||||
def initialize(message)
|
||||
@message = message
|
||||
super(message)
|
||||
end
|
||||
end
|
||||
|
||||
class StaffAssignment
|
||||
def self.call(team:, user:, staff_kind:, membership: nil)
|
||||
new(team: team, user: user, staff_kind: staff_kind, membership: membership).call
|
||||
end
|
||||
|
||||
def initialize(team:, user:, staff_kind:, membership: nil)
|
||||
@team = team
|
||||
@user = user
|
||||
@staff_kind = staff_kind.to_s
|
||||
@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)
|
||||
|
||||
ut = @membership || @user.user_teams.find_by!(team: @team)
|
||||
return ut if ut.staff_kind == @staff_kind
|
||||
|
||||
ent = Entitlements.new(@team)
|
||||
ent.assert_can_invite!(staff_kind: @staff_kind)
|
||||
ut.update!(staff_kind: @staff_kind)
|
||||
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!
|
||||
end
|
||||
|
||||
def initialize(team:, email:, staff_kind:, 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
|
||||
end
|
||||
|
||||
conflict = conflicting_assignment
|
||||
return unless conflict
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user