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.

Open source admin exports UI (#12212)

Damian Legawiec2e17818656ff
diff --git a/admin/app/controllers/spree/admin/exports_controller.rb b/admin/app/controllers/spree/admin/exports_controller.rb
new file mode 100644
index 0000000000..94fae19adc
--- /dev/null
+++ b/admin/app/controllers/spree/admin/exports_controller.rb
@@ -0,0 +1,46 @@
+module Spree
+ module Admin
+ class ExportsController < ResourceController
+ new_action.before :assign_params
+ create.before :set_user
+
+ def show
+ redirect_to @object.attachment.url, status: :see_other, allow_other_host: true
+ end
+
+ protected
+
+ def create_turbo_stream_enabled?
+ true
+ end
+
+ def message_after_create
+ Spree.t(:export_created)
+ end
+
+ def collection
+ return @collection if @collection.present?
+
+ @collection = super
+
+ params[:q] ||= {}
+ params[:q][:s] ||= 'created_at desc'
+ @search = @collection.ransack(params[:q])
+ @collection = @search.result.includes(:user, attachment_attachment: :blob).page(params[:page])
+ end
+
+ def set_user
+ @object.user = try_spree_current_user
+ end
+
+ def location_after_save
+ spree.admin_exports_path
+ end
+
+ def assign_params
+ @object.type = params.dig(:export, :type) if Spree::Export.available_types.map(&:to_s).include?(params.dig(:export, :type))
+ @object.search_params = params.dig(:export, :search_params)
+ end
+ end
+ end
+end
diff --git a/admin/app/views/spree/admin/exports/_export.html.erb b/admin/app/views/spree/admin/exports/_export.html.erb
new file mode 100644
index 0000000000..d0694e722d
--- /dev/null
+++ b/admin/app/views/spree/admin/exports/_export.html.erb
@@ -0,0 +1,42 @@
+<tr>
+ <td class="w-10"><%= export.number %></td>
+ <td class="text-center w-10">
+ <small class="badge badge-light border">
+ <%= Spree.t(export.type.demodulize) %>
+ </small>
+ </td>
+ <td class="text-center w-10">
+ <% if export.done? %>
+ <span class="badge badge-success">
+ <%= icon('check') %>
+ <%= Spree.t(:done) %>
+ </span>
+ <% else %>
+ <span class="badge badge-warning">
+ <%= icon('progress') %>
+ <%= Spree.t(:pending) %>
+ </span>
+ <% end %>
+ </td>
+
+ <td class="w-25">
+ <% if export.user %>
+ <span>
+ <%= export.user.name %>
+ </span>
+ <% end %>
+ </td>
+ <td>
+ <%= export.attachment.filename %>
+ </td>
+ <td class="w-15"><%= local_time_ago(export.created_at, class: 'with-tip') %></td>
+ <td>
+ <%= number_to_human_size(export.attachment.byte_size) %>
+ </td>
+ <td class="w-15 text-center">
+ <%= link_to spree.admin_export_path(export), class: 'btn btn-sm btn-light mx-auto', target: '_blank' do %>
+ <%= icon 'download', class: 'mr-1' %>
+ <%= Spree.t(:download) %>
+ <% end %>
+ </td>
+</tr>
\ No newline at end of file
diff --git a/admin/app/views/spree/admin/exports/create.turbo_stream.erb b/admin/app/views/spree/admin/exports/create.turbo_stream.erb
new file mode 100644
index 0000000000..90c38d2259
--- /dev/null
+++ b/admin/app/views/spree/admin/exports/create.turbo_stream.erb
@@ -0,0 +1,2 @@
+<%= turbo_render_alerts %>
+<%= turbo_close_modal %>
diff --git a/admin/app/views/spree/admin/exports/index.html.erb b/admin/app/views/spree/admin/exports/index.html.erb
new file mode 100644
index 0000000000..8f3b5fa4d3
--- /dev/null
+++ b/admin/app/views/spree/admin/exports/index.html.erb
@@ -0,0 +1,30 @@
+<%= render 'spree/admin/shared/audit_nav' %>
+
+<% if @collection.present? %>
+ <div class="table-responsive card-lg p-0">
+ <table class="table">
+ <thead class="text-muted">
+ <tr data-hook="admin_imports_index_headers">
+ <th><%= Spree.t(:number) %></th>
+ <th class="text-center"><%= Spree.t(:kind) %></th>
+ <th class="text-center"><%= Spree.t(:status) %></th>
+ <th><%= Spree.t(:user) %></th>
+ <th><%= Spree.t(:filename) %></th>
+ <th><%= Spree.t(:date) %></th>
+ <th><%= Spree.t(:size) %></th>
+ <th class="text-center"><%= Spree.t(:download) %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <%= render partial: 'export', collection: @exports, cached: true %>
+ </tbody>
+ </table>
+ </div>
+ </div>
+<% else %>
+ <div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">
+ <%= Spree.t(:no_resource_found, resource: Spree.t('admin.exports.plural_resource_name')) %>
+ </div>
+<% end %>
+
+<%= render 'spree/admin/shared/index_table_options', collection: @imports, simple: true if @imports.present? %>
diff --git a/admin/app/views/spree/admin/exports/new.html.erb b/admin/app/views/spree/admin/exports/new.html.erb
new file mode 100644
index 0000000000..0450be1bd9
--- /dev/null
+++ b/admin/app/views/spree/admin/exports/new.html.erb
@@ -0,0 +1,42 @@
+<%= turbo_frame_tag :dialog_modal do %>
+ <%= form_for @export, url: spree.admin_exports_path do |f| %>
+ <%= f.hidden_field :type %>
+ <%= f.hidden_field :search_params %>
+ <div class="modal-content">
+ <div class="modal-header">
+ <h5 class="modal-title" id="exampleModalLabel">
+ <%= Spree.t(:export) %>
+ <%= plural_resource_name(@export.model_class) %>
+ </h5>
+ <button type="button" class="btn-close" data-dismiss="modal" aria-label="<%= Spree.t(:close) %>" />
+ </div>
+ <div class="modal-body">
+ <%= render 'spree/admin/shared/error_messages', target: @export %>
+ <div class="custom-control custom-radio">
+ <%= f.radio_button :record_selection, 'filtered', class: 'custom-control-input' %>
+ <%= f.label :record_selection, for: :export_record_selection_filtered, class: 'custom-control-label' do %>
+ <%= Spree.t(:filtered_records) %>
+ <br />
+ <span class="text-muted font-weight-normal">
+ <%= Spree.t(:export_only_filtered_records) %>
+ </span>
+ <% end %>
+ </div>
+ <div class="custom-control custom-radio mt-3">
+ <%= f.radio_button :record_selection, 'all', class: 'custom-control-input' %>
+ <%= f.label :record_selection, for: :export_record_selection_all, class: 'custom-control-label' do %>
+ <%= Spree.t(:all) %>
+ <br />
+ <span class="text-muted font-weight-normal">
+ <%= Spree.t(:export_all) %>
+ </span>
+ <% end %>
+ </div>
+ </div>
+ <div class="modal-footer d-flex justify-content-between">
+ <button type="button" class="btn btn-light" data-dismiss="modal"><%= Spree.t('actions.discard') %></button>
+ <%= turbo_save_button_tag Spree.t(:export), class: 'btn btn-primary' %>
+ </div>
+ </div>
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.yml
new file mode 100644
index 0000000000..5979beb053
--- /dev/null
+++ b/admin/config/locales/en.yml
@@ -0,0 +1,347 @@
+en:
+ spree:
+ admin:
+ url: URL
+ active: Active
+ name: Name
+ successful: Successful
+ created_at: Created At
+ response_code: Response Code
+ execution_time: Execution Time
+ request_errors: Request Errors
+ filters: Filters
+ kind: Kind
+ home: Home
+ cms:
+ all_pages: All Pages
+ add_new_page: Add New Page
+ add_new_section: Add New Section
+ content: Content
+ click_here: click here
+ draft_mode: Draft Mode
+ full_width: Full width
+ link_to_taxon: Link to Taxon
+ link_to_product: Link to Product
+ title: Title
+ fit: Fit To
+ info_hero_image_body: "<p>The Hero Image section adds a large image with a button and tagline text to your page.</p>
+ <p>The button can link to a Product, Taxon or Page. This section can be set to fit within the central container or to the edges of the screen.</p>
+ <p><b>Tip:</b> Use a hero image with no button text or title, and then set the <b>Fit:</b> to <b>Container</b> and <b>Gutters</b> to <b>Use Gutters</b> this creates an image section that looks great above a Side-by-Side Images section, or an Image Gallery section.</p>
+ <p>Experiment with the settings, and don't be afraid to use more than one Hero Image section per page.</p>"
+ info_image_gallery_body: "<p>The Image Gallery section can be configured in several ways. For example, each image can link to a product or taxon. If you do not provide a link, you can display three images. Additionally, you can also use labels to add text to your images.</p>
+ <p>There are two layout configurations for the Image Gallery section, with the taller image used on the left or the right. You can also set this section to fit the edges of the screen or the central container to match your website's style.</p>"
+ info_product_carousel_body: "<p>Product Carousel is a simple section to use. Search for the taxon you wish to display, save the changes, and the products in your chosen taxon will be displayed on your page.</p>"
+ info_featured_article_body: "<p>The Feature Article section allows you to add rich text to your page with a set title subtitle and linking button.</p>
+ <p>This section can be set to use full screen or container and also use gutters.</p>"
+ info_side_by_side_images_body: "<p>The Side-by-Side Images section can be configured in several ways, you have the option of using them as plane images, images with text, and either of those options can be clickable links if a link is set.</p>
+ <p><b>Tip:</b> You can blow these images out to the edge of the screen and remove the gutters to create a completely different look.</p>"
+ info_rich_text_content_body: "<p>The Rich Text Content section is simply a section that offers nothing more than an area of rich text editor content to be displayed on your page.</p>"
+ brand_bar:
+ uses_menu: This section uses your Spree Menu named <b>%{menu}</b> to manage the images and links,
+ vist_menu_to_edit: to edit this menu.
+ full_width_on_small: Full width on small devices
+ button_text: Button Text
+ go_to_fullscreen_section_manager: Go To Fullscreen Section Manager
+ page_type: Page Type
+ gutters: Gutters
+ you_have_no_pages: You have no Pages, click the <b>+ Add New Page</b> button to get started.
+ new_page: New Page
+ toggle_page_visibility: Toggle page visibility
+ meta_title: Meta Title
+ meta_description: Meta Description
+ page: Page
+ full_screen_mode: '<span class="exit">Exit </span>Full Screen Mode'
+ hero:
+ aspect_ratio: Please use an image with the aspect ratio of 12:5 (2400px x 1000px)
+ select_page_type: Select a page type
+ section_type: Section Type
+ subtitle: Subtitle
+ set_gutters: Set Gutters
+ click_button_to_change_page_type: Click the <b>%{button_type}</b> button to load the options for this page type.
+ more_page_settings: '<span class="more">More</span><span class="less">Less</span> Page Settings'
+ seo_settings: SEO Settings
+ no_sections_found_please_add_one: Add your first section to this page by clicking the <b>+ Add New Section</b> button above.
+ click_create_to_load_new_link: 'Click the <b>Create</b> button below to save your new page section, and load the section settings.'
+ click_update_to_load_new_link: 'Click the <b>Update</b> button below to load the new section settings.'
+ settings_for: 'Options For: <b>%{section}</b>'
+ page_sections: '%{page_name} Sections'
+ page_sections_info: 'The area below represents your %{page_type} displayed in %{store}, add sections and drag them into position'
+ visible: Visible
+ side_by_side:
+ left_image: Left Image
+ right_image: Right Image
+ image_info: 'Please use an image with an aspect ratio of 54:35 (1468px x 952px).'
+ image_gallery:
+ display_labels: Display labels
+ image_a: Image A
+ image_b: Image B
+ image_c: Image C
+ layout_style: Layout Style
+ square_image: Please use an image with an aspect ratio of 18:13 (1080px x 780px).
+ tall_image: Please use an image with an aspect ratio of 27:40 (1080px x 1600px).
+ copy_to_clipboard: Copy to clipboard
+ data_feeds:
+ data_feeds: Data Feeds
+ type: Type
+ slug_label: Slug (leave blank to generate)
+ new_data_feed: New Data Feed
+ digitals:
+ digital: Digital
+ add_new_file: Add a new digital asset.
+ digital_assets: Digital Assets
+ reset_download_links: Reset Digital Download Links
+ downloads_reset: Digital Download Links Reset
+ no_digital_assets_added: No digital assets.
+ delete_file_confirmation: "Are you sure you want to delete: %{filename}"
+ upload: Upload
+ export_only_filtered_records: Export only filtered records, matching the search criteria
+ export_all: Export all records (can be slow for large datasets)
+ export_created: Your export was started. You will receive an email with a download link when it is ready!
+ linkable:
+ search_for_a_page: Search for a page
+ search_for_a_taxon: Search for a Taxon
+ search_for_a_product: Search for a Product
+ store:
+ digital_settings:
+ digital_asset_settings: Digital Asset Settings
+ limit_digital_download_count: Limit Download Count
+ limit_digital_download_days: Limit Download Days
+ digital_asset_authorized_clicks:
+ authorized_clicks: Authorized Download Count
+ info: Number of times a download link can be clicked.
+ digital_asset_authorized_days:
+ authorized_days: Authorized Download Days
+ info: The number of days a purchase can be downloaded after purchase.
+ digital_asset_link_expire_time:
+ download_link_expire_time: Download Link Expire Time
+ link_expire_time: Set the expire time of each download link. (seconds).
+ product_kinds:
+ physical: Physical
+ digital: Digital
+ tab:
+ configuration: Configuration
+ content: Content
+ option_types: Option Types
+ orders: Orders
+ overview: Overview
+ pages: Pages
+ products: Products
+ promotions: Promotions
+ promotion_categories: Promotion Categories
+ properties: Properties
+ prototypes: Prototypes
+ reports: Reports
+ navigation: Navigation
+ taxonomies: Taxonomies
+ taxons: Taxons
+ users: Users
+ return_authorizations: Return Authorizations
+ stock: Stock
+ customer_returns: Customer Returns
+ apps: Apps
+ applications: Applications
+ integrations: Integrations
+ webhook_subscribers: Webhook Subscribers
+ taxon:
+ nested_under_info: Nest this Taxon within the Taxonomy tree.
+ taxonomies:
+ edit_root_taxonomy: Edit %{name} Taxonomy
+ taxonomies: Taxonomies
+ taxons_belonging_to: "Taxons Belonging To %{taxonomy_name}"
+ submenu: Submenu
+ add_new_taxon: Add a new Taxon
+ no_taxons: '<b>%{taxonomy}</b> has no Taxons. Click the <b>Add a new Taxon</b> button, to begin adding Taxons.'
+ order:
+ changing_store_warning: If you change the store this order belongs to, the order will be reset.
+ once_an_order_is_complete_you_can_not_change_store: 'Sorry, once an order is complete, you can no longer change the store that the order belongs to.'
+ events:
+ approve: Approve
+ cancel: Cancel
+ resume: Resume
+ resend: Resend
+ orders:
+ all: All
+ unpaid: Unpaid
+ unfulfilled: Unfulfilled
+ cart: Cart
+ all_orders: All Orders
+ draft_orders: Draft Orders
+ abandoned_checkouts: Abandoned Checkouts
+ oauth_applications:
+ list: oAuth applications
+ new: New oAuth application
+ uid: UID
+ scopes: Scopes
+ documentation_message: 'To learn how to authenticate requests to the Platform API, '
+ documentation_cta: see the documentation
+ reports:
+ for: For %{store_name}
+ return_authorization:
+ product: Product
+ store_form:
+ look_and_feel: Look and feel
+ code_help: "Store unique identifier, which is an abbreviated version of the store’s name (used as the layout directory name, and also helpful for separating templates by store)"
+ checkout_zone_help: "Selecting zone will limit to which Countries or States products are shipped.
+ For more information <a href='https://guides.spreecommerce.org/user/configuration/configuring_geography.html#zones' target='_blank' class='alert-link'>please see documentation</a>"
+ currencies_help: "You can accept payments in multiple currencies. Each product and product variant can have different price in different currency"
+ locales_help: "Install <a href='https://github.com/spree-contrib/spree_i18n' target='_blank' class='alert-link'>Spree I18n extension</a> to add more locales"
+ default_locale_notice: "Warning: Before changing the default locale, ensure that all products, taxons and stores have translations in the new locale"
+ social_help: "If you want to link to your social accounts in the footer part of your website please fill below fields"
+ default_country_help: "This is the Country that will be pre-selected on the Checkout Address form"
+ footer_help: "This content is visible in the footer section of your Store"
+ mail_from_address_help: "This is the email which will be the sender of all your Store emails (Order Confirmation, Shipment notification etc)"
+ customer_support_email_help: "This email is visible to your Store visitors in the Footer section"
+ new_order_notifications_email_help: "If you want to receive an email notification every time someone places an Order please provide an email address for that notification to be sent to"
+ seo_robots: "Please check <a href='https://developers.google.com/search/reference/robots_meta_tag' target='_blank'>this page for more help</a>"
+ user:
+ account: Account
+ addresses: Addresses
+ items: Items
+ items_purchased: Items Purchased
+ order_history: Order History
+ order_num: "Order #"
+ orders: Orders
+ user_information: User Information
+ stores: Stores
+ store_credits: Store Credits
+ no_store_credit: User has no Store Credit available.
+ available_store_credit: User has %{amount} in Store Credit available.
+ navigation:
+ all_menus: All Menus
+ add_new_menu: Add New Menu
+ add_new_item: 'Add New Item'
+ code: Code
+ default_menus_info:
+ title: Default Menus
+ body: "Default menus are menus whose language matches the associated store's default language.<br><br>
+ <h5>Example</h5>If you have a store that uses Spanish as the default language but also offers the options of German and French; your default header menu for this store would be set to use <b>Español (es)</b> for the language and <b>Header</b> as the location.<br><br>
+ <h5>Why Are Default Menus Important?</h5> Default menus are displayed to your visitor if no menu is available in the current language they are browsing. It is recommended that you create a default menu for each menu location within each store.<br><br>
+ <h5>More Information</h5>To learn more about menus, view the official Spree user documentation by <a href='https://guides.spreecommerce.org/user/navigation/building_the_main_menu.html' target='_blank' class='alert-link'>clicking here</a>."
+ allow_this_menu_item_to_contain_nested_menu_items: Allow this Menu Item to contain nested items
+ back_to_all_menus: Back To All Menus
+ click_create_to_load_new_link: 'Click the <b>Create</b> button below to change the link field.'
+ click_update_to_load_new_link: 'Click the <b>Update</b> button below to change the link field.'
+ give_your_menu_a_unique_name: 'Use the unique code to identify your menu: spree-eu-main'
+ link_settings: Link Settings
+ link_to: Link To
+ image_alt_text: Add alt text to your image
+ image_asset: Add a Promotion image or Link icon.
+ move_could_not_be_saved: 'ERROR: This move could not be saved.'
+ managing_by_store_title: 'Managing Menus By Store'
+ managing_by_store: <p>You are managing the menus for <b>%{store}</b>. To manage menus for other stores, change the global store using the drop-down in the main navbar found at the top of the screen.</p>
+ new_menu_item: New Menu Item
+ new_menu: New Menu
+ nested_under: Nested under
+ no_menu_items: '<b>%{menu}</b> has no items. Click the <b>Add New Item</b> button to begin adding links to this menu.'
+ nested_under_info: Quickly nest your Menu Item if you already know where it needs to be.
+ item_type: Item Type
+ image_info: '<b>NOTE:</b> You can attach an image to any menu item, but your image will only be displayed in the main menu when nested inside a container with the code <b>promo</b>.<br><br> For best results use images with a width of 540px and height of 350px.'
+ open_link_in_new_window: Open this link in a new window
+ menu_item_type_container_message: "Containers are menu items that do not link to a destination. If you are building the Spree Main Menu
+ create containers with the code: <b>category</b> or <b>promo</b>, and then nest your links inside these containers build out your menu.
+ <br><br> For an indepth guide to building the main menu see the documenttation page <a href='https://guides.spreecommerce.org/user/navigation/building_the_main_menu.html' target='_blank' class='alert-link'>Building The Main Menu</a>"
+ menus: Menus
+ menu_items: '%{menu_name} Items'
+ public_details: Public Details
+ subtitle: Subtitle
+ url_info: 'The URL field can link to an external website using <b>https://example.com</b>, link to an otherwise unreachable internal path using <b>/policies/privacy</b>,
+ launch an email client using <b>mailto:[email protected]</b> or used to create a clickable phone number with <b>tel:123456789</b>'
+ search_for_a_product: Search for a Product
+ search_for_a_taxon: Search for a Taxon
+ settings: Settings
+ set_a_code: "Adding a code is optional but can be useful if you need to identify this menu item. When building
+ the Spree main menu use the code <b>category</b> or <b>promo</b> to create the containers that organize links and promotions appropriately. To learn more view the documentation by <a href='https://guides.spreecommerce.org/user/navigation/add_menu_items.html' target='_blank' class='alert-link'>clicking here</a>."
+ type: Type
+ used_in: Used In
+ you_have_no_menus: You have no Menus, click the Add New Menu button to create your first Menu.
+ this_link_takes_you_to_your_stores_home_page: This link takes you to your stores home page.
+ settings: Settings
+ utilities:
+ preview: Preview
+ webhooks_subscribers:
+ webhooks_subscribers: Webhooks Subscribers
+ new_webhooks_subscriber: New Webhooks Subscriber
+ webhooks_events: Webhooks Events
+ subscriptions: Subscriptions
+ time_of_last_event: Time of Last Event
+ all_events: All Events
+ no_events: No Events
+ subscribe_to_all_events: Subscribe to all events
+ select_events: Select events
+ addresses: Addresses
+ assets: Assets
+ cms_pages: Cms Pages
+ credit_cards: Credit Cards
+ customer_returns: Customer Returns
+ digital_links: Digital Links
+ digitals: Digitals
+ inventory_units: Inventory Units
+ line_items: Line Items
+ menu_items: Menu Items
+ menus: Menus
+ option_types: Option Types
+ option_values: Option Values
+ orders: Orders
+ payments: Payments
+ payment_capture_events: Payment Capture Events
+ prices: Prices
+ products: Products
+ promotions: Promotions
+ properties: Properties
+ prototypes: Prototypes
+ refunds: Refunds
+ reimbursements: Reimbursements
+ return_authorizations: Return Authorizations
+ return_items: Return Items
+ roles: Roles
+ shipments: Shipments
+ shipping_categories: Shipping Categories
+ shipping_methods: Shipping Methods
+ shipping_rates: Shipping Rates
+ stock_items: Stock Items
+ stock_locations: Stock Locations
+ stock_movements: Stock Movements
+ stock_transfers: Stock Transfers
+ store_credits: Store Credits
+ stores: Stores
+ tax_rates: Tax Rates
+ taxonomies: Taxonomies
+ taxons: Taxons
+ variants: Variants
+ wished_items: Wished Items
+ wishlists: Wishlists
+ zones: Zones
+ display_on:
+ both: All
+ front_end: Storefront
+ back_end: Admin Panel
+ product:
+ all: All
+ active: Active
+ archived: Archived
+ deleted: Deleted
+ draft: Draft
+ pre_order: Pre-order
+ getting_started:
+ lets_get_you_started: Let's get you started
+ add_products: Add products
+ setup_shipping: Setup shipping
+ setup_payment_method: Setup payment methods
+ setup_taxes: Setup taxes
+ setup_taxes_calculation: Setup tax calculation
+ products_section:
+ message_with_products_html: You have added <strong> %{count} products</strong> so far - good job!</p>
+ message_without_products: You can add products manually or
+ import_message: import them via the API.
+ shipping_section:
+ message_with_shipping: You have setup shipping for
+ message_without_shipping: You can add multiple shipping methods, different for each country, continent or region.
+ payment_methods_section:
+ message_with_payment_method: You're ready to accept payments!
+ message_without_payment_method: You can setup multiple payment methods such as Stripe, PayPal, ApplePay, etc.
+ taxes_section:
+ message_with_taxes: You're tax calculation is setup!
+ message_without_taxes: You can use tax services such as TaxJar or setup tax calculation manually
+ payment_methods:
+ edit:
+ payment_method_configuration: "Payment Method Configuration"
\ No newline at end of file
diff --git a/admin/config/routes.rb b/admin/config/routes.rb
index 6c03937dc3..57e6997d8b 100644
--- a/admin/config/routes.rb
+++ b/admin/config/routes.rb
@@ -6,5 +6,8 @@ Spree::Core::Engine.add_routes do
delete :bulk_destroy
end
end
+
+ # audit log
+ resources :exports, only: %i[new create show index]
end
end
diff --git a/admin/spec/controllers/spree/admin/exports_controller_spec.rb b/admin/spec/controllers/spree/admin/exports_controller_spec.rb
new file mode 100644
index 0000000000..249e7ee6be
--- /dev/null
+++ b/admin/spec/controllers/spree/admin/exports_controller_spec.rb
@@ -0,0 +1,61 @@
+require 'spec_helper'
+
+describe Spree::Admin::ExportsController, type: :controller do
+ stub_authorization!
+
+ let(:store) { Spree::Store.default }
+
+ describe '#new' do
+ subject { get :new, params: { export: { type: 'Spree::Exports::Products', search_params: { name_cont: 'Product' }.as_json } } }
+
+ it 'renders the new template' do
+ expect(subject).to render_template(:new)
+ end
+
+ it 'assigns permitted params' do
+ subject
+ expect(assigns(:export).type).to eq('Spree::Exports::Products')
+ expect(assigns(:export).search_params).to eq({ 'name_cont' => 'Product' })
+ end
+ end
+
+ describe '#create' do
+ subject { post :create, params: params, format: :turbo_stream }
+
+ let(:params) do
+ {
+ export: {
+ type: 'Spree::Exports::Products',
+ format: 'csv',
+ search_params: {
+ name_cont: 'Product'
+ }.as_json,
+ record_selection: 'filtered'
+ }
+ }
+ end
+
+ it 'creates the export' do
+ expect { subject }.to change(Spree::Exports::Products, :count).by(1)
+
+ export = Spree::Exports::Products.last
+ expect(export.user).to eq(controller.try_spree_current_user)
+ expect(export.format).to eq('csv')
+ expect(export.search_params).to eq({ 'name_cont' => 'Product' })
+ end
+
+ it 'sets a flash message' do
+ subject
+ expect(flash[:success]).to eq(Spree.t(:export_created))
+ end
+
+ context 'when filtered is set to all' do
+ subject { post :create, params: params.merge(export: { record_selection: 'all' }), format: :turbo_stream }
+
+ it 'does not assign search_params' do
+ subject
+ expect(assigns(:export).search_params).to be_nil
+ end
+ end
+ end
+end
diff --git a/core/app/models/spree/export.rb b/core/app/models/spree/export.rb
index e04531a027..dec04f3cea 100644
--- a/core/app/models/spree/export.rb
+++ b/core/app/models/spree/export.rb
@@ -112,7 +112,7 @@ module Spree
def records_to_export
if search_params.present?
- scope.ransack(JSON.parse(search_params).to_h)
+ scope.ransack(search_params.is_a?(String) ? JSON.parse(search_params.to_s).to_h : search_params)
else
scope.ransack
end.result
diff --git a/core/lib/spree/testing_support/authorization_helpers.rb b/core/lib/spree/testing_support/authorization_helpers.rb
index 0b07f7e655..6a0c404a53 100644
--- a/core/lib/spree/testing_support/authorization_helpers.rb
+++ b/core/lib/spree/testing_support/authorization_helpers.rb
@@ -16,8 +16,15 @@ module Spree
def stub_authorization!(&block)
ability_class = build_ability(&block)
+
+ let(:user) { Spree.admin_user_class.new(email: FFaker::Internet.email) }
+
before do
allow(controller).to receive(:current_ability).and_return(ability_class.new(nil))
+
+ if defined?(Spree::Admin::BaseController)
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:try_spree_current_user).and_return(user)
+ end
end
end
end
@@ -37,13 +44,13 @@ module Spree
ability_class.register_ability(ability)
end
- let(:user) { Spree.admin_user_class.new }
+ let(:user) { Spree.admin_user_class.new(email: FFaker::Internet.email) }
let(:admin_app) { Spree::OauthApplication.create!(name: 'Admin Panel', scopes: 'admin') }
let(:admin_token) { Spree::OauthAccessToken.create!(application: admin_app, scopes: 'admin').token }
before do
allow(Spree.admin_user_class).to receive(:find_by).and_return(user)
- if defined?(Spree::Admin)
+ if defined?(Spree::Admin::BaseController)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:try_spree_current_user).and_return(user)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:admin_oauth_application).and_return(admin_app)
allow_any_instance_of(Spree::Admin::BaseController).to receive(:admin_oauth_token).and_return(admin_token)
diff --git a/core/spec/mailers/spree/export_mailer_spec.rb b/core/spec/mailers/spree/export_mailer_spec.rb
index 5b336d046e..f1c358fa60 100644
--- a/core/spec/mailers/spree/export_mailer_spec.rb
+++ b/core/spec/mailers/spree/export_mailer_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Spree::ExportMailer, type: :mailer do
before do
export.generate
export.reload
- allow(spree).to receive(:admin_export_url).and_return('http://test.com/admin/exports/1')
+ allow(spree).to receive(:admin_export_url).and_return("http://test.com/admin/exports/#{export.id}")
end
describe '#export_done' do