Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/controllers/api/v1/accounts/portals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create

def update
ActiveRecord::Base.transaction do
@portal.update!(portal_params.merge(live_chat_widget_params)) if params[:portal].present?
@portal.update!(merged_portal_params.merge(live_chat_widget_params)) if params[:portal].present?
# @portal.custom_domain = parsed_custom_domain
process_attached_logo if params[:blob_id].present?
rescue ActiveRecord::RecordInvalid => e
Expand Down Expand Up @@ -79,10 +79,20 @@ def permitted_params
def portal_params
params.require(:portal).permit(
:id, :color, :custom_domain, :header_text, :homepage_link,
:name, :page_title, :slug, :archived, { config: [:default_locale, { allowed_locales: [] }] }
:name, :page_title, :slug, :archived, { config: [:default_locale, :show_author, { allowed_locales: [] }] }
)
end

def merged_portal_params
update_params = portal_params.to_h
if update_params.key?('config')
base_config = @portal.config.is_a?(Hash) ? @portal.config : {}
incoming_config = update_params['config']
update_params['config'] = incoming_config.is_a?(Hash) ? base_config.merge(incoming_config) : base_config
end
update_params
end

def live_chat_widget_params
permitted_params = params.permit(:inbox_id)
return {} unless permitted_params.key?(:inbox_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Input from 'dashboard/components-next/input/Input.vue';
import Avatar from 'dashboard/components-next/avatar/Avatar.vue';
import ComboBox from 'dashboard/components-next/combobox/ComboBox.vue';
import ColorPicker from 'dashboard/components-next/colorpicker/ColorPicker.vue';
import Switch from 'dashboard/components-next/switch/Switch.vue';

const props = defineProps({
activePortal: {
Expand Down Expand Up @@ -45,6 +46,7 @@ const state = reactive({
liveChatWidgetInboxId: '',
logoUrl: '',
avatarBlobId: '',
showAuthor: true,
});

const originalState = reactive({ ...state });
Expand Down Expand Up @@ -117,6 +119,7 @@ watch(
homePageLink: newVal.homepage_link,
slug: newVal.slug,
liveChatWidgetInboxId: newVal.inbox?.id || '',
showAuthor: newVal.config?.show_author !== false,
});
if (newVal.logo) {
const {
Expand Down Expand Up @@ -149,6 +152,7 @@ const handleUpdatePortal = () => {
homepage_link: state.homePageLink,
blob_id: state.avatarBlobId,
inbox_id: state.liveChatWidgetInboxId,
config: { show_author: state.showAuthor },
};
emit('updatePortal', portal);
};
Expand Down Expand Up @@ -335,6 +339,21 @@ const handleAvatarDelete = () => {
<ColorPicker v-model="state.widgetColor" />
</div>
</div>
<div
class="grid items-start justify-between w-full gap-2 grid-cols-[200px,1fr]"
>
<label
class="text-sm font-medium whitespace-nowrap py-2.5 text-n-slate-12"
>
{{ t('HELP_CENTER.PORTAL_SETTINGS.FORM.SHOW_AUTHOR.LABEL') }}
</label>
<div class="flex flex-col gap-1 py-2.5">
<Switch v-model="state.showAuthor" />
<span class="text-xs text-n-slate-11">
{{ t('HELP_CENTER.PORTAL_SETTINGS.FORM.SHOW_AUTHOR.HELP_TEXT') }}
</span>
</div>
</div>
<div class="flex justify-end w-full gap-2">
<Button
:label="t('HELP_CENTER.PORTAL_SETTINGS.FORM.SAVE_CHANGES')"
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/dashboard/i18n/locale/en/helpCenter.json
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@
"BRAND_COLOR": {
"LABEL": "Brand color"
},
"SHOW_AUTHOR": {
"LABEL": "Show article authors",
"HELP_TEXT": "Display author information on category pages"
},
"SAVE_CHANGES": "Save changes"
},
"CONFIGURATION_FORM": {
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/dashboard/i18n/locale/pt_BR/helpCenter.json
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@
"BRAND_COLOR": {
"LABEL": "Cor da Marca"
},
"SHOW_AUTHOR": {
"LABEL": "Mostrar autores dos artigos",
"HELP_TEXT": "Exibir informações de autoria nas páginas de categorias"
},
"SAVE_CHANGES": "Salvar Alterações"
},
"CONFIGURATION_FORM": {
Expand Down
6 changes: 5 additions & 1 deletion app/models/portal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class Portal < ApplicationRecord

scope :active, -> { where(archived: false) }

CONFIG_JSON_KEYS = %w[allowed_locales default_locale website_token].freeze
CONFIG_JSON_KEYS = %w[allowed_locales default_locale website_token show_author].freeze

def show_author?
!ActiveModel::Type::Boolean.new.cast(config['show_author']).equal?(false)
end

def file_base_data
{
Expand Down
1 change: 1 addition & 0 deletions app/views/api/v1/accounts/portals/_portal.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ json.config do
json.partial! 'api/v1/models/portal_config', formats: [:json], locale: locale, portal: portal
end
end
json.show_author portal.show_author?
end

if portal.channel_web_widget
Expand Down
2 changes: 2 additions & 0 deletions app/views/public/api/v1/portals/_category-block.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
</div>
<div class="flex justify-between flex-row items-center <%= !@is_plain_layout_enabled && 'px-2' %>">
<div class="flex flex-row items-center gap-1">
<% if portal.show_author? %>
<%= render "public/api/v1/portals/authors", category: category, show_expanded: false %>
<span class="text-slate-600 dark:text-slate-400">•</span>
<% end %>
<span class="text-sm font-medium text-slate-600 dark:text-slate-400"><%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.order(position: :asc).size %></span>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
<% end %>
</div>
<div class="flex flex-row items-center gap-1">
<% if portal.show_author? %>
<%= render "public/api/v1/portals/authors", category: category, show_expanded: true %>
<span class="text-slate-600 dark:text-slate-400">•</span>
<% end %>
<span class="flex items-center text-base text-slate-600 dark:text-slate-400 font-medium"><%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %></span>
</div>
</div>
Expand Down
44 changes: 43 additions & 1 deletion spec/controllers/api/v1/accounts/portals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,49 @@
json_response = response.parsed_body
expect(json_response['name']).to eql(portal_params[:portal][:name])
expect(json_response['config']).to eql({ 'allowed_locales' => [{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'en' },
{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'es' }] })
{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'es' }],
'show_author' => true })
end

it 'persists show_author as false when explicitly set' do
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
params: { portal: { config: { show_author: false } } },
headers: admin.create_new_auth_token,
as: :json

expect(response).to have_http_status(:success)
json_response = response.parsed_body
expect(json_response['config']['show_author']).to be(false)

portal.reload
expect(portal.show_author?).to be(false)
end

it 'preserves show_author when updating other portal fields' do
portal.update!(config: portal.config.merge('show_author' => false))

put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
params: { portal: { name: 'renamed_portal' } },
headers: admin.create_new_auth_token,
as: :json

expect(response).to have_http_status(:success)
portal.reload
expect(portal.show_author?).to be(false)
expect(portal.name).to eql('renamed_portal')
end

it 'preserves show_author when updating only allowed_locales' do
portal.update!(config: portal.config.merge('show_author' => false))

put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
params: { portal: { config: { allowed_locales: %w[en fr] } } },
headers: admin.create_new_auth_token,
as: :json

expect(response).to have_http_status(:success)
portal.reload
expect(portal.show_author?).to be(false)
end

it 'archive portal' do
Expand Down