Improved error handling.

This commit is contained in:
Martin Edenhofer 2017-07-24 09:06:15 +02:00
parent 4609829d68
commit 0986e89335
7 changed files with 25 additions and 9 deletions

View file

@ -62,6 +62,7 @@ class SearchController < ApplicationController
items.each { |item| items.each { |item|
require item[:type].to_filename require item[:type].to_filename
record = Kernel.const_get(item[:type]).lookup(id: item[:id]) record = Kernel.const_get(item[:type]).lookup(id: item[:id])
next if !record
assets = record.assets(assets) assets = record.assets(assets)
result.push item result.push item
} }

View file

@ -282,12 +282,12 @@ class SessionsController < ApplicationController
assets = {} assets = {}
sessions_clean = [] sessions_clean = []
SessionHelper.list.each { |session| SessionHelper.list.each { |session|
next if !session.data['user_id'] next if session.data['user_id'].blank?
sessions_clean.push session sessions_clean.push session
if session.data['user_id'] next if session.data['user_id']
user = User.lookup(id: session.data['user_id']) user = User.lookup(id: session.data['user_id'])
next if !user
assets = user.assets(assets) assets = user.assets(assets)
end
} }
render json: { render json: {
sessions: sessions_clean, sessions: sessions_clean,

View file

@ -41,7 +41,7 @@ class Observer::Ticket::ArticleChanges < ActiveRecord::Observer
record.ticket.touch record.ticket.touch
return return
end end
record.ticket.save record.ticket.save!
end end
# get article count # get article count

View file

@ -54,7 +54,7 @@ class Transaction::Karma
if @item[:type] == 'reminder_reached' if @item[:type] == 'reminder_reached'
return if ticket.owner_id == 1 return if ticket.owner_id == 1
return if ticket.pending_time > Time.zone.now - 2.days return if ticket.pending_time && ticket.pending_time > Time.zone.now - 2.days
Karma::ActivityLog.add('ticket reminder overdue (+2 days)', ticket.owner, 'Ticket', ticket.id) Karma::ActivityLog.add('ticket reminder overdue (+2 days)', ticket.owner, 'Ticket', ticket.id)
return return
end end

View file

@ -43,7 +43,7 @@ class User < ApplicationModel
before_update :check_preferences_default, :validate_roles, :reset_login_failed before_update :check_preferences_default, :validate_roles, :reset_login_failed
after_create :avatar_for_email_check after_create :avatar_for_email_check
after_update :avatar_for_email_check after_update :avatar_for_email_check
after_destroy :avatar_destroy after_destroy :avatar_destroy, :user_device_destroy
has_and_belongs_to_many :roles, after_add: [:cache_update, :check_notifications], after_remove: :cache_update, before_add: :validate_agent_limit, before_remove: :last_admin_check, class_name: 'Role' has_and_belongs_to_many :roles, after_add: [:cache_update, :check_notifications], after_remove: :cache_update, before_add: :validate_agent_limit, before_remove: :last_admin_check, class_name: 'Role'
has_and_belongs_to_many :organizations, after_add: :cache_update, after_remove: :cache_update, class_name: 'Organization' has_and_belongs_to_many :organizations, after_add: :cache_update, after_remove: :cache_update, class_name: 'Organization'
@ -1014,6 +1014,10 @@ raise 'Minimum one user need to have admin permissions'
Avatar.remove('User', id) Avatar.remove('User', id)
end end
def user_device_destroy
UserDevice.remove(id)
end
def ensure_password def ensure_password
return true if password_empty? return true if password_empty?
return true if PasswordHash.crypted?(password) return true if PasswordHash.crypted?(password)

View file

@ -210,4 +210,15 @@ send user notification about new device or new location for device
) )
end end
=begin
delete device devices of user
user_devices = UserDevice.remove(user.id)
=end
def self.remove(user_id)
UserDevice.where(user_id: user_id).destroy_all
end
end end

View file

@ -7,7 +7,7 @@ class ReportTest < ActiveSupport::TestCase
setup do setup do
# set config # set config
if !ENV['ES_URL'] if ENV['ES_URL'].blank?
raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'" raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
end end
Setting.set('es_url', ENV['ES_URL']) Setting.set('es_url', ENV['ES_URL'])