Skip to content

Commit

Permalink
Merge pull request #5 from ontoportal-lirmm/pr/feature/sycn-slice-groups
Browse files Browse the repository at this point in the history
Feature: Add endpoint to sync groups with slices
  • Loading branch information
alexskr authored Sep 23, 2024
2 parents ceb9bcf + 8ca9428 commit e67e0bb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions controllers/slices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e67e0bb

Please sign in to comment.