mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-11 00:41:41 +08:00
Merge pull request #3528 from okriuchykhin/ok_SCI_6036
Prevent creation of duplicated repository cells [SCI-6036]
This commit is contained in:
commit
0db9bf46ff
4 changed files with 22 additions and 3 deletions
|
|
@ -63,11 +63,12 @@ module Api
|
||||||
p.require(%i(id attributes))
|
p.require(%i(id attributes))
|
||||||
p.require(:attributes).require(:value)
|
p.require(:attributes).require(:value)
|
||||||
end
|
end
|
||||||
@inventory_item.transaction do
|
@inventory_item.with_lock do
|
||||||
inventory_cells_params.each do |cell_params|
|
inventory_cells_params.each do |cell_params|
|
||||||
cell = @inventory_item.repository_cells.find(cell_params[:id])
|
cell = @inventory_item.repository_cells.find(cell_params[:id])
|
||||||
cell_value = cell_params.dig(:attributes, :value)
|
cell_value = cell_params.dig(:attributes, :value)
|
||||||
next unless cell.value.data_changed?(cell_value)
|
next unless cell.value.data_changed?(cell_value)
|
||||||
|
|
||||||
cell.value.update_data!(cell_value, current_user)
|
cell.value.update_data!(cell_value, current_user)
|
||||||
item_changed = true
|
item_changed = true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ module RepositoryRows
|
||||||
def call
|
def call
|
||||||
return self unless valid?
|
return self unless valid?
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
@repository_row.with_lock do
|
||||||
# Update invetory row's cells
|
# Update invetory row's cells
|
||||||
params[:repository_cells]&.each do |column_id, value|
|
params[:repository_cells]&.each do |column_id, value|
|
||||||
column = @repository_row.repository.repository_columns.find_by(id: column_id)
|
column = @repository_row.repository.repository_columns.find_by(id: column_id)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddUniqueConstraintToRepositoryCell < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_index :repository_cells,
|
||||||
|
%i(repository_row_id repository_column_id),
|
||||||
|
name: 'index_repository_cells_on_repository_row_and_repository_column',
|
||||||
|
unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -5210,6 +5210,13 @@ CREATE INDEX index_repository_asset_values_on_last_modified_by_id ON public.repo
|
||||||
CREATE INDEX index_repository_cells_on_repository_column_id ON public.repository_cells USING btree (repository_column_id);
|
CREATE INDEX index_repository_cells_on_repository_column_id ON public.repository_cells USING btree (repository_column_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_repository_cells_on_repository_row_and_repository_column; Type: INDEX; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX index_repository_cells_on_repository_row_and_repository_column ON public.repository_cells USING btree (repository_row_id, repository_column_id);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_repository_cells_on_repository_row_id; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_repository_cells_on_repository_row_id; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
@ -7489,6 +7496,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20210715125349'),
|
('20210715125349'),
|
||||||
('20210716124649'),
|
('20210716124649'),
|
||||||
('20210720112050'),
|
('20210720112050'),
|
||||||
('20210811103123');
|
('20210811103123'),
|
||||||
|
('20210906132120');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue