summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHeiko Bernlöhr <Heiko.Bernloehr@FreeIT.de>2021-12-16 18:44:23 +0100
committerHeiko Bernlöhr <Heiko.Bernloehr@FreeIT.de>2022-09-15 09:51:34 +0200
commit8b7cb6b761741a201044be076bd75eb0e28566b9 (patch)
tree50fa91b4f89cc36a24702dd5e2e69d473454b242 /app
parent9e9bc737baab9a78f5bfa7be152ca4726508708b (diff)
downloadecs-8b7cb6b761741a201044be076bd75eb0e28566b9.tar.gz
ecs-8b7cb6b761741a201044be076bd75eb0e28566b9.zip
WIP: Rails 5
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/communities_controller.rb4
-rw-r--r--app/controllers/admin/organizations_controller.rb2
-rw-r--r--app/controllers/admin/participants_controller.rb10
-rw-r--r--app/controllers/application_controller.rb18
-rw-r--r--app/controllers/configs_controller.rb4
-rw-r--r--app/controllers/events_controller.rb6
-rw-r--r--app/controllers/memberships_controller.rb6
-rw-r--r--app/controllers/messages_controller.rb36
-rw-r--r--app/controllers/subparticipants_controller.rb14
-rw-r--r--app/middleware/content_length.rb32
-rw-r--r--app/models/application_record.rb3
-rw-r--r--app/models/auth.rb2
-rw-r--r--app/models/community.rb2
-rw-r--r--app/models/community_message.rb2
-rw-r--r--app/models/ev_type.rb2
-rw-r--r--app/models/event.rb2
-rw-r--r--app/models/identity.rb2
-rw-r--r--app/models/membership.rb4
-rw-r--r--app/models/membership_message.rb6
-rw-r--r--app/models/message.rb10
-rw-r--r--app/models/organization.rb2
-rw-r--r--app/models/participant.rb4
-rw-r--r--app/models/ressource.rb2
-rw-r--r--app/models/subparticipant.rb2
-rw-r--r--app/views/admin/participants/show.html.haml24
25 files changed, 86 insertions, 115 deletions
diff --git a/app/controllers/admin/communities_controller.rb b/app/controllers/admin/communities_controller.rb
index cb6d6d4..e44ab6a 100644
--- a/app/controllers/admin/communities_controller.rb
+++ b/app/controllers/admin/communities_controller.rb
@@ -28,7 +28,7 @@ class Admin::CommunitiesController < ApplicationController
end
def list
- @communities=Community.all.uniq
+ @communities=Community.all.distinct
end
def show
@@ -71,7 +71,7 @@ class Admin::CommunitiesController < ApplicationController
# lists all participants of the community
def index_participants
@community = Community.find(params[:id])
- @participants=Community.find(params[:id]).memberships.collect {|i| i.participant }.uniq.sort{|x,y| x.id <=> y.id }
+ @participants=Community.find(params[:id]).memberships.collect {|i| i.participant }.distinct.sort{|x,y| x.id <=> y.id }
end
# lists all those participants which has not joined the community
diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb
index e52323e..95c1e00 100644
--- a/app/controllers/admin/organizations_controller.rb
+++ b/app/controllers/admin/organizations_controller.rb
@@ -28,7 +28,7 @@ class Admin::OrganizationsController < ApplicationController
end
def list
- @organizations=Organization.all.uniq
+ @organizations=Organization.all.distinct
end
def show
diff --git a/app/controllers/admin/participants_controller.rb b/app/controllers/admin/participants_controller.rb
index e2af77e..550e904 100644
--- a/app/controllers/admin/participants_controller.rb
+++ b/app/controllers/admin/participants_controller.rb
@@ -39,15 +39,15 @@ class Admin::ParticipantsController < ApplicationController
when "true"
@list_anonymous=true
@list_participants_count = Participant.all.count
- Participant.all.uniq
+ Participant.all.distinct
when "false"
@list_anonymous=false
@list_participants_count = Participant.all.count - @list_participants_anonymous_count
- Participant.without_anonymous.uniq
+ Participant.without_anonymous.distinct
else
@list_anonymous=false
@list_participants_count = Participant.all.count - @list_participants_anonymous_count
- Participant.without_anonymous.uniq
+ Participant.without_anonymous.distinct
end
@action_buttons = case params[:actionbuttons]
when "true"
@@ -118,7 +118,7 @@ class Admin::ParticipantsController < ApplicationController
def index_communities
@participant = Participant.find(params[:id])
- @communities=Participant.find(params[:id]).memberships.collect {|i| i.community }.uniq.sort{|x,y| x.id <=> y.id }
+ @communities=Participant.find(params[:id]).memberships.collect {|i| i.community }.distinct.sort{|x,y| x.id <=> y.id }
end
# lists all those communities which the participant has not yet joined
@@ -168,7 +168,7 @@ private
leaved_messages << Membership.find_by_participant_id_and_community_id(participant.id, cid).messages
leaved_messages << Community.find(cid).messages
end
- leaved_messages.flatten.compact.uniq
+ leaved_messages.flatten.compact.distinct
end
def participant_params
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 131b504..a2798c3 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -185,50 +185,50 @@ protected
def rescue_body_401
@http_error= $!
logger.error $!.to_s
- render :text => "#{$!.to_s}\n", :layout => false, :status => 401
+ render :plain => "#{$!.to_s}\n", :layout => false, :status => 401
end
def rescue_body_500
@http_error= $!
logger.error $!.to_s
- render :text => "#{$!.to_s}\n", :layout => false, :status => 500
+ render :plain => "#{$!.to_s}\n", :layout => false, :status => 500
end
def rescue_body_400
@http_error= $!
logger.error $!.to_s
- render :text => "#{$!.to_s}\n" , :layout => false, :status => 400
+ render :plain => "#{$!.to_s}\n" , :layout => false, :status => 400
end
def rescue_body_403
@http_error= $!
logger.error $!.to_s
- render :text => "#{$!.to_s}\n" , :layout => false, :status => 403
+ render :plain => "#{$!.to_s}\n" , :layout => false, :status => 403
end
def rescue_body_404
@http_error= $!
logger.error $!.to_s
if $!.to_s.blank?
- render :text => "The server does not know the ressource\nor the message queue in question is empty.\n" , :layout => false, :status => 404
+ render :plain => "The server does not know the ressource\nor the message queue in question is empty.\n" , :layout => false, :status => 404
else
- render :text => "#{$!.to_s}\n" , :layout => false, :status => 404
+ render :plain => "#{$!.to_s}\n" , :layout => false, :status => 404
end
end
def rescue_body_409
@http_error= $!
logger.error $!.to_s
- render :text => "#{$!.to_s}\n" , :layout => false, :status => 409
+ render :plain => "#{$!.to_s}\n" , :layout => false, :status => 409
end
def rescue_body_415(controller_binding)
@http_error= $!
logger.error $!.to_s
if $!.to_s.blank?
- render :text => "The format of the client data is not supported by the server.\nIf your format is right please doublecheck the encoding !\nIt has to be UTF8 !\n", :layout => false, :status => 415
+ render :plain => "The format of the client data is not supported by the server.\nIf your format is right please doublecheck the encoding !\nIt has to be UTF8 !\n", :layout => false, :status => 415
else
- render :text => "#{$!.to_s}\n" , :layout => false, :status => 415
+ render :plain => "#{$!.to_s}\n" , :layout => false, :status => 415
end
end
diff --git a/app/controllers/configs_controller.rb b/app/controllers/configs_controller.rb
index 5a62379..8acf048 100644
--- a/app/controllers/configs_controller.rb
+++ b/app/controllers/configs_controller.rb
@@ -1,7 +1,7 @@
class ConfigsController < ApplicationController
- before_filter :authentication
- before_filter :add_cookie_header # only for anonymous participants
+ before_action :authentication
+ before_action :add_cookie_header # only for anonymous participants
def initialize
super
diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb
index c151f6b..02f97aa 100644
--- a/app/controllers/events_controller.rb
+++ b/app/controllers/events_controller.rb
@@ -18,8 +18,8 @@
class EventsController < ApplicationController
- before_filter :authentication
- before_filter :add_cookie_header # only for anonymous participants
+ before_action :authentication
+ before_action :add_cookie_header # only for anonymous participants
def initialize
super
@@ -70,7 +70,7 @@ private
respond_to do |format|
format.json { render :json => JSON.pretty_generate(events) }
format.xml { render :xml => events }
- format.text { render :text => events_render_txt(events) }
+ format.text { render :plain => events_render_txt(events) }
end
end
diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb
index fa73ae0..42f6578 100644
--- a/app/controllers/memberships_controller.rb
+++ b/app/controllers/memberships_controller.rb
@@ -18,8 +18,8 @@
class MembershipsController < ApplicationController
- before_filter :authentication
- before_filter :add_cookie_header # only for anonymous participants
+ before_action :authentication
+ before_action :add_cookie_header # only for anonymous participants
def initialize
super
@@ -28,7 +28,7 @@ class MembershipsController < ApplicationController
def index
memberships= index_querystring_list
if memberships.empty?
- render :text => "", :content_type => "application/json", :layout => false
+ render :plain => "", :content_type => "application/json", :layout => false
else
respond_to do |format|
format.json { render :json => JSON.pretty_generate(memberships) }
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 2bb9b05..d87065d 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -18,11 +18,11 @@
class MessagesController < ApplicationController
- before_filter :late_initialize
- before_filter :authentication
- before_filter :add_cookie_header
- before_filter :get_record, :only => [:show, :update, :destroy]
- after_filter :touch_participant_ttl
+ before_action :late_initialize
+ before_action :authentication
+ before_action :add_cookie_header
+ before_action :get_record, :only => [:show, :update, :destroy]
+ after_action :touch_participant_ttl
def initialize
super
@@ -110,7 +110,7 @@ class MessagesController < ApplicationController
if details.empty? then no_data_to_render = true end
end
if no_data_to_render
- render :text => "", :content_type => "application/json", :layout => false
+ render :plain => "", :content_type => "application/json", :layout => false
else
respond_to do |format|
format.json { render :json => JSON.pretty_generate(details) }
@@ -160,15 +160,15 @@ protected
all ||= params["all"] ? params["all"] : nil
case
when sender == "true"
- @list = Message.for_participant_sender(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.uniq
+ @list = Message.for_participant_sender(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.distinct.to_a
when receiver == "true"
- @list = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.uniq
+ @list = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.distinct.to_a
when all == "true"
list1 = Message.for_participant_sender(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed
list2 = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed
- @list = list1.concat(list2).uniq
+ @list = list1.to_a.concat(list2.to_a).uniq
else
- @list = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.uniq
+ @list = Message.for_participant_receiver(@participant).for_resource(@app_namespace,@ressource_name).for_not_removed.distinct
end
end
@@ -216,11 +216,11 @@ protected
end
def empty_render
- render :text => "", :content_type => "application/json"
+ render :plain => "", :content_type => "application/json"
end
def index_render
- render :text => @body, :content_type => "text/uri-list"
+ render plain: @body, :content_type => "text/uri-list"
end
def show_render
@@ -238,7 +238,7 @@ protected
end unless @memberships.blank?
headers["X-EcsReceiverCommunities"]= x_ecs_receiver_communities unless x_ecs_receiver_communities.blank?
headers["X-EcsSender"]= x_ecs_sender unless x_ecs_sender.blank?
- @render_cmd='render :text => @body, :layout => false, :status => 200, :content_type => Mime::Type.lookup(@record.content_type)'
+ @render_cmd='render plain: @body, :layout => false, :status => 200, :content_type => Mime::Type.lookup(@record.content_type)'
end
def create_render
@@ -249,9 +249,9 @@ protected
location += request.path.gsub(/\/*$/,'') + "/" + @record.id.to_s
logger.info "Location: #{location}"
if @app_namespace == 'sys' and @ressource_name == 'auths'
- render :text => @body, :layout => false, :status => 201, :location => location, :content_type => Mime::Type.lookup_by_extension("json")
+ render plain: @body, :layout => false, :status => 201, :location => location, :content_type => Mime::Type.lookup_by_extension("json")
else
- render :text => "", :layout => false, :status => 201, :location => location, :content_type => Mime::Type.lookup(@record.content_type)
+ render plain: "", :layout => false, :status => 201, :location => location, :content_type => Mime::Type.lookup(@record.content_type)
end
end
@@ -259,13 +259,13 @@ protected
location = request.protocol + request.host
location += request.headers["SCRIPT_NAME"] if request.headers["SCRIPT_NAME"]
location += request.path.gsub(/\/*$/,'')
- render :text => "", :layout => false, :status => 200,
+ render plain: "", :layout => false, :status => 200,
:location => location
end
def destroy_render
- render :nothing => true, :layout => false, :status => 200,
- :content_type => "application/json"
+ render plain: "", :layout => false, :status => 200,
+ :location => location
end
end
diff --git a/app/controllers/subparticipants_controller.rb b/app/controllers/subparticipants_controller.rb
index 3d585ae..62df87b 100644
--- a/app/controllers/subparticipants_controller.rb
+++ b/app/controllers/subparticipants_controller.rb
@@ -17,11 +17,11 @@
class SubparticipantsController < ApplicationController
- before_filter :authentication
- before_filter :block_anonymous_participants
- before_filter :block_subparticipants
- before_filter :check_json_contenttype, :only => :create
- before_filter :check_parent, :only => [:show, :destroy, :update]
+ before_action :authentication
+ before_action :block_anonymous_participants
+ before_action :block_subparticipants
+ before_action :check_json_contenttype, :only => :create
+ before_action :check_parent, :only => [:show, :destroy, :update]
def initialize
super
@@ -33,7 +33,7 @@ class SubparticipantsController < ApplicationController
@body << "subparticipants/" << child.id.to_s << "\n"
end unless childs.empty?
respond_to do |format|
- format.text { render :text => @body, :content_type => "text/uri-list" }
+ format.text { render :plain => @body, :content_type => "text/uri-list" }
end
end
@@ -79,7 +79,7 @@ class SubparticipantsController < ApplicationController
def destroy
subparticipant= Subparticipant.find(params[:id])
subparticipant.participant.destroy
- render :text => "", :layout => false, :status => 200, :content_type => :json
+ render :plain => "", :layout => false, :status => 200, :content_type => :json
end
private
diff --git a/app/middleware/content_length.rb b/app/middleware/content_length.rb
deleted file mode 100644
index fa51160..0000000
--- a/app/middleware/content_length.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require 'rack/utils'
-
-class ContentLength
-
- include Rack::Utils
-
- def initialize app
- @app = app
- end
-
- def call env
- status, headers, body = @app.call(env)
- headers = HeaderHash.new(headers)
- if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
- !headers['Content-Length'] &&
- !headers['Transfer-Encoding']
-
- #see https://stackoverflow.com/questions/26534165/unable-to-get-content-length-header-working-under-rails-4-1puma
- #see https://github.com/rails/rails/pull/16793
- #&& body.respond_to?(:to_ary)
-
- obody = body
- body, length = [], 0
- obody.each { |part| body << part; length += bytesize(part) }
- obody.close if obody.respond_to?(:close)
-
- headers['Content-Length'] = length.to_s
- end
- [status, headers, body]
- end
-
-end
diff --git a/app/models/application_record.rb b/app/models/application_record.rb
new file mode 100644
index 0000000..10a4cba
--- /dev/null
+++ b/app/models/application_record.rb
@@ -0,0 +1,3 @@
+class ApplicationRecord < ActiveRecord::Base
+ self.abstract_class = true
+end
diff --git a/app/models/auth.rb b/app/models/auth.rb
index 1ac5c3c..e32634e 100644
--- a/app/models/auth.rb
+++ b/app/models/auth.rb
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Auth < ActiveRecord::Base
+class Auth < ApplicationRecord
belongs_to :message
#scope :hash, lambda {|hash| {
diff --git a/app/models/community.rb b/app/models/community.rb
index 27a34b2..33800d8 100644
--- a/app/models/community.rb
+++ b/app/models/community.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Community < ActiveRecord::Base
+class Community < ApplicationRecord
has_many :memberships, -> { order 'memberships.id ASC' }
has_many :participants, :through => :memberships
has_many :community_messages, :dependent => :destroy
diff --git a/app/models/community_message.rb b/app/models/community_message.rb
index 1f7b1f3..8832aac 100644
--- a/app/models/community_message.rb
+++ b/app/models/community_message.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class CommunityMessage < ActiveRecord::Base
+class CommunityMessage < ApplicationRecord
belongs_to :message
belongs_to :community
end
diff --git a/app/models/ev_type.rb b/app/models/ev_type.rb
index f701793..c29827f 100644
--- a/app/models/ev_type.rb
+++ b/app/models/ev_type.rb
@@ -16,6 +16,6 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class EvType < ActiveRecord::Base
+class EvType < ApplicationRecord
has_many :events
end
diff --git a/app/models/event.rb b/app/models/event.rb
index 126048d..504ca6d 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Event < ActiveRecord::Base
+class Event < ApplicationRecord
belongs_to :ev_type
belongs_to :participant
belongs_to :message
diff --git a/app/models/identity.rb b/app/models/identity.rb
index b8b0e91..a187e3c 100644
--- a/app/models/identity.rb
+++ b/app/models/identity.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Identity < ActiveRecord::Base
+class Identity < ApplicationRecord
require 'securerandom'
diff --git a/app/models/membership.rb b/app/models/membership.rb
index 6c0b4d3..42371de 100644
--- a/app/models/membership.rb
+++ b/app/models/membership.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Membership < ActiveRecord::Base
+class Membership < ApplicationRecord
belongs_to :participant
belongs_to :community
belongs_to :community_with_reduced_attributes,
@@ -49,7 +49,7 @@ class Membership < ActiveRecord::Base
def self.senders(participant, message)
sender_mids=[]
- Community.for_participant(participant).for_message(message).uniq.each do |comm|
+ Community.for_participant(participant).for_message(message).distinct.each do |comm|
sender_mids << Membership.find_by_participant_id_and_community_id(participant.id,comm.id)
end
if sender_mids.empty?
diff --git a/app/models/membership_message.rb b/app/models/membership_message.rb
index b62da0a..a8b7c74 100644
--- a/app/models/membership_message.rb
+++ b/app/models/membership_message.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class MembershipMessage < ActiveRecord::Base
+class MembershipMessage < ApplicationRecord
belongs_to :membership
belongs_to :message
@@ -116,10 +116,10 @@ private
def self.delete_relations(message, memberships=nil)
if memberships
memberships.each do |m|
- destroy_all ["membership_id = ? and message_id = ?", m.id, message.id]
+ where(["membership_id = ? and message_id = ?", m.id, message.id]).destroy_all
end
else
- destroy_all ["message_id = ?", message.id]
+ where(["message_id = ?", message.id]).destroy_all
end
end
diff --git a/app/models/message.rb b/app/models/message.rb
index 67d87f6..922cae2 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Message < ActiveRecord::Base
+class Message < ApplicationRecord
require 'exceptions'
@@ -64,7 +64,7 @@ class Message < ActiveRecord::Base
request.headers["X-EcsReceiverMemberships"],
request.headers["X-EcsReceiverCommunities"],
participant)
- Participant.for_message(message).uniq.each do |p|
+ Participant.for_message(message).distinct.each do |p|
Event.make(:event_type_name => EvType.find(1).name, :participant => p, :message => message)
end if message.ressource.events
if app_namespace == 'sys' and ressource_name == 'auths'
@@ -90,14 +90,14 @@ class Message < ActiveRecord::Base
# by converting ActiveRecord::Relation to an array of Model-Objects. We could
# have done this # also by calling #load!, but would have get back still an
# ActiveRecord::Relation, which works also.
- receivers_old = Participant.for_message(self).uniq.to_a
+ receivers_old = Participant.for_message(self).distinct.to_a
#puts "*** receivers_old: #{receivers_old.inspect}"
MembershipMessage.de_populate_jointable(self)
MembershipMessage.populate_jointable(self,
request.headers["X-EcsReceiverMemberships"],
request.headers["X-EcsReceiverCommunities"],
participant)
- receivers_new = Participant.for_message(self).uniq.to_a
+ receivers_new = Participant.for_message(self).distinct.to_a
# TODO: if there are only the headers X-EcsReceiverMemberships and
# X-EcsReceiverCommunities are updated, then we have to generate events only
# for these new and removed receivers. To distinguish if the message body
@@ -273,7 +273,7 @@ class Message < ActiveRecord::Base
# 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 = Participant.for_message(self).distinct
participants.each do |participant|
Event.make(:event_type_name => EvType.find(2).name, :participant => participant, :message => self)
end if ressource.events
diff --git a/app/models/organization.rb b/app/models/organization.rb
index 2fcbb3c..28c6d92 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Organization < ActiveRecord::Base
+class Organization < ApplicationRecord
# TODO: warn the user about possible deletions of participants.
has_many :participants, :dependent => :destroy
diff --git a/app/models/participant.rb b/app/models/participant.rb
index 205bd2c..dff6160 100644
--- a/app/models/participant.rb
+++ b/app/models/participant.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Participant < ActiveRecord::Base
+class Participant < ApplicationRecord
TTL = 1.hour # how long an anonymous participant lives
TYPE={ :main => "main", :sub => "sub", :anonym => "anonym" }
@@ -162,7 +162,7 @@ class Participant < ActiveRecord::Base
private
def delete_messages
- Message.destroy_all(["sender = ?", self.id])
+ Message.where(["sender = ?", self.id]).destroy_all
end
end
diff --git a/app/models/ressource.rb b/app/models/ressource.rb
index 26f656a..82a5799 100644
--- a/app/models/ressource.rb
+++ b/app/models/ressource.rb
@@ -16,7 +16,7 @@
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Ressource < ActiveRecord::Base
+class Ressource < ApplicationRecord
# TODO prevent invalid namespace and ressource strings.
has_many :messages, :dependent => :destroy
validates_presence_of :namespace, :ressource
diff --git a/app/models/subparticipant.rb b/app/models/subparticipant.rb
index 2efc504..825b5e1 100644
--- a/app/models/subparticipant.rb
+++ b/app/models/subparticipant.rb
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-class Subparticipant < ActiveRecord::Base
+class Subparticipant < ApplicationRecord
TTL = 3600 # seconds, how long a subparticipant lives, after last
# communication with ECS
diff --git a/app/views/admin/participants/show.html.haml b/app/views/admin/participants/show.html.haml
index d230446..033175d 100644
--- a/app/views/admin/participants/show.html.haml
+++ b/app/views/admin/participants/show.html.haml
@@ -99,12 +99,12 @@
- eventsm = 10
-- events_count = Event.for_participant(@participant,-1).uniq.count
+- events_count = Event.for_participant(@participant,-1).distinct.count
- if events_count < eventsm or events_count < 5
- - events_first = Event.for_participant(@participant,-1).uniq
+ - events_first = Event.for_participant(@participant,-1).distinct
-else
- - events_first = Event.for_participant(@participant,-1).uniq.limit(eventsm/2)
- - events_last = Event.for_participant(@participant,-1).uniq.limit(eventsm/2).offset(events_count-(eventsm/2))
+ - events_first = Event.for_participant(@participant,-1).distinct.limit(eventsm/2)
+ - events_last = Event.for_participant(@participant,-1).distinct.limit(eventsm/2).offset(events_count-(eventsm/2))
- events_diff = events_last - events_first
- unless events_first.blank?
%p
@@ -143,12 +143,12 @@
- msgsm = 10
-- messages_count = Message.for_participant_receiver(@participant).for_not_removed.uniq.count
+- messages_count = Message.for_participant_receiver(@participant).for_not_removed.distinct.count
- if messages_count < msgsm or messages_count < 5
- - messages_first = Message.for_participant_receiver(@participant).for_not_removed.uniq
+ - messages_first = Message.for_participant_receiver(@participant).for_not_removed.distinct
-else
- - messages_first = Message.for_participant_receiver(@participant).for_not_removed.uniq.limit(msgsm/2)
- - messages_last = Message.for_participant_receiver(@participant).for_not_removed.uniq.limit(msgsm/2).offset(messages_count-(msgsm/2))
+ - messages_first = Message.for_participant_receiver(@participant).for_not_removed.distinct.limit(msgsm/2)
+ - messages_last = Message.for_participant_receiver(@participant).for_not_removed.distinct.limit(msgsm/2).offset(messages_count-(msgsm/2))
- messages_diff = messages_last - messages_first
- unless messages_first.blank?
%p
@@ -187,12 +187,12 @@
- msgsm = 10
-- messages_count = Message.for_participant_sender(@participant).for_not_removed.uniq.count
+- messages_count = Message.for_participant_sender(@participant).for_not_removed.distinct.count
- if messages_count < msgsm or messages_count < 5
- - messages_first = Message.for_participant_sender(@participant).for_not_removed.uniq
+ - messages_first = Message.for_participant_sender(@participant).for_not_removed.distinct
-else
- - messages_first = Message.for_participant_sender(@participant).for_not_removed.uniq.limit(msgsm/2)
- - messages_last = Message.for_participant_sender(@participant).for_not_removed.uniq.limit(msgsm/2).offset(messages_count-(msgsm/2))
+ - messages_first = Message.for_participant_sender(@participant).for_not_removed.distinct.limit(msgsm/2)
+ - messages_last = Message.for_participant_sender(@participant).for_not_removed.distinct.limit(msgsm/2).offset(messages_count-(msgsm/2))
- messages_diff = messages_last - messages_first
- unless messages_first.blank?
%p