Skip to content
Snippets Groups Projects
Unverified Commit fd6fecd1 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

about website connected

parent bba90422
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@ module Communication::Website::WithConnectedObjects
included do
has_many :connections
after_save :connect_about, if: :saved_change_to_about_id?
end
# Appelé par un objet avec des connexions lorsqu'il est destroyed
......@@ -59,6 +61,11 @@ module Communication::Website::WithConnectedObjects
protected
def connect_about
self.connect(about, self) if about.present? && about.try(:is_indirect_object?)
destroy_obsolete_connections
end
def connect_object(indirect_object, direct_source, direct_source_type: nil)
return unless should_connect?(indirect_object, direct_source)
# puts "connect #{object} (#{object.class})"
......@@ -81,7 +88,7 @@ module Communication::Website::WithConnectedObjects
# On ne connecte pas le site à lui-même
return false if indirect_object.is_a?(Communication::Website)
# On ne connecte pas les objets directs (en principe ça n'arrive pas)
return false if indirect_object.respond_to?(:is_direct_object?) && indirect_object.is_direct_object?
return false if indirect_object.try(:is_direct_object?)
true
end
end
\ No newline at end of file
......@@ -41,15 +41,15 @@ module Communication::Website::WithOldDependencies
end
def administrators
about&.administrators
has_administrators? ? about.administrators : University::Person.none
end
def researchers
about&.researchers
has_researchers? ? about.researchers : University::Person.none
end
def teachers
about&.teachers
has_teachers? ? about.teachers : University::Person.none
end
def people_in_blocks
......
......@@ -6,6 +6,8 @@ module WithAbouts
polymorphic: true,
optional: true
before_validation :nullify_about_id_if_about_type_changed_to_blank
scope :for_about_type, -> (type) { where(about_type: type) }
def self.about_types
......@@ -17,6 +19,11 @@ module WithAbouts
Research::Journal.name,
]
end
end
protected
def nullify_about_id_if_about_type_changed_to_blank
self.about_id = nil if about_type_changed? && about_type.blank?
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment