Merge branch 'main' into collaudo
Porta in collaudo l'invito trasmissione con email automatica.
This commit is contained in:
@@ -58,7 +58,7 @@ module Public
|
||||
|
||||
def invite
|
||||
require_club_owner_for_team!(@team)
|
||||
@entitlements = @team.entitlements
|
||||
redirect_to public_team_details_path(@team, anchor: "invita-trasmissione")
|
||||
end
|
||||
|
||||
def assign_self_staff
|
||||
@@ -87,18 +87,32 @@ module Public
|
||||
email = params[:email]&.downcase&.strip
|
||||
Teams::StaffEmailValidator.assert_available!(team: @team, email: email, staff_kind: staff_kind)
|
||||
token = TeamInvitation.generate_token
|
||||
@team.team_invitations.create!(
|
||||
invitation = @team.team_invitations.create!(
|
||||
email: email,
|
||||
token_digest: Digest::SHA256.hexdigest(token),
|
||||
role: "member",
|
||||
staff_kind: staff_kind,
|
||||
expires_at: 7.days.from_now
|
||||
)
|
||||
@invite_url = join_public_invitation_url(token: token)
|
||||
flash.now[:notice] = t("flash.teams.invite_link_generated")
|
||||
render :invite
|
||||
invite_url = public_invitation_url(token: token)
|
||||
flash[:invite_url] = invite_url
|
||||
|
||||
begin
|
||||
Teams::InvitationMailer.transmission_invite(
|
||||
team: @team,
|
||||
invitation: invitation,
|
||||
invite_url: invite_url,
|
||||
invited_by: current_user
|
||||
).deliver_now
|
||||
flash[:notice] = t("flash.teams.invite_email_sent", email: email)
|
||||
rescue StandardError => e
|
||||
Rails.logger.error("[invite_email] #{e.class}: #{e.message}")
|
||||
flash[:alert] = t("flash.teams.invite_email_failed", email: email)
|
||||
end
|
||||
|
||||
redirect_to public_team_details_path(@team, anchor: "invito-generato")
|
||||
rescue Teams::EntitlementError, Teams::StaffAssignmentError => e
|
||||
redirect_to public_team_invite_path(@team), alert: e.message
|
||||
redirect_to public_team_details_path(@team, anchor: "invita-trasmissione"), alert: e.message
|
||||
end
|
||||
|
||||
def remove_member
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
module Teams
|
||||
class InvitationMailer < ApplicationMailer
|
||||
default from: -> { MatchLiveTv.mail_from }
|
||||
|
||||
def transmission_invite(team:, invitation:, invite_url:, invited_by:)
|
||||
@team = team
|
||||
@club = team.club
|
||||
@invitation = invitation
|
||||
@invite_url = invite_url
|
||||
@invited_by = invited_by
|
||||
@expires_on = I18n.l(invitation.expires_at.to_date, format: :long)
|
||||
|
||||
I18n.with_locale(I18n.locale) do
|
||||
mail(
|
||||
to: invitation.email,
|
||||
subject: t(
|
||||
"mailers.transmission_invite.subject",
|
||||
team: @team.name,
|
||||
club: @club.name
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,13 +1,4 @@
|
||||
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: "transmission", membership: nil)
|
||||
new(team: team, user: user, staff_kind: staff_kind, membership: membership).call
|
||||
@@ -33,31 +24,4 @@ module Teams
|
||||
ut
|
||||
end
|
||||
end
|
||||
|
||||
class StaffEmailValidator
|
||||
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:, except_user: nil)
|
||||
@team = team
|
||||
@email = email.to_s.downcase.strip
|
||||
@except_user = except_user
|
||||
end
|
||||
|
||||
def assert_available!
|
||||
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
|
||||
|
||||
inv = @team.team_invitations.pending.where("LOWER(email) = ?", @email)
|
||||
return unless inv.exists?
|
||||
|
||||
raise StaffAssignmentError,
|
||||
"Esiste già un invito in sospeso per #{@email}."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
module Teams
|
||||
class StaffAssignmentError < StandardError
|
||||
attr_reader :message
|
||||
|
||||
def initialize(message)
|
||||
@message = message
|
||||
super(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,28 @@
|
||||
module Teams
|
||||
class StaffEmailValidator
|
||||
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:, except_user: nil)
|
||||
@team = team
|
||||
@email = email.to_s.downcase.strip
|
||||
@except_user = except_user
|
||||
end
|
||||
|
||||
def assert_available!
|
||||
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
|
||||
|
||||
inv = @team.team_invitations.pending.where("LOWER(email) = ?", @email)
|
||||
return unless inv.exists?
|
||||
|
||||
raise StaffAssignmentError,
|
||||
"Esiste già un invito in sospeso per #{@email}."
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -7,7 +7,7 @@
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body style="margin:0;padding:24px;background:#ffffff;color:#1a1a1a;">
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<%= render "shared/meta_tags" %>
|
||||
<%= yield :head %>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer">
|
||||
<link rel="stylesheet" href="/marketing.css?v=63">
|
||||
<link rel="stylesheet" href="/marketing.css?v=64">
|
||||
</head>
|
||||
<body data-confirm-i18n='<%= raw confirm_dialog_i18n_json %>'<% if MatchLiveTv.google_analytics_configured? %> data-ga-id="<%= MatchLiveTv.google_analytics_measurement_id %>"<% end %>>
|
||||
<%= render "shared/cookie_banner" %>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<title><%= content_for?(:title) ? yield(:title) : "Match Live TV" %></title>
|
||||
<%= render "shared/meta_tags" %>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer">
|
||||
<link rel="stylesheet" href="/marketing.css?v=63">
|
||||
<link rel="stylesheet" href="/marketing.css?v=64">
|
||||
<link rel="stylesheet" href="/live.css?v=26">
|
||||
<%= yield :head %>
|
||||
</head>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<% recordings = local_assigns[:recordings] %>
|
||||
<% entitlements = local_assigns[:entitlements] %>
|
||||
|
||||
<section class="team-streaming-staff">
|
||||
<section class="team-streaming-staff" id="responsabili-trasmissione">
|
||||
<% if can_manage %>
|
||||
<% if owner_membership&.staff_kind.blank? %>
|
||||
<div class="card team-streaming-staff__self">
|
||||
@@ -51,12 +51,34 @@
|
||||
<% else %>
|
||||
<p class="muted">
|
||||
<%= t("team.streaming_staff.no_staff") %>
|
||||
<% if can_manage %><%= link_to t("team.streaming_staff.invite_someone"), public_team_invite_path(team) %>.<% end %>
|
||||
<% if can_manage %><%= link_to t("team.streaming_staff.invite_someone"), "#invita-trasmissione" %>.<% end %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if can_manage %>
|
||||
<div class="card team-invite-form" id="invita-trasmissione">
|
||||
<h2><%= t("team.streaming_staff.invite_form_heading") %></h2>
|
||||
<p class="muted team-invite-form__hint"><%= t("team.streaming_staff.invite_form_hint") %></p>
|
||||
<%= form_with url: public_team_invite_path(team), method: :post, class: "team-invite-form__fields" do %>
|
||||
<%= hidden_field_tag :staff_kind, "transmission" %>
|
||||
<%= label_tag :email, t("team.invite.email_label") %>
|
||||
<%= email_field_tag :email, params[:email], required: true, autocomplete: "email", placeholder: "nome@email.it" %>
|
||||
<%= submit_tag t("team.invite.submit"), class: "btn btn-primary" %>
|
||||
<% end %>
|
||||
|
||||
<% if flash[:invite_url].present? %>
|
||||
<div class="team-invite-link" id="invito-generato">
|
||||
<p class="team-invite-link__title"><%= t("team.invite.share_hint") %></p>
|
||||
<code class="team-invite-link__url" id="team-invite-url"><%= flash[:invite_url] %></code>
|
||||
<button type="button" class="btn btn-secondary team-invite-link__copy" data-copy-target="team-invite-url">
|
||||
<%= t("regia.copy_link") %>
|
||||
</button>
|
||||
<p class="muted team-invite-link__note"><%= t("team.streaming_staff.invite_once_note") %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<h2><%= t("team.streaming_staff.pending_invitations_heading") %></h2>
|
||||
<div class="card">
|
||||
<% if pending_invitations.any? %>
|
||||
@@ -114,3 +136,18 @@
|
||||
</div>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll("[data-copy-target]").forEach(function (btn) {
|
||||
btn.addEventListener("click", async function () {
|
||||
var el = document.getElementById(btn.getAttribute("data-copy-target"));
|
||||
if (!el) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(el.textContent.trim());
|
||||
btn.textContent = <%= raw t("team.streaming_staff.copied").to_json %>;
|
||||
} catch (e) {
|
||||
window.getSelection().selectAllChildren(el);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<% if @can_manage %>
|
||||
<%= link_to t("club.back_to_club"), public_club_path(@club), class: "btn btn-secondary" %>
|
||||
<%= link_to t("team.details.public_page"), public_team_page_path(@team.slug), class: "btn btn-secondary", target: "_blank", rel: "noopener" %>
|
||||
<%= link_to t("team.details.streaming_managers"), public_team_invite_path(@team), class: "btn btn-secondary" %>
|
||||
<%= link_to t("team.details.streaming_managers"), "#responsabili-trasmissione", class: "btn btn-secondary" %>
|
||||
<% end %>
|
||||
<% if current_user.can_stream_for?(@team) %>
|
||||
<%= link_to t("team.details.schedule_matches"), public_team_matches_path(@team), class: "btn btn-primary" %>
|
||||
|
||||
@@ -1,38 +1,8 @@
|
||||
<%# Pagina legacy: l'invito è sulla pagina dettagli squadra. %>
|
||||
<% content_for :title, t("team.invite.title", name: @team.name) %>
|
||||
<% content_for :robots, "noindex, nofollow" %>
|
||||
|
||||
<div class="wrap" style="padding-top:20px">
|
||||
<h1><%= t("team.invite.heading") %></h1>
|
||||
<p>
|
||||
<%= t("team.invite.assigned_label") %> <strong><%= @entitlements.staff_count_for("transmission") %> / <%= @entitlements.max_staff_transmission || "∞" %></strong>
|
||||
<%= t("team.invite.per_team_note") %>
|
||||
</p>
|
||||
<p class="muted" style="max-width:640px">
|
||||
<%= raw t("team.invite.info") %>
|
||||
</p>
|
||||
|
||||
<% owner_membership = current_user.user_teams.find_by(team: @team) %>
|
||||
<% if owner_membership&.staff_kind.blank? %>
|
||||
<div class="card" style="max-width:520px;margin-bottom:16px">
|
||||
<p style="margin:0 0 12px;color:#aaa;font-size:0.92rem">
|
||||
<%= raw t("team.invite.self_assign_hint_html", email: current_user.email) %>
|
||||
</p>
|
||||
<%= button_to t("team.invite.self_assign_submit"), public_team_assign_self_staff_path(@team), method: :post, params: { staff_kind: "transmission" }, class: "btn btn-primary" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="card" style="max-width:520px">
|
||||
<h2 style="margin-top:0;font-size:1.05rem"><%= t("team.invite.invite_other_heading") %></h2>
|
||||
<%= form_with url: public_team_invite_path(@team), method: :post do %>
|
||||
<%= hidden_field_tag :staff_kind, "transmission" %>
|
||||
<%= label_tag :email, t("team.invite.email_label") %>
|
||||
<%= email_field_tag :email, params[:email], required: true %>
|
||||
<%= submit_tag t("team.invite.submit"), class: "btn btn-primary" %>
|
||||
<% end %>
|
||||
<% if defined?(@invite_url) && @invite_url.present? %>
|
||||
<p style="margin-top:16px"><%= t("team.invite.share_hint") %></p>
|
||||
<code style="word-break:break-all;display:block;background:#0a0a0e;padding:12px;border-radius:8px"><%= @invite_url %></code>
|
||||
<% end %>
|
||||
</div>
|
||||
<p><%= link_to t("team.back_to_details"), public_team_details_path(@team) %></p>
|
||||
<p class="muted"><%= t("team.streaming_staff.invite_form_hint") %></p>
|
||||
<p><%= link_to t("team.back_to_details"), public_team_details_path(@team, anchor: "invita-trasmissione"), class: "btn btn-primary" %></p>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 16px; line-height: 1.5; color: #1a1a1a; max-width: 560px;">
|
||||
<p style="margin: 0 0 16px;"><%= t("mailers.transmission_invite.hello") %></p>
|
||||
|
||||
<p style="margin: 0 0 16px;">
|
||||
<%= raw t(
|
||||
"mailers.transmission_invite.body_html",
|
||||
inviter: @invited_by.name,
|
||||
team: @team.name,
|
||||
club: @club.name
|
||||
) %>
|
||||
</p>
|
||||
|
||||
<p style="margin: 0 0 16px;">
|
||||
<a href="<%= @invite_url %>" style="display: inline-block; background: #e53935; color: #ffffff; text-decoration: none; padding: 12px 18px; border-radius: 8px; font-weight: 600;">
|
||||
<%= t("mailers.transmission_invite.cta") %>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p style="margin: 0 0 16px; color: #444; font-size: 14px;">
|
||||
<%= t("mailers.transmission_invite.link_fallback") %><br>
|
||||
<a href="<%= @invite_url %>" style="color: #e53935; word-break: break-all;"><%= @invite_url %></a>
|
||||
</p>
|
||||
|
||||
<p style="margin: 0 0 16px;"><%= t("mailers.transmission_invite.steps") %></p>
|
||||
|
||||
<p style="margin: 0 0 16px;"><%= t("mailers.transmission_invite.expiry", date: @expires_on) %></p>
|
||||
|
||||
<p style="margin: 0 0 24px; color: #666;"><%= t("mailers.transmission_invite.ignore") %></p>
|
||||
|
||||
<p style="margin: 0; color: #888; font-size: 12px;"><%= t("mailers.transmission_invite.footer", email: MatchLiveTv.privacy_controller_email) %></p>
|
||||
</div>
|
||||
@@ -0,0 +1,19 @@
|
||||
<%= t("mailers.transmission_invite.hello") %>
|
||||
|
||||
<%= t(
|
||||
"mailers.transmission_invite.body_text",
|
||||
inviter: @invited_by.name,
|
||||
team: @team.name,
|
||||
club: @club.name
|
||||
) %>
|
||||
|
||||
<%= t("mailers.transmission_invite.link_text") %>
|
||||
<%= @invite_url %>
|
||||
|
||||
<%= t("mailers.transmission_invite.steps") %>
|
||||
|
||||
<%= t("mailers.transmission_invite.expiry", date: @expires_on) %>
|
||||
|
||||
<%= t("mailers.transmission_invite.ignore") %>
|
||||
|
||||
<%= t("mailers.transmission_invite.footer", email: MatchLiveTv.privacy_controller_email) %>
|
||||
Reference in New Issue
Block a user