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

Fix: hide private artefacts when getting all artefacts #187

Merged
merged 6 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
33 changes: 17 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: 27300f28ca6c656c7e78af65013d88b792a6312f
revision: e48a2d13a65cc2dd1c12d116cfc9da9061106861
branch: development
specs:
goo (0.0.2)
addressable (~> 2.8)
pry
rdf (= 3.2.11)
rdf
rdf-raptor
rdf-rdfxml
rdf-vocab
Expand All @@ -18,7 +18,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/sparql-client.git
revision: 4364d34e9e4c411f1dd0ea706bf052465bf0b467
revision: 736b7650e28db3ce5e3e49511ac30f958a29e8f1
branch: development
specs:
sparql-client (3.2.2)
Expand Down Expand Up @@ -92,19 +92,20 @@ GEM
domain_name (~> 0.5)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (2.9.1)
json (2.10.1)
json-ld (3.0.2)
multi_json (~> 1.12)
rdf (>= 2.2.8, < 4.0)
jwt (2.10.1)
base64
language_server-protocol (3.17.0.3)
launchy (3.0.1)
language_server-protocol (3.17.0.4)
launchy (3.1.0)
addressable (~> 2.8)
childprocess (~> 5.0)
logger (~> 1.6)
libxml-ruby (5.0.3)
link_header (0.0.8)
logger (1.6.5)
logger (1.6.6)
macaddr (1.7.2)
systemu (~> 2.6.5)
mail (2.8.1)
Expand All @@ -116,7 +117,7 @@ GEM
mime-types (3.6.0)
logger
mime-types-data (~> 3.2015)
mime-types-data (3.2025.0107)
mime-types-data (3.2025.0204)
mini_mime (1.1.5)
minitest (4.7.5)
minitest-reporters (0.14.24)
Expand All @@ -128,14 +129,14 @@ GEM
multipart-post (2.4.1)
net-http-persistent (4.0.5)
connection_pool (~> 2.2)
net-imap (0.4.18)
net-imap (0.4.19)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.5.0)
net-smtp (0.5.1)
net-protocol
netrc (0.11.0)
oj (3.16.9)
Expand All @@ -145,7 +146,7 @@ GEM
logger
ostruct (0.6.1)
parallel (1.26.3)
parser (3.3.7.0)
parser (3.3.7.1)
ast (~> 2.4.1)
racc
pony (1.13.1)
Expand All @@ -162,7 +163,7 @@ GEM
rack (>= 1.0, < 3)
rainbow (3.1.1)
rake (10.5.0)
rdf (3.2.11)
rdf (3.2.12)
link_header (~> 0.0, >= 0.0.8)
rdf-raptor (3.2.0)
ffi (~> 1.15)
Expand Down Expand Up @@ -192,17 +193,17 @@ GEM
rexml (3.4.0)
rsolr (1.1.2)
builder (>= 2.1.2)
rubocop (1.70.0)
rubocop (1.71.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
rubocop-ast (1.38.0)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
Expand Down Expand Up @@ -231,7 +232,7 @@ GEM
unicode-emoji (4.0.4)
uuid (2.3.9)
macaddr (~> 1.0)
webmock (3.24.0)
webmock (3.25.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down
12 changes: 7 additions & 5 deletions lib/ontologies_linked_data/models/mod/semantic_artefact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def attribute_mapped(name, **options)
attribute_mapped :metrics, namespace: :mod, mapped_to: {model: :ontology_submission, attribute: :metrics}


attribute :ontology, type: :ontology
attribute :ontology, type: :ontology, enforce: [:existence]

links_load :acronym
link_to LinkedData::Hypermedia::Link.new("distributions", lambda {|s| "artefacts/#{s.acronym}/distributions"}, LinkedData::Models::SemanticArtefactDistribution.type_uri),
Expand All @@ -132,7 +132,9 @@ def attribute_mapped(name, **options)
LinkedData::Hypermedia::Link.new("collection", lambda {|s| "artefacts/#{s.acronym}/collections"}, LinkedData::Models::SKOS::Collection.uri_type),
LinkedData::Hypermedia::Link.new("labels", lambda {|s| "artefacts/#{s.acronym}/labels"}, LinkedData::Models::SKOS::Label.uri_type)


# Access control
read_restriction_based_on ->(artefct) { artefct.ontology }

serialize_default :acronym, :accessRights, :subject, :URI, :versionIRI, :creator, :identifier, :status, :language,
:license, :rightsHolder, :description, :landingPage, :keyword, :bibliographicCitation, :contactPoint,
:contributor, :publisher, :coverage, :createdWith, :accrualMethod, :accrualPeriodicity,
Expand All @@ -157,7 +159,7 @@ def self.type_uri
end

def self.find(artefact_id)
ont = Ontology.find(artefact_id).include(:acronym).first
ont = Ontology.find(artefact_id).include(:acronym, :viewingRestriction, :administeredBy, :acl).first
return nil unless ont

new.tap do |sa|
Expand Down Expand Up @@ -192,9 +194,9 @@ def bring(*attributes)

def self.all_artefacts(options = {})
onts = if options[:also_include_views]
Ontology.where.to_a
Ontology.where().include(:acronym, :viewingRestriction, :administeredBy, :acl).to_a
else
Ontology.where.filter(Goo::Filter.new(:viewOf).unbound).include(:acronym).to_a
Ontology.where().filter(Goo::Filter.new(:viewOf).unbound).include(:acronym, :viewingRestriction, :administeredBy, :acl).to_a
end

onts.map do |o|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def attribute_mapped(name, **options)

# Attr special to SemanticArtefactDistribution
attribute :submission, type: :ontology_submission

# Access control
read_restriction_based_on ->(artefct_distribution) { artefct_distribution.submission.ontology }

serialize_default :distributionId, :title, :hasRepresentationLanguage, :hasSyntax, :description, :created, :modified,
:conformsToKnowledgeRepresentationParadigm, :usedEngineeringMethodology, :prefLabelProperty,
Expand All @@ -80,7 +83,7 @@ def self.distribution_id_generator(ss)
def initialize(sub)
super()
@submission = sub
@submission.bring(*[:submissionId, :ontology=>[:acronym]])
@submission.bring(*[:submissionId, :ontology=>[:acronym, :administeredBy, :acl, :viewingRestriction]])
@distributionId = sub.submissionId
end

Expand Down
10 changes: 4 additions & 6 deletions test/models/test_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ def test_class_parents
assert_equal(cls.parents[0].submission, os)

# transitive
assert_raises ArgumentError do
cls.bring(:ancestors)
end
cls.bring(:ancestors)
assert_includes cls.loaded_attributes.to_a, :ancestors
ancestors = cls.ancestors.dup
ancestors.each do |a|
assert !a.submission.nil?
Expand Down Expand Up @@ -83,9 +82,8 @@ def test_class_children
assert_equal(cls.children[0].submission, os)

# transitive
assert_raises ArgumentError do
cls.bring(:descendants)
end
cls.bring(:descendants)
assert_includes cls.loaded_attributes.to_a, :descendants
descendants = cls.descendants.dup
descendants.map! { |a| a.id.to_s }
data_descendants = ["http://bioportal.bioontology.org/ontologies/msotes#class_5",
Expand Down
Loading