Skip to content

Commit

Permalink
Merge pull request #117 from mamhoff/deface-dsl
Browse files Browse the repository at this point in the history
Fix Deface loading, add ransack allowlists
  • Loading branch information
tvdeyen authored Jan 25, 2024
2 parents 90d5261 + f85e177 commit 4383138
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 47 deletions.
17 changes: 17 additions & 0 deletions app/models/spree/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ class Spree::Review < ApplicationRecord
scope :not_approved, -> { where(approved: false) }
scope :default_approval_filter, -> { Spree::Reviews::Config[:include_unapproved_reviews] ? all : approved }

def self.ransackable_attributes(*)
[
"approved",
"name",
"review",
"title"
]
end

def self.ransackable_associations(*)
[
"feedback_reviews",
"product",
"user"
]
end

def feedback_stars
return 0 if feedback_reviews.size <= 0

Expand Down
7 changes: 0 additions & 7 deletions app/overrides/add_reviews_after_product_properties.rb

This file was deleted.

20 changes: 0 additions & 20 deletions app/overrides/add_reviews_tab_to_admin.rb

This file was deleted.

20 changes: 0 additions & 20 deletions app/overrides/add_reviews_to_admin_configuration_sidebar.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- insert_after "[data-hook='product_properties']" -->

<%= render "spree/shared/reviews" %>
33 changes: 33 additions & 0 deletions config/initializers/add_spree_reviews_to_menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

Rails.application.config.to_prepare do
Spree::Backend::Config.configure do |config|
config.menu_items = config.menu_items.map do |item|
if item.label.to_sym == :settings
# The API of the MenuItem class changes in Solidus 4.2.0
if item.respond_to?(:children)
item.children << Spree::BackendConfiguration::MenuItem.new(
label: :reviews,
condition: -> { can?(:admin, Spree::ReviewsConfiguration) },
url: -> { Spree::Core::Engine.routes.url_helpers.edit_admin_review_settings_path },
match_path: /review_settings/
)
else
item.sections << :reviews
end
elsif item.label.to_sym == :products
if item.respond_to?(:children)
item.children << Spree::BackendConfiguration::MenuItem.new(
label: :reviews,
condition: -> { can?(:admin, Spree::Review) },
url: -> { Spree::Core::Engine.routes.url_helpers.admin_reviews_path },
match_path: /reviews/
)
else
item.sections << :reviews
end
end
item
end
end
end
12 changes: 12 additions & 0 deletions spec/models/review_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@
end
end

describe '.ransackable_attributes' do
subject { described_class.ransackable_attributes }

it { is_expected.to contain_exactly("approved", "name", "review", "title") }
end

describe '.ransackable_associations' do
subject { described_class.ransackable_associations }

it { is_expected.to contain_exactly("feedback_reviews", "product", "user") }
end

describe '#recalculate_product_rating' do
let(:product) { create(:product) }
let!(:review) { create(:review, product: product) }
Expand Down

0 comments on commit 4383138

Please sign in to comment.