Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add slice controller action to sync slices and groups if wanted #158

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading