Skip to content
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
19 changes: 19 additions & 0 deletions lib/ontologies_linked_data/models/users/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class User < LinkedData::Models::Base
attribute :resetToken
attribute :resetTokenExpireTime
attribute :provisionalClasses, inverse: { on: :provisional_class, attribute: :creator }
attribute :createdOntologies, enforce: [:list], handler: :load_created_ontologies

# Hypermedia settings
embed :subscription
Expand All @@ -43,6 +44,8 @@ class User < LinkedData::Models::Base
serialize_never :passwordHash, :show_apikey, :resetToken, :resetTokenExpireTime
serialize_filter lambda {|inst| show_apikey?(inst)}

link_to LinkedData::Hypermedia::Link.new("createdOntologies", lambda {|s| "users/#{s.id.split('/').last}/ontologies"}, nil)

# Cache
cache_timeout 3600

Expand Down Expand Up @@ -96,6 +99,22 @@ def save(*args)
super
end

def load_created_ontologies
ontologies = []
q = Goo.sparql_query_client.select(:id, :acronym, :administeredBy).distinct
.from(Ontology.uri_type)
.where(
[:id, LinkedData::Models::Ontology.attribute_uri(:administeredBy), :administeredBy],
[:id, LinkedData::Models::Ontology.attribute_uri(:acronym), :acronym],
)
.filter("?administeredBy = <#{self.id}>")
acronyms = q.execute.map { |o| o.acronym.to_s }
return ontologies if acronyms.empty?
filter_by_acronym = Goo::Filter.new(:acronym).regex(acronyms.join('|'))
ontologies = Ontology.where.include(Ontology.goo_attrs_to_load([:all])).filter(filter_by_acronym).all
return ontologies
end

def admin?
return false unless persistent?
bring(role: [:role])
Expand Down