Updating repository table state of every user belonging to the team of the repository, when custom column is removed or added. [SCI-1384]

This commit is contained in:
Matej Zrimšek 2017-06-20 14:52:41 +02:00
parent 14429a270c
commit 6c7987681c

View file

@ -14,12 +14,12 @@ class RepositoryTableState < ActiveRecord::Base
end
def self.update_state(custom_column, column_index, user)
table_state = RepositoryTableState.where(
user: user,
# table state of every user having access to this repository needs udpating
table_states = RepositoryTableState.where(
repository: custom_column.repository
)
return if table_state.empty?
repository_state = table_state.first['state']
table_states.each do |table_state|
repository_state = table_state['state']
if column_index
# delete column
repository_state['columns'].delete(column_index)
@ -31,6 +31,7 @@ class RepositoryTableState < ActiveRecord::Base
index
end
end
repository_state['ColReorder'].delete(column_index)
repository_state['ColReorder'].map! do |index|
if index.to_i > column_index.to_i
@ -46,7 +47,8 @@ class RepositoryTableState < ActiveRecord::Base
REPOSITORY_TABLE_DEFAULT_STATE['columns'].first
repository_state['ColReorder'].insert(2, index)
end
table_state.first.update(state: repository_state)
table_state.update(state: repository_state)
end
end
def self.create_state(user, repository)