2025-10-07 12:38:06 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class Family::InvitationPolicy < ApplicationPolicy
|
|
|
|
|
def show?
|
|
|
|
|
# Public endpoint for invitation acceptance - no authentication required
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create?
|
2025-10-11 08:17:48 -04:00
|
|
|
return false unless user
|
|
|
|
|
|
2025-10-07 12:38:06 -04:00
|
|
|
user.family == record.family && user.family_owner?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def accept?
|
|
|
|
|
# Users can accept invitations sent to their email
|
2025-10-11 08:17:48 -04:00
|
|
|
return false unless user
|
|
|
|
|
|
2025-10-07 12:38:06 -04:00
|
|
|
user.email == record.email
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy?
|
|
|
|
|
# Only family owners can cancel invitations
|
2025-10-11 08:17:48 -04:00
|
|
|
create?
|
2025-10-07 12:38:06 -04:00
|
|
|
end
|
|
|
|
|
end
|