Skip to content

Commit

Permalink
reject private ontologies for non admin users in groups controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ontoportal-bot-lirmm committed Dec 18, 2024
1 parent ce2c8d0 commit c6140cd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ class GroupsController < ApplicationController
# Display all groups
get do
check_last_modified_collection(LinkedData::Models::Group)
groups = Group.where.include(Group.goo_attrs_to_load(includes_param)).to_a
groups = Group.where.include(*Group.goo_attrs_to_load(includes_param), ontologies: [:viewingRestriction]).to_a
# Private ontologies viewd only by admins of the portal
groups = reject_private_ontologies(groups) unless current_user.admin?
reply groups
end

# Display a single group
get '/:acronym' do
check_last_modified_collection(LinkedData::Models::Group)
acronym = params["acronym"]
g = Group.find(acronym).include(Group.goo_attrs_to_load(includes_param)).first
g = Group.find(acronym).include(*Group.goo_attrs_to_load(includes_param), ontologies: [:viewingRestriction]).first
error 404, "Group #{acronym} not found" if g.nil?
# Private ontologies viewd only by admins of the portal
g = reject_private_ontologies([g]).first unless current_user.admin?
reply 200, g
end

Expand Down Expand Up @@ -81,5 +85,13 @@ def create_group
end
reply 201, group
end

def reject_private_ontologies(groups)
groups.each do |group|
public_ontologies = group.ontologies.reject { |ontology| ontology.viewingRestriction == "private" }
group.instance_variable_set(:@ontologies, public_ontologies)
end
end

end
end

0 comments on commit c6140cd

Please sign in to comment.