Files
leadchat/app/controllers/widgets_controller.rb
Sivin Varghese a4d2cb18f9 feat: Add INSTALLATION_NAME to global config (#12376)
# Pull Request Template

## Description

This PR fixes an issue where the widget and survey page did not show the
correct installation name in the “Powered by” label, and also updates
the Help Center to use the installation name.

Fixes
[CW-5580](https://linear.app/chatwoot/issue/CW-5580/widget-footer-shows-powered-by-chatwoot-after-45x-when-installation),
https://github.com/chatwoot/chatwoot/issues/12375#event-19521953660

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?

### Screenshots

**Survey**
<img width="969" height="364" alt="image"
src="https://github.com/user-attachments/assets/094291cb-35dd-4654-ab12-97174c20be55"
/>

**Widget**
<img width="426" height="668" alt="image"
src="https://github.com/user-attachments/assets/7593bfbc-436f-4cc2-9be5-150178bafe30"
/>

**HC**
<img width="432" height="717" alt="image"
src="https://github.com/user-attachments/assets/106cfc25-409e-4e68-bddd-53b2d3e79400"
/>



## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
2025-09-09 12:13:35 +05:30

78 lines
2.2 KiB
Ruby

# TODO : Delete this and associated spec once 'api/widget/config' end point is merged
class WidgetsController < ActionController::Base
include WidgetHelper
before_action :set_global_config
before_action :set_web_widget
before_action :ensure_account_is_active
before_action :ensure_location_is_supported
before_action :set_token
before_action :set_contact
before_action :build_contact
after_action :allow_iframe_requests
private
def set_global_config
@global_config = GlobalConfig.get('LOGO_THUMBNAIL', 'BRAND_NAME', 'WIDGET_BRAND_URL', 'DIRECT_UPLOADS_ENABLED', 'INSTALLATION_NAME')
end
def set_web_widget
@web_widget = ::Channel::WebWidget.find_by!(website_token: permitted_params[:website_token])
rescue ActiveRecord::RecordNotFound
Rails.logger.error('web widget does not exist')
render json: { error: 'web widget does not exist' }, status: :not_found
end
def set_token
@token = permitted_params[:cw_conversation]
@auth_token_params = if @token.present?
::Widget::TokenService.new(token: @token).decode_token
else
{}
end
end
def set_contact
return if @auth_token_params[:source_id].nil?
@contact_inbox = ::ContactInbox.find_by(
inbox_id: @web_widget.inbox.id,
source_id: @auth_token_params[:source_id]
)
@contact = @contact_inbox&.contact
end
def build_contact
return if @contact.present?
@contact_inbox, @token = build_contact_inbox_with_token(@web_widget, additional_attributes)
@contact = @contact_inbox.contact
end
def ensure_account_is_active
render json: { error: 'Account is suspended' }, status: :unauthorized unless @web_widget.inbox.account.active?
end
def ensure_location_is_supported; end
def additional_attributes
if @web_widget.inbox.account.feature_enabled?('ip_lookup')
{ created_at_ip: request.remote_ip }
else
{}
end
end
def permitted_params
params.permit(:website_token, :cw_conversation)
end
def allow_iframe_requests
response.headers.delete('X-Frame-Options')
end
end
WidgetsController.prepend_mod_with('WidgetsController')