From 18307393d44ea683ca3c8080f14a207a61b4fb6c Mon Sep 17 00:00:00 2001 From: Heiko Bernloehr Date: Wed, 31 Dec 2014 09:28:46 +0100 Subject: Memberships element added. For easier communication of a participant with its newly created subparticipant I exchanged the community element with a memberships element. Now the creating participant gets all necessary information of its subparticipant to start communication right after creation. The memberships element has the same structure as a resource representation of /sys/memberships but there is only the newly created subparticipant listed in the participants array (itsyou=true). The /sys/memberships representation lists *all* participants (and subparticipants) joining the same community. After creating a subparticipant: curl ... -H 'Content-Type: application/json' \ -X POST -d '{"realm":"tux","communities":["stephan","public"]}' \ https://.../sys/subparticipants you get something like this as answer (example): { "description": "Created from \"Teacher client\" (pid:3)", "community_selfrouting": false, "realm": "tux", "auth_ids": [ { "desc": "Randomized authid", "auth_id": "06e9506fa723b2353cbe4acc32a9a568" } ], "memberships": [ { "participants": [ { "email": "xaver@freeit.de", "org": { "abbr": "S", "name": "Development FreeIT Suttgart" }, "name": "Subparticipant (id:67)", "mid": 190100, "dns": "N/A", "description": "Created from \"Teacher client\" (pid:3)", "pid": 190376, "itsyou": true } ], "community": { "cid": 2, "name": "devel", "description": "Devel test community." } }, { "participants": [ { "email": "xaver@FreeIT.de", "org": { "abbr": "S", "name": "Development FreeIT Stuttgart" }, "name": "Subparticipant (id:67)", "mid": 190101, "dns": "N/A", "description": "Created from \"Teacher client\" (pid:3)", "pid": 190376, "itsyou": true } ], "community": { "cid": 1, "name": "public", "description": "For anonymous participants." } } ], "name": "Subparticipant (id:67)", "email": "xaver@freeit.de", "events": true, "dns": "N/A" } --- app/controllers/subparticipants_controller.rb | 2 +- app/models/community.rb | 5 +++++ app/models/membership.rb | 10 ++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/subparticipants_controller.rb b/app/controllers/subparticipants_controller.rb index daf1b72..6284536 100644 --- a/app/controllers/subparticipants_controller.rb +++ b/app/controllers/subparticipants_controller.rb @@ -98,7 +98,7 @@ private :email => participant.email, :community_selfrouting => participant.community_selfrouting, :events => participant.events_, - :communities => participant.communities.map{|c| c.name}, + :memberships => Membership.memberships(participant,true), :realm => subparticipant.realm, } data diff --git a/app/models/community.rb b/app/models/community.rb index 9faa3d1..cf0d258 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -24,6 +24,11 @@ class Community < ActiveRecord::Base :conditions => ["participants.anonymous = ?", false], :order => "participants.id ASC" end + def with_reduced_attributes_and_only_itsyou_and_without_anonymous(pid) + find :all, :select => "participants.id, name, description, email, dns, organization_id", + :conditions => ["participants.anonymous = ? and participants.id = ?", false, pid], + :order => "participants.id ASC" + end end has_many :community_messages, :dependent => :destroy has_many :messages, :through => :community_messages diff --git a/app/models/membership.rb b/app/models/membership.rb index 7e7aebf..895d7e6 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -59,7 +59,7 @@ class Membership < ActiveRecord::Base end end - def self.memberships(participant) + def self.memberships(participant,itsyou=false) memberships = [] Membership.for_participant_id(participant.id).each do |membership| community= lambda { |memb| @@ -68,7 +68,13 @@ class Membership < ActiveRecord::Base attribs }.call(membership) logger.debug "**** Membership::memberships: community: #{community.inspect}" - participants= membership.community.participants.with_reduced_attributes_and_without_anonymous.map do |p| + if itsyou + participants_with_reduced_attribs= membership.community.participants.with_reduced_attributes_and_only_itsyou_and_without_anonymous(participant.id) + logger.debug "**** Membership::memberships: participants_with_reduced_attribs: #{participants_with_reduced_attribs.inspect}" + else + participants_with_reduced_attribs= membership.community.participants.with_reduced_attributes_and_without_anonymous + end + participants= participants_with_reduced_attribs.map do |p| attribs = p.attributes attribs["mid"] = Membership.for_participant_id_and_community_id(p.id, membership.community.id).first.id attribs["org"] = {"name" => p.organization.name, "abbr" => p.organization.abrev} -- cgit v1.2.3