diff options
author | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2013-03-02 04:34:14 +0100 |
---|---|---|
committer | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2013-03-11 13:32:14 +0100 |
commit | 55608fa5b7cfa51e8cbf88c182232abc0827a09a (patch) | |
tree | 37e0671a2132304e0f3b67b24c5f13d3424e8887 /app | |
parent | 84911f08afa07654c2d43ba2d1951f698c51fc1d (diff) | |
download | ecs2-55608fa5b7cfa51e8cbf88c182232abc0827a09a.tar.gz ecs2-55608fa5b7cfa51e8cbf88c182232abc0827a09a.zip |
Postrouting when entering community.
The postrouting after creating a new participant was removed and is now
done when entering a community.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/participants_controller.rb | 1 | ||||
-rw-r--r-- | app/models/membership.rb | 15 | ||||
-rw-r--r-- | app/models/ressource.rb | 22 |
3 files changed, 15 insertions, 23 deletions
diff --git a/app/controllers/admin/participants_controller.rb b/app/controllers/admin/participants_controller.rb index 1c40592..e7bf389 100644 --- a/app/controllers/admin/participants_controller.rb +++ b/app/controllers/admin/participants_controller.rb @@ -68,7 +68,6 @@ class Admin::ParticipantsController < ApplicationController @participant = Participant.new(params[:participant]) if @participant.save flash[:notice] = 'Participant was successfully created.' - Ressource.postrouting(@participant) redirect_to admin_participants_path else @organizations = Organization.find(:all, :order => :id) diff --git a/app/models/membership.rb b/app/models/membership.rb index c2d2317..d26f8f0 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -26,6 +26,8 @@ class Membership < ActiveRecord::Base has_many :messages, :through => :membership_messages has_many :membership_messages, :dependent => :destroy + after_create :postroute + # returns memberships of the relation between a participant and a message # if no relationship then returns empty array. named_scope :receiver, lambda { |participant_id,message_id| { @@ -56,4 +58,17 @@ class Membership < ActiveRecord::Base sender_mids.flatten end end + + +private + + # generate created events for all messages connected to this community membership + def postroute + community.messages.map{|m| m.ressource.postroute ? m : nil}.compact.each do |msg| + messages << msg + Event.make(:event_type_name => EvType.find_by_name("created").name, :participant => participant, :message => msg) + logger.info "**** postrouting message.id=#{msg.id} to participant:#{participant.name} (pid:#{participant.id})" + end + end + end diff --git a/app/models/ressource.rb b/app/models/ressource.rb index 4730d9b..1aba41a 100644 --- a/app/models/ressource.rb +++ b/app/models/ressource.rb @@ -24,28 +24,6 @@ class Ressource < ActiveRecord::Base named_scope :list, :order => "namespace, ressource ASC" - def self.postrouting(participant) - find_all_by_postroute(true).each do |res| - res.messages.each do |msg| - rec_cids = msg.communities.map{|c|c.id} - rec_mids = [] - participant.memberships.each do |memb| - if rec_cids.include?(memb.community.id) - logger.info "**** postrouting message.id=#{msg.id} to participant:#{participant.name}" - rec_mids << memb.id - end - end - unless rec_mids.empty? - begin - MembershipMessage.populate_jointable(msg, rec_mids.join(',') , nil, Participant.find(msg.sender)) - Event.make(:event_type_name => EvType.find(1).name, :participant => participant, :message => msg) - rescue Ecs::InvalidMessageException, Ecs::AuthorizationException - end - end - end - end - end - def self.validates_ressource_path(namespace, ressource) r = Ressource.find_by_namespace_and_ressource(namespace, ressource) raise(Ecs::InvalidRessourceUriException, "*** ressource uri error ***") unless r |