Class: Spree::ReviewsAbility
- Inherits:
-
Object
- Object
- Spree::ReviewsAbility
- Includes:
- CanCan::Ability
- Defined in:
- app/models/spree/reviews_ability.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user) ⇒ ReviewsAbility
constructor
A new instance of ReviewsAbility.
Constructor Details
#initialize(user) ⇒ ReviewsAbility
Returns a new instance of ReviewsAbility.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/spree/reviews_ability.rb', line 6 def initialize(user) review_ability_class = self.class can :create, Spree::Review do |_review| review_ability_class.allow_anonymous_reviews? || user.email.present? end can :create, Spree::FeedbackReview do |_review| review_ability_class.allow_anonymous_reviews? || user.email.present? end # You can only change your own feedback_review can [:update, :destroy], Spree::FeedbackReview do |feedback_review| feedback_review.user == user end # You can read your own reviews, and everyone can read approved ones can :read, Spree::Review do |review| review.user == user || review.approved? end # You can only change your own review can [:update, :destroy], Spree::Review do |review| review.user == user end end |
Class Method Details
.allow_anonymous_reviews? ⇒ Boolean
33 34 35 |
# File 'app/models/spree/reviews_ability.rb', line 33 def self.allow_anonymous_reviews? !Spree::Reviews::Config[:require_login] end |