From 33777c2bab996d029065548330ad000890c0819a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 8 Mar 2016 07:32:58 +0100 Subject: [PATCH] Code cleanup. --- app/models/application_model.rb | 37 +++++++++++-------- .../application_model/history_log_base.rb | 14 +++---- .../application_model/search_index_base.rb | 7 ++-- app/models/authorization.rb | 4 +- app/models/avatar.rb | 12 +++--- .../ticket/article/communicate_email.rb | 6 +-- .../ticket/article/fillup_from_email.rb | 10 ++--- .../ticket/article/signature_detection.rb | 6 +-- app/models/observer/ticket/close_time.rb | 4 +- app/models/observer/ticket/notification.rb | 6 +-- .../ticket/notification/background_job.rb | 10 ++--- .../ticket/online_notification_seen.rb | 2 +- app/models/observer/ticket/reset_new_state.rb | 8 ++-- .../user_ticket_counter/background_job.rb | 6 +-- app/models/observer/user/geo.rb | 6 +-- app/models/observer/user/ref_object_touch.rb | 2 +- .../observer/user/ticket_organization.rb | 2 +- app/models/organization/assets.rb | 2 +- app/models/organization/permission.rb | 2 +- app/models/organization/search_index.rb | 9 +++-- app/models/user.rb | 3 +- app/models/user/assets.rb | 22 ++++++----- app/models/user/permission.rb | 2 +- app/models/user/search.rb | 2 +- 24 files changed, 99 insertions(+), 85 deletions(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 92731b4f2..cc52f1aca 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -47,7 +47,7 @@ class ApplicationModel < ActiveRecord::Base # do noting, use id as it is return if !Setting.get('system_init_done') - return if Setting.get('import_mode') && import_class_list.include?( self.class.to_s ) + return if Setting.get('import_mode') && import_class_list.include?(self.class.to_s) self[:id] = nil end @@ -589,7 +589,7 @@ returns def self.latest_change key = "#{new.class.name}_latest_change" - updated_at = Cache.get( key ) + updated_at = Cache.get(key) # if we do not have it cached, do lookup if !updated_at @@ -739,11 +739,13 @@ class OwnModel < ApplicationModel serve methode to configure and enable search index support for this model class Model < ApplicationModel - search_index_support ignore_attributes: { - create_article_type_id: true, - create_article_sender_id: true, - article_count: true, - } + search_index_support + ignore_attributes: { + create_article_type_id: true, + create_article_sender_id: true, + article_count: true, + }, + ignore_ids: [1,2,4] end @@ -763,11 +765,13 @@ update search index, if configured - will be executed automatically =end def search_index_update - return if !self.class.search_index_support_config + config = self.class.search_index_support_config + return if !config + return if config[:ignore_ids] && config[:ignore_ids].include?(id) # start background job to transfer data to search index return if !SearchIndexBackend.enabled? - Delayed::Job.enqueue( ApplicationModel::BackgroundJobSearchIndex.new( self.class.to_s, id ) ) + Delayed::Job.enqueue(ApplicationModel::BackgroundJobSearchIndex.new(self.class.to_s, id)) end =begin @@ -780,7 +784,10 @@ delete search index object, will be executed automatically =end def search_index_destroy - return if !self.class.search_index_support_config + config = self.class.search_index_support_config + return if !config + return if config[:ignore_ids] && config[:ignore_ids].include?(id) + SearchIndexBackend.remove(self.class.to_s, id) end @@ -796,7 +803,7 @@ reload search index with full data return if !@search_index_support_config all_ids = select('id').all.order('created_at DESC') all_ids.each { |item_with_id| - item = find( item_with_id.id ) + item = find(item_with_id.id) item.search_index_update_backend } end @@ -979,10 +986,10 @@ log object update history with all updated attributes, if configured - will be e value_id[0] = value[0] value_id[1] = value[1] - if respond_to?( attribute_name ) && send(attribute_name) + if respond_to?(attribute_name) && send(attribute_name) relation_class = send(attribute_name).class if relation_class && value_id[0] - relation_model = relation_class.lookup( id: value_id[0] ) + relation_model = relation_class.lookup(id: value_id[0]) if relation_model if relation_model['name'] value_str[0] = relation_model['name'] @@ -992,7 +999,7 @@ log object update history with all updated attributes, if configured - will be e end end if relation_class && value_id[1] - relation_model = relation_class.lookup( id: value_id[1] ) + relation_model = relation_class.lookup(id: value_id[1]) if relation_model if relation_model['name'] value_str[1] = relation_model['name'] @@ -1059,7 +1066,7 @@ store attachments for this object self.attachments_buffer = attachments # update if object already exists - return if !( id && id != 0 ) + return if !(id && id != 0) attachments_buffer_check end diff --git a/app/models/application_model/history_log_base.rb b/app/models/application_model/history_log_base.rb index e3cc06ce2..1e6f6df69 100644 --- a/app/models/application_model/history_log_base.rb +++ b/app/models/application_model/history_log_base.rb @@ -6,7 +6,7 @@ module ApplicationModel::HistoryLogBase create history entry for this object organization = Organization.find(123) - result = organization.history_log( 'created', user_id ) + result = organization.history_log('created', user_id) returns @@ -77,19 +77,19 @@ returns def history_get(fulldata = false) if !fulldata - return History.list( self.class.name, self['id'] ) + return History.list(self.class.name, self['id']) end # get related objects - history = History.list( self.class.name, self['id'], nil, true ) + history = History.list(self.class.name, self['id'], nil, true) history[:list].each {|item| - record = Kernel.const_get( item['object'] ).find( item['o_id'] ) + record = Kernel.const_get(item['object']).find(item['o_id']) - history[:assets] = record.assets( history[:assets] ) + history[:assets] = record.assets(history[:assets]) if item['related_object'] - record = Kernel.const_get( item['related_object'] ).find( item['related_o_id'] ) - history[:assets] = record.assets( history[:assets] ) + record = Kernel.const_get(item['related_object']).find(item['related_o_id']) + history[:assets] = record.assets(history[:assets]) end } { diff --git a/app/models/application_model/search_index_base.rb b/app/models/application_model/search_index_base.rb index 197f003d9..e3d501b79 100644 --- a/app/models/application_model/search_index_base.rb +++ b/app/models/application_model/search_index_base.rb @@ -74,7 +74,8 @@ returns lookup name of ref. objects - attributes = search_index_attribute_lookup(attributes, Ticket) + ticket = Ticket.find(123) + attributes = ticket.search_index_attribute_lookup(attributes, Ticket) returns @@ -95,14 +96,14 @@ returns attribute_name = attribute_name[ 0, attribute_name.length - 3 ] # check if attribute method exists - next if !ref_object.respond_to?( attribute_name ) + next if !ref_object.respond_to?(attribute_name) # check if method has own class relation_class = ref_object.send(attribute_name).class next if !relation_class # lookup ref object - relation_model = relation_class.lookup( id: value ) + relation_model = relation_class.lookup(id: value) next if !relation_model # get name of ref object diff --git a/app/models/authorization.rb b/app/models/authorization.rb index 94cde865c..c741bcd1d 100644 --- a/app/models/authorization.rb +++ b/app/models/authorization.rb @@ -10,7 +10,7 @@ class Authorization < ApplicationModel validates :provider, presence: true def self.find_from_hash(hash) - auth = Authorization.find_by( provider: hash['provider'], uid: hash['uid'] ) + auth = Authorization.find_by(provider: hash['provider'], uid: hash['uid']) if auth # update auth tokens @@ -28,7 +28,7 @@ class Authorization < ApplicationModel # update image if needed if hash['info']['image'] - user = User.find( auth.user_id ) + user = User.find(auth.user_id) # save/update avatar avatar = Avatar.add( diff --git a/app/models/avatar.rb b/app/models/avatar.rb index 23c07c0f3..1615877b6 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -62,7 +62,7 @@ add a avatar # lookups if data[:object] - object_id = ObjectLookup.by_name( data[:object] ) + object_id = ObjectLookup.by_name(data[:object]) end # add initial avatar @@ -159,7 +159,7 @@ add a avatar end # check if avatar need to be updated - record[:store_hash] = Digest::MD5.hexdigest( data[:resize][:content] ) + record[:store_hash] = Digest::MD5.hexdigest(data[:resize][:content]) if avatar_already_exists && avatar_already_exists.store_hash == record[:store_hash] avatar_already_exists.touch return @@ -179,7 +179,7 @@ add a avatar created_by_id: data[:created_by_id], ) record[:store_full_id] = store_full.id - record[:store_hash] = Digest::MD5.hexdigest( data[:full][:content] ) + record[:store_hash] = Digest::MD5.hexdigest(data[:full][:content]) end if data[:resize] store_resize = Store.add( @@ -193,7 +193,7 @@ add a avatar created_by_id: data[:created_by_id], ) record[:store_resize_id] = store_resize.id - record[:store_hash] = Digest::MD5.hexdigest( data[:resize][:content] ) + record[:store_hash] = Digest::MD5.hexdigest(data[:resize][:content] ) end # update existing @@ -218,8 +218,8 @@ set avatars as default =end - def self.set_default( object_name, o_id, avatar_id ) - object_id = ObjectLookup.by_name( object_name ) + def self.set_default(object_name, o_id, avatar_id) + object_id = ObjectLookup.by_name(object_name) avatar = Avatar.find_by( object_lookup_id: object_id, o_id: o_id, diff --git a/app/models/observer/ticket/article/communicate_email.rb b/app/models/observer/ticket/article/communicate_email.rb index b2efb34fd..10a383eb6 100644 --- a/app/models/observer/ticket/article/communicate_email.rb +++ b/app/models/observer/ticket/article/communicate_email.rb @@ -9,15 +9,15 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer return if Setting.get('import_mode') # if sender is customer, do not communication - sender = Ticket::Article::Sender.lookup( id: record.sender_id ) + sender = Ticket::Article::Sender.lookup(id: record.sender_id) return 1 if sender.nil? return 1 if sender['name'] == 'Customer' # only apply on emails - type = Ticket::Article::Type.lookup( id: record.type_id ) + type = Ticket::Article::Type.lookup(id: record.type_id) return if type['name'] != 'email' # send background job - Delayed::Job.enqueue( Observer::Ticket::Article::CommunicateEmail::BackgroundJob.new( record.id ) ) + Delayed::Job.enqueue(Observer::Ticket::Article::CommunicateEmail::BackgroundJob.new(record.id)) end end diff --git a/app/models/observer/ticket/article/fillup_from_email.rb b/app/models/observer/ticket/article/fillup_from_email.rb index 5a75064c9..01f4927ea 100644 --- a/app/models/observer/ticket/article/fillup_from_email.rb +++ b/app/models/observer/ticket/article/fillup_from_email.rb @@ -9,22 +9,22 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer return if Setting.get('import_mode') # if sender is customer, do not change anything - sender = Ticket::Article::Sender.lookup( id: record.sender_id ) + sender = Ticket::Article::Sender.lookup(id: record.sender_id) return if sender.nil? return if sender['name'] == 'Customer' # set email attributes - type = Ticket::Article::Type.lookup( id: record.type_id ) + type = Ticket::Article::Type.lookup(id: record.type_id) return if type['name'] != 'email' # set subject if empty - ticket = Ticket.lookup( id: record.ticket_id ) + ticket = Ticket.lookup(id: record.ticket_id) if !record.subject || record.subject == '' record.subject = ticket.title end # clean subject - record.subject = ticket.subject_clean( record.subject ) + record.subject = ticket.subject_clean(record.subject) # generate message id, force it in prodution, in test allow to set it for testing reasons if !record.message_id || Rails.env.production? @@ -43,7 +43,7 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer system_sender = "#{email_address.realname} <#{email_address.email}>" if Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName' seperator = Setting.get('ticket_define_email_from_seperator') - sender = User.find( record.created_by_id ) + sender = User.find(record.created_by_id) record.from = "#{sender.firstname} #{sender.lastname} #{seperator} #{system_sender}" else record.from = system_sender diff --git a/app/models/observer/ticket/article/signature_detection.rb b/app/models/observer/ticket/article/signature_detection.rb index f07839eab..a3b520215 100644 --- a/app/models/observer/ticket/article/signature_detection.rb +++ b/app/models/observer/ticket/article/signature_detection.rb @@ -11,16 +11,16 @@ class Observer::Ticket::Article::SignatureDetection < ActiveRecord::Observer return if Setting.get('import_mode') # if sender is not customer, do not change anything - sender = Ticket::Article::Sender.lookup( id: record.sender_id ) + sender = Ticket::Article::Sender.lookup(id: record.sender_id) return if !sender return if sender['name'] != 'Customer' # set email attributes - type = Ticket::Article::Type.lookup( id: record.type_id ) + type = Ticket::Article::Type.lookup(id: record.type_id) return if type['name'] != 'email' # add queue job to update current signature of user id - Delayed::Job.enqueue( Observer::Ticket::Article::SignatureDetection::BackgroundJob.new( record.created_by_id ) ) + Delayed::Job.enqueue(Observer::Ticket::Article::SignatureDetection::BackgroundJob.new(record.created_by_id)) # user user = User.lookup(id: record.created_by_id) diff --git a/app/models/observer/ticket/close_time.rb b/app/models/observer/ticket/close_time.rb index 2e6806fba..f2d8a0213 100644 --- a/app/models/observer/ticket/close_time.rb +++ b/app/models/observer/ticket/close_time.rb @@ -22,8 +22,8 @@ class Observer::Ticket::CloseTime < ActiveRecord::Observer return true if record.close_time # check if ticket is closed now - state = Ticket::State.lookup( id: record.state_id ) - state_type = Ticket::StateType.lookup( id: state.state_type_id ) + state = Ticket::State.lookup(id: record.state_id) + state_type = Ticket::StateType.lookup(id: state.state_type_id) return true if state_type.name != 'closed' # set close_time diff --git a/app/models/observer/ticket/notification.rb b/app/models/observer/ticket/notification.rb index 5cecc0dd8..4c8611990 100644 --- a/app/models/observer/ticket/notification.rb +++ b/app/models/observer/ticket/notification.rb @@ -27,7 +27,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer list_objects.each {|_ticket_id, item| # send background job - Delayed::Job.enqueue( Observer::Ticket::Notification::BackgroundJob.new( item, via_web ) ) + Delayed::Job.enqueue(Observer::Ticket::Notification::BackgroundJob.new(item, via_web)) } end @@ -59,7 +59,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer # get current state of objects if event[:name] == 'Ticket::Article' - article = Ticket::Article.lookup( id: event[:id] ) + article = Ticket::Article.lookup(id: event[:id]) # next if article is already deleted next if !article @@ -76,7 +76,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer end elsif event[:name] == 'Ticket' - ticket = Ticket.lookup( id: event[:id] ) + ticket = Ticket.lookup(id: event[:id]) # next if ticket is already deleted next if !ticket diff --git a/app/models/observer/ticket/notification/background_job.rb b/app/models/observer/ticket/notification/background_job.rb index 7f3cea77d..f116fad4c 100644 --- a/app/models/observer/ticket/notification/background_job.rb +++ b/app/models/observer/ticket/notification/background_job.rb @@ -83,7 +83,7 @@ class Observer::Ticket::Notification::BackgroundJob # ignore if no changes has been done changes = human_changes(user, ticket) - next if @p[:type] == 'update' && !article && ( !changes || changes.empty? ) + next if @p[:type] == 'update' && !article && (!changes || changes.empty?) # check if today already notified if @p[:type] == 'reminder_reached' || @p[:type] == 'escalation' || @p[:type] == 'escalation_warning' @@ -241,10 +241,10 @@ class Observer::Ticket::Notification::BackgroundJob value_id[0] = value[0] value_id[1] = value[1] - if record.respond_to?( attribute_name ) && record.send(attribute_name) + if record.respond_to?(attribute_name) && record.send(attribute_name) relation_class = record.send(attribute_name).class if relation_class && value_id[0] - relation_model = relation_class.lookup( id: value_id[0] ) + relation_model = relation_class.lookup(id: value_id[0]) if relation_model if relation_model['name'] value_str[0] = relation_model['name'] @@ -254,7 +254,7 @@ class Observer::Ticket::Notification::BackgroundJob end end if relation_class && value_id[1] - relation_model = relation_class.lookup( id: value_id[1] ) + relation_model = relation_class.lookup(id: value_id[1]) if relation_model if relation_model['name'] value_str[1] = relation_model['name'] @@ -271,7 +271,7 @@ class Observer::Ticket::Notification::BackgroundJob if object_manager_attribute && object_manager_attribute[:display] # delete old key - changes.delete( display ) + changes.delete(display) # set new key display = object_manager_attribute[:display].to_s diff --git a/app/models/observer/ticket/online_notification_seen.rb b/app/models/observer/ticket/online_notification_seen.rb index 9196bac21..c071fbd41 100644 --- a/app/models/observer/ticket/online_notification_seen.rb +++ b/app/models/observer/ticket/online_notification_seen.rb @@ -28,6 +28,6 @@ class Observer::Ticket::OnlineNotificationSeen < ActiveRecord::Observer # set all online notifications to seen # send background job - Delayed::Job.enqueue( Observer::Ticket::OnlineNotificationSeen::BackgroundJob.new( record.id, record.updated_by_id ) ) + Delayed::Job.enqueue(Observer::Ticket::OnlineNotificationSeen::BackgroundJob.new(record.id, record.updated_by_id)) end end diff --git a/app/models/observer/ticket/reset_new_state.rb b/app/models/observer/ticket/reset_new_state.rb index 04c2b6405..4dfb6180e 100644 --- a/app/models/observer/ticket/reset_new_state.rb +++ b/app/models/observer/ticket/reset_new_state.rb @@ -12,17 +12,17 @@ class Observer::Ticket::ResetNewState < ActiveRecord::Observer return true if record.internal # if sender is agent - return true if Ticket::Article::Sender.lookup( id: record.sender_id ).name != 'Agent' + return true if Ticket::Article::Sender.lookup(id: record.sender_id).name != 'Agent' # if article is a message to customer - return true if !Ticket::Article::Type.lookup( id: record.type_id ).communication + return true if !Ticket::Article::Type.lookup(id: record.type_id).communication # if current ticket state is still new - ticket = Ticket.lookup( id: record.ticket_id ) + ticket = Ticket.lookup(id: record.ticket_id) return true if ticket.state.state_type.name != 'new' # TODO: add config option to state managment in UI - state = Ticket::State.lookup( name: 'open' ) + state = Ticket::State.lookup(name: 'open') return if !state # set ticket to open diff --git a/app/models/observer/ticket/user_ticket_counter/background_job.rb b/app/models/observer/ticket/user_ticket_counter/background_job.rb index 392d99085..d9e8eec09 100644 --- a/app/models/observer/ticket/user_ticket_counter/background_job.rb +++ b/app/models/observer/ticket/user_ticket_counter/background_job.rb @@ -7,21 +7,21 @@ class Observer::Ticket::UserTicketCounter::BackgroundJob def perform # open ticket count - state_open = Ticket::State.by_category( 'open' ) + state_open = Ticket::State.by_category('open') tickets_open = Ticket.where( customer_id: @customer_id, state_id: state_open, ).count() # closed ticket count - state_closed = Ticket::State.by_category( 'closed' ) + state_closed = Ticket::State.by_category('closed') tickets_closed = Ticket.where( customer_id: @customer_id, state_id: state_closed, ).count() # check if update is needed - customer = User.lookup( id: @customer_id ) + customer = User.lookup(id: @customer_id) need_update = false if customer[:preferences][:tickets_open] != tickets_open need_update = true diff --git a/app/models/observer/user/geo.rb b/app/models/observer/user/geo.rb index 92ffe2abb..3c89860ff 100644 --- a/app/models/observer/user/geo.rb +++ b/app/models/observer/user/geo.rb @@ -18,7 +18,7 @@ class Observer::User::Geo < ActiveRecord::Observer # check if geo update is needed based on old/new location if record.id - current = User.find_by( id: record.id ) + current = User.find_by(id: record.id) return if !current current_location = {} @@ -34,7 +34,7 @@ class Observer::User::Geo < ActiveRecord::Observer } # return if address hasn't changed and geo data is already available - return if ( current_location == next_location ) && record.preferences['lat'] && record.preferences['lng'] + return if (current_location == next_location) && record.preferences['lat'] && record.preferences['lng'] # geo update geo_update(record) @@ -54,7 +54,7 @@ class Observer::User::Geo < ActiveRecord::Observer return if address == '' # lookup - latlng = Service::GeoLocation.geocode( address ) + latlng = Service::GeoLocation.geocode(address) return if !latlng # store data diff --git a/app/models/observer/user/ref_object_touch.rb b/app/models/observer/user/ref_object_touch.rb index bad925f7b..d35c30295 100644 --- a/app/models/observer/user/ref_object_touch.rb +++ b/app/models/observer/user/ref_object_touch.rb @@ -25,7 +25,7 @@ class Observer::User::RefObjectTouch < ActiveRecord::Observer organization_id_changed = record.changes['organization_id'] if organization_id_changed && organization_id_changed[0] != organization_id_changed[1] if organization_id_changed[0] - organization = Organization.find( organization_id_changed[0] ) + organization = Organization.find(organization_id_changed[0]) organization.touch member_ids = organization.member_ids end diff --git a/app/models/observer/user/ticket_organization.rb b/app/models/observer/user/ticket_organization.rb index bed6dcac0..ad5cc24a0 100644 --- a/app/models/observer/user/ticket_organization.rb +++ b/app/models/observer/user/ticket_organization.rb @@ -18,7 +18,7 @@ class Observer::User::TicketOrganization < ActiveRecord::Observer return if !record.changes['organization_id'] # update last 100 tickets of user - tickets = Ticket.where( customer_id: record.id ).limit(100) + tickets = Ticket.where(customer_id: record.id).limit(100) tickets.each {|ticket| if ticket.organization_id != record.organization_id ticket.organization_id = record.organization_id diff --git a/app/models/organization/assets.rb b/app/models/organization/assets.rb index 383d50ab7..3784c063d 100644 --- a/app/models/organization/assets.rb +++ b/app/models/organization/assets.rb @@ -8,7 +8,7 @@ class Organization get all assets / related models for this organization organization = Organization.find(123) - result = organization.assets( assets_if_exists ) + result = organization.assets(assets_if_exists) returns diff --git a/app/models/organization/permission.rb b/app/models/organization/permission.rb index 91d34ccf6..05e27590e 100644 --- a/app/models/organization/permission.rb +++ b/app/models/organization/permission.rb @@ -8,7 +8,7 @@ class Organization check if user has access to user user = Organization.find(123) - result = organization.permission( :type => 'rw', :current_user => User.find(123) ) + result = organization.permission(type: 'rw', current_user: User.find(123)) returns diff --git a/app/models/organization/search_index.rb b/app/models/organization/search_index.rb index c68dd37e3..2b9adc282 100644 --- a/app/models/organization/search_index.rb +++ b/app/models/organization/search_index.rb @@ -7,7 +7,8 @@ class Organization lookup name of ref. objects - attributes = search_index_attribute_lookup(attributes, Ticket) + organization = Organization.find(123) + attributes = organization.search_index_attribute_lookup(attributes, Organization) returns @@ -26,14 +27,14 @@ returns attribute_name = attribute_name[ 0, attribute_name.length - 3 ] # check if attribute method exists - next if !ref_object.respond_to?( attribute_name ) + next if !ref_object.respond_to?(attribute_name) # check if method has own class relation_class = ref_object.send(attribute_name).class next if !relation_class # lookup ref object - relation_model = relation_class.lookup( id: value ) + relation_model = relation_class.lookup(id: value) next if !relation_model # get name of ref object @@ -50,7 +51,7 @@ returns # add org member for search index data attributes['member'] = [] - users = User.where( organization_id: id ) + users = User.where(organization_id: id) users.each { |user| attributes['member'].push user.search_index_data } diff --git a/app/models/user.rb b/app/models/user.rb index 801a37865..0afb1e4aa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -70,7 +70,8 @@ class User < ApplicationModel source: true, login_failed: true, preferences: true, - } + }, + ignore_ids: [1], ) =begin diff --git a/app/models/user/assets.rb b/app/models/user/assets.rb index 75b07b8a8..0f977c143 100644 --- a/app/models/user/assets.rb +++ b/app/models/user/assets.rb @@ -8,7 +8,7 @@ class User get all assets / related models for this user user = User.find(123) - result = user.assets( assets_if_exists ) + result = user.assets(assets_if_exists) returns @@ -63,8 +63,8 @@ returns local_attributes['role_ids'] = local_role_ids if local_role_ids local_role_ids.each {|role_id| - role = Role.lookup( id: role_id ) - data = role.assets( data ) + role = Role.lookup(id: role_id) + data = role.assets(data) } end @@ -78,8 +78,9 @@ returns local_attributes['group_ids'] = local_group_ids if local_group_ids local_group_ids.each {|group_id| - group = Group.lookup( id: group_id ) - data = group.assets( data ) + group = Group.lookup(id: group_id) + next if !group + data = group.assets(data) } end @@ -93,8 +94,9 @@ returns local_attributes['organization_ids'] = local_organization_ids if local_organization_ids local_organization_ids.each {|organization_id| - organization = Organization.lookup( id: organization_id ) - data = organization.assets( data ) + organization = Organization.lookup(id: organization_id) + next if !organization + data = organization.assets(data) } end @@ -104,8 +106,10 @@ returns # add organization if self.organization_id if !data[ Organization.to_app_model ] || !data[ Organization.to_app_model ][ self.organization_id ] - organization = Organization.lookup( id: self.organization_id ) - data = organization.assets( data ) + organization = Organization.lookup(id: self.organization_id) + if organization + data = organization.assets(data) + end end end %w(created_by_id updated_by_id).each {|local_user_id| diff --git a/app/models/user/permission.rb b/app/models/user/permission.rb index 55e1226b2..9fcc70df3 100644 --- a/app/models/user/permission.rb +++ b/app/models/user/permission.rb @@ -8,7 +8,7 @@ class User check if user has access to user user = User.find(123) - result = user.permission( :type => 'rw', :current_user => User.find(123) ) + result = user.permission(type: 'rw', current_user: User.find(123)) returns diff --git a/app/models/user/search.rb b/app/models/user/search.rb index 54aee72c8..ac328087b 100644 --- a/app/models/user/search.rb +++ b/app/models/user/search.rb @@ -70,7 +70,7 @@ returns # - stip out * we already search for *query* - query.delete! '*' users = if params[:role_ids] - User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where( + User.joins(:roles).where('roles.id' => params[:role_ids]).where( '(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ).order('firstname').limit(limit) else