diff options
author | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2017-03-01 22:54:51 +0100 |
---|---|---|
committer | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2017-03-01 22:54:51 +0100 |
commit | 2eb9ae7abd49aa03a19a97508d3ee5246bcd40e2 (patch) | |
tree | b144786c8d59cd60b41e6d46719eef93e921ea31 | |
parent | 441b8be1921d91717ba1ff963b6138ef61769da7 (diff) | |
download | ecs-2eb9ae7abd49aa03a19a97508d3ee5246bcd40e2.tar.gz ecs-2eb9ae7abd49aa03a19a97508d3ee5246bcd40e2.zip |
Fix order.
-rw-r--r-- | app/models/community.rb | 2 | ||||
-rw-r--r-- | app/models/event.rb | 12 | ||||
-rw-r--r-- | app/models/message.rb | 36 |
3 files changed, 25 insertions, 25 deletions
diff --git a/app/models/community.rb b/app/models/community.rb index 3005aba..19a4945 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -17,7 +17,7 @@ class Community < ActiveRecord::Base - has_many :memberships, :order => :id + has_many :memberships, -> { order 'id ASC' } has_many :participants, :through => :memberships has_many :community_messages, :dependent => :destroy has_many :messages, :through => :community_messages diff --git a/app/models/event.rb b/app/models/event.rb index 1a21133..25c8cf2 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,17 +1,17 @@ # Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). -# +# # This file is part of ECS. -# +# # ECS is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of # the License, or (at your option) any later version. -# +# # ECS is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public # License along with ECS. If not, see <http://www.gnu.org/licenses/>. @@ -30,11 +30,11 @@ private # if count <0 then list all events otherwise maximal count events scope :for_participant, lambda { |participant_id,count| { :conditions => { :participant_id => participant_id }, - :order => "id ASC", + -> { order 'id ASC' }, count<0 ? :readonly : :limit => count }} scope :for_participant_and_message_desc_order, lambda { |participant_id,message_id| { :conditions => { :participant_id => participant_id, :message_id => message_id }, - :order => "id DESC", + -> { order 'id DESC' }, :limit => 1 }} def self.make(options) diff --git a/app/models/message.rb b/app/models/message.rb index 26ba03f..6e50704 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,17 +1,17 @@ # Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). -# +# # This file is part of ECS. -# +# # ECS is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of # the License, or (at your option) any later version. -# +# # ECS is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public # License along with ECS. If not, see <http://www.gnu.org/licenses/>. @@ -31,32 +31,32 @@ class Message < ActiveRecord::Base scope :for_participant_receiver, lambda {|participant| { :joins => {:membership_messages => {:membership => :participant}}, - :order => "id ASC", + -> { order 'id ASC' }, :conditions => {:participants => {:id => participant.id}}, :readonly => false}} scope :for_participant_sender, lambda {|participant| { - :order => "id ASC", + -> { order 'id ASC' }, :conditions => {:sender => participant.id}, :readonly => false}} scope :for_not_removed, lambda { { - :order => "id ASC", + -> { order 'id ASC' }, :conditions => {:removed => false}}} scope :for_removed, lambda { { - :order => "id ASC", + -> { order 'id ASC' }, :conditions => {:removed => true}}} scope :for_resource, lambda {|namespace, name| { :joins => :ressource, - :order => "id ASC", + -> { order 'id ASC' }, :conditions => {:ressources => {:namespace => namespace, :ressource => name}}}} def self.create__(request, app_namespace, ressource_name, participant) transaction do message = create! do |arm| - arm.create_update_helper(request, app_namespace, ressource_name, participant.id) + arm.create_update_helper(request, app_namespace, ressource_name, participant.id) end MembershipMessage.extract_x_ecs_receiver_communities(request.headers["X-EcsReceiverCommunities"]).each do |cid| message.communities << Community.find(cid) @@ -124,19 +124,19 @@ class Message < ActiveRecord::Base if sender.blank? then errors.add_to_base("*** There is no \"sender\"; this is a fatal error; please report this to ecs@freeit.de. *** ") end - end + end # return first messages from fifo/lifo queue def self.fifo_lifo_rest(namespace, ressource, participant_id, options={:queue_type => :fifo}) m=find(:all, :readonly => false, :lock => true, :select => "messages.id", - :joins => [:ressource, { :membership_messages => { :membership => :participant } }], + :joins => [:ressource, { :membership_messages => { :membership => :participant } }], :conditions => { :participants => { :id => participant_id }, :ressources => { :namespace => namespace, :ressource => ressource } }, :order => :messages.to_s+".id #{(options[:queue_type]==:fifo)?'ASC':'DESC'}") if m.empty? then nil else find(m[0]) end end - + # get a record out of the message table def self.get_record(msg_id, app_namespace, ressource_name) outdated_auth_token = nil @@ -233,7 +233,7 @@ class Message < ActiveRecord::Base if (Time.parse(b["eov"]) < Time.now) or (Time.parse(b["eov"]) < Time.parse(b["sov"])) raise Ecs::InvalidMessageException, 'invalid times either in sov or eov' end - end + end b["abbr"] = participant.organization.abrev one_touch_token_hash = Digest::SHA1.hexdigest(rand.to_s+Time.now.to_s) b["hash"] = one_touch_token_hash @@ -258,15 +258,15 @@ class Message < ActiveRecord::Base end destroy_or_tag_as_removed if membership_messages.blank? and !ressource.postroute end - alias destroy_unlinked_and_not_postrouted destroy_as_receiver - + alias destroy_unlinked_and_not_postrouted destroy_as_receiver + # Delete a message and send appropriate events. It will only be "fully" # deleted when there are no references from any events otherwise it will be # tagged as deleted. def destroy_as_sender participants = Participant.for_message(self).uniq - participants.each do |participant| + participants.each do |participant| Event.make(:event_type_name => EvType.find(2).name, :participant => participant, :message => self) end if ressource.events MembershipMessage.delete_relations(self) @@ -298,7 +298,7 @@ class Message < ActiveRecord::Base !participant.sender?(self) end - # Helper function for create and update + # Helper function for create and update def create_update_helper(request, app_namespace, ressource_name, participant_id) ressource = Ressource.find_by_namespace_and_ressource(app_namespace, ressource_name) raise(Ecs::InvalidRessourceUriException, "*** ressource uri error ***") unless ressource |