Add aditional checks for inventory state objects [SCI-3412]

This commit is contained in:
Oleksii Kriuchykhin 2019-05-27 16:42:57 +02:00
parent 0b3b6d593b
commit 5a9640c5d1
2 changed files with 12 additions and 8 deletions

View file

@ -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: {

View file

@ -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