aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2015-04-09 15:01:23 +0200
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-01-27 01:50:44 +0100
commit8bbf9218728ae2664d83dd03e4aaec6e638eb1ce (patch)
treefa83d1420ab859bcb1f189e7c08493f69405bc00
parentede1b68570ad9d190a8e167dae31a03c46c9a1d9 (diff)
downloadecs2-8bbf9218728ae2664d83dd03e4aaec6e638eb1ce.tar.gz
ecs2-8bbf9218728ae2664d83dd03e4aaec6e638eb1ce.zip
Query filter for /sys/memberships.
Now it's possible to filter /sys/memberships resource: * /sys/memberships?mainparticipants=true You get only memberships concerning mainparticipants (MPs). MPs are participants which have to be registered/configured by hand over the ECS Webinterface. * /sys/memberships?subparticipants=true You get only memberships concerning/containing subparticipants (SPs). SPs are participants which are created dynamically by MPs. * /sys/memberships?anonymous=true You get only memberships concerning/containing anonymous participants (APs). The creation of new APs automatically takes place by every call to an ECS resource if the calling participant didn’t set X-EcsAuthId or Cookie header. AP-Handling has to be activated explicitly in the ECS configuration. * /sys/memberships?all=true You get all available memberships irrespectively of their type. The default filter is set to "mainparticipants=true". The filter could also be specified by a HTTP variable e.g.: curl ... -H 'X-EcsQueryStrings: mainparticipants=true' http://.../sys/memberships
-rw-r--r--app/controllers/memberships_controller.rb24
-rw-r--r--app/models/membership.rb15
-rw-r--r--app/models/participant.rb17
3 files changed, 53 insertions, 3 deletions
diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb
index 6a7bd50..dbd60ca 100644
--- a/app/controllers/memberships_controller.rb
+++ b/app/controllers/memberships_controller.rb
@@ -28,7 +28,7 @@ class MembershipsController < ApplicationController
end
def index
- memberships = Membership.memberships(@participant)
+ memberships= index_querystring_list
if memberships.empty?
render :text => "", :content_type => "application/json", :layout => false
else
@@ -39,4 +39,26 @@ class MembershipsController < ApplicationController
end
end
+ private
+
+ def index_querystring_list
+ header_querystrings = request.headers["X-EcsQueryStrings"]
+ if header_querystrings
+ hqs = header_querystrings.split(",").map{|s| s.strip}.map{|s| s.split("=").map{|s| s.strip}}
+ mainparticipants = (m=hqs.assoc("mainparticipants")) ? m[1] : nil
+ subparticipants = (m=hqs.assoc("subparticipants")) ? m[1] : nil
+ anonymous = (m=hqs.assoc("anonymous")) ? m[1] : nil
+ all = (m=hqs.assoc("all")) ? m[1] : nil
+ end
+ mainparticipants ||= params["mainparticipants"] ? params["mainparticipants"] : nil
+ subparticipants ||= params["subparticipants"] ? params["subparticipants"] : nil
+ anonymous ||= params["anonymous"] ? params["anonymous"] : nil
+ all ||= params["all"] ? params["all"] : nil
+ Membership.memberships(@participant,false,
+ { :mainparticipants => mainparticipants,
+ :subparticipants => subparticipants,
+ :anonymous => anonymous,
+ :all => all })
+ end
+
end
diff --git a/app/models/membership.rb b/app/models/membership.rb
index 6eb4d74..00254f7 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,itsyou=false)
+ def self.memberships(participant,itsyou=false,filter=nil)
memberships = []
Membership.for_participant_id(participant.id).each do |membership|
community= lambda { |memb|
@@ -72,7 +72,18 @@ class Membership < ActiveRecord::Base
participants_with_reduced_attribs= membership.community.participants.itsyou(participant.id).without_anonymous.reduced_attributes
logger.debug "**** Membership::memberships: participants_with_reduced_attribs: #{participants_with_reduced_attribs.inspect}"
else
- participants_with_reduced_attribs= membership.community.participants.without_anonymous.reduced_attributes
+ participants_with_reduced_attribs= case
+ when filter[:all]
+ membership.community.participants.order_id_asc.reduced_attributes
+ when filter[:mainparticipants]
+ membership.community.participants.mainparticipants_with_reduced_attributes
+ when filter[:subparticipants]
+ membership.community.participants.subparticipants_with_reduced_attributes
+ when filter[:anonymous]
+ membership.community.participants.anonymous_participants_with_reduced_attributes
+ else
+ membership.community.participants.without_anonymous_with_reduced_attributes
+ end
end
participants= participants_with_reduced_attribs.map do |p|
attribs = p.attributes
diff --git a/app/models/participant.rb b/app/models/participant.rb
index 296fd17..944d75e 100644
--- a/app/models/participant.rb
+++ b/app/models/participant.rb
@@ -52,11 +52,28 @@ class Participant < ActiveRecord::Base
:conditions => { :communities => { :id => community.id }}}}
named_scope :for_subparticipants
named_scope :itsyou, lambda { |itsyoupid| { :conditions => { :participants => { :id => itsyoupid } } } }
+ named_scope :only_subparticipants, :joins => [:subparticipant]
def self.reduced_attributes
find :all, :select => "participants.id, participants.name, participants.description, participants.email, participants.dns, participants.organization_id"
end
+ def self.mainparticipants_with_reduced_attributes
+ without_anonymous.order_id_asc.reduced_attributes - only_subparticipants.reduced_attributes
+ end
+
+ def self.subparticipants_with_reduced_attributes
+ only_subparticipants.order_id_asc.reduced_attributes
+ end
+
+ def self.without_anonymous_with_reduced_attributes
+ without_anonymous.order_id_asc.reduced_attributes
+ end
+
+ def self.anonymous_participants_with_reduced_attributes
+ anonymous.order_id_asc.reduced_attributes
+ end
+
# test if the participant is the initial sender of the message in question.
def sender?(message)
if message.sender == id