Browse Source

Corrected with rubocop cop 'Style/Next'.

Thorsten Eckel 9 years ago
parent
commit
1ac1cf4184

+ 0 - 2
.rubocop.yml

@@ -218,8 +218,6 @@ Metrics/AbcSize:
 
 Style/RedundantSelf:
   Enabled: false
-Style/Next:
-  Enabled: false
 Style/CommentIndentation:
   Enabled: false
 Metrics/CyclomaticComplexity:

+ 90 - 87
app/controllers/getting_started_controller.rb

@@ -233,28 +233,28 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
     end
     provider_map.each {|provider, settings|
       domains.each {|domain_to_check|
-        if domain_to_check =~ /#{settings[:domain]}/i
 
-          # probe inbound
-          result = email_probe_inbound( settings[:inbound] )
-          if result[:result] != 'ok'
-            render json: result
-            return # rubocop:disable Lint/NonLocalExitFromIterator
-          end
+        next if domain_to_check !~ /#{settings[:domain]}/i
 
-          # probe outbound
-          result = email_probe_outbound( settings[:outbound], params[:email] )
-          if result[:result] != 'ok'
-            render json: result
-            return # rubocop:disable Lint/NonLocalExitFromIterator
-          end
+        # probe inbound
+        result = email_probe_inbound( settings[:inbound] )
+        if result[:result] != 'ok'
+          render json: result
+          return # rubocop:disable Lint/NonLocalExitFromIterator
+        end
 
-          render json: {
-            result: 'ok',
-            setting: settings,
-          }
+        # probe outbound
+        result = email_probe_outbound( settings[:outbound], params[:email] )
+        if result[:result] != 'ok'
+          render json: result
           return # rubocop:disable Lint/NonLocalExitFromIterator
         end
+
+        render json: {
+          result: 'ok',
+          setting: settings,
+        }
+        return # rubocop:disable Lint/NonLocalExitFromIterator
       }
     }
 
@@ -394,11 +394,12 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
       logger.info "INBOUND PROBE: #{config.inspect}"
       result = email_probe_inbound( config )
       logger.info "INBOUND RESULT: #{result.inspect}"
-      if result[:result] == 'ok'
-        success = true
-        settings[:inbound] = config
-        break
-      end
+
+      next if result[:result] != 'ok'
+
+      success = true
+      settings[:inbound] = config
+      break
     }
 
     if !success
@@ -543,11 +544,12 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
       logger.info "OUTBOUND PROBE: #{config.inspect}"
       result = email_probe_outbound( config, params[:email] )
       logger.info "OUTBOUND RESULT: #{result.inspect}"
-      if result[:result] == 'ok'
-        success = true
-        settings[:outbound] = config
-        break
-      end
+
+      next if result[:result] != 'ok'
+
+      success = true
+      settings[:outbound] = config
+      break
     }
 
     if !success
@@ -635,66 +637,66 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
         return # rubocop:disable Lint/NonLocalExitFromIterator
       end
 
-      if found && found == 'verify ok'
-
-        # remember address
-        address = EmailAddress.where( email: params[:meta][:email] ).first
-        if !address
-          address = EmailAddress.first
-        end
-        if address
-          address.update_attributes(
-            realname: params[:meta][:realname],
-            email: params[:meta][:email],
-            active: 1,
-            updated_by_id: 1,
-            created_by_id: 1,
-          )
-        else
-          EmailAddress.create(
-            realname: params[:meta][:realname],
-            email: params[:meta][:email],
-            active: 1,
-            updated_by_id: 1,
-            created_by_id: 1,
-          )
-        end
+      next if !found
+      next if found != 'verify ok'
 
-        # store mailbox
-        Channel.create(
-          area: 'Email::Inbound',
-          adapter: params[:inbound][:adapter],
-          options: params[:inbound][:options],
-          group_id: 1,
+      # remember address
+      address = EmailAddress.where( email: params[:meta][:email] ).first
+      if !address
+        address = EmailAddress.first
+      end
+      if address
+        address.update_attributes(
+          realname: params[:meta][:realname],
+          email: params[:meta][:email],
+          active: 1,
+          updated_by_id: 1,
+          created_by_id: 1,
+        )
+      else
+        EmailAddress.create(
+          realname: params[:meta][:realname],
+          email: params[:meta][:email],
           active: 1,
           updated_by_id: 1,
           created_by_id: 1,
         )
+      end
 
-        # save settings
-        if params[:outbound][:adapter] =~ /^smtp$/i
-          smtp = Channel.where( adapter: 'SMTP', area: 'Email::Outbound' ).first
-          smtp.options = params[:outbound][:options]
-          smtp.active  = true
-          smtp.save!
-          sendmail = Channel.where( adapter: 'Sendmail' ).first
-          sendmail.active = false
-          sendmail.save!
-        else
-          sendmail = Channel.where( adapter: 'Sendmail', area: 'Email::Outbound' ).first
-          sendmail.options = {}
-          sendmail.active  = true
-          sendmail.save!
-          smtp = Channel.where( adapter: 'SMTP' ).first
-          smtp.active = false
-          smtp.save
-        end
+      # store mailbox
+      Channel.create(
+        area: 'Email::Inbound',
+        adapter: params[:inbound][:adapter],
+        options: params[:inbound][:options],
+        group_id: 1,
+        active: 1,
+        updated_by_id: 1,
+        created_by_id: 1,
+      )
 
-        render json: {
-          result: 'ok',
-        }
-        return # rubocop:disable Lint/NonLocalExitFromIterator
+      # save settings
+      if params[:outbound][:adapter] =~ /^smtp$/i
+        smtp = Channel.where( adapter: 'SMTP', area: 'Email::Outbound' ).first
+        smtp.options = params[:outbound][:options]
+        smtp.active  = true
+        smtp.save!
+        sendmail = Channel.where( adapter: 'Sendmail' ).first
+        sendmail.active = false
+        sendmail.save!
+      else
+        sendmail = Channel.where( adapter: 'Sendmail', area: 'Email::Outbound' ).first
+        sendmail.options = {}
+        sendmail.active  = true
+        sendmail.save!
+        smtp = Channel.where( adapter: 'SMTP' ).first
+        smtp.active = false
+        smtp.save
       end
+
+      render json: {
+        result: 'ok',
+      }
+      return # rubocop:disable Lint/NonLocalExitFromIterator
     }
 
     # check delivery for 30 sek.
@@ -768,14 +770,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
             'Recipient address rejected' => true,
           }
           white_map.each {|key, message|
-            if e.message =~ /#{Regexp.escape(key)}/i
-              result = {
-                result: 'ok',
-                settings: params,
-                notice: e.message,
-              }
-              return result
-            end
+
+            next if e.message !~ /#{Regexp.escape(key)}/i
+
+            result = {
+              result: 'ok',
+              settings: params,
+              notice: e.message,
+            }
+            return result
           }
         end
         message_human = ''

+ 11 - 10
app/models/application_model.rb

@@ -107,17 +107,18 @@ returns
     # set relations
     self.class.reflect_on_all_associations.map { |assoc|
       real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids'
-      if params.key?( real_key.to_sym )
-        list_of_items = params[ real_key.to_sym ]
-        if params[ real_key.to_sym ].class != Array
-          list_of_items = [ params[ real_key.to_sym ] ]
-        end
-        list = []
-        list_of_items.each {|item|
-          list.push( assoc.klass.find(item) )
-        }
-        self.send( assoc.name.to_s + '=', list )
+
+      next if !params.key?( real_key.to_sym )
+
+      list_of_items = params[ real_key.to_sym ]
+      if params[ real_key.to_sym ].class != Array
+        list_of_items = [ params[ real_key.to_sym ] ]
       end
+      list = []
+      list_of_items.each {|item|
+        list.push( assoc.klass.find(item) )
+      }
+      self.send( assoc.name.to_s + '=', list )
     }
   end
 

+ 43 - 38
app/models/channel/email_parser.rb

@@ -66,35 +66,37 @@ class Channel::EmailParser
 
     # set all headers
     mail.header.fields.each { |field|
-      if field.name
 
-        # full line, encode, ready for storage
-        data[field.name.to_s.downcase.to_sym] = Encode.conv( 'utf8', field.to_s )
+      next if !field.name
 
-        # if we need to access the lines by objects later again
-        data[ "raw-#{field.name.downcase}".to_sym ] = field
-      end
+      # full line, encode, ready for storage
+      data[field.name.to_s.downcase.to_sym] = Encode.conv( 'utf8', field.to_s )
+
+      # if we need to access the lines by objects later again
+      data[ "raw-#{field.name.downcase}".to_sym ] = field
     }
 
     # get sender
     from = nil
     ['from', 'reply-to', 'return-path'].each { |item|
-      if !from
-        if mail[ item.to_sym ]
-          from = mail[ item.to_sym ].value
-        end
-      end
+
+      next if !mail[ item.to_sym ]
+
+      from = mail[ item.to_sym ].value
+
+      break if from
     }
 
     # set x-any-recipient
     data['x-any-recipient'.to_sym] = ''
     ['to', 'cc', 'delivered-to', 'x-original-to', 'envelope-to'].each { |item|
-      if mail[item.to_sym]
-        if data['x-any-recipient'.to_sym] != ''
-          data['x-any-recipient'.to_sym] += ', '
-        end
-        data['x-any-recipient'.to_sym] += mail[item.to_sym].to_s
+
+      next if !mail[item.to_sym]
+
+      if data['x-any-recipient'.to_sym] != ''
+        data['x-any-recipient'.to_sym] += ', '
       end
+      data['x-any-recipient'.to_sym] += mail[item.to_sym].to_s
     }
 
     # set extra headers
@@ -374,16 +376,18 @@ class Channel::EmailParser
 
       # create to and cc user
       ['raw-to', 'raw-cc'].each { |item|
-        if mail[item.to_sym] && mail[item.to_sym].tree
-          items = mail[item.to_sym].tree
-          items.addresses.each {|item|
-            user_create(
-              firstname: item.display_name,
-              lastname: '',
-              email: item.address,
-            )
-          }
-        end
+
+        next if !mail[item.to_sym]
+        next if !mail[item.to_sym].tree
+
+        items = mail[item.to_sym].tree
+        items.addresses.each {|item|
+          user_create(
+            firstname: item.display_name,
+            lastname: '',
+            email: item.address,
+          )
+        }
       }
 
       # set current user
@@ -541,18 +545,19 @@ class Channel::EmailParser
         if mail[ header.to_sym ]
           Rails.logger.info "header #{header} found #{mail[ header.to_sym ]}"
           item_object.class.reflect_on_all_associations.map { |assoc|
-            if assoc.name.to_s == key_short
-              Rails.logger.info "ASSOC found #{assoc.class_name} lookup #{mail[ header.to_sym ]}"
-              item = assoc.class_name.constantize
-
-              if item.respond_to?(:name)
-                if item.lookup( name: mail[ header.to_sym ] )
-                  item_object[key] = item.lookup( name: mail[ header.to_sym ] ).id
-                end
-              elsif item.respond_to?(:login)
-                if item.lookup( login: mail[ header.to_sym ] )
-                  item_object[key] = item.lookup( login: mail[ header.to_sym ] ).id
-                end
+
+            next if assoc.name.to_s != key_short
+
+            Rails.logger.info "ASSOC found #{assoc.class_name} lookup #{mail[ header.to_sym ]}"
+            item = assoc.class_name.constantize
+
+            if item.respond_to?(:name)
+              if item.lookup( name: mail[ header.to_sym ] )
+                item_object[key] = item.lookup( name: mail[ header.to_sym ] ).id
+              end
+            elsif item.respond_to?(:login)
+              if item.lookup( login: mail[ header.to_sym ] )
+                item_object[key] = item.lookup( login: mail[ header.to_sym ] ).id
               end
             end
           }

+ 10 - 8
app/models/channel/filter/database.rb

@@ -10,9 +10,9 @@ module Channel::Filter::Database
     filters.each {|filter|
       Rails.logger.info " proccess filter #{filter.name} ..."
       match = true
-      loop = false
+      looped = false
       filter[:match].each {|key, value|
-        loop = true
+        looped = true
         begin
           scan = []
           if mail
@@ -31,12 +31,14 @@ module Channel::Filter::Database
           Rails.logger.error e.inspect
         end
       }
-      if loop && match
-        filter[:perform].each {|key, value|
-          Rails.logger.info "  perform '#{ key.downcase }' = '#{value}'"
-          mail[ key.downcase.to_sym ] = value
-        }
-      end
+
+      next if !looped
+      next if !match
+
+      filter[:perform].each {|key, value|
+        Rails.logger.info "  perform '#{ key.downcase }' = '#{value}'"
+        mail[ key.downcase.to_sym ] = value
+      }
     }
 
   end

+ 7 - 5
app/models/observer/ticket/article/communicate_email/background_job.rb

@@ -37,12 +37,14 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
     # add history record
     recipient_list = ''
     [:to, :cc].each { |key|
-      if record[key] && record[key] != ''
-        if recipient_list != ''
-          recipient_list += ','
-        end
-        recipient_list += record[key]
+
+      next if !record[key]
+      next if record[key] == ''
+
+      if recipient_list != ''
+        recipient_list += ','
       end
+      recipient_list += record[key]
     }
 
     return if recipient_list == ''

+ 14 - 13
app/models/package.rb

@@ -313,14 +313,15 @@ class Package < ApplicationModel
   def self.reload_classes
     %w(app lib).each {|dir|
       Dir.glob( Rails.root.join( dir + '/**/*') ).each {|entry|
-        if entry =~ /\.rb$/
-          begin
-            load entry
-          rescue => e
-            logger.error "TRIED TO RELOAD '#{entry}'"
-            logger.error 'ERROR: ' + e.inspect
-            logger.error 'Traceback: ' + e.backtrace.inspect
-          end
+
+        next if entry !~ /\.rb$/
+
+        begin
+          load entry
+        rescue => e
+          logger.error "TRIED TO RELOAD '#{entry}'"
+          logger.error 'ERROR: ' + e.inspect
+          logger.error 'Traceback: ' + e.backtrace.inspect
         end
       }
     }
@@ -396,11 +397,11 @@ class Package < ApplicationModel
       (1..position).each {|count|
         tmp_path = tmp_path + '/' + directories[count].to_s
       }
-      if tmp_path != ''
-        if !File.exist?(tmp_path)
-          Dir.mkdir( tmp_path, 0755)
-        end
-      end
+
+      next if tmp_path == ''
+      next if File.exist?(tmp_path)
+
+      Dir.mkdir(tmp_path, 0755)
     }
 
     # install file

+ 7 - 6
app/models/store/file.rb

@@ -46,12 +46,13 @@ class Store
         content = item.content
         sha = Digest::SHA256.hexdigest( content )
         logger.info "CHECK: Store::File.find(#{item.id}) "
-        if sha != item.sha
-          success = false
-          logger.error "DIFF: sha diff of Store::File.find(#{item.id}) "
-          if fix_it
-            item.update_attribute( :sha, sha )
-          end
+
+        next if sha == item.sha
+
+        success = false
+        logger.error "DIFF: sha diff of Store::File.find(#{item.id}) "
+        if fix_it
+          item.update_attribute( :sha, sha )
         end
       }
       success

+ 10 - 9
app/models/ticket/escalation.rb

@@ -189,15 +189,16 @@ returns
           [ 'tickets.group_id', 'group_id' ]
         ]
         map.each {|item|
-          if sla.condition[ item[0] ]
-            if sla.condition[ item[0] ].class == String
-              sla.condition[ item[0] ] = [ sla.condition[ item[0] ] ]
-            end
-            if sla.condition[ item[0] ].include?( self[ item[1] ].to_s )
-              hit = true
-            else
-              hit = false
-            end
+
+          next if !sla.condition[ item[0] ]
+
+          if sla.condition[ item[0] ].class == String
+            sla.condition[ item[0] ] = [ sla.condition[ item[0] ] ]
+          end
+          if sla.condition[ item[0] ].include?( self[ item[1] ].to_s )
+            hit = true
+          else
+            hit = false
           end
         }
         if hit

+ 11 - 6
app/models/ticket/overviews.rb

@@ -73,12 +73,17 @@ returns
 
       # replace e.g. 'current_user.id' with current_user.id
       overview.condition.each { |item, value|
-        if value && value.class.to_s == 'String'
-          parts = value.split( '.', 2 )
-          if parts[0] && parts[1] && parts[0] == 'current_user'
-            overview.condition[item] = data[:current_user][parts[1].to_sym]
-          end
-        end
+
+        next if !value
+        next if value.class.to_s != 'String'
+
+        parts = value.split( '.', 2 )
+
+        next if !parts[0]
+        next if !parts[1]
+        next if parts[0] != 'current_user'
+
+        overview.condition[item] = data[:current_user][parts[1].to_sym]
       }
     }
 

Some files were not shown because too many files changed in this diff