Class: MyContactsController
- Inherits:
-
BasePortalController
- Object
- ActionController::Base
- ApplicationController
- BasePortalController
- MyContactsController
- Defined in:
- app/controllers/my_contacts_controller.rb
Overview
Controller for managing user contacts.
Constant Summary
Constants included from Controllers::MasqueradeGuarded
Controllers::MasqueradeGuarded::DEFAULT_BLOCK_MESSAGE
Constants included from Controllers::AnalyticsEvents
Controllers::AnalyticsEvents::MAX_QUEUED_EVENTS, Controllers::AnalyticsEvents::SESSION_KEY
Constants included from Controllers::ErrorRendering
Controllers::ErrorRendering::NON_CONTENT_PATH_PREFIXES
Instance Method Summary collapse
-
#account_create ⇒ Object
Create an online account for a contact.
-
#account_destroy ⇒ Object
Delete a contact's online account.
-
#account_reset_password ⇒ Object
Reset a contact's account password.
-
#account_roles ⇒ Object
Update a contact's account roles.
-
#create ⇒ Object
Create a new contact.
-
#destroy ⇒ Object
Delete or deactivate a contact.
-
#edit ⇒ Object
Display contact for editing.
-
#new ⇒ Object
Initialize a new contact.
-
#restore ⇒ Object
Restore an inactive contact.
-
#set_report_errors_for ⇒ void
protected
Set the contact for error reporting.
-
#show ⇒ Object
Redirect to edit page.
-
#update ⇒ Object
Update a contact.
Methods inherited from BasePortalController
#current_ability, #portal_party, #set_catalog, #set_webpack
Methods included from Controllers::MasqueradeGuarded
block_while_masquerading, #masquerade_blocks?
Methods inherited from ApplicationController
#account_impersonated?, #add_to_flash, #after_sign_in_path_for, #bypass_forgery_protection?, #chat_enabled?, #cloudflare_cleared?, #default_catalog, #default_url_options, #enable_turbo_frames, #find_publication, #fix_invalid_accept_header, #init_js_utils, #is_globals_call?, #layout_by_resource, #locale_store, #redirect_to, #require_employee_for_crm, #set_base_host, #set_real_ip, #should_render_layout?, #skip_layout_for_turbo_frame?, #stamp_impersonation_context, #tab_frame_breakout_request?, #warmlyyours_canada_ip?, #warmlyyours_ip?, #y
Methods included from Controllers::ReturnPathHandling
#check_for_return_path, #redirect_to_return_path_or_default
Methods included from Controllers::AnalyticsEvents
#consume_queued_analytics_events, #registration_lead_type, #track_event
Methods included from Controllers::DeviceDetection
Methods included from Controllers::SubdomainDetection
#is_crm_request?, #is_www_request?, #json_request?
Methods included from Controllers::TurboSafeRedirect
Methods included from Controllers::TrackingDetection
#bot_request?, #gdpr_country?, #gdpr_country_data, #prevent_bots, #set_tracking_cookie, #track_visitor?
Methods included from Controllers::AcceleratedFileSending
#send_file_accelerated, #send_upload_accelerated
Methods included from Controllers::ErrorRendering
#excp_string, #mail_to_for_error_reporting, #render_400, #render_404, #render_406, #render_410, #render_500, #render_invalid_authenticity_token, #render_ip_spoof_error, #render_unpermitted_parameters, #safe_referer_or_fallback
Methods included from Controllers::TurnstileVerification
#load_turnstile_script_tag, #turnstile_lazy_widget, #turnstile_script_tag, #turnstile_widget, #validate_turnstile!
Methods included from Controllers::CloudflareCaching
edge_cached, #edge_cached_action?, #reset_cloudflare_cache, #set_cloudflare_cache, #skip_edge_cache!, #skip_session
Methods included from Controllers::Webpackable
#preload_webpack_fonts, #webpack_css_include, #webpack_css_url, #webpack_js_include, #wpd_is_running?
Methods included from Controllers::Localizable
#cloudflare_country_locale, #determine_request_locale, #geocoder_locale, #guest_user_locale_check, #locale_optional_www_auth_path?, #param_locale, #set_locale, #set_request_locale, #skip_localization?, #warmlyyours_ip_locale
Methods included from Controllers::Authenticable
#access_denied, #authenticate_account, #authenticate_account!, #authenticate_account_from_login_token!, #check_is_a_manager, #check_is_a_sales_manager, #check_is_an_admin, #check_is_an_employee, #check_party, #clear_mismatched_guest_user, #create_guest_user, #credentials?, #current_or_guest_user, #current_or_guest_user_id_read_only, #current_user, #devise_mapping, #fully_logged_in?, #generate_bot_id, #guest_user, #identifiable?, #init_current_user, #initialize_guest, #load_context_user, #logging_in, #resource, #resource_name, #restrict_access_for_non_employees, #scrubbed_request_path, #user_object, #warn_on_session_guest_id_leak
Methods included from UrlsHelper
#catalog_breadcrumb_links, #catalog_link, #catalog_link_for_product_line, #catalog_link_for_sku, #cms_link, #delocalized_path, #path_to_sales_product_sku, #path_to_sales_product_sku_for_product_line, #path_to_sales_product_sku_for_product_line_slug, #product_line_from_catalog_link, #protocol_neutral_url, #sanitize_external_url, #valid_external_url?
Instance Method Details
#account_create ⇒ Object
Create an online account for a contact.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/my_contacts_controller.rb', line 77 def account_create return render_edit_with_errors if invitation_email_missing? # ignore_if_exist: false - CRM employees on this action do want to # revoke and re-issue if the contact already has an account. The # default flipped to true to protect the public web /register path. account, msg = @contact.online_account_invite(params[:email], ignore_if_exist: false) if account.nil? || account.errors.present? render_invitation_failure(account, msg) else finalize_account_invitation(account, msg) end end |
#account_destroy ⇒ Object
Delete a contact's online account.
92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/my_contacts_controller.rb', line 92 def account_destroy account = @contact.account sign_out(account) if account.destroy flash[:info] = 'Online account deleted' else flash[:error] = 'Could not delete online account.' end redirect_to edit_my_account_contact_path(@contact) end |
#account_reset_password ⇒ Object
Reset a contact's account password.
104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/my_contacts_controller.rb', line 104 def account_reset_password account = @contact.account begin account.send_reset_password_instructions flash[:info] = "Password reset instructions have been sent to #{account.email}" rescue StandardError => e flash[:error] = "Password reset instructions could not be sent, message : #{e}, please contact a system administrator." end redirect_to edit_my_account_contact_path(@contact) end |
#account_roles ⇒ Object
Update a contact's account roles.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/controllers/my_contacts_controller.rb', line 116 def account_roles rid = params.dig(:account, :role_ids)&.to_i if rid # HABTM `role_ids=` persists immediately to the join table — see # CollectionAssociation#ids_writer. The previous `(... = [rid])` # assignment-as-condition was always truthy and made the else # branch unreachable; the real gate is `rid` itself. @contact.account.role_ids = [rid] flash[:info] = "Role/permissions were set for login: #{@contact.account.email}" redirect_to edit_my_account_contact_path(@contact) else flash.now[:error] = "Role/permissions could not be set for login: #{@contact.account.email}" render_edit_with_errors end end |
#create ⇒ Object
Create a new contact.
28 29 30 31 32 33 34 35 |
# File 'app/controllers/my_contacts_controller.rb', line 28 def create @contact = @context_user.customer.contacts.build(params[:contact]) if @contact.save redirect_to my_account_path else render :new, status: :unprocessable_content end end |
#destroy ⇒ Object
Delete or deactivate a contact.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/my_contacts_controller.rb', line 49 def destroy begin if @contact.ok_to_delete? success = @contact.destroy flash[:info] = "User #{@contact.full_name} was deleted." if success else success = @contact.deactivate flash[:info] = "User #{@contact.full_name} was marked inactive and their online login (if any) was deleted. There are still projects, orders, services or other users linked to #{@contact.full_name}. Please reassign these." if success end raise @contact.errors_to_s unless @contact.errors.empty? rescue StandardError => e flash[:error] = "A system error occured when we tried to delete this contact, #{e}. " end redirect_to my_account_path end |
#edit ⇒ Object
Display contact for editing.
23 24 25 |
# File 'app/controllers/my_contacts_controller.rb', line 23 def edit set_edit_variables end |
#new ⇒ Object
Initialize a new contact.
18 19 20 |
# File 'app/controllers/my_contacts_controller.rb', line 18 def new @contact = @context_user.customer.contacts.new end |
#restore ⇒ Object
Restore an inactive contact.
66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/my_contacts_controller.rb', line 66 def restore success = @contact.update(inactive: false) if success flash[:info] = "User #{@contact.full_name} was marked active." else flash[:error] = "User #{@contact.full_name} could not be restored. #{@contact.errors_to_s}" end redirect_to my_account_path end |
#set_report_errors_for ⇒ void (protected)
This method returns an undefined value.
Set the contact for error reporting.
137 138 139 140 |
# File 'app/controllers/my_contacts_controller.rb', line 137 def set_report_errors_for @report_errors_for ||= [] @report_errors_for << @contact end |
#show ⇒ Object
Redirect to edit page.
13 14 15 |
# File 'app/controllers/my_contacts_controller.rb', line 13 def show redirect_to edit_my_account_contact_path(@contact) end |
#update ⇒ Object
Update a contact.
38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/my_contacts_controller.rb', line 38 def update @contact.attributes = params[:contact] if @contact.save redirect_to my_account_path else set_edit_variables render :edit, status: :unprocessable_content end end |