From 8ca942852aaf442dbd81661fbd968f42fb09f16a Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Mon, 6 May 2024 20:58:35 +0200 Subject: [PATCH] add slice controller action to sync slices and groups if wanted --- controllers/slices_controller.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/controllers/slices_controller.rb b/controllers/slices_controller.rb index 04e0d53e..727093e8 100644 --- a/controllers/slices_controller.rb +++ b/controllers/slices_controller.rb @@ -40,6 +40,30 @@ class SlicesController < ApplicationController end halt 204 end + + + # Check to make sure each group has a corresponding slice (and ontologies match) + get '/synchronize_groups' do + error 403, "Access denied" unless current_user && current_user.admin? + + groups = LinkedData::Models::Group.where.include(LinkedData::Models::Group.attributes(:all)).all + groups.each do |g| + slice = LinkedData::Models::Slice.find(g.acronym.downcase.gsub(" ", "_")).include(LinkedData::Models::Slice.attributes(:all)).first + if slice + slice.ontologies = g.ontologies + slice.save if slice.valid? + else + slice = LinkedData::Models::Slice.new({ + acronym: g.acronym.downcase.gsub(" ", "_"), + name: g.name, + description: g.description, + ontologies: g.ontologies + }) + slice.save rescue reply "Error creating slice: " + slice.errors.to_s + end + end + reply LinkedData::Models::Slice.where.include(LinkedData::Models::Slice.attributes(:all)).all + end private