From 642faf1488a4b762dcd3426706a346f84b431517 Mon Sep 17 00:00:00 2001 From: StarmanMartin Date: Wed, 8 May 2024 07:01:10 +0200 Subject: [PATCH 1/4] feat: activate segment visibility field in generic elements (#1702) * Update user profile: Added Layout details for generic elements * Added ElementDetailSortTab to the generic elements. This allows to sort and hide segment tabs in generic elements. During development some bugs were fixed that were not part of this problem: * The 'class' property was changed to className in several elements * The popover for hiding and sorting the segments was placed correctly under its button --- .../components/generic/GenericElDetails.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/packs/src/components/generic/GenericElDetails.js b/app/packs/src/components/generic/GenericElDetails.js index 15c0bd0bc3..6529ce24c7 100644 --- a/app/packs/src/components/generic/GenericElDetails.js +++ b/app/packs/src/components/generic/GenericElDetails.js @@ -61,6 +61,9 @@ const onNaviClick = (type, id) => { export default class GenericElDetails extends Component { constructor(props) { super(props); + // generic type + this.type = props.genericEl.type; + this.state = { genericEl: props.genericEl, activeTab: 0, @@ -82,6 +85,33 @@ export default class GenericElDetails extends Component { this.handleExport = this.handleExport.bind(this); } + /** + * This method retrieves values for the detailed + * layout. If the user profile lacks these values, + * they are automatically added. + */ + setupDetailLayoutProfile() { + + const userProfile = UserStore.getState().profile; + const layout = userProfile && userProfile.data && userProfile.data[`layout_detail_${this.type}`]; + if(!layout) { + const layoutName = `data.layout_detail_${this.type}`; + const defaultLayout = { + properties: 1, analyses: 2, attachments: 3 + }; + const currentCollection = UIStore.getState().currentCollection; + let tabSegment = currentCollection?.tabs_segment; + lowdashset(tabSegment, `${this.type}`, defaultLayout); + tabSegment = { ...tabSegment, [`${this.type}`]: defaultLayout }; + if (currentCollection && !currentCollection.is_sync_to_me) { + CollectionActions.updateTabsSegment({ segment: tabSegment, cId: currentCollection.id }); + } + lowdashset(userProfile, layoutName, defaultLayout); + + UserActions.updateUserProfile(userProfile); + } + } + componentDidMount() { UIStore.listen(this.onChangeUI); ElementStore.listen(this.onChangeElement); From 67199ab80e8e262129d05554e8a8fa9923502d35 Mon Sep 17 00:00:00 2001 From: PiTrem Date: Mon, 29 Apr 2024 18:06:42 +0200 Subject: [PATCH 2/4] fix: ensure wait_until is set for cron delayed jobs when initializing the app so that job's run_at does not default to ~ created_at - refactor delayed_job initializer: moved cron scheduling logic out of the initializers to an ActiveJob - added notes about idempotent initialization PC jobs: molecules LIFO TODO: filter invalid molecules --- config/initializers/delayed_job_config.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config/initializers/delayed_job_config.rb b/config/initializers/delayed_job_config.rb index f36575787f..7b6f0d23d4 100644 --- a/config/initializers/delayed_job_config.rb +++ b/config/initializers/delayed_job_config.rb @@ -24,6 +24,19 @@ # ``` # otherwise InitCronJobsJob will be called multiple times +# NB: this initialiser is NOT idempotent (yet), do NOT use: `Rails.application.reloader.to_prepare do` block +# to supress: +# ``` +# DEPRECATION WARNING: Initialization autoloaded the constants ApplicationRecord +# ApplicationJob, CollectDataFromMailJob, CollectDataFromSftpJob, CollectDataFromLocalJob, +# CollectFileFromLocalJob, CollectFileFromSftpJob, PubchemCidJob, PubchemLcssJob, +# RefreshElementTagJob, ChemrepoIdJob, and InitCronJobsJob. +# +# Being able to do this is deprecated. Autoloading during initialization is going +# to be an error condition in future versions of Rails. +# ``` +# otherwise InitCronJobsJob will be called multiple times + ActiveSupport.on_load(:active_record) do next unless ActiveRecord::Base.connection.table_exists?('delayed_jobs') && Delayed::Job.column_names.include?('cron') From e5d86dd1a4309d3060514969f2b0c6e548cb225e Mon Sep 17 00:00:00 2001 From: PiTrem Date: Mon, 13 May 2024 16:17:47 +0200 Subject: [PATCH 3/4] chore: prepare v1.9.3 --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcc68ede82..c1b2481ec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -177,6 +177,25 @@ ## [v1.9.3] > (2024-05-13) +* Features and enhancements + * structure editor compatibility ([#1894](https://github.com/ComPlat/chemotion_ELN/pull/1894)) + * enable spectra report for samples ([#1902](https://github.com/ComPlat/chemotion_ELN/pull/1902)) + * activate segment visibility field in generic elements ([#1702](https://github.com/ComPlat/chemotion_ELN/pull/1702)) + +* Bug fixes + * advanced search ([#1888](https://github.com/ComPlat/chemotion_ELN/pull/1888)) + * converter inbox issue for NMR ([#1903](https://github.com/ComPlat/chemotion_ELN/pull/1903)) + * add updating of annotations also in reaction container ([#1913](https://github.com/ComPlat/chemotion_ELN/pull/1913)) + * Yield calculation with purity ([#1904](https://github.com/ComPlat/chemotion_ELN/pull/1904)) + * ensure wait_until is set when initializing cron delayed jobs ([#1892](https://github.com/ComPlat/chemotion_ELN/pull/1892)) + +* Chores + * Bump react-pdf from 5.7.0 to 7.7.3 ([#1909](https://github.com/ComPlat/chemotion_ELN/pull/1909)) + + +## [v1.9.3] +> (2024-05-13) + * Features and enhancements * structure editor compatibility ([#1894](https://github.com/ComPlat/chemotion_ELN/pull/1894)) * enable spectra report for samples ([#1902](https://github.com/ComPlat/chemotion_ELN/pull/1902)) From be59ce744e93610cc8d53c0707dbea225ce850c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Krau=C3=9F?= Date: Thu, 7 Nov 2024 16:28:35 +0100 Subject: [PATCH 4/4] fix: you can now create entities in sync collections if you own a collection with same id as the id of the share --- app/api/chemotion/reaction_api.rb | 47 ++++++++++++------- app/api/chemotion/research_plan_api.rb | 36 +++++++++----- app/api/chemotion/sample_api.rb | 36 +++++++++----- app/api/chemotion/screen_api.rb | 30 ++++++++---- app/api/chemotion/wellplate_api.rb | 1 + .../details/reactions/ReactionDetails.js | 2 + .../researchPlans/ResearchPlanDetails.js | 2 + .../elements/details/samples/SampleDetails.js | 2 + .../elements/details/screens/ScreenDetails.js | 2 + .../details/wellplates/WellplateDetails.js | 2 + app/packs/src/fetchers/ReactionsFetcher.js | 2 +- .../src/fetchers/ResearchPlansFetcher.js | 2 +- app/packs/src/fetchers/SamplesFetcher.js | 2 +- app/packs/src/fetchers/ScreensFetcher.js | 2 +- app/packs/src/fetchers/WellplatesFetcher.js | 2 +- app/usecases/wellplates/create.rb | 40 +++++++++++----- 16 files changed, 142 insertions(+), 68 deletions(-) diff --git a/app/api/chemotion/reaction_api.rb b/app/api/chemotion/reaction_api.rb index 0aca150b49..1e5c565512 100644 --- a/app/api/chemotion/reaction_api.rb +++ b/app/api/chemotion/reaction_api.rb @@ -246,6 +246,7 @@ class ReactionAPI < Grape::API optional :variations, type: [Hash] optional :vessel_size, type: Hash optional :gaseous, type: Boolean + optional :is_sync_to_me, type: Boolean, default: false end post do @@ -257,9 +258,8 @@ class ReactionAPI < Grape::API container_info = params[:container] attributes.delete(:container) attributes.delete(:segments) - attributes.delete(:user_labels) - - collection = current_user.collections.where(id: collection_id).take + is_sync_to_me = attributes.delete(:is_sync_to_me) + attributes[:created_by] = current_user.id reaction = Reaction.create!(attributes) recent_ols_term_update('rxno', [params[:rxno]]) if params[:rxno].present? @@ -294,26 +294,39 @@ class ReactionAPI < Grape::API reaction.save! update_element_labels(reaction, params[:user_labels], current_user.id) reaction.save_segments(segments: params[:segments], current_user_id: current_user.id) - CollectionsReaction.create(reaction: reaction, collection: collection) if collection.present? - is_shared_collection = false - if collection.blank? + if is_sync_to_me sync_collection = current_user.all_sync_in_collections_users.where(id: collection_id).take - if sync_collection.present? - is_shared_collection = true - sync_in_collection_receiver = Collection.find(sync_collection['collection_id']) - CollectionsReaction.create(reaction: reaction, - collection: sync_in_collection_receiver) - sync_out_collection_sharer = Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + + collection = Collection.find(sync_collection['collection_id']) + CollectionsReaction.create(reaction: reaction, collection: collection) if collection.present? + + sync_out_collection_sharer = Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + CollectionsReaction.create(reaction: reaction, collection: sync_out_collection_sharer) + else + collection = current_user.collections.where(id: collection_id).take + CollectionsReaction.create(reaction: reaction, collection: collection) if collection.present? + + is_shared_collection = false + if collection.blank? + sync_collection = current_user.all_sync_in_collections_users.where(id: collection_id).take + if sync_collection.present? + is_shared_collection = true + sync_in_collection_receiver = Collection.find(sync_collection['collection_id']) + CollectionsReaction.create(reaction: reaction, + collection: sync_in_collection_receiver) + sync_out_collection_sharer = Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + CollectionsReaction.create(reaction: reaction, + collection: sync_out_collection_sharer) + end + end + + unless is_shared_collection CollectionsReaction.create(reaction: reaction, - collection: sync_out_collection_sharer) + collection: Collection.get_all_collection_for_user(current_user.id)) end end - unless is_shared_collection - CollectionsReaction.create(reaction: reaction, - collection: Collection.get_all_collection_for_user(current_user.id)) - end CollectionsReaction.update_tag_by_element_ids(reaction.id) if reaction if attributes['origin'] && attributes['origin']['short_label'] && materials['products'].present? diff --git a/app/api/chemotion/research_plan_api.rb b/app/api/chemotion/research_plan_api.rb index e04cdaa512..56c48f9751 100644 --- a/app/api/chemotion/research_plan_api.rb +++ b/app/api/chemotion/research_plan_api.rb @@ -69,6 +69,7 @@ class ResearchPlanAPI < Grape::API requires :container, type: Hash, desc: 'Containers' optional :segments, type: Array, desc: 'Segments' optional :attachments, type: Array, desc: 'Attachments' + optional :is_sync_to_me, type: Boolean, default: false end post do attributes = { @@ -85,24 +86,35 @@ class ResearchPlanAPI < Grape::API clone_attachs = params[:attachments]&.reject { |a| a[:is_new] } Usecases::Attachments::Copy.execute!(clone_attachs, research_plan, current_user.id) if clone_attachs - if params[:collection_id] - collection = current_user.collections.where(id: params[:collection_id]).take - research_plan.collections << collection if collection.present? - end - - is_shared_collection = false - unless collection.present? + if params[:is_sync_to_me] + Rails.logger.debug('Creating rplan in sync collection due to user request (param :is_sync_to_me is set).') sync_collection = current_user.all_sync_in_collections_users.where(id: params[:collection_id]).take if sync_collection.present? - is_shared_collection = true research_plan.collections << Collection.find(sync_collection['collection_id']) research_plan.collections << Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + else + error!('400 Bad Request (Cant find sync collection)', 400) + end + else + if params[:collection_id] + collection = current_user.collections.where(id: params[:collection_id]).take + research_plan.collections << collection if collection.present? end - end - unless is_shared_collection - all_coll = Collection.get_all_collection_for_user(current_user.id) - research_plan.collections << all_coll + is_shared_collection = false + if collection.blank? + sync_collection = current_user.all_sync_in_collections_users.where(id: params[:collection_id]).take + if sync_collection.present? + is_shared_collection = true + research_plan.collections << Collection.find(sync_collection['collection_id']) + research_plan.collections << Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + end + end + + unless is_shared_collection + all_coll = Collection.get_all_collection_for_user(current_user.id) + research_plan.collections << all_coll + end end present research_plan, with: Entities::ResearchPlanEntity, root: :research_plan diff --git a/app/api/chemotion/sample_api.rb b/app/api/chemotion/sample_api.rb index 65de0f419d..da2d7044de 100644 --- a/app/api/chemotion/sample_api.rb +++ b/app/api/chemotion/sample_api.rb @@ -480,6 +480,7 @@ class SampleAPI < Grape::API optional :inventory_sample, type: Boolean, default: false optional :molecular_mass, type: Float optional :sum_formula, type: String + optional :is_sync_to_me, type: Boolean, default: false end post do molecule_id = if params[:decoupled] && params[:molfile].blank? @@ -551,24 +552,35 @@ class SampleAPI < Grape::API sample = Sample.new(attributes) - if params[:collection_id] - collection = current_user.collections.where(id: params[:collection_id]).take - sample.collections << collection if collection.present? - end - - is_shared_collection = false - if collection.blank? + if params[:is_sync_to_me] + Rails.logger.debug('Creating sample in sync collection due to user request (param :is_sync_to_me is set).') sync_collection = current_user.all_sync_in_collections_users.where(id: params[:collection_id]).take if sync_collection.present? - is_shared_collection = true sample.collections << Collection.find(sync_collection['collection_id']) sample.collections << Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + else + error!('400 Bad Request (Cant find sync collection)', 400) + end + else + if params[:collection_id] + collection = current_user.collections.where(id: params[:collection_id]).take + sample.collections << collection if collection.present? end - end - unless is_shared_collection - all_coll = Collection.get_all_collection_for_user(current_user.id) - sample.collections << all_coll + is_shared_collection = false + if collection.blank? + sync_collection = current_user.all_sync_in_collections_users.where(id: params[:collection_id]).take + if sync_collection.present? + is_shared_collection = true + sample.collections << Collection.find(sync_collection['collection_id']) + sample.collections << Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + end + end + + unless is_shared_collection + all_coll = Collection.get_all_collection_for_user(current_user.id) + sample.collections << all_coll + end end sample.container = update_datamodel(params[:container]) diff --git a/app/api/chemotion/screen_api.rb b/app/api/chemotion/screen_api.rb index 805a1d97f2..6b251e9f58 100644 --- a/app/api/chemotion/screen_api.rb +++ b/app/api/chemotion/screen_api.rb @@ -172,6 +172,7 @@ class ScreenAPI < Grape::API requires :container, type: Hash optional :segments, type: Array, desc: 'Segments' optional :component_graph_data, type: JSON + optional :is_sync_to_me, type: Boolean, default: false end post do attributes = { @@ -191,24 +192,35 @@ class ScreenAPI < Grape::API screen.save! screen.save_segments(segments: params[:segments], current_user_id: current_user.id) - #save to profile + # save to profile kinds = screen.container&.analyses&.pluck(Arel.sql("extended_metadata->'kind'")) recent_ols_term_update('chmo', kinds) if kinds&.length&.positive? - collection = current_user.collections.where(id: params[:collection_id]).take - screen.collections << collection if collection.present? - - is_shared_collection = false - unless collection.present? + if params[:is_sync_to_me] + Rails.logger.debug('Creating screen in sync collection due to user request (param :is_sync_to_me is set).') sync_collection = current_user.all_sync_in_collections_users.where(id: params[:collection_id]).take if sync_collection.present? - is_shared_collection = true screen.collections << Collection.find(sync_collection['collection_id']) screen.collections << Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + else + error!('400 Bad Request (Cant find sync collection)', 400) + end + else + collection = current_user.collections.where(id: params[:collection_id]).take + screen.collections << collection if collection.present? + + is_shared_collection = false + if collection.blank? + sync_collection = current_user.all_sync_in_collections_users.where(id: params[:collection_id]).take + if sync_collection.present? + is_shared_collection = true + screen.collections << Collection.find(sync_collection['collection_id']) + screen.collections << Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + end end - end - screen.collections << Collection.get_all_collection_for_user(current_user.id) unless is_shared_collection + screen.collections << Collection.get_all_collection_for_user(current_user.id) unless is_shared_collection + end params[:wellplate_ids].each do |id| ScreensWellplate.find_or_create_by(wellplate_id: id, screen_id: screen.id) diff --git a/app/api/chemotion/wellplate_api.rb b/app/api/chemotion/wellplate_api.rb index 1323093ef9..bc86ceb488 100644 --- a/app/api/chemotion/wellplate_api.rb +++ b/app/api/chemotion/wellplate_api.rb @@ -183,6 +183,7 @@ class WellplateAPI < Grape::API # rubocop:disable Metrics/ClassLength optional :height, type: Integer, default: 8, values: 1..100 optional :width, type: Integer, default: 12, values: 1..100 optional :segments, type: Array, desc: 'Segments' + optional :is_sync_to_me, type: Boolean, default: false end post do container = params[:container] diff --git a/app/packs/src/apps/mydb/elements/details/reactions/ReactionDetails.js b/app/packs/src/apps/mydb/elements/details/reactions/ReactionDetails.js index 165ea1f7cc..0314bf51b7 100644 --- a/app/packs/src/apps/mydb/elements/details/reactions/ReactionDetails.js +++ b/app/packs/src/apps/mydb/elements/details/reactions/ReactionDetails.js @@ -142,6 +142,8 @@ export default class ReactionDetails extends Component { const { reaction } = this.state; if (reaction && reaction.isNew) { + const { currentCollection } = UIStore.getState(); + reaction["is_sync_to_me"] = currentCollection ? Boolean(currentCollection["is_sync_to_me"]) : false; ElementActions.createReaction(reaction); } else { ElementActions.updateReaction(reaction, closeView); diff --git a/app/packs/src/apps/mydb/elements/details/researchPlans/ResearchPlanDetails.js b/app/packs/src/apps/mydb/elements/details/researchPlans/ResearchPlanDetails.js index a4ce1ba224..7c24bcfeb4 100644 --- a/app/packs/src/apps/mydb/elements/details/researchPlans/ResearchPlanDetails.js +++ b/app/packs/src/apps/mydb/elements/details/researchPlans/ResearchPlanDetails.js @@ -111,6 +111,8 @@ export default class ResearchPlanDetails extends Component { this.context.attachmentNotificationStore.clearMessages(); if (researchPlan.isNew) { + const { currentCollection } = UIStore.getState(); + researchPlan["is_sync_to_me"] = currentCollection ? Boolean(currentCollection["is_sync_to_me"]) : false; ElementActions.createResearchPlan(researchPlan); } else { ElementActions.updateResearchPlan(researchPlan); diff --git a/app/packs/src/apps/mydb/elements/details/samples/SampleDetails.js b/app/packs/src/apps/mydb/elements/details/samples/SampleDetails.js index 35243d2ec1..2da0d43752 100644 --- a/app/packs/src/apps/mydb/elements/details/samples/SampleDetails.js +++ b/app/packs/src/apps/mydb/elements/details/samples/SampleDetails.js @@ -355,6 +355,8 @@ export default class SampleDetails extends React.Component { const wellplate = sample.belongTo; ElementActions.updateSampleForWellplate(sample, wellplate); } else if (sample.isNew) { + const { currentCollection } = UIStore.getState(); + sample["is_sync_to_me"] = currentCollection ? Boolean(currentCollection["is_sync_to_me"]) : false; ElementActions.createSample(sample, closeView); } else { sample.cleanBoilingMelting(); diff --git a/app/packs/src/apps/mydb/elements/details/screens/ScreenDetails.js b/app/packs/src/apps/mydb/elements/details/screens/ScreenDetails.js index 4bae9c8b8f..7ebc5acaf8 100644 --- a/app/packs/src/apps/mydb/elements/details/screens/ScreenDetails.js +++ b/app/packs/src/apps/mydb/elements/details/screens/ScreenDetails.js @@ -99,6 +99,8 @@ export default class ScreenDetails extends Component { LoadingActions.start(); if (screen.isNew) { + const { currentCollection } = UIStore.getState(); + screen["is_sync_to_me"] = currentCollection ? Boolean(currentCollection["is_sync_to_me"]) : false; ElementActions.createScreen(screen); } else { ElementActions.updateScreen(screen); diff --git a/app/packs/src/apps/mydb/elements/details/wellplates/WellplateDetails.js b/app/packs/src/apps/mydb/elements/details/wellplates/WellplateDetails.js index 2875ba522e..417e233bc2 100644 --- a/app/packs/src/apps/mydb/elements/details/wellplates/WellplateDetails.js +++ b/app/packs/src/apps/mydb/elements/details/wellplates/WellplateDetails.js @@ -98,6 +98,8 @@ export default class WellplateDetails extends Component { this.context.attachmentNotificationStore.clearMessages(); LoadingActions.start(); if (wellplate.isNew) { + const { currentCollection } = UIStore.getState(); + wellplate["is_sync_to_me"] = currentCollection ? Boolean(currentCollection["is_sync_to_me"]) : false; ElementActions.createWellplate(wellplate); } else { ElementActions.updateWellplate(wellplate); diff --git a/app/packs/src/fetchers/ReactionsFetcher.js b/app/packs/src/fetchers/ReactionsFetcher.js index 8548e670e3..5097b86b59 100644 --- a/app/packs/src/fetchers/ReactionsFetcher.js +++ b/app/packs/src/fetchers/ReactionsFetcher.js @@ -86,7 +86,7 @@ export default class ReactionsFetcher { Accept: 'application/json', 'Content-Type': 'application/json' }, - body: JSON.stringify(reaction.serialize()) + body: JSON.stringify({...reaction.serialize(), is_sync_to_me: reaction["is_sync_to_me"]}) }).then((response) => response.json()) .then((json) => GenericElsFetcher.uploadGenericFiles(reaction, json.reaction.id, 'Reaction') .then(() => ReactionsFetcher.updateAnnotationsInReaction(reaction)) diff --git a/app/packs/src/fetchers/ResearchPlansFetcher.js b/app/packs/src/fetchers/ResearchPlansFetcher.js index e012633b73..3334645088 100644 --- a/app/packs/src/fetchers/ResearchPlansFetcher.js +++ b/app/packs/src/fetchers/ResearchPlansFetcher.js @@ -40,7 +40,7 @@ export default class ResearchPlansFetcher { Accept: 'application/json', 'Content-Type': 'application/json' }, - body: JSON.stringify(researchPlan.serialize()) + body: JSON.stringify({...researchPlan.serialize(), is_sync_to_me: researchPlan["is_sync_to_me"]}) }) .then((response) => response.json()) .then((json) => AttachmentFetcher.updateAttachables( diff --git a/app/packs/src/fetchers/SamplesFetcher.js b/app/packs/src/fetchers/SamplesFetcher.js index a94a9cb1f5..adbe525c10 100644 --- a/app/packs/src/fetchers/SamplesFetcher.js +++ b/app/packs/src/fetchers/SamplesFetcher.js @@ -99,7 +99,7 @@ export default class SamplesFetcher { Accept: 'application/json', 'Content-Type': 'application/json' }, - body: JSON.stringify(sample.serialize()) + body: JSON.stringify({...sample.serialize(), is_sync_to_me: sample["is_sync_to_me"]}) }).then((response) => response.json()) .then((json) => GenericElsFetcher.uploadGenericFiles(sample, json.sample.id, 'Sample') .then(() => this.fetchById(json.sample.id))).catch((errorMessage) => { diff --git a/app/packs/src/fetchers/ScreensFetcher.js b/app/packs/src/fetchers/ScreensFetcher.js index d636e21441..3bf5b8cc6a 100644 --- a/app/packs/src/fetchers/ScreensFetcher.js +++ b/app/packs/src/fetchers/ScreensFetcher.js @@ -65,7 +65,7 @@ export default class ScreensFetcher { Accept: 'application/json', 'Content-Type': 'application/json' }, - body: JSON.stringify(screen.serialize()) + body: JSON.stringify({...screen.serialize(), is_sync_to_me: screen["is_sync_to_me"]}) }).then(response => response.json()) .then(json => GenericElsFetcher.uploadGenericFiles(screen, json.screen.id, 'Screen') .then(() => this.fetchById(json.screen.id))).catch((errorMessage) => { diff --git a/app/packs/src/fetchers/WellplatesFetcher.js b/app/packs/src/fetchers/WellplatesFetcher.js index 38b938de09..aef37dc77e 100644 --- a/app/packs/src/fetchers/WellplatesFetcher.js +++ b/app/packs/src/fetchers/WellplatesFetcher.js @@ -87,7 +87,7 @@ export default class WellplatesFetcher { Accept: 'application/json', 'Content-Type': 'application/json' }, - body: JSON.stringify(wellplate.serialize()) + body: JSON.stringify({...wellplate.serialize(), is_sync_to_me: wellplate["is_sync_to_me"]}) }) .then((response) => response.json()) .then((json) => { diff --git a/app/usecases/wellplates/create.rb b/app/usecases/wellplates/create.rb index 5a49fd6b92..ffcb47e8b6 100644 --- a/app/usecases/wellplates/create.rb +++ b/app/usecases/wellplates/create.rb @@ -12,25 +12,39 @@ def initialize(params, current_user) def execute! # rubocop:disable Metrics/AbcSize ActiveRecord::Base.transaction do - wellplate = Wellplate.create(params.except(:collection_id, :wells, :segments, :size)) + is_sync_to_me = params[:is_sync_to_me] + + wellplate = Wellplate.create(params.except(:collection_id, :wells, :segments, :is_sync_to_me)) wellplate.set_short_label(user: @current_user) wellplate.reload wellplate.save_segments(segments: params[:segments], current_user_id: @current_user.id) - is_shared_collection = false - if user_collection - CollectionsWellplate.create(wellplate: wellplate, collection: user_collection) - elsif sync_collection_user - is_shared_collection = true - CollectionsWellplate.create(wellplate: wellplate, collection: sync_collection_user.collection) + if is_sync_to_me + Rails.logger.debug('Creating wellplate in sync collection due to user request (param :is_sync_to_me is set).') + sync_collection = current_user.all_sync_in_collections_users.where(id: params[:collection_id]).take + error!('400 Bad Request (Cant find sync collection)', 400) if sync_collection.blank? - CollectionsWellplate.create(wellplate: wellplate, collection: all_collection_of_sharer) - end + collection = Collection.find(sync_collection['collection_id']) + CollectionsWellplate.create(wellplate: wellplate, collection: collection) if collection.present? + + sync_out_collection_sharer = Collection.get_all_collection_for_user(sync_collection['shared_by_id']) + CollectionsWellplate.create(wellplate: wellplate, collection: sync_out_collection_sharer) + else + is_shared_collection = false + if user_collection + CollectionsWellplate.create(wellplate: wellplate, collection: user_collection) + elsif sync_collection_user + is_shared_collection = true + CollectionsWellplate.create(wellplate: wellplate, collection: sync_collection_user.collection) - CollectionsWellplate.create( - wellplate: wellplate, - collection: all_collection_of_current_user - ) unless is_shared_collection + CollectionsWellplate.create(wellplate: wellplate, collection: all_collection_of_sharer) + end + + CollectionsWellplate.create( + wellplate: wellplate, + collection: all_collection_of_current_user + ) unless is_shared_collection + end WellplateUpdater .new(wellplate: wellplate, current_user: current_user)