Permette all’admin di forzare anagrafica, fiscali, owner, staff e inviti.
Ops può correggere dati clienti errati (es. email titolare) dalla scheda società senza interventi manuali sul DB. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module Admin
|
||||
class ClubsController < BaseController
|
||||
before_action :set_club, only: %i[show grant_comped revoke_comped set_quote revoke_quote]
|
||||
before_action :set_club, only: %i[show edit update grant_comped revoke_comped set_quote revoke_quote]
|
||||
|
||||
def index
|
||||
@clubs = Club.includes(:teams, :billing_quote, { club_memberships: :user }, subscription: %i[plan admin_comped_by])
|
||||
@@ -8,11 +8,27 @@ module Admin
|
||||
end
|
||||
|
||||
def show
|
||||
@subscription = @club.subscription || @club.build_subscription(plan: Plan["free"], status: "active")
|
||||
@plans = Plan.ordered.reject { |p| p.slug == "free" }
|
||||
@teams = @club.teams.order(:name)
|
||||
@quote = @club.active_billing_quote
|
||||
@concurrency_violations = StreamConcurrencyViolation.for_club(@club.id).recent.limit(20)
|
||||
load_show_context
|
||||
end
|
||||
|
||||
def edit
|
||||
load_edit_context
|
||||
end
|
||||
|
||||
def update
|
||||
Admin::UpdateClubData.call(
|
||||
club: @club,
|
||||
club_attrs: club_update_params,
|
||||
owner_attrs: owner_params,
|
||||
staff_attrs: staff_params,
|
||||
invitation_attrs: invitation_params,
|
||||
team_attrs: team_params
|
||||
)
|
||||
redirect_to admin_club_path(@club), notice: t("admin.flash.club_updated", club: @club.name)
|
||||
rescue Admin::UpdateClubData::Error, ActiveRecord::RecordInvalid => e
|
||||
flash.now[:alert] = e.message
|
||||
load_edit_context
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
def grant_comped
|
||||
@@ -66,6 +82,75 @@ module Admin
|
||||
@club = Club.includes(club_memberships: :user).find(params[:id])
|
||||
end
|
||||
|
||||
def load_show_context
|
||||
@subscription = @club.subscription || @club.build_subscription(plan: Plan["free"], status: "active")
|
||||
@plans = Plan.ordered.reject { |p| p.slug == "free" }
|
||||
@teams = @club.teams.order(:name)
|
||||
@quote = @club.active_billing_quote
|
||||
@concurrency_violations = StreamConcurrencyViolation.for_club(@club.id).recent.limit(20)
|
||||
end
|
||||
|
||||
def load_edit_context
|
||||
@teams = @club.teams.includes(:user_teams, :team_invitations).order(:name)
|
||||
@owner = @club.owner
|
||||
@staff_users = User.joins(:user_teams)
|
||||
.where(user_teams: { team_id: @club.teams.select(:id) })
|
||||
.distinct
|
||||
.order(:email)
|
||||
.to_a
|
||||
@pending_invitations = TeamInvitation.pending
|
||||
.where(team_id: @club.teams.select(:id))
|
||||
.includes(:team)
|
||||
.order(:email)
|
||||
@sport_options = Sports::Catalog.as_api_list.map { |entry| [entry[:label], entry[:key]] }
|
||||
end
|
||||
|
||||
def club_update_params
|
||||
params.require(:club).permit(
|
||||
:name, :sport, :logo_url, :primary_color, :secondary_color,
|
||||
:billing_entity_type, :billing_legal_name, :billing_vat_number, :billing_fiscal_code,
|
||||
:billing_email, :billing_phone, :billing_address_line, :billing_city, :billing_province,
|
||||
:billing_postal_code, :billing_country, :billing_recipient_code, :billing_pec
|
||||
)
|
||||
end
|
||||
|
||||
def owner_params
|
||||
params.fetch(:owner, {}).permit(:name, :email).to_h.symbolize_keys
|
||||
end
|
||||
|
||||
def staff_params
|
||||
raw = params[:staff_users]
|
||||
return {} if raw.blank?
|
||||
|
||||
raw.permit!.to_h.each_with_object({}) do |(user_id, attrs), acc|
|
||||
next unless attrs.is_a?(Hash)
|
||||
|
||||
acc[user_id] = attrs.slice("name", "email").symbolize_keys
|
||||
end
|
||||
end
|
||||
|
||||
def invitation_params
|
||||
raw = params[:invitations]
|
||||
return {} if raw.blank?
|
||||
|
||||
raw.permit!.to_h.each_with_object({}) do |(invitation_id, attrs), acc|
|
||||
next unless attrs.is_a?(Hash)
|
||||
|
||||
acc[invitation_id] = attrs.slice("email").symbolize_keys
|
||||
end
|
||||
end
|
||||
|
||||
def team_params
|
||||
raw = params[:teams]
|
||||
return {} if raw.blank?
|
||||
|
||||
raw.permit!.to_h.each_with_object({}) do |(team_id, attrs), acc|
|
||||
next unless attrs.is_a?(Hash)
|
||||
|
||||
acc[team_id] = attrs.slice("name", "sport").symbolize_keys
|
||||
end
|
||||
end
|
||||
|
||||
def redirect_back_or_club(notice: nil, alert: nil)
|
||||
target = params[:return_to].presence || admin_club_path(@club)
|
||||
redirect_to target, notice: notice, alert: alert
|
||||
|
||||
Reference in New Issue
Block a user