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:
@@ -48,11 +48,15 @@ module Teams
|
||||
end
|
||||
|
||||
def staff_count
|
||||
staff_count_for("transmission") + staff_count_for("regia")
|
||||
staff_count_for("transmission")
|
||||
end
|
||||
|
||||
def staff_count_for(kind)
|
||||
members_count_for(kind) + pending_invitations_count_for(kind)
|
||||
def staff_count_for(_kind = "transmission")
|
||||
staff_coverage.covered_count
|
||||
end
|
||||
|
||||
def staff_assigned_for(_kind = "transmission")
|
||||
staff_coverage.assigned_count
|
||||
end
|
||||
|
||||
def members_count
|
||||
@@ -149,29 +153,19 @@ module Teams
|
||||
def assert_can_invite!(staff_kind: "transmission")
|
||||
return unless active?
|
||||
|
||||
kind = staff_kind.to_s
|
||||
unless TeamInvitation::STAFF_KINDS.include?(kind)
|
||||
raise EntitlementError.new("Ruolo staff non valido", code: "invalid_staff_kind")
|
||||
end
|
||||
|
||||
limit = staff_limit_for(kind)
|
||||
limit = max_staff_transmission
|
||||
return if limit.nil?
|
||||
|
||||
used = staff_count_for(kind)
|
||||
used = staff_assigned_for
|
||||
return if used < limit
|
||||
|
||||
label = kind == "regia" ? "regia" : "trasmissione"
|
||||
raise EntitlementError.new(
|
||||
"Limite staff #{label} raggiunto (#{limit} all'anno). Passa a un piano superiore.",
|
||||
"Limite responsabili trasmissione raggiunto (#{limit} all'anno). Passa a un piano superiore.",
|
||||
code: "staff_limit_reached",
|
||||
billing_url: billing_url
|
||||
)
|
||||
end
|
||||
|
||||
def staff_limit_for(kind)
|
||||
kind == "regia" ? max_staff_regia : max_staff_transmission
|
||||
end
|
||||
|
||||
def assert_can_connect_youtube!
|
||||
unless premium_full?
|
||||
raise EntitlementError.new(
|
||||
@@ -216,10 +210,8 @@ module Teams
|
||||
staff_manage_url: staff_manage_url,
|
||||
max_staff: max_staff,
|
||||
max_staff_transmission: max_staff_transmission,
|
||||
max_staff_regia: max_staff_regia,
|
||||
staff_used: staff_count,
|
||||
staff_transmission_used: staff_count_for("transmission"),
|
||||
staff_regia_used: staff_count_for("regia"),
|
||||
concurrent_streams_used: concurrent_streams_used,
|
||||
concurrent_streams_limit: concurrent_streams_limit,
|
||||
recordings_enabled: can_access_recordings?,
|
||||
@@ -230,6 +222,10 @@ module Teams
|
||||
}
|
||||
end
|
||||
|
||||
def staff_coverage
|
||||
@staff_coverage ||= StaffCoverage.new(@team)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_free_subscription!
|
||||
|
||||
@@ -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
|
||||
|
||||
35
backend/app/services/teams/staff_coverage.rb
Normal file
35
backend/app/services/teams/staff_coverage.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
module Teams
|
||||
class StaffCoverage
|
||||
def initialize(team)
|
||||
@team = team
|
||||
end
|
||||
|
||||
def assigned_count(_kind = "transmission")
|
||||
members_count + pending_invitations_count
|
||||
end
|
||||
|
||||
def covered_count(_kind = "transmission")
|
||||
assigned_count.positive? ? 1 : 0
|
||||
end
|
||||
|
||||
def role_label_for(membership)
|
||||
return "Trasmissione" if membership.staff_kind.present?
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
def open_slot_for_invite?(_kind = "transmission")
|
||||
assigned_count < 1
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def members_count
|
||||
@team.user_teams.where.not(staff_kind: nil).count
|
||||
end
|
||||
|
||||
def pending_invitations_count
|
||||
@team.team_invitations.pending.count
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user