* Get rid of early pathname requirement * Use require_relative where approciate * Drop unused files * Imported new application.rb, environment.rb and environments/* from fresh Rails app * Cleaned up boot.rb * Load config in boot.rb * Deduplicate environments/integration*.rb * Move username blacklist into defaults.yml * Ruby 1.9 Hash syntax everywhere * Reorganize lib/diaspora/markdownify to match conventions * Get rid of full path requires where possible * Add dummy content to production section diaspora.yml.example to prevent warning * Drop sqlite? method * Move postgres? method into ConfigurationMethods * Drop token authentication from User
44 lines
1.5 KiB
Ruby
44 lines
1.5 KiB
Ruby
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
|
# licensed under the Affero General Public License version 3 or later. See
|
|
# the COPYRIGHT file.
|
|
|
|
class ShareVisibility < ActiveRecord::Base
|
|
belongs_to :contact
|
|
belongs_to :shareable, :polymorphic => :true
|
|
|
|
scope :for_a_users_contacts, lambda { |user|
|
|
where(:contact_id => user.contacts.map {|c| c.id})
|
|
}
|
|
scope :for_contacts_of_a_person, lambda { |person|
|
|
where(:contact_id => person.contacts.map {|c| c.id})
|
|
}
|
|
|
|
validate :not_public
|
|
|
|
# Perform a batch import, given a set of contacts and a shareable
|
|
# @note performs a bulk insert in mySQL; performs linear insertions in postgres
|
|
# @param contacts [Array<Contact>] Recipients
|
|
# @param share [Shareable]
|
|
# @return [void]
|
|
def self.batch_import(contact_ids, share)
|
|
return false unless ShareVisibility.new(:shareable_id => share.id, :shareable_type => share.class.to_s).valid?
|
|
|
|
if AppConfig.postgres?
|
|
contact_ids.each do |contact_id|
|
|
ShareVisibility.find_or_create_by_contact_id_and_shareable_id_and_shareable_type(contact_id, share.id, share.class.base_class.to_s)
|
|
end
|
|
else
|
|
new_share_visibilities_data = contact_ids.map do |contact_id|
|
|
[contact_id, share.id, share.class.base_class.to_s]
|
|
end
|
|
ShareVisibility.import([:contact_id, :shareable_id, :shareable_type], new_share_visibilities_data)
|
|
end
|
|
end
|
|
|
|
private
|
|
def not_public
|
|
if shareable.public?
|
|
errors[:base] << "Cannot create visibility for a public object"
|
|
end
|
|
end
|
|
end
|