diff --git a/app/controllers/user_repositories_controller.rb b/app/controllers/user_repositories_controller.rb index 2a6562c8f..3f1852a51 100644 --- a/app/controllers/user_repositories_controller.rb +++ b/app/controllers/user_repositories_controller.rb @@ -3,7 +3,7 @@ class UserRepositoriesController < ApplicationController def save_table_state service = RepositoryTableStateService.new(current_user, @repository) - service.update_state(params[:state]) + service.update_state(params.require(:state).permit!.to_h) respond_to do |format| format.json do render json: { diff --git a/app/services/repository_table_state_service.rb b/app/services/repository_table_state_service.rb index 4fc78334c..da1ee0350 100644 --- a/app/services/repository_table_state_service.rb +++ b/app/services/repository_table_state_service.rb @@ -13,16 +13,20 @@ class RepositoryTableStateService # record, has EVERYTHING (booleans, symbols, keys, ...) saved as Strings. def load_state - state = RepositoryTableState.where(user: @user, repository: @repository).take - if state.blank? - state = self.create_default_state - end - state + loaded = RepositoryTableState.where(user: @user, repository: @repository).take + loaded = create_default_state unless loaded&.state&.present? && + loaded.state['order'] && + loaded.state['columns'] && + loaded.state['ColReorder'] && + loaded.state.dig('columns', '1', 'visible') == 'true' && + loaded.state.dig('columns', '3', 'visible') == 'true' + loaded end def update_state(state) - self.load_state - .update(state: state) + saved_state = load_state + return if saved_state.state.except('time') == state.except('time') + saved_state.update(state: state) end def create_default_state