dawarich/app/controllers/family_memberships_controller.rb

40 lines
1.1 KiB
Ruby
Raw Normal View History

2025-09-27 07:23:33 -04:00
# frozen_string_literal: true
class FamilyMembershipsController < ApplicationController
before_action :authenticate_user!
2025-09-28 07:10:07 -04:00
before_action :ensure_family_feature_enabled!
2025-09-27 07:23:33 -04:00
before_action :set_family
2025-10-04 10:17:26 -04:00
before_action :set_membership, only: %i[destroy]
2025-09-27 07:23:33 -04:00
def destroy
authorize @membership
if @membership.owner?
2025-09-27 07:23:33 -04:00
redirect_to family_path(@family),
alert: 'Family owners cannot remove their own membership. To leave the family, delete it instead.'
2025-09-27 07:23:33 -04:00
else
member_email = @membership.user.email
@membership.destroy!
redirect_to family_path(@family), notice: "#{member_email} has been removed from the family"
end
end
private
2025-09-28 07:10:07 -04:00
def ensure_family_feature_enabled!
unless DawarichSettings.family_feature_enabled?
redirect_to root_path, alert: 'Family feature is not available'
end
end
2025-09-27 07:23:33 -04:00
def set_family
@family = current_user.family
redirect_to families_path, alert: 'Family not found' and return unless @family
end
def set_membership
@membership = @family.family_memberships.find(params[:id])
end
end