aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2014-12-31 09:28:46 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-01-27 01:50:43 +0100
commit18307393d44ea683ca3c8080f14a207a61b4fb6c (patch)
tree40e6b5391f9ba3b4e2239dd91bc152bc59246826
parent2473c5588b1d89cc5cbf934d5a0b4df08c161dd5 (diff)
downloadecs2-18307393d44ea683ca3c8080f14a207a61b4fb6c.tar.gz
ecs2-18307393d44ea683ca3c8080f14a207a61b4fb6c.zip
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" }
-rw-r--r--app/controllers/subparticipants_controller.rb2
-rw-r--r--app/models/community.rb5
-rw-r--r--app/models/membership.rb10
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}