diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 14059fb15..39cfd8b2d 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -159,6 +159,7 @@ class ArticlesController < ApplicationController def update authorize @article @user = @article.user || current_user + updated = Articles::Updater.call(@user, @article, article_params_json) respond_to do |format| @@ -327,6 +328,12 @@ class ArticlesController < ApplicationController allowed_params << :organization_id end + manage_published_at_params + + @article_params_json = params.require(:article).permit(allowed_params) + end + + def manage_published_at_params time_zone_str = params["article"].delete("timezone") time = params["article"].delete("published_at_time") @@ -336,11 +343,9 @@ class ArticlesController < ApplicationController time_zone = Time.find_zone(time_zone_str) time_zone ||= Time.find_zone("UTC") params["article"]["published_at"] = time_zone.parse("#{date} #{time}") - elsif params["article"]["version"] != "v1" + elsif params["article"]["version"] != "v1" && !params["article"]["from_dashboard"] params["article"]["published_at"] = nil end - - @article_params_json = params.require(:article).permit(allowed_params) end def allowed_to_change_org_id? diff --git a/app/services/articles/updater.rb b/app/services/articles/updater.rb index bdedd6620..969ef3ebc 100644 --- a/app/services/articles/updater.rb +++ b/app/services/articles/updater.rb @@ -23,6 +23,7 @@ module Articles attrs = Articles::Attributes.new(article_params, article.user) .for_update(update_edited_at: update_edited_at) + success = article.update(attrs) if success user.rate_limiter.track_limit_by_action(:article_update) diff --git a/app/views/dashboards/_dashboard_article.html.erb b/app/views/dashboards/_dashboard_article.html.erb index 06c46057e..22665ba87 100644 --- a/app/views/dashboards/_dashboard_article.html.erb +++ b/app/views/dashboards/_dashboard_article.html.erb @@ -16,7 +16,7 @@
<% if organization && org_admin %> <%= form_for(article) do |f| %> + <%= f.hidden_field :from_dashboard, value: 1 %> <%= t("views.dashboard.article.author_is") %><%= f.select(:user_id, options_for_select(organization.users.pluck(:name, :id), article.user_id)) %> <%= f.submit t("views.dashboard.article.submit"), class: "crayons-btn crayons-btn--secondary" %> diff --git a/app/views/dashboards/_dashboard_article_row.html.erb b/app/views/dashboards/_dashboard_article_row.html.erb index a1e4078d1..01704e306 100644 --- a/app/views/dashboards/_dashboard_article_row.html.erb +++ b/app/views/dashboards/_dashboard_article_row.html.erb @@ -107,19 +107,19 @@ <%= t("views.dashboard.article.stats") %> <%= form_for(article, method: :patch, remote: true, authenticity_token: true, html: { "data-type": "json", class: "js-archive-toggle" }) do |f| %> <%= f.hidden_field :archived, value: !article.archived, id: "article_archived_#{article.id}" %> + <%= f.hidden_field :from_dashboard, value: 1 %> <% end %> - <% if organization && org_admin %> <%= form_for(article, html: { class: "mt-4 pt-4 border-0 border-t-1 border-color-base-10 border-solid" }) do |f| %>