repository.rb revision d79e030993a7d41dd0becfe941633e23997a6717
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Boseclass Repository < ActiveRecord::Base
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose include Permissionable
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose include Repository::Ontologies
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose include Repository::GitRepositories
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose include Repository::FilesList
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose include Repository::Validations
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose include Repository::Importing
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose include Repository::Scopes
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose include Repository::Symlink
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose has_many :ontologies, dependent: :destroy
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose has_many :url_maps, dependent: :destroy
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose attr_accessible :name, :description, :source_type, :source_address, :is_private
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose attr_accessor :user
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose after_save :clear_readers
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose scope :latest, order('updated_at DESC')
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose scope :pub, where(is_private: false)
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose scope :accessible_by, ->(user) do
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose if user
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose where("is_private = false
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose OR id IN (SELECT item_id FROM permissions WHERE item_type = 'Repository' AND subject_type = 'User' AND subject_id = ?)
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose OR id IN (SELECT item_id FROM permissions INNER JOIN team_users ON team_users.team_id = permissions.subject_id AND team_users.user_id = ?
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose WHERE item_type = 'Repository' AND subject_type = 'Team')", user, user)
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose else
8a5e793a0576250da80371e53aa3e7eba15cdb63Sumit Bose pub
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose def to_s
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose name
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose def to_param
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose path
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose # list all failed versions, grouped by their errors
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose def failed_ontology_versions
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose versions = self.ontologies.map{|o| o.versions.last}.compact
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose versions.select{|v| v.state!="done"}.group_by do |v|
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose title = [v.state]
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose if err = v.last_error
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose if err.include?("exited with status")
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose title << err[0,50] + " ... " + err.match("exited with status.*")[0]
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose else
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose title << err.each_line.first
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
2ca45dfa0144fea08bd360dafded57bc90111e68Sumit Bose end
2ca45dfa0144fea08bd360dafded57bc90111e68Sumit Bose title.join(": ")
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose private
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose def clear_readers
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose if is_private_changed?
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose permissions.where(role: 'reader').each { |p| p.destroy }
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose end
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Boseend
6b5044001e4b0a0caf971a2cf5f27674e0d270f4Sumit Bose