diff --git a/app/controllers/api/v1/accounts/articles_controller.rb b/app/controllers/api/v1/accounts/articles_controller.rb index d164778ac..9148e4386 100644 --- a/app/controllers/api/v1/accounts/articles_controller.rb +++ b/app/controllers/api/v1/accounts/articles_controller.rb @@ -6,13 +6,15 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController def index @portal_articles = @portal.articles - @all_articles = @portal_articles.search(list_params) - @articles_count = @all_articles.count + + set_article_count + + @articles = @articles.search(list_params) @articles = if list_params[:category_slug].present? - @all_articles.order_by_position.page(@current_page) + @articles.order_by_position.page(@current_page) else - @all_articles.order_by_updated_at.page(@current_page) + @articles.order_by_updated_at.page(@current_page) end end @@ -43,6 +45,19 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController private + def set_article_count + # Search the params without status and author_id, use this to + # compute mine count published draft etc + base_search_params = list_params.except(:status, :author_id) + @articles = @portal_articles.search(base_search_params) + + @articles_count = @articles.count + @mine_articles_count = @articles.search_by_author(Current.user.id).count + @published_articles_count = @articles.published.count + @draft_articles_count = @articles.draft.count + @archived_articles_count = @articles.archived.count + end + def fetch_article @article = @portal.articles.find(params[:id]) end @@ -53,9 +68,10 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController def article_params params.require(:article).permit( - :title, :slug, :position, :content, :description, :position, :category_id, :author_id, :associated_article_id, :status, meta: [:title, - :description, - { tags: [] }] + :title, :slug, :position, :content, :description, :position, :category_id, :author_id, :associated_article_id, :status, + :locale, meta: [:title, + :description, + { tags: [] }] ) end diff --git a/app/controllers/api/v1/accounts/portals_controller.rb b/app/controllers/api/v1/accounts/portals_controller.rb index bd8da5549..fe9a03ef5 100644 --- a/app/controllers/api/v1/accounts/portals_controller.rb +++ b/app/controllers/api/v1/accounts/portals_controller.rb @@ -20,7 +20,7 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController end def create - @portal = Current.account.portals.build(portal_params) + @portal = Current.account.portals.build(portal_params.merge(live_chat_widget_params)) @portal.custom_domain = parsed_custom_domain @portal.save! process_attached_logo @@ -28,7 +28,7 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController def update ActiveRecord::Base.transaction do - @portal.update!(portal_params) if params[:portal].present? + @portal.update!(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 StandardError => e @@ -70,11 +70,21 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController def portal_params params.require(:portal).permit( - :account_id, :color, :custom_domain, :header_text, :homepage_link, :name, :page_title, :slug, :archived, { config: [:default_locale, - { allowed_locales: [] }] } + :account_id, :color, :custom_domain, :header_text, :homepage_link, + :name, :page_title, :slug, :archived, { config: [:default_locale, { allowed_locales: [] }] } ) end + def live_chat_widget_params + permitted_params = params.permit(:inbox_id) + return {} if permitted_params[:inbox_id].blank? + + inbox = Inbox.find(permitted_params[:inbox_id]) + return {} unless inbox.web_widget? + + { channel_web_widget_id: inbox.channel.id } + end + def portal_member_params params.require(:portal).permit(:account_id, member_ids: []) end diff --git a/app/controllers/public/api/v1/portals/articles_controller.rb b/app/controllers/public/api/v1/portals/articles_controller.rb index 2807ae41a..08c62bada 100644 --- a/app/controllers/public/api/v1/portals/articles_controller.rb +++ b/app/controllers/public/api/v1/portals/articles_controller.rb @@ -30,7 +30,7 @@ class Public::Api::V1::Portals::ArticlesController < Public::Api::V1::Portals::B def set_article @article = @portal.articles.find_by(slug: permitted_params[:article_slug]) - @article.increment_view_count + @article.increment_view_count if @article.published? @parsed_content = render_article_content(@article.content) end diff --git a/app/javascript/dashboard/api/helpCenter/articles.js b/app/javascript/dashboard/api/helpCenter/articles.js index e5847dc1b..727340ed5 100644 --- a/app/javascript/dashboard/api/helpCenter/articles.js +++ b/app/javascript/dashboard/api/helpCenter/articles.js @@ -52,12 +52,13 @@ class ArticlesAPI extends PortalsAPI { } createArticle({ portalSlug, articleObj }) { - const { content, title, author_id, category_id } = articleObj; + const { content, title, authorId, categoryId, locale } = articleObj; return axios.post(`${this.url}/${portalSlug}/articles`, { content, title, - author_id, - category_id, + author_id: authorId, + category_id: categoryId, + locale, }); } diff --git a/app/javascript/dashboard/components-next/CardLayout.vue b/app/javascript/dashboard/components-next/CardLayout.vue index 6012512a7..9949ec86b 100644 --- a/app/javascript/dashboard/components-next/CardLayout.vue +++ b/app/javascript/dashboard/components-next/CardLayout.vue @@ -7,7 +7,7 @@ const handleClick = () => {