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.

Making sure we enforce everywhere permission through out the admin UI (#12574)

Damian Legawiec4a6c7f49340f
diff --git a/admin/app/helpers/spree/admin/navigation_helper.rb b/admin/app/helpers/spree/admin/navigation_helper.rb
index 8c6a7d1658..6fa60acf16 100644
--- a/admin/app/helpers/spree/admin/navigation_helper.rb
+++ b/admin/app/helpers/spree/admin/navigation_helper.rb
@@ -4,17 +4,20 @@ module Spree
# the per_page_dropdown is used on index pages like orders, products, promotions etc.
# this method generates the select_tag
def per_page_dropdown
- # there is a config setting for admin_products_per_page, only for the orders page
- if @products && per_page_default = ENV.fetch('ADMIN_PRODUCTS_PER_PAGE', 25)
- per_page_options = []
- 5.times do |amount|
- per_page_options << (amount + 1) * ENV.fetch('ADMIN_PRODUCTS_PER_PAGE', 25)
- end
- per_page_options << 250
- else
- per_page_default = ENV.fetch('ADMIN_PRODUCTS_PER_PAGE', 25)
- per_page_options = %w{25 50 75 100 125 250}
- end
+ per_page_default = if @products
+ Spree::Admin::RuntimeConfig.admin_products_per_page
+ elsif @orders
+ Spree::Admin::RuntimeConfig.admin_orders_per_page
+ else
+ Spree::Admin::RuntimeConfig.admin_records_per_page
+ end
+
+ per_page_options = [
+ per_page_default,
+ per_page_default * 2,
+ per_page_default * 4,
+ per_page_default * 8
+ ]
selected_option = (params[:per_page].try(:to_i) || per_page_default).to_s
@@ -45,13 +48,7 @@ module Spree
options[:data] ||= {}
options[:data][:action] ||= 'edit'
options[:class] ||= 'btn btn-light btn-sm'
- link_to_with_icon('pencil', Spree.t(:edit), url, options)
- end
-
- def link_to_edit_url(url, options = {})
- options[:data] ||= { action: 'edit' }
- options[:class] ||= 'btn btn-light btn-sm'
- link_to_with_icon('pencil', Spree.t(:edit), url, options)
+ link_to_with_icon('pencil', Spree.t(:edit), url, options) if can?(:update, resource)
end
def link_to_delete(resource, options = {})
@@ -60,6 +57,8 @@ module Spree
options[:class] ||= 'btn btn-danger btn-sm'
options[:data] ||= { turbo_confirm: Spree.t(:are_you_sure), turbo_method: :delete }
+ return unless can?(:destroy, resource)
+
if options[:no_text]
link_to_with_icon 'trash', name, url, options
elsif options[:icon]
@@ -69,12 +68,6 @@ module Spree
end
end
- def link_to_delete_url(url, options = {})
- options[:data] = { turbo_confirm: Spree.t(:are_you_sure), turbo_method: :delete }
- options[:class] = 'btn btn-danger btn-sm'
- link_to_with_icon('trash', Spree.t('actions.destroy'), url, options)
- end
-
def link_to_with_icon(icon_name, text, url, options = {})
options[:class] ||= (options[:class].to_s + " with-tip").strip
options[:title] ||= text if options[:no_text]
@@ -143,24 +136,6 @@ module Spree
end
end
- def turbo_link_to(text, url, **options)
- icon = options[:icon]
-
- text_components = []
- text_components << icon(icon) if icon.present?
- text_components << text
-
- link_text = text_components.compact.join
-
- options[:data] ||= {}
- options[:data][:turbo_method] = options[:method] || :get
- options[:data][:turbo_confirm] = Spree.t(:are_you_sure) if options[:confirm].present?
-
- html_options = options.except(:icon, :method, :confirm)
-
- link_to(link_text.html_safe, url, html_options)
- end
-
def active_badge(condition, options = {})
label = options[:label]
label ||= condition ? Spree.t(:say_yes) : Spree.t(:say_no)
diff --git a/admin/app/helpers/spree/admin/translations_helper.rb b/admin/app/helpers/spree/admin/translations_helper.rb
index 8f17d511d0..9b64bf5a80 100644
--- a/admin/app/helpers/spree/admin/translations_helper.rb
+++ b/admin/app/helpers/spree/admin/translations_helper.rb
@@ -7,7 +7,7 @@ module Spree
Spree.t(:translations),
spree.edit_admin_translation_path(resource, resource_type: resource.class.to_s),
class: classes
- )
+ ) if can?(:update, resource)
end
end
end
diff --git a/admin/app/views/spree/admin/dashboard/setup_tasks/_add_products.html.erb b/admin/app/views/spree/admin/dashboard/setup_tasks/_add_products.html.erb
index 3891576392..c8e068f683 100644
--- a/admin/app/views/spree/admin/dashboard/setup_tasks/_add_products.html.erb
+++ b/admin/app/views/spree/admin/dashboard/setup_tasks/_add_products.html.erb
@@ -15,7 +15,7 @@
<% end %>
<div class="d-flex gap-3">
- <%= link_to_with_icon 'plus', Spree.t(:add_product), spree.new_admin_product_path, class: 'btn btn-primary', data: { turbo_frame: '_top' } %>
+ <%= link_to_with_icon 'plus', Spree.t(:add_product), spree.new_admin_product_path, class: 'btn btn-primary', data: { turbo_frame: '_top' } if can?(:create, Spree::Product) %>
<%= render 'spree/admin/products/import_button' %>
<%= invite_vendor_button(class: 'btn-light') if defined?(invite_vendor_button) %>
diff --git a/admin/app/views/spree/admin/payment_methods/index.html.erb b/admin/app/views/spree/admin/payment_methods/index.html.erb
index b1f49d4684..6a6ace53ab 100644
--- a/admin/app/views/spree/admin/payment_methods/index.html.erb
+++ b/admin/app/views/spree/admin/payment_methods/index.html.erb
@@ -19,7 +19,7 @@
</table>
</div>
-<% if available_payment_methods.present? %>
+<% if available_payment_methods.present? && can?(:create, Spree::PaymentMethod) %>
<h5 class="pb-2 pt-3">Available Payment Methods</h5>
<div class="table-responsive card-lg p-0">
<table class="table" id='listing_shipping_methods'>
@@ -35,11 +35,4 @@
</tbody>
</table>
</div>
-<% end %>
-
-<% unless defined?(SpreeGateway) %>
- <div class="text-muted text-center p-5 d-flex align-items-center justify-content-center">
- More payment methods can be added by installing
- <%= external_link_to 'Spree Gateway gem', 'https://github.com/spree/spree_gateway', class: 'btn btn-link btn-sm ml-1' %>
- </div>
<% end %>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/products/edit.html.erb b/admin/app/views/spree/admin/products/edit.html.erb
index 5c51abb680..c555acb940 100644
--- a/admin/app/views/spree/admin/products/edit.html.erb
+++ b/admin/app/views/spree/admin/products/edit.html.erb
@@ -5,7 +5,7 @@
Spree.t(:digital_assets),
spree.admin_product_digital_assets_path(@product),
class: "dropdown-item",
- ) %>
+ ) if can?(:manage, Spree::Digital) %>
<%= external_page_preview_link(@product) %>
<% if can?(:clone, @product) %>
diff --git a/admin/app/views/spree/admin/promotion_actions/_promotion_action.html.erb b/admin/app/views/spree/admin/promotion_actions/_promotion_action.html.erb
index 70e02b2c68..1a33a5d5da 100644
--- a/admin/app/views/spree/admin/promotion_actions/_promotion_action.html.erb
+++ b/admin/app/views/spree/admin/promotion_actions/_promotion_action.html.erb
@@ -3,15 +3,17 @@
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="card-title"><%= promotion_action.human_name %></h5>
- <div class="dropdown">
- <button class="btn btn-light btn-sm" type="button" data-toggle="dropdown" aria-expanded="false">
- <%= icon('dots', class: 'mr-0') %>
+ <% if can?(:update, promotion_action) || can?(:destroy, promotion_action) %>
+ <div class="dropdown">
+ <button class="btn btn-light btn-sm" type="button" data-toggle="dropdown" aria-expanded="false">
+ <%= icon('dots', class: 'mr-0') %>
</button>
<div class="dropdown-menu">
- <%= link_to_with_icon 'pencil', Spree.t('actions.edit'), spree.edit_admin_promotion_action_path(promotion_action.promotion, promotion_action), class: 'dropdown-item' %>
- <%= link_to_with_icon 'trash', Spree.t('actions.destroy'), spree.admin_promotion_action_path(promotion_action.promotion, promotion_action), class: 'dropdown-item text-danger', data: { turbo_method: :delete, turbo_confirm: Spree.t(:are_you_sure), turbo_frame: '_top' } %>
+ <%= link_to_with_icon 'pencil', Spree.t('actions.edit'), spree.edit_admin_promotion_action_path(promotion_action.promotion, promotion_action), class: 'dropdown-item' if can?(:update, promotion_action) %>
+ <%= link_to_with_icon 'trash', Spree.t('actions.destroy'), spree.admin_promotion_action_path(promotion_action.promotion, promotion_action), class: 'dropdown-item text-danger', data: { turbo_method: :delete, turbo_confirm: Spree.t(:are_you_sure), turbo_frame: '_top' } if can?(:destroy, promotion_action) %>
+ </div>
</div>
- </div>
+ <% end %>
</div>
<div class="card-body">
<p class="text-muted"><%= promotion_action.human_description %></p>
diff --git a/admin/app/views/spree/admin/promotion_rules/_promotion_rule.html.erb b/admin/app/views/spree/admin/promotion_rules/_promotion_rule.html.erb
index a5126f2cbf..fd9a109a4c 100644
--- a/admin/app/views/spree/admin/promotion_rules/_promotion_rule.html.erb
+++ b/admin/app/views/spree/admin/promotion_rules/_promotion_rule.html.erb
@@ -3,15 +3,17 @@
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="card-title"><%= promotion_rule.human_name %></h5>
- <div class="dropdown">
- <button class="btn btn-light btn-sm" type="button" data-toggle="dropdown" aria-expanded="false">
- <%= icon('dots', class: 'mr-0') %>
+ <% if can?(:update, promotion_rule) || can?(:destroy, promotion_rule) %>
+ <div class="dropdown">
+ <button class="btn btn-light btn-sm" type="button" data-toggle="dropdown" aria-expanded="false">
+ <%= icon('dots', class: 'mr-0') %>
</button>
<div class="dropdown-menu">
- <%= link_to_with_icon 'pencil', Spree.t('actions.edit'), spree.edit_admin_promotion_rule_path(promotion_rule.promotion, promotion_rule), class: 'dropdown-item' %>
- <%= link_to_with_icon 'trash', Spree.t('actions.destroy'), spree.admin_promotion_rule_path(promotion_rule.promotion, promotion_rule), class: 'dropdown-item text-danger', data: { turbo_method: :delete, turbo_confirm: Spree.t(:are_you_sure), turbo_frame: '_top' } %>
+ <%= link_to_with_icon 'pencil', Spree.t('actions.edit'), spree.edit_admin_promotion_rule_path(promotion_rule.promotion, promotion_rule), class: 'dropdown-item' if can?(:update, promotion_rule) %>
+ <%= link_to_with_icon 'trash', Spree.t('actions.destroy'), spree.admin_promotion_rule_path(promotion_rule.promotion, promotion_rule), class: 'dropdown-item text-danger', data: { turbo_method: :delete, turbo_confirm: Spree.t(:are_you_sure), turbo_frame: '_top' } if can?(:destroy, promotion_rule) %>
+ </div>
</div>
- </div>
+ <% end %>
</div>
<div class="card-body">
<p class="text-muted"><%= promotion_rule.human_description %></p>
diff --git a/admin/app/views/spree/admin/promotions/_actions.html.erb b/admin/app/views/spree/admin/promotions/_actions.html.erb
index 41de056109..2feb3827a9 100644
--- a/admin/app/views/spree/admin/promotions/_actions.html.erb
+++ b/admin/app/views/spree/admin/promotions/_actions.html.erb
@@ -4,17 +4,21 @@
<%= icon('bolt', class: 'mr-2') %>
<%= Spree.t(:promotion_actions) %>
</h5>
- <span data-toggle="modal" data-target="#modal">
- <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_action_path(@promotion), class: 'btn btn-primary btn-sm', data: { turbo_frame: 'dialog_modal' } %>
- </span>
+ <% if can?(:create, Spree::PromotionAction.new(promotion: @promotion)) %>
+ <span data-toggle="modal" data-target="#modal">
+ <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_action_path(@promotion), class: 'btn btn-primary btn-sm', data: { turbo_frame: 'dialog_modal' } %>
+ </span>
+ <% end %>
</div>
<div class="card-body d-flex flex-column gap-2 px-1 pt-0 pb-1">
<% if @promotion.promotion_actions.empty? %>
<div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">
<%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::PromotionAction)) %>
- <span data-toggle="modal" data-target="#modal">
- <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_action_path(@promotion), class: 'btn btn-light btn-sm ml-3', data: { turbo_frame: 'dialog_modal' } %>
- </span>
+ <% if can?(:create, Spree::PromotionAction.new(promotion: @promotion)) %>
+ <span data-toggle="modal" data-target="#modal">
+ <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_action_path(@promotion), class: 'btn btn-light btn-sm ml-3', data: { turbo_frame: 'dialog_modal' } %>
+ </span>
+ <% end %>
</div>
<% else %>
<%= render collection: @promotion.promotion_actions,
diff --git a/admin/app/views/spree/admin/promotions/_rules.html.erb b/admin/app/views/spree/admin/promotions/_rules.html.erb
index b87655295b..31e94aff1e 100644
--- a/admin/app/views/spree/admin/promotions/_rules.html.erb
+++ b/admin/app/views/spree/admin/promotions/_rules.html.erb
@@ -4,10 +4,11 @@
<%= icon('checklist', class: 'mr-2') %>
<%= Spree.t(:rules) %>
</h5>
-
- <span data-toggle="modal" data-target="#modal">
- <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_rule_path(@promotion), class: 'btn btn-primary btn-sm', data: { turbo_frame: 'dialog_modal' } %>
- </span>
+ <% if can?(:create, Spree::PromotionRule.new(promotion: @promotion)) %>
+ <span data-toggle="modal" data-target="#modal">
+ <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_rule_path(@promotion), class: 'btn btn-primary btn-sm', data: { turbo_frame: 'dialog_modal' } %>
+ </span>
+ <% end %>
</div>
<div class="card-body">
<div class="form-group mb-0">
@@ -27,9 +28,11 @@
<% if @promotion.promotion_rules.empty? %>
<div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">
<%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::PromotionRule)) %>
- <span data-toggle="modal" data-target="#modal">
- <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_rule_path(@promotion), class: 'btn btn-light btn-sm ml-3', data: { turbo_frame: 'dialog_modal' } %>
- </span>
+ <% if can?(:create, Spree::PromotionRule.new(promotion: @promotion)) %>
+ <span data-toggle="modal" data-target="#modal">
+ <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_rule_path(@promotion), class: 'btn btn-light btn-sm ml-3', data: { turbo_frame: 'dialog_modal' } %>
+ </span>
+ <% end %>
</div>
<% else %>
<%= render collection: @promotion.promotion_rules,
diff --git a/admin/app/views/spree/admin/shared/_content_header.html.erb b/admin/app/views/spree/admin/shared/_content_header.html.erb
index 02cc5b711d..b573b54511 100644
--- a/admin/app/views/spree/admin/shared/_content_header.html.erb
+++ b/admin/app/views/spree/admin/shared/_content_header.html.erb
@@ -12,11 +12,11 @@
<%= yield :page_title %>
</h3>
<div id="page_actions" class="ml-auto page-actions d-flex align-items-center gap-2">
- <% if action_name == 'index' && defined?(model_class) && model_class && Spree::Export.available_models.include?(model_class) %>
+ <% if action_name == 'index' && defined?(model_class) && model_class && Spree::Export.available_models.include?(model_class) && can?(:create, Spree::Export) %>
<span data-toggle="modal" data-target="#modal">
<%= link_to spree.new_admin_export_path(export: { search_params: params[:q]&.to_json, type: Spree::Export.type_for_model(model_class) }), class: 'btn btn-light bg-transparent with-tip', title: 'Download records as CSV file', data: { turbo_frame: :dialog_modal } do %>
- <%= icon 'download', class: 'mr-0 mr-lg-2' %>
- <span class="d-none d-lg-inline"><%= Spree.t(:download) %></span>
+ <%= icon 'table-export', class: 'mr-0 mr-lg-2' %>
+ <span class="d-none d-lg-inline"><%= Spree.t(:export) %></span>
<% end %>
</span>
<% end %>
@@ -32,7 +32,7 @@
<div class="dropdown-menu dropdown-menu-right">
<%= yield :page_actions_dropdown if content_for(:page_actions_dropdown) %>
<% if record %>
- <% if record.respond_to?(:audits) && spree.respond_to?(:admin_audits_path) %>
+ <% if record.respond_to?(:audits) && spree.respond_to?(:admin_audits_path) && defined?(Audited) && can?(:read, Audited.audit_class) %>
<a href="<%= spree.admin_audits_path(q: { auditable_id_eq: record.id, auditable_type_eq: record.class.to_s }) %>" target="_blank" class="dropdown-item">
<%= icon 'history' %>
<%= Spree.t(:audit_log) %>
diff --git a/admin/app/views/spree/admin/shared/_developers_nav.html.erb b/admin/app/views/spree/admin/shared/_developers_nav.html.erb
index bfa5bec5a4..10790b5daa 100644
--- a/admin/app/views/spree/admin/shared/_developers_nav.html.erb
+++ b/admin/app/views/spree/admin/shared/_developers_nav.html.erb
@@ -2,6 +2,6 @@
<%= Spree.t(:developers) %>
<% end %>
<%= content_for :page_tabs do %>
- <%= nav_pill_list_item(:api_keys, label: Spree.t(:api_keys), url: spree.admin_oauth_applications_path) %>
- <%= nav_pill_list_item(:webhooks, label: Spree.t(:webhooks), url: spree.admin_webhooks_subscribers_path) %>
+ <%= nav_pill_list_item(:api_keys, label: Spree.t(:api_keys), url: spree.admin_oauth_applications_path) if can?(:manage, Spree::OauthApplication) %>
+ <%= nav_pill_list_item(:webhooks, label: Spree.t(:webhooks), url: spree.admin_webhooks_subscribers_path) if can?(:manage, Spree::Webhooks::Subscriber) %>
<% end %>
diff --git a/admin/app/views/spree/admin/shared/_posts_tabs.html.erb b/admin/app/views/spree/admin/shared/_posts_tabs.html.erb
index c762cc855e..48579b44cf 100644
--- a/admin/app/views/spree/admin/shared/_posts_tabs.html.erb
+++ b/admin/app/views/spree/admin/shared/_posts_tabs.html.erb
@@ -3,6 +3,6 @@
<% end %>
<% content_for(:page_tabs) do %>
- <%= nav_pill_list_item(:posts) %>
- <%= nav_pill_list_item(:post_categories, label: Spree.t(:categories)) %>
+ <%= nav_pill_list_item(:posts) if can?(:manage, Spree::Post) %>
+ <%= nav_pill_list_item(:post_categories, label: Spree.t(:categories)) if can?(:manage, Spree::PostCategory) %>
<% 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 7d4d888d40..e63ad52845 100644
--- a/admin/app/views/spree/admin/shared/_user_dropdown.html.erb
+++ b/admin/app/views/spree/admin/shared/_user_dropdown.html.erb
@@ -13,7 +13,9 @@
<%= icon 'dots-vertical', class: 'mr-0 ml-2 mb-0 d-none d-lg-block' %>
</button>
<div class="dropdown-menu dropdown-menu-right w-100 mb-1 mt-1 mt-lg-0">
- <%= link_to_with_icon 'user-scan', Spree.t('admin.edit_profile'), spree.edit_admin_profile_path, class: 'dropdown-item' %>
+ <% if can?(:update, try_spree_current_user) %>
+ <%= 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">
@@ -21,7 +23,7 @@
</div>
<% end %>
- <% if enterprise_edition? && defined?(app_domain) %>
+ <% 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 } %>
<% end %>
diff --git a/admin/app/views/spree/admin/shared/sidebar/_orders_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_orders_nav.html.erb
index ff4ae5ac0d..9fc20ec8c7 100644
--- a/admin/app/views/spree/admin/shared/sidebar/_orders_nav.html.erb
+++ b/admin/app/views/spree/admin/shared/sidebar/_orders_nav.html.erb
@@ -1,33 +1,35 @@
<% orders_active = %[orders checkouts].include?(controller_name) || @order %>
-<li class="nav-item">
- <%= active_link_to spree.admin_orders_path, class: 'nav-link', active: orders_active do %>
- <%= icon 'inbox' %>
- <%= Spree.t(:orders) %>
+<% if can?(:manage, Spree::Order) %>
+ <li class="nav-item">
+ <%= active_link_to spree.admin_orders_path, class: 'nav-link', active: orders_active do %>
+ <%= icon 'inbox' %>
+ <%= Spree.t(:orders) %>
- <% if ready_to_ship_orders_count&.positive? %>
- <span class="badge ml-auto">
- <%= ready_to_ship_orders_count %>
- </span>
- <% end %>
- <% end %>
- <% if orders_active && (ready_to_ship_orders_count&.positive? || can?(:manage, :checkouts)) %>
- <ul class="ml-4 pl-1 mb-2 nav-submenu mt-1">
<% if ready_to_ship_orders_count&.positive? %>
- <li class="nav-item">
- <%= active_link_to spree.admin_orders_path(q: {shipment_state_not_in: [:shipped, :canceled]}), class: 'nav-link', active: params.dig(:q, :shipment_state_not_in).present? do %>
- <span><%= Spree.t('admin.orders.orders_to_fulfill') %></span>
- <span class="badge ml-auto">
- <%= ready_to_ship_orders_count %>
- </span>
- <% end %>
- </li>
+ <span class="badge ml-auto">
+ <%= ready_to_ship_orders_count %>
+ </span>
<% end %>
+ <% end %>
+ <% if orders_active && (ready_to_ship_orders_count&.positive? || can?(:manage, :checkouts)) %>
+ <ul class="ml-4 pl-1 mb-2 nav-submenu mt-1">
+ <% if ready_to_ship_orders_count&.positive? %>
+ <li class="nav-item">
+ <%= active_link_to spree.admin_orders_path(q: {shipment_state_not_in: [:shipped, :canceled]}), class: 'nav-link', active: params.dig(:q, :shipment_state_not_in).present? do %>
+ <span><%= Spree.t('admin.orders.orders_to_fulfill') %></span>
+ <span class="badge ml-auto">
+ <%= ready_to_ship_orders_count %>
+ </span>
+ <% end %>
+ </li>
+ <% end %>
- <% if can?(:manage, :checkouts) %>
- <li class="nav-item">
- <%= active_link_to Spree.t(:draft_orders), spree.admin_checkouts_path, class: 'nav-link' %>
- </li>
- <% end %>
- </ul>
- <% end %>
-</li>
+ <% if can?(:manage, :checkouts) %>
+ <li class="nav-item">
+ <%= active_link_to Spree.t(:draft_orders), spree.admin_checkouts_path, class: 'nav-link' %>
+ </li>
+ <% end %>
+ </ul>
+ <% end %>
+ </li>
+<% end %>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/shared/sidebar/_products_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_products_nav.html.erb
index 6ff09de742..7dc0a3a474 100644
--- a/admin/app/views/spree/admin/shared/sidebar/_products_nav.html.erb
+++ b/admin/app/views/spree/admin/shared/sidebar/_products_nav.html.erb
@@ -1,7 +1,8 @@
<% products_active = %w[products external_categories taxons taxonomies option_types option_values properties stock_items stock_transfers].include?(controller_name) || request.path.include?('products') %>
-<li class="nav-item">
- <%= active_link_to spree.admin_products_path, class: 'nav-link', active: products_active do %>
- <span class="position-relative">
+<% if can?(:manage, Spree::Product) %>
+ <li class="nav-item">
+ <%= active_link_to spree.admin_products_path, class: 'nav-link', active: products_active do %>
+ <span class="position-relative">
<%= icon 'box-seam' %>
</span>
<%= Spree.t(:products) %>
@@ -13,7 +14,7 @@
<%= active_link_to Spree.t(:stock), spree.admin_stock_items_path, class: 'nav-link', active: %w[stock_items stock_transfers].include?(controller_name) %>
</li>
<% end %>
- <% if can?(:manage, Spree::Taxonomy) %>
+ <% if can?(:manage, Spree::Taxonomy) && can?(:manage, Spree::Taxon) %>
<li class="nav-item">
<%= active_link_to Spree.t(:taxonomies), spree.admin_taxonomies_path, class: 'nav-link' %>
</li>
@@ -35,5 +36,6 @@
</li>
<% end %>
</ul>
- <% end %>
-</li>
+ <% end %>
+ </li>
+<% end %>
diff --git a/admin/app/views/spree/admin/shared/sidebar/_returns_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_returns_nav.html.erb
index 3a9e6c17f6..db4721e4d5 100644
--- a/admin/app/views/spree/admin/shared/sidebar/_returns_nav.html.erb
+++ b/admin/app/views/spree/admin/shared/sidebar/_returns_nav.html.erb
@@ -1,6 +1,6 @@
<% returns_active = %[customer_returns return_authorizations].include?(controller_name) %>
-<% if can?(:manage, :customer_returns) || can?(:manage, :return_authorizations) %>
+<% if can?(:manage, Spree::CustomerReturn) || can?(:manage, Spree::ReturnAuthorization) %>
<li class="nav-item">
<%= active_link_to spree.admin_customer_returns_path, class: 'nav-link', active: returns_active do %>
<%= icon 'receipt-refund' %>
@@ -9,7 +9,7 @@
<% if returns_active %>
<ul class="ml-4 pl-1 mb-2 nav-submenu mt-1">
- <% if can?(:manage, :return_authorizations) %>
+ <% if can?(:manage, Spree::ReturnAuthorization) %>
<li class="nav-item">
<%= active_link_to Spree.t(:return_authorizations), spree.admin_return_authorizations_path, class: 'nav-link' %>
</li>
diff --git a/admin/app/views/spree/admin/shared/sidebar/_store_dropdown.html.erb b/admin/app/views/spree/admin/shared/sidebar/_store_dropdown.html.erb
index 3b4f4da54c..c21da582ab 100644
--- a/admin/app/views/spree/admin/shared/sidebar/_store_dropdown.html.erb
+++ b/admin/app/views/spree/admin/shared/sidebar/_store_dropdown.html.erb
@@ -15,7 +15,7 @@
<%= link_to spree.edit_admin_theme_path(current_store.default_theme), class: 'dropdown-item' do %>
<%= icon 'tools' %>
<%= Spree.t('admin.edit_theme') %>
- <% end if current_store.default_theme %>
+ <% end if current_store.default_theme && can?(:manage, Spree::Theme) %>
<% if available_stores.count > 1 %>
<div class="dropdown-header">
@@ -41,17 +41,19 @@
<%= link_to spree.new_admin_product_path, class: 'dropdown-item' do %>
<%= icon 'box' %>
<%= Spree.t(:new_product) %>
- <% end %>
+ <% end if can?(:create, Spree::Product) %>
<%= link_to spree.new_admin_user_path, class: 'dropdown-item' do %>
<%= icon 'user' %>
<%= Spree.t(:new_user) %>
- <% end %>
+ <% end if can?(:create, Spree.user_class) %>
- <div class="dropdown-divider"></div>
+ <% if can?(:create, Spree::Store) %>
+ <div class="dropdown-divider"></div>
- <span data-toggle="modal" data-target="#modal-lg">
- <%= link_to_with_icon 'building-store', Spree.t(:new_store), spree.new_admin_store_path, class: 'dropdown-item', data: { turbo_frame: 'dialog_modal_lg' } %>
- </span>
+ <span data-toggle="modal" data-target="#modal-lg">
+ <%= link_to_with_icon 'building-store', Spree.t(:new_store), spree.new_admin_store_path, class: 'dropdown-item', data: { turbo_frame: 'dialog_modal_lg' } %>
+ </span>
+ <% end %>
</div>
</div>
</div>
diff --git a/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb
index ceff52fb0a..af819f6dc8 100644
--- a/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb
+++ b/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb
@@ -4,11 +4,13 @@
<%= active_link_to_with_icon('chevron-left', Spree.t('admin.back_to_dashboard'), spree.admin_dashboard_path, class: 'nav-link') %>
</li>
- <li class="nav-item">
- <%= active_link_to_with_icon('building-store', Spree.t(:store_details), spree.edit_admin_store_path(section: 'general-settings'), class: 'nav-link', active: params[:section] == 'general-settings') %>
- </li>
+ <% if can?(:manage, current_store) %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('building-store', Spree.t(:store_details), spree.edit_admin_store_path(section: 'general-settings'), class: 'nav-link', active: params[:section] == 'general-settings') %>
+ </li>
+ <% end %>
- <% if defined?(current_account) && current_account.present? %>
+ <% if defined?(current_account) && current_account.present? && can?(:manage, current_account) %>
<li class="nav-item">
<%= active_link_to_with_icon 'receipt', Spree.t(:account), main_app.edit_account_path(current_account), class: 'nav-link' %>
</li>
@@ -17,56 +19,82 @@
</li>
<% end %>
- <li class="nav-item">
- <%= active_link_to_with_icon('send', Spree.t(:emails), spree.edit_admin_store_path(section: 'emails'), class: 'nav-link', active: params[:section] == 'emails') %>
- </li>
- <li class="nav-item">
- <%= active_link_to_with_icon('list-check', Spree.t(:policies), spree.edit_admin_store_path(section: 'policies'), class: 'nav-link', active: params[:section] == 'policies') %>
- </li>
- <li class="nav-item">
- <%= active_link_to_with_icon('shopping-cart', Spree.t(:checkout), spree.edit_admin_store_path(section: 'checkout'), class: 'nav-link', active: params[:section] == 'checkout') %>
- </li>
+ <% if can?(:manage, current_store) %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('send', Spree.t(:emails), spree.edit_admin_store_path(section: 'emails'), class: 'nav-link', active: params[:section] == 'emails') %>
+ </li>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('list-check', Spree.t(:policies), spree.edit_admin_store_path(section: 'policies'), class: 'nav-link', active: params[:section] == 'policies') %>
+ </li>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('shopping-cart', Spree.t(:checkout), spree.edit_admin_store_path(section: 'checkout'), class: 'nav-link', active: params[:section] == 'checkout') %>
+ </li>
+ <% end %>
- <li class="nav-item">
- <%= active_link_to_with_icon('world-www', Spree.t(:domains), spree.admin_custom_domains_path, class: 'nav-link') %>
- </li>
+ <% if can?(:manage, Spree::CustomDomain) %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('world-www', Spree.t(:domains), spree.admin_custom_domains_path, class: 'nav-link') %>
+ </li>
+ <% end %>
- <li class="nav-item">
- <%= active_link_to_with_icon('credit-card', Spree.t(:payments), spree.admin_payment_methods_path, class: 'nav-link') %>
- </li>
+ <% if can?(:manage, Spree::PaymentMethod) %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('credit-card', Spree.t(:payments), spree.admin_payment_methods_path, class: 'nav-link') %>
+ </li>
+ <% end %>
- <li class="nav-item">
- <%= active_link_to_with_icon('world', Spree.t(:zones), spree.admin_zones_path, { active: %w[zones countries states].include?(controller_name), class: 'nav-link' }) %>
- </li>
- <li class="nav-item">
- <%= active_link_to_with_icon('truck', Spree.t(:shipping), spree.admin_shipping_methods_path, { active: %w[shipping_methods shipping_categories].include?(controller_name), class: 'nav-link' }) %>
- </li>
- <li class="nav-item">
- <%= active_link_to_with_icon('receipt-tax', Spree.t(:tax), spree.admin_tax_rates_path, active: %w[tax_rates tax_categories stripe_tax_registrations].include?(controller_name), class: 'nav-link') %>
- </li>
- <li class="nav-item">
- <%= active_link_to_with_icon('receipt-refund', Spree.t(:returns), spree.admin_return_authorization_reasons_path, active: %w[refund_reasons reimbursement_types return_authorization_reasons].include?(controller_name), class: 'nav-link') %>
- </li>
- <li class="nav-item">
- <%= active_link_to_with_icon('map-pin', Spree.t(:stock_locations), spree.admin_stock_locations_path, class: 'nav-link') %>
- </li>
- <% if enterprise_edition? %>
+ <% if can?(:manage, Spree::Zone) %>
<li class="nav-item">
- <%= active_link_to_with_icon('history', Spree.t('admin.audit_log'), spree.admin_audits_path, class: 'nav-link w-auto', active: %w[audits exports imports].include?(controller_name)) %>
+ <%= active_link_to_with_icon('world', Spree.t(:zones), spree.admin_zones_path, { active: %w[zones countries states].include?(controller_name), class: 'nav-link' }) %>
</li>
- <% else %>
+ <% end %>
+
+ <% if can?(:manage, Spree::ShippingMethod) %>
<li class="nav-item">
- <%= external_link_to nil, 'https://spreecommerce.org/pricing', class: 'nav-link d-flex align-items-center w-100' do %>
- <%= icon 'history' %>
- <%= Spree.t('admin.audit_log') %>
+ <%= active_link_to_with_icon('truck', Spree.t(:shipping), spree.admin_shipping_methods_path, { active: %w[shipping_methods shipping_categories].include?(controller_name), class: 'nav-link' }) %>
+ </li>
+ <% end %>
- <span class="badge ml-auto with-tip rounded-pill" title="This feature is part of the Enterprise Edition.">Enterprise</span>
- <% end %>
+ <% if can?(:manage, Spree::TaxRate) %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('receipt-tax', Spree.t(:tax), spree.admin_tax_rates_path, active: %w[tax_rates tax_categories stripe_tax_registrations].include?(controller_name), class: 'nav-link') %>
+ </li>
+ <% end %>
+
+ <% if can?(:manage, Spree::ReturnAuthorizationReason) %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('receipt-refund', Spree.t(:returns), spree.admin_return_authorization_reasons_path, active: %w[refund_reasons reimbursement_types return_authorization_reasons].include?(controller_name), class: 'nav-link') %>
+ </li>
+ <% end %>
+
+ <% if can?(:manage, Spree::StockLocation) %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('map-pin', Spree.t(:stock_locations), spree.admin_stock_locations_path, class: 'nav-link') %>
+ </li>
+ <% end %>
+
+ <% if can?(:manage, Spree::Store) %>
+ <% if enterprise_edition? %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('history', Spree.t('admin.audit_log'), spree.admin_audits_path, class: 'nav-link w-auto', active: %w[audits exports imports].include?(controller_name)) %>
+ </li>
+ <% else %>
+ <li class="nav-item">
+ <%= external_link_to nil, 'https://spreecommerce.org/pricing', class: 'nav-link d-flex align-items-center w-100' do %>
+ <%= icon 'history' %>
+ <%= Spree.t('admin.audit_log') %>
+
+ <span class="badge ml-auto with-tip rounded-pill" title="This feature is part of the Enterprise Edition.">Enterprise</span>
+ <% end %>
+ </li>
+ <% end %>
+ <% end %>
+
+ <% if can?(:manage, Spree::OauthApplication) %>
+ <li class="nav-item">
+ <%= active_link_to_with_icon('terminal', Spree.t(:developers), spree.admin_oauth_applications_path, class: 'nav-link', active: %w[oauth_applications webhooks_subscribers].include?(controller_name)) %>
</li>
<% end %>
- <li class="nav-item">
- <%= active_link_to_with_icon('terminal', Spree.t(:developers), spree.admin_oauth_applications_path, class: 'nav-link', active: %w[oauth_applications webhooks_subscribers].include?(controller_name)) %>
- </li>
</ul>
<% else %>
<%= render 'spree/admin/shared/sidebar/store_dropdown' %>
@@ -136,7 +164,7 @@
<li class="nav-item border-top border-top-dashed pt-2">
<%= active_link_to_with_icon('settings', Spree.t(:settings), spree.edit_admin_store_path(section: 'general-settings'), class: 'nav-link', active: params[:section] == 'general-settings') %>
</li>
- <% if defined?(current_account) && current_account.present? %>
+ <% if defined?(current_account) && current_account.present? && can?(:manage, current_account) %>
<li class="nav-item">
<%= active_link_to_with_icon 'users', Spree.t(:account_members), main_app.account_members_path(current_account), class: 'nav-link' %>
</li>
diff --git a/admin/app/views/spree/admin/shared/sidebar/_storefront_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_storefront_nav.html.erb
index f78be98f26..8b81c476da 100644
--- a/admin/app/views/spree/admin/shared/sidebar/_storefront_nav.html.erb
+++ b/admin/app/views/spree/admin/shared/sidebar/_storefront_nav.html.erb
@@ -1,21 +1,29 @@
-<li class="nav-item border-top border-top-dashed pt-2">
- <% storefront_active = %w[themes posts post_categories pages storefront].include?(controller_name) %>
- <%= active_link_to_with_icon('building-store', Spree.t('admin.storefront'), spree.admin_themes_path, class: 'nav-link', active: storefront_active) %>
+<% if can?(:manage, Spree::Theme) %>
+ <li class="nav-item border-top border-top-dashed pt-2">
+ <% storefront_active = %w[themes posts post_categories pages storefront].include?(controller_name) %>
+ <%= active_link_to_with_icon('building-store', Spree.t('admin.storefront'), spree.admin_themes_path, class: 'nav-link', active: storefront_active) %>
- <% if storefront_active %>
- <ul class="ml-4 pl-1 mb-2 nav-submenu mt-1">
- <li class="nav-item">
- <%= active_link_to Spree.t(:themes), spree.admin_themes_path, class: 'nav-link' %>
- </li>
- <li class="nav-item">
- <%= active_link_to Spree.t(:pages), spree.admin_pages_path, class: 'nav-link' %>
- </li>
- <li class="nav-item">
- <%= active_link_to Spree.t(:posts), spree.admin_posts_path, class: 'nav-link', active: %w[posts post_categories].include?(controller_name) %>
- </li>
- <li class="nav-item">
- <%= active_link_to Spree.t(:settings), spree.edit_admin_storefront_path, class: 'nav-link' %>
- </li>
- </ul>
- <% end %>
-</li>
+ <% if storefront_active %>
+ <ul class="ml-4 pl-1 mb-2 nav-submenu mt-1">
+ <li class="nav-item">
+ <%= active_link_to Spree.t(:themes), spree.admin_themes_path, class: 'nav-link' %>
+ </li>
+ <% if can?(:manage, Spree::Page) %>
+ <li class="nav-item">
+ <%= active_link_to Spree.t(:pages), spree.admin_pages_path, class: 'nav-link' %>
+ </li>
+ <% end %>
+ <% if can?(:manage, Spree::Post) %>
+ <li class="nav-item">
+ <%= active_link_to Spree.t(:posts), spree.admin_posts_path, class: 'nav-link', active: %w[posts post_categories].include?(controller_name) %>
+ </li>
+ <% end %>
+ <% if can?(:manage, current_store) %>
+ <li class="nav-item">
+ <%= active_link_to Spree.t(:settings), spree.edit_admin_storefront_path, class: 'nav-link' %>
+ </li>
+ <% end %>
+ </ul>
+ <% end %>
+ </li>
+<% end %>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb b/admin/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb
index 5874f5d324..80ecad86bf 100644
--- a/admin/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb
+++ b/admin/app/views/spree/admin/shared/sortable_tree/_taxonomy.html.erb
@@ -54,8 +54,10 @@
<%= icon('dots', class: 'mr-0') %>
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton-<%= taxon.id %>">
- <%= link_to_with_icon 'plus', Spree.t(:new_nested_taxon), spree.new_admin_taxonomy_taxon_path(taxonomy, taxon: { parent_id: taxon.id }), class: 'dropdown-item' %>
- <div class="dropdown-divider"></div>
+ <% if can?(:create, Spree::Taxon) %>
+ <%= link_to_with_icon 'plus', Spree.t(:new_nested_taxon), spree.new_admin_taxonomy_taxon_path(taxonomy, taxon: { parent_id: taxon.id }), class: 'dropdown-item' %>
+ <div class="dropdown-divider"></div>
+ <% end %>
<%= link_to_delete(taxon, icon: 'trash', url: spree.admin_taxonomy_taxon_path(taxonomy, taxon.id), class: 'dropdown-item btn-danger') if can?(:destroy, taxon) %>
</div>
</div>
diff --git a/admin/app/views/spree/admin/store_credits/_list.html.erb b/admin/app/views/spree/admin/store_credits/_list.html.erb
index b5523be5d8..7793d98894 100644
--- a/admin/app/views/spree/admin/store_credits/_list.html.erb
+++ b/admin/app/views/spree/admin/store_credits/_list.html.erb
@@ -23,7 +23,7 @@
<td><%= local_date(store_credit.created_at) %></td>
<td class="actions">
<% if store_credit.editable? && can?(:edit, store_credit) %>
- <%= link_to_edit_url spree.edit_admin_user_store_credit_path(@user, store_credit), no_text: true, data: { 'turbo-frame': '_top' } %>
+ <%= link_to_edit store_credit, url: spree.edit_admin_user_store_credit_path(@user, store_credit), no_text: true, data: { 'turbo-frame': '_top' } %>
<% end %>
</td>
</tr>
diff --git a/admin/app/views/spree/admin/taxons/_form.html.erb b/admin/app/views/spree/admin/taxons/_form.html.erb
index 9b342111be..029ca3aed9 100644
--- a/admin/app/views/spree/admin/taxons/_form.html.erb
+++ b/admin/app/views/spree/admin/taxons/_form.html.erb
@@ -70,7 +70,7 @@
</span>
</h5>
- <% if @taxon.manual? %>
+ <% if @taxon.manual? && can?(:create, Spree::Classification) %>
<span data-toggle="modal" data-target="#modal">
<%= link_to_with_icon 'plus', Spree.t(:add_products), spree.new_admin_taxon_classification_path(@taxon.id), class: 'btn btn-light btn-sm', data: { turbo_frame: 'dialog_modal' } %>
</span>
diff --git a/admin/app/views/spree/admin/users/_billing.html.erb b/admin/app/views/spree/admin/users/_billing.html.erb
index 6dcbdd7f3f..4143d9c095 100644
--- a/admin/app/views/spree/admin/users/_billing.html.erb
+++ b/admin/app/views/spree/admin/users/_billing.html.erb
@@ -15,7 +15,7 @@
<%= link_to_with_icon 'plus', Spree.t(:add),
spree.new_admin_address_path(user_id: @user.id, default_billing: true, type: 'billing'),
class: 'btn btn-light btn-sm',
- data: { turbo_frame: :new_address_billing } %>
+ data: { turbo_frame: :new_address_billing } if can?(:create, Spree::Address) && can?(:update, @user) %>
<% end %>
</div>
<div class="card-body">
diff --git a/admin/app/views/spree/admin/users/_shipping.html.erb b/admin/app/views/spree/admin/users/_shipping.html.erb
index 50f3ab13ed..4e976bb8f2 100644
--- a/admin/app/views/spree/admin/users/_shipping.html.erb
+++ b/admin/app/views/spree/admin/users/_shipping.html.erb
@@ -6,12 +6,12 @@
<%= link_to_with_icon 'edit', Spree.t(:edit),
spree.edit_admin_address_path(@user.shipping_address, type: 'shipping'),
class: 'btn btn-light btn-sm',
- data: { turbo_frame: :edit_address_shipping } %>
+ data: { turbo_frame: :edit_address_shipping } if can?(:update, @user.shipping_address) %>
<% else %>
<%= link_to_with_icon 'plus', Spree.t(:add),
spree.new_admin_address_path(user_id: @user.id, default_shipping: true, type: 'shipping'),
class: 'btn btn-light btn-sm',
- data: { turbo_frame: :new_address_shipping } %>
+ data: { turbo_frame: :new_address_shipping } if can?(:create, Spree::Address) && can?(:update, @user) %>
<% end %>
</div>
<div class="card-body">
diff --git a/admin/app/views/spree/admin/users/_tabs.html.erb b/admin/app/views/spree/admin/users/_tabs.html.erb
index 8dce5aadde..39ddad5cc6 100644
--- a/admin/app/views/spree/admin/users/_tabs.html.erb
+++ b/admin/app/views/spree/admin/users/_tabs.html.erb
@@ -5,22 +5,26 @@
</li>
<% end %>
- <li class="nav-item" role="presentation">
- <a class="nav-link <%= 'active' unless spree.respond_to?(:admin_user_visits_path) %>" id="pills-orders2-tab" data-toggle="pill" data-target="#pills-orders2" role="tab" aria-controls="pills-orders2" aria-selected="false"><%= Spree.t(:orders) %></a>
- </li>
- <li class="nav-item" role="presentation">
- <a class="nav-link" id="pills-checkouts-tab" data-toggle="pill" data-target="#pills-checkouts" role="tab" aria-controls="pills-checkouts" aria-selected="false"><%= Spree.t(:draft_orders) %></a>
- </li>
+ <% if can?(:read, Spree::Order) %>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link <%= 'active' unless spree.respond_to?(:admin_user_visits_path) %>" id="pills-orders2-tab" data-toggle="pill" data-target="#pills-orders2" role="tab" aria-controls="pills-orders2" aria-selected="false"><%= Spree.t(:orders) %></a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="pills-checkouts-tab" data-toggle="pill" data-target="#pills-checkouts" role="tab" aria-controls="pills-checkouts" aria-selected="false"><%= Spree.t(:draft_orders) %></a>
+ </li>
+ <% end %>
- <% if spree.respond_to?(:admin_user_gift_cards_path) %>
+ <% if spree.respond_to?(:admin_user_gift_cards_path) && can?(:read, Spree::GiftCard) %>
<li class="nav-item" role="presentation">
<a class="nav-link" id="pills-gift-cards-tab" data-toggle="pill" data-target="#pills-gift-cards" role="tab" aria-controls="pills-gift-cards" aria-selected="false"><%= Spree.t(:gift_cards) %></a>
</li>
<% end %>
- <li class="nav-item" role="presentation">
- <a class="nav-link" id="pills-store-credits-tab" data-toggle="pill" data-target="#pills-store-credits" role="tab" aria-controls="pills-store-credits" aria-selected="false"><%= Spree.t(:store_credits) %></a>
- </li>
+ <% if can?(:read, Spree::StoreCredit) %>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="pills-store-credits-tab" data-toggle="pill" data-target="#pills-store-credits" role="tab" aria-controls="pills-store-credits" aria-selected="false"><%= Spree.t(:store_credits) %></a>
+ </li>
+ <% end %>
</ul>
<div class="tab-content" id="vendorContent">
@@ -30,23 +34,25 @@
</div>
<% end %>
- <div class="tab-pane fade <%= 'show active' unless spree.respond_to?(:admin_user_visits_path) %>" id="pills-orders2" role="tabpanel" aria-labelledby="pills-orders2">
- <div class="card-lg p-0">
- <%= turbo_frame_tag :orders_list, src: spree.admin_user_orders_path(@user, frame_name: :orders_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
- <%= render 'spree/admin/shared/spinner' %>
- <% end %>
+ <% if can?(:read, Spree::Order) %>
+ <div class="tab-pane fade <%= 'show active' unless spree.respond_to?(:admin_user_visits_path) %>" id="pills-orders2" role="tabpanel" aria-labelledby="pills-orders2">
+ <div class="card-lg p-0">
+ <%= turbo_frame_tag :orders_list, src: spree.admin_user_orders_path(@user, frame_name: :orders_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
+ <%= render 'spree/admin/shared/spinner' %>
+ <% end %>
+ </div>
</div>
- </div>
- <div class="tab-pane fade" id="pills-checkouts" role="tabpanel" aria-labelledby="pills-checkouts">
- <div class="card-lg p-0">
- <%= turbo_frame_tag :orders_list, src: spree.admin_user_checkouts_path(@user, frame_name: :orders_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
- <%= render 'spree/admin/shared/spinner' %>
- <% end %>
+ <div class="tab-pane fade" id="pills-checkouts" role="tabpanel" aria-labelledby="pills-checkouts">
+ <div class="card-lg p-0">
+ <%= turbo_frame_tag :orders_list, src: spree.admin_user_checkouts_path(@user, frame_name: :orders_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
+ <%= render 'spree/admin/shared/spinner' %>
+ <% end %>
+ </div>
</div>
- </div>
+ <% end %>
- <% if spree.respond_to?(:admin_user_gift_cards_path) %>
+ <% if spree.respond_to?(:admin_user_gift_cards_path) && can?(:read, Spree::GiftCard) %>
<div class="tab-pane fade" id="pills-gift-cards" role="tabpanel" aria-labelledby="pills-gift-cards">
<div class="card-lg p-0">
<%= turbo_frame_tag :gift_cards_list, src: spree.admin_user_gift_cards_path(@user, frame_name: :gift_cards_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
@@ -56,11 +62,13 @@
</div>
<% end %>
- <div class="tab-pane fade" id="pills-store-credits" role="tabpanel" aria-labelledby="pills-store-credits">
- <div class="card-lg p-0">
- <%= turbo_frame_tag :store_credits_list, src: spree.admin_user_store_credits_path(@user, frame_name: :store_credits_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
- <%= render 'spree/admin/shared/spinner' %>
- <% end %>
+ <% if can?(:read, Spree::StoreCredit) %>
+ <div class="tab-pane fade" id="pills-store-credits" role="tabpanel" aria-labelledby="pills-store-credits">
+ <div class="card-lg p-0">
+ <%= turbo_frame_tag :store_credits_list, src: spree.admin_user_store_credits_path(@user, frame_name: :store_credits_list), loading: :lazy, autoscroll: true, data: { autoscroll_block: :nearest, autoscroll_behavior: :smooth } do %>
+ <%= render 'spree/admin/shared/spinner' %>
+ <% end %>
+ </div>
</div>
- </div>
+ <% end %>
</div>
diff --git a/admin/app/views/spree/admin/users/index.html.erb b/admin/app/views/spree/admin/users/index.html.erb
index bfa8f9a82f..ff49a8c364 100644
--- a/admin/app/views/spree/admin/users/index.html.erb
+++ b/admin/app/views/spree/admin/users/index.html.erb
@@ -5,8 +5,8 @@
<% content_for :page_actions do %>
<%= link_to spree.admin_users_path(q: params[:q].to_unsafe_hash, page: params[:page], per_page: params[:per_page], format: :csv), class: 'btn btn-light bg-transparent with-tip mr-2 d-none d-lg-inline-flex', title: 'Export Customers to a CSV file. To filter specific Customers use "Filters" or Customers/Subscribers tabs before clicking this button' do %>
<%= icon 'table-export', class: 'mr-2' %>
- Export
- <% end %>
+ <%= Spree.t(:export) %>
+ <% end if can?(:export, Spree::Export) %>
<%= render 'extra_actions' %>
<%= button_link_to Spree.t(:create_customer), spree.new_admin_user_path, class: "btn-primary", icon: 'plus', id: 'admin_new_user_link' %>
<% end if can? :create, Spree::user_class %>
diff --git a/admin/app/views/spree/admin/users/show.html.erb b/admin/app/views/spree/admin/users/show.html.erb
index d260192e9a..39b407ede8 100644
--- a/admin/app/views/spree/admin/users/show.html.erb
+++ b/admin/app/views/spree/admin/users/show.html.erb
@@ -8,11 +8,13 @@
<% end %>
<% content_for(:page_actions_dropdown) do %>
- <% if spree.respond_to?(:new_admin_user_gift_card_path) %>
- <%= link_to_with_icon 'plus.svg', Spree.t(:issue_gift_card), spree.new_admin_user_gift_card_path(@user), class: 'text-left dropdown-item' %>
+ <% if spree.respond_to?(:new_admin_user_gift_card_path) && can?(:create, Spree::GiftCard) %>
+ <%= link_to_with_icon 'plus', Spree.t(:issue_gift_card), spree.new_admin_user_gift_card_path(@user), class: 'text-left dropdown-item' %>
<% end %>
- <%= link_to_with_icon 'plus.svg', Spree.t(:add_store_credit), spree.new_admin_user_store_credit_path(@user), class: 'text-left dropdown-item' %>
+ <% if can?(:create, Spree::StoreCredit) %>
+ <%= link_to_with_icon 'plus', Spree.t(:add_store_credit), spree.new_admin_user_store_credit_path(@user), class: 'text-left dropdown-item' %>
+ <% end %>
<% end %>
<div class="row">
diff --git a/admin/lib/spree/admin/runtime_configuration.rb b/admin/lib/spree/admin/runtime_configuration.rb
index f65eab008f..594579a8cd 100644
--- a/admin/lib/spree/admin/runtime_configuration.rb
+++ b/admin/lib/spree/admin/runtime_configuration.rb
@@ -3,6 +3,10 @@ module Spree
class RuntimeConfiguration < ::Spree::Preferences::RuntimeConfiguration
preference :admin_path, :string, default: '/admin'
preference :admin_updater_enabled, :boolean, default: true
+
+ preference :admin_records_per_page, :integer, default: Kaminari.config.default_per_page
+ preference :admin_products_per_page, :integer, default: Kaminari.config.default_per_page
+ preference :admin_orders_per_page, :integer, default: Kaminari.config.default_per_page
end
end
end
diff --git a/admin/spec/helpers/spree/admin/navigation_helper_spec.rb b/admin/spec/helpers/spree/admin/navigation_helper_spec.rb
new file mode 100644
index 0000000000..a1ce8031f4
--- /dev/null
+++ b/admin/spec/helpers/spree/admin/navigation_helper_spec.rb
@@ -0,0 +1,91 @@
+require 'spec_helper'
+
+describe Spree::Admin::NavigationHelper, type: :helper do
+ describe '#link_to_edit' do
+ let(:resource) { double('Resource') }
+
+ before do
+ allow(helper).to receive(:can?).and_return(true)
+ allow(helper).to receive(:edit_object_url).with(resource).and_return('/edit/resource')
+ allow(helper).to receive(:link_to_with_icon).and_return('link')
+ end
+
+ it 'calls link_to_with_icon with pencil icon' do
+ expect(helper).to receive(:link_to_with_icon).with('pencil', Spree.t(:edit), '/edit/resource', anything)
+ helper.link_to_edit(resource)
+ end
+
+ it 'returns nil if user cannot update resource' do
+ allow(helper).to receive(:can?).and_return(false)
+ expect(helper.link_to_edit(resource)).to be_nil
+ end
+ end
+
+ describe '#link_to_delete' do
+ let(:resource) { double('Resource') }
+
+ before do
+ allow(helper).to receive(:can?).and_return(true)
+ allow(helper).to receive(:object_url).with(resource).and_return('/resource')
+ allow(helper).to receive(:link_to_with_icon).and_return('link')
+ allow(helper).to receive(:link_to).and_return('link')
+ end
+
+ it 'returns nil if user cannot destroy resource' do
+ allow(helper).to receive(:can?).and_return(false)
+ expect(helper.link_to_delete(resource)).to be_nil
+ end
+
+ it 'uses link_to_with_icon when no_text option is true' do
+ expect(helper).to receive(:link_to_with_icon).with('trash', anything, '/resource', hash_including(no_text: true))
+ helper.link_to_delete(resource, no_text: true)
+ end
+
+ it 'uses link_to_with_icon when icon option is provided' do
+ expect(helper).to receive(:link_to_with_icon).with('custom-icon', anything, '/resource', hash_including(icon: 'custom-icon'))
+ helper.link_to_delete(resource, icon: 'custom-icon')
+ end
+
+ it 'uses link_to when no icon options are provided' do
+ expect(helper).to receive(:link_to).with(Spree.t('actions.destroy'), '/resource', anything)
+ helper.link_to_delete(resource)
+ end
+ end
+
+ describe '#button' do
+ it 'creates a button with spinner for turbo' do
+ result = helper.button('Submit', 'save')
+ expect(result).to include('data-turbo-submits-with')
+ expect(result).to include('spinner-border')
+ end
+ end
+
+ describe '#active_badge' do
+ it 'returns active badge when condition is true' do
+ result = helper.active_badge(true)
+ expect(result).to include('badge-active')
+ end
+
+ it 'returns inactive badge when condition is false' do
+ result = helper.active_badge(false)
+ expect(result).to include('badge-inactive')
+ end
+ end
+
+ describe '#page_header_back_button' do
+ before do
+ allow(helper).to receive(:session).and_return({})
+ allow(helper).to receive(:icon).and_return('icon')
+ end
+
+ it 'returns link to default url when no object is provided' do
+ expect(helper.page_header_back_button('/default')).to include('/default')
+ end
+
+ it 'returns link to session url when object is provided and session key exists' do
+ object = Spree::Product.new
+ allow(helper).to receive(:session).and_return(products_return_to: '/from_session')
+ expect(helper.page_header_back_button('/default', object)).to include('/from_session')
+ end
+ end
+end