Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fixes admin permissions to better adjust features (#12665)

Damian Legawiece0cf2cb12093
diff --git a/admin/app/views/spree/admin/dashboard/_top_products.html.erb b/admin/app/views/spree/admin/dashboard/_top_products.html.erb
index 788c54db44..a56ed631d4 100644
--- a/admin/app/views/spree/admin/dashboard/_top_products.html.erb
+++ b/admin/app/views/spree/admin/dashboard/_top_products.html.erb
@@ -5,7 +5,9 @@
<h5 class="card-title">
<%= Spree.t('admin.dashboard.top_products') %>
</h5>
- <%= link_to Spree.t('admin.dashboard.view_report'), report_link, class: 'btn btn-light btn-sm', data: { turbo_frame: '_top' } %>
+ <% if can?(:manage, Spree::Report) %>
+ <%= link_to Spree.t('admin.dashboard.view_report'), report_link, class: 'btn btn-light btn-sm', data: { turbo_frame: '_top' } %>
+ <% end %>
</div>
<div class="card-body m-0 p-0">
<div class="table-responsive">
@@ -72,7 +74,7 @@
</tbody>
</table>
</div>
- <% if @top_products.any? %>
+ <% if @top_products.any? && can?(:manage, Spree::Report) %>
<p class="text-center mt-0 border-top py-2 mb-0">
<%= link_to Spree.t('admin.dashboard.view_report'), report_link, class: 'm-2 w-50 btn btn-light mt-2', data: { turbo_frame: '_top' } %>
</p>
diff --git a/admin/app/views/spree/admin/products/form/_categorization.html.erb b/admin/app/views/spree/admin/products/form/_categorization.html.erb
index 724b876c2f..a9c77e06af 100644
--- a/admin/app/views/spree/admin/products/form/_categorization.html.erb
+++ b/admin/app/views/spree/admin/products/form/_categorization.html.erb
@@ -1,35 +1,39 @@
-<div class="card mb-4">
- <div class="card-header">
- <h5 class="card-title">
- <%= Spree.t(:categorization) %>
- </h5>
- </div>
- <div class="card-body">
- <div class="form-group">
- <% if can? :modify, Spree::Taxon %>
- <%= f.label :taxon_ids, Spree.t(:taxonomies) %>
+<% if can?(:manage, Spree::Classification) || can?(:manage, ActsAsTaggableOn::Tag) %>
+ <div class="card mb-4">
+ <div class="card-header">
+ <h5 class="card-title">
+ <%= Spree.t(:categorization) %>
+ </h5>
+ </div>
+ <div class="card-body">
+ <div class="form-group">
+ <% if can? :manage, Spree::Classification %>
+ <%= f.label :taxon_ids, Spree.t(:taxonomies) %>
- <%= tom_select_tag 'product[taxon_ids]',
- multiple: true,
- active_option: @product.taxon_ids,
- url: spree.admin_taxons_select_options_path(format: :json),
- class: 'w-100' %>
- <% elsif @product.taxons.any? %>
- <%= f.label :taxon_ids, Spree.t(:taxonomies) %>
+ <%= tom_select_tag 'product[taxon_ids]',
+ multiple: true,
+ active_option: @product.taxon_ids,
+ url: spree.admin_taxons_select_options_path(format: :json),
+ class: 'w-100' %>
+ <% elsif @product.taxons.any? %>
+ <%= f.label :taxon_ids, Spree.t(:taxonomies) %>
- <ul class="text_list">
- <% @product.taxons.manual.pluck(:name).each do |taxon_name| %>
- <li><%= taxon_name %></li>
- <% end %>
- </ul>
- <% else %>
- <div class="alert alert-info"><%= Spree.t(:no_resource_found, resource: :taxons) %></div>
- <% end %>
- </div>
+ <ul class="text_list">
+ <% @product.taxons.manual.pluck(:name).each do |taxon_name| %>
+ <li><%= taxon_name %></li>
+ <% end %>
+ </ul>
+ <% else %>
+ <div class="alert alert-info"><%= Spree.t(:no_resource_found, resource: :taxons) %></div>
+ <% end %>
+ </div>
- <div class="form-group">
- <%= f.label :tag_list, Spree.t(:tags) %>
- <%= tom_select_tag 'product[tag_list]', multiple: true, class: 'w-100', options: tags_json_array, active_option: @product.tag_list, value_field: :name, create: true %>
+ <% if can?(:manage, ActsAsTaggableOn::Tag) %>
+ <div class="form-group">
+ <%= f.label :tag_list, Spree.t(:tags) %>
+ <%= tom_select_tag 'product[tag_list]', multiple: true, class: 'w-100', options: tags_json_array, active_option: @product.tag_list, value_field: :name, create: true %>
+ </div>
+ <% end %>
</div>
</div>
-</div>
\ No newline at end of file
+<% end%>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/shared/_user_dropdown.html.erb b/admin/app/views/spree/admin/shared/_user_dropdown.html.erb
index 9d8c0e59b5..646dce7567 100644
--- a/admin/app/views/spree/admin/shared/_user_dropdown.html.erb
+++ b/admin/app/views/spree/admin/shared/_user_dropdown.html.erb
@@ -16,21 +16,24 @@
<%= link_to_with_icon 'user-scan', Spree.t('admin.edit_profile'), spree.edit_admin_profile_path, class: 'dropdown-item' %>
<% end %>
- <% if enterprise_edition? && try_spree_current_user.respond_to?(:accounts) && try_spree_current_user.accounts.count > 1 %>
- <div data-toggle="modal" data-target="#modal">
- <%= link_to_with_icon 'switch-3', Spree.t(:switch_team), main_app.accounts_path, class: 'dropdown-item', data: { turbo_frame: 'dialog_modal' } %>
- </div>
- <% end %>
+ <% if enterprise_edition? %>
+ <% if try_spree_current_user.respond_to?(:accounts) && try_spree_current_user.accounts.count > 1 %>
+ <div data-toggle="modal" data-target="#modal">
+ <%= link_to_with_icon 'switch-3', Spree.t(:switch_team), main_app.accounts_path, class: 'dropdown-item', data: { turbo_frame: 'dialog_modal' } %>
+ </div>
+ <% end %>
- <% if enterprise_edition? && defined?(app_domain) && defined?(Vendo::Account) && can?(:create, Vendo::Account) %>
- <%= link_to_with_icon 'plus', Spree.t(:create_new_team), main_app.new_account_url(host: app_domain), class: 'dropdown-item', data: { turbo: false } %>
+ <% if defined?(app_domain) && defined?(Vendo::Account) && can?(:create, Vendo::Account) %>
+ <%= link_to_with_icon 'plus', Spree.t(:create_new_team), main_app.new_account_url(host: app_domain), class: 'dropdown-item', data: { turbo: false } %>
+ <% end %>
+ <div class="dropdown-divider"></div>
<% end %>
- <div class="dropdown-divider"></div>
-
- <%= link_to_with_icon 'book', 'Help center', 'https://spreecommerce.org/docs/user', class: 'dropdown-item', target: '_blank' %>
- <%= link_to_with_icon 'message-circle', 'Contact us', 'https://spreecommerce.org/contact/', class: 'dropdown-item', target: '_blank' %>
- <div class="dropdown-divider"></div>
+ <% if can?(:manage, current_store) %>
+ <%= link_to_with_icon 'book', 'Help center', 'https://spreecommerce.org/docs/user', class: 'dropdown-item', target: '_blank' %>
+ <%= link_to_with_icon 'message-circle', 'Contact us', 'https://spreecommerce.org/contact/', class: 'dropdown-item', target: '_blank' %>
+ <div class="dropdown-divider"></div>
+ <% end %>
<%= button_to spree_admin_logout_path, class: 'dropdown-item mb-0', method: :delete do %>
<%= icon('logout', class: "icon icon-logout") %>
diff --git a/admin/app/views/spree/admin/stock_locations/_stock_location.html.erb b/admin/app/views/spree/admin/stock_locations/_stock_location.html.erb
index 92c24df888..6234a2f778 100644
--- a/admin/app/views/spree/admin/stock_locations/_stock_location.html.erb
+++ b/admin/app/views/spree/admin/stock_locations/_stock_location.html.erb
@@ -7,13 +7,15 @@
<td data-action="click->row-link#openLink">
<%= active_badge(stock_location.active?) %>
</td>
- <td data-action="click->row-link#openLink"><%= active_badge(stock_location.default?) %></td>
+ <% if can?(:mark_as_default, Spree::StockLocation) %>
+ <td data-action="click->row-link#openLink"><%= active_badge(stock_location.default?) %></td>
+ <% end %>
<td class="actions">
<% if can? :edit, stock_location %>
<div class="d-flex justify-content-end align-items-center">
<div><%= link_to_edit stock_location, data: { row_link_target: 'link' } %></div>
- <% unless stock_location.default? %>
+ <% if !stock_location.default? && can?(:mark_as_default, Spree::StockLocation) %>
<div class="dropdown">
<button class="btn btn-sm btn-light h-100" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<%= icon('dots', class: 'mr-0') %>
diff --git a/admin/app/views/spree/admin/stock_locations/index.html.erb b/admin/app/views/spree/admin/stock_locations/index.html.erb
index 8eb94c68d7..f6a3add138 100644
--- a/admin/app/views/spree/admin/stock_locations/index.html.erb
+++ b/admin/app/views/spree/admin/stock_locations/index.html.erb
@@ -14,7 +14,9 @@
<th><%= Spree.t(:name) %></th>
<th><%= Spree.t(:country) %></th>
<th><%= Spree.t(:active) %>?</th>
- <th><%= Spree.t(:default) %>?</th>
+ <% if can?(:mark_as_default, Spree::StockLocation) %>
+ <th><%= Spree.t(:default) %>?</th>
+ <% end %>
<th></th>
</tr>
</thead>
diff --git a/core/app/models/spree/reports/sales_total.rb b/core/app/models/spree/reports/sales_total.rb
index 3c0349c527..dfa97824fb 100644
--- a/core/app/models/spree/reports/sales_total.rb
+++ b/core/app/models/spree/reports/sales_total.rb
@@ -2,12 +2,16 @@ module Spree
module Reports
class SalesTotal < Spree::Report
def line_items_scope
- store.line_items.where(
+ scope = store.line_items.where(
order: Spree::Order.complete.where(
currency: currency,
completed_at: (date_from.to_time.beginning_of_day)..(date_to.to_time.end_of_day)
)
).includes(:order, variant: :product)
+
+ scope = scope.where(vendor_id: vendor.id) if defined?(vendor) && vendor.present?
+
+ scope
end
end
end