From 6ea8e8e9ea86c9053b64bb7235240ffb7bcbef70 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 19 Feb 2013 20:04:35 +0100 Subject: [PATCH] Small code improvements. --- .../lib/app_post/interface_handle.js.coffee | 3 ++- app/models/user.rb | 18 ++++++++++++++++- lib/import/otrs.rb | 7 +++++++ lib/session.rb | 20 ++++++++----------- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/interface_handle.js.coffee b/app/assets/javascripts/app/lib/app_post/interface_handle.js.coffee index a0e0bb8af..e8902cf23 100644 --- a/app/assets/javascripts/app/lib/app_post/interface_handle.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/interface_handle.js.coffee @@ -23,7 +23,8 @@ class App.Run extends App.Controller new App.Content( el: @el.find('#content') ) # start chat - new App.ChatWidget( el: @el.find('#chat') ) + if App.ChatWidget + new App.ChatWidget( el: @el.find('#chat') ) # bind to fill selected text into App.ClipBoard.bind( @el ) diff --git a/app/models/user.rb b/app/models/user.rb index 46c346bcb..2643e1766 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < ApplicationModel include Gmaps before_create :check_name, :check_email, :check_login, :check_image, :check_geo, :check_password - before_update :check_password, :check_image, :check_geo, :check_email, :check_login + before_update :check_password, :check_image, :check_geo, :check_email, :check_login_update has_and_belongs_to_many :groups, :after_add => :cache_update, :after_remove => :cache_update has_and_belongs_to_many :roles, :after_add => :cache_update, :after_remove => :cache_update @@ -449,6 +449,22 @@ Your #{config.product_name} Team end def check_login + if self.login + self.login = self.login.downcase + check = true + while check + exists = User.where( :login => self.login ).first + if exists + self.login = self.login + rand(99).to_s + else + check = false + end + end + end + end + + # FIXME: Remove me later + def check_login_update if self.login self.login = self.login.downcase end diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index 10aa80272..631a4ffa5 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -122,6 +122,13 @@ module Import::OTRS return end + def self.diff_loop + while true + self.diff + sleep 30 + end + end + def self.diff puts 'Start diff...' diff --git a/lib/session.rb b/lib/session.rb index 2fd340caf..91b102166 100644 --- a/lib/session.rb +++ b/lib/session.rb @@ -82,17 +82,13 @@ module Session def self.send( client_id, data ) path = @path + '/' + client_id.to_s + '/' filename = 'send-' + Time.new().to_i.to_s + '-' + rand(99999999).to_s - if File::exists?( path + filename ) - filename = filename + '-1' + check = true + while check if File::exists?( path + filename ) - filename = filename + '-1' - if File::exists?( path + filename ) - filename = filename + '-1' - if File::exists?( path + filename ) - filename = filename + '-' + rand(99999999).to_s - end - end - end + filename = filename + '-' + rand(99999).to_s + else + check = false + end end return false if !File.directory? path File.open( path + 'a-' + filename, 'w' ) { |file| @@ -101,8 +97,8 @@ module Session file.flock( File::LOCK_UN ) file.close } - - FileUtils.mv( path + 'a-' + filename, path + filename) +# return false if !File.exists?( path + 'a-' + filename ) + FileUtils.mv( path + 'a-' + filename, path + filename ) return true end