From b7c0ddb90f859276a206f5f740cadab512a2c1fc Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 19 Aug 2016 13:02:34 +0200 Subject: [PATCH] Prevent user_ids lookup for role assets (not needed in frontend - Customer role will have almost any user id in it). --- app/models/application_model.rb | 17 ++++++++++++++++- app/models/role.rb | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index ce7d837ee..8a39b67c3 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -37,7 +37,7 @@ class ApplicationModel < ActiveRecord::Base # create instance accessor class << self - attr_accessor :activity_stream_support_config, :history_support_config, :search_index_support_config + attr_accessor :activity_stream_support_config, :history_support_config, :search_index_support_config, :attributes_with_associations_support_config end attr_accessor :history_changes_last_done @@ -197,6 +197,7 @@ returns attributes = self.attributes self.class.reflect_on_all_associations.map { |assoc| real_ids = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids' + next if self.class.attributes_with_associations_support_config && self.class.attributes_with_associations_support_config[:ignore][real_ids.to_sym] == true next if !respond_to?(real_ids) attributes[real_ids] = send(real_ids) } @@ -1327,6 +1328,20 @@ delete object history, will be executed automatically =begin +serve methode to configure and attributes_with_associations support for this model + +class Model < ApplicationModel + attributes_with_associations(ignore: { user_ids: => true }) +end + +=end + + def self.attributes_with_associations_support(data = {}) + @attributes_with_associations_support_config = data + end + +=begin + get list of attachments of this object item = Model.find(123) diff --git a/app/models/role.rb b/app/models/role.rb index 42395f628..133208f4a 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -9,6 +9,7 @@ class Role < ApplicationModel before_create :validate_permissions before_update :validate_permissions + attributes_with_associations_support ignore: { user_ids: true } activity_stream_support permission: 'admin.role' notify_clients_support latest_change_support