ruby-hyperloop / hyper-mesh

The project has moved to Hyperstack!! - Synchronization of active record models across multiple clients using Pusher, ActionCable, or Polling
https://hyperstack.org/
MIT License
22 stars 12 forks source link

Set acting_user within regulate_broadcast on save as well as fetch #104

Open sfcgeorge opened 6 years ago

sfcgeorge commented 6 years ago

bug / feature request, acting_user isn't set in regulate_broadcast after a save so I can't use it as I wanted to increase performance of policies by eliminating unnecessary queries. But I can work around by checking for saved_changes?

class CandidateProfilePolicy
  regulate_broadcast do |policy|
    policy.send_only(
      :id, :candidate_id, :avatar
    ).to(Employer)

    if saved_changes? || acting_user&.type&.==("Candidate")
      policy.send_only(
        :id, :candidate_id, :score, :ethnicity_id,
        :driving_level, :avatar, :ethnicity_description, :work_eligibility
      ).to(candidate)
    end
  end

  allow_change do
    acting_user&.id == candidate_id
  end
end