conference-opportunities/conference-opportunities

View on GitHub
app/policies/event_policy.rb

Summary

Maintainability
A
0 mins
Test Coverage
class EventPolicy < ApplicationPolicy
  def index?
    true
  end

  def show?
    return true if user.present? && user.conference == record.conference
    scope.where(id: record.id).exists?
  end

  def update?
    return false if user.nil?
    user.admin? || user.conference == record.conference
  end

  class Scope < ApplicationPolicy::Scope
    def resolve
      return scope.all if user.present? && user.admin?
      scope.joins(:conference).merge(Conference.approved.followed)
    end
  end
end