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.

Added ability to update your profile in Admin

Damian Legawiec3e39fbec0295
diff --git a/admin/app/controllers/spree/admin/profile_controller.rb b/admin/app/controllers/spree/admin/profile_controller.rb
new file mode 100644
index 0000000000..7cf8efbe65
--- /dev/null
+++ b/admin/app/controllers/spree/admin/profile_controller.rb
@@ -0,0 +1,31 @@
+module Spree
+ module Admin
+ class ProfileController < BaseController
+ def edit
+ @user = try_spree_current_user
+ end
+
+ def update
+ @user = try_spree_current_user
+
+ if @user.update(user_params)
+ if params[:remove_avatar] == '1' && @user.avatar.attached?
+ @user.avatar.detach
+ @user.avatar.purge_later
+ end
+
+ flash[:success] = flash_message_for(@user, :successfully_updated)
+ redirect_to spree.edit_admin_profile_path
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
+ private
+
+ def user_params
+ params.require(:user).permit(permitted_user_attributes)
+ end
+ end
+ end
+end
diff --git a/admin/app/views/spree/admin/profile/edit.html.erb b/admin/app/views/spree/admin/profile/edit.html.erb
new file mode 100644
index 0000000000..45da6cd912
--- /dev/null
+++ b/admin/app/views/spree/admin/profile/edit.html.erb
@@ -0,0 +1,79 @@
+<%= content_for(:page_title) do %>
+ <%= Spree.t('admin.edit_profile') %>
+<% end %>
+
+<%= form_for @user, url: spree.admin_profile_path, method: :put, as: :user do |f| %>
+ <div class="row">
+ <div class="col-lg-6 mb-4">
+ <div class="card">
+ <div class="card-header">
+ <h5 class="card-title"><%= Spree.t('admin.personal_details') %></h5>
+ </div>
+ <div class="card-body">
+ <div class="form-group mb-4">
+ <%= f.label :email, class: 'form-label' %>
+ <%= f.email_field :email, class: 'form-control', disabled: true %>
+ </div>
+ <div class="form-group mb-4">
+ <%= f.label :first_name, class: 'form-label' %>
+ <%= f.text_field :first_name, class: 'form-control' %>
+ </div>
+ <div class="form-group mb-4">
+ <%= f.label :last_name, class: 'form-label' %>
+ <%= f.text_field :last_name, class: 'form-control' %>
+ </div>
+ <div class="form-group mb-0">
+ <div>
+ <%= f.label :avatar, class: 'form-label' %>
+ </div>
+ <%= render 'active_storage/upload_form', form: f, field_name: :avatar, crop: true %>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="col-lg-6 mb-4">
+ <div class="card">
+ <div class="card-header">
+ <h5 class="card-title"><%= Spree.t('admin.notifications') %></h5>
+ </div>
+ <div class="card-body">
+ <% if @user.respond_to?(:deliver_invitation_accepted_email) %>
+ <div class="custom-control custom-switch mb-3">
+ <%= f.check_box :deliver_invitation_accepted_email, class: 'custom-control-input' %>
+ <%= f.label :deliver_invitation_accepted_email, 'Someone accepted your team invitation', class: 'custom-control-label' %>
+ </div>
+ <% end %>
+
+ <% if @user.respond_to?(:deliver_vendor_new_order_email) %>
+ <hr />
+ <div class="custom-control custom-switch mb-3">
+ <%= f.check_box :deliver_vendor_new_order_email, class: 'custom-control-input' %>
+ <%= f.label :deliver_vendor_new_order_email, 'New order notification', class: 'custom-control-label' %>
+ </div>
+ <% end %>
+
+ <% if @user.respond_to?(:deliver_vendor_onboarding_started_email) %>
+ <hr />
+ <div class="custom-control custom-switch mb-3">
+ <%= f.check_box :deliver_vendor_onboarding_started_email, class: 'custom-control-input' %>
+ <%= f.label :deliver_vendor_onboarding_started_email, 'Vendor started onboarding', class: 'custom-control-label' %>
+ </div>
+ <div class="custom-control custom-switch mb-3">
+ <%= f.check_box :deliver_vendor_onboarding_completed_email, class: 'custom-control-input' %>
+ <%= f.label :deliver_vendor_onboarding_completed_email, 'Vendor completed onboarding', class: 'custom-control-label' %>
+ </div>
+ <div class="custom-control custom-switch mb-3">
+ <%= f.check_box :deliver_vendor_approved_email, class: 'custom-control-input' %>
+ <%= f.label :deliver_vendor_approved_email, 'Vendor has been approved', class: 'custom-control-label' %>
+ </div>
+ <% end %>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="form-actions">
+ <%= turbo_save_button_tag Spree.t('actions.update') %>
+ </div>
+<% end %>
diff --git a/admin/config/locales/en.yml b/admin/config/locales/en.yml
index 5979beb053..c7a69ae5ba 100644
--- a/admin/config/locales/en.yml
+++ b/admin/config/locales/en.yml
@@ -9,76 +9,12 @@ en:
response_code: Response Code
execution_time: Execution Time
request_errors: Request Errors
+ edit_profile: Edit Profile
+ personal_details: Personal Details
+ notifications: Notifications
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
diff --git a/admin/config/routes.rb b/admin/config/routes.rb
index 57e6997d8b..61261c8a2b 100644
--- a/admin/config/routes.rb
+++ b/admin/config/routes.rb
@@ -9,5 +9,8 @@ Spree::Core::Engine.add_routes do
# audit log
resources :exports, only: %i[new create show index]
+
+ # profile settings
+ resource :profile, controller: 'profile', only: %i[edit update]
end
end
diff --git a/admin/spec/controllers/spree/admin/profile_controller_spec.rb b/admin/spec/controllers/spree/admin/profile_controller_spec.rb
new file mode 100644
index 0000000000..6322cdc0be
--- /dev/null
+++ b/admin/spec/controllers/spree/admin/profile_controller_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Spree::Admin::ProfileController, type: :controller do
+ stub_authorization!
+
+ describe '#edit' do
+ subject { get :edit }
+
+ it 'renders the edit template' do
+ expect(subject).to render_template(:edit)
+ end
+ end
+
+ describe '#update' do
+ subject { put :update, params: params }
+
+ let(:params) do
+ { user: { first_name: 'John', last_name: 'Doe' } }
+ end
+
+ it 'updates the user' do
+ expect { subject }.to change { user.first_name }.to('John')
+ end
+ end
+end