metamaps--metamaps/app/models/synapse.rb
Connor Turland 8c51108a0c enable shared private and public maps (#530)
* enable shared private and public maps

* change the list

* yeehaw add collaborators

* I believe this fixes the error connor brought up

* when topic or synapse is no longer on a map, don't defer

* needs to be before?

* just do it in the controller

* make recommendation they sign in and retry

* better email

* config for mailer previews

* improve wording

* shouldn't have included that

* switch to green

* don't execute if there's no map

* wasn't including the right people in some circumstances

* Finish breaking out JS files (#551)

* metamaps.Realtime refactor

* Metamaps.Util

* Metamaps.Visualize

* Metamaps.SynapseCard

* Metamaps.TopicCard

* Metamaps.Create.js

* Remove erb extension from Metamaps.Map.js

* Metmaps.Account and Metamaps.GlobalUI remove extension

* Metamaps.JIT no more erb extension

* move Backbone.init; standard-format on Metamaps.js.erb

* factor out canvas support check function

* some llittle template bugs

* remove featured from signed in explore maps bar

* don't let it overflow off the page
2016-04-24 11:50:35 -04:00

62 lines
1.4 KiB
Ruby

class Synapse < ActiveRecord::Base
belongs_to :user
belongs_to :defer_to_map, :class_name => 'Map', :foreign_key => 'defer_to_map_id'
belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id"
belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id"
has_many :mappings, as: :mappable, dependent: :destroy
has_many :maps, :through => :mappings
validates :desc, length: { minimum: 0, allow_nil: false }
validates :permission, presence: true
validates :node1_id, presence: true
validates :node2_id, presence: true
validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) }
validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true }
scope :for_topic, ->(topic_id = nil) {
where("node1_id = ? OR node2_id = ?", topic_id, topic_id)
}
# :nocov:
def user_name
user.name
end
# :nocov:
# :nocov:
def user_image
user.image.url
end
# :nocov:
# :nocov:
def collaborator_ids
if defer_to_map
defer_to_map.editors.select{|mapper| not mapper == self.user }.map(&:id)
else
[]
end
end
# :nocov:
# :nocov:
def calculated_permission
if defer_to_map
defer_to_map.permission
else
permission
end
end
# :nocov:
# :nocov:
def as_json(options={})
super(:methods =>[:user_name, :user_image, :calculated_permission, :collaborator_ids])
end
# :nocov:
end