From 460182e663fcc7320b171fac46d7ca1f79b77553 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 21 Nov 2017 15:25:04 +0100 Subject: [PATCH] Small code cleanup. --- .../controllers/_application_controller_generic.coffee | 4 ++-- .../ticket_zoom/article_action/twitter_reply.coffee | 2 +- .../app/controllers/widget/ticket_stats.coffee | 1 + app/controllers/monitoring_controller.rb | 6 +++--- app/controllers/user_access_token_controller.rb | 6 +++--- app/models/channel/email_parser.rb | 4 ++-- app/models/package.rb | 2 +- app/models/ticket.rb | 4 +--- lib/enrichment/clearbit/organization.rb | 9 ++++----- lib/enrichment/clearbit/user.rb | 1 - 10 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee index 71789f94c..20991117e 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee @@ -685,8 +685,8 @@ class App.Sidebar extends App.Controller for item in @items area = localEl.filter('.sidebar[data-tab="' + item.name + '"]') if item.callback - item.callback( area.find('.sidebar-content') ) - if item.actions + item.callback(area.find('.sidebar-content')) + if !_.isEmpty(item.actions) new App.ActionRow( el: area.find('.js-actions') items: item.actions diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_action/twitter_reply.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_action/twitter_reply.coffee index 8b03ba249..6ce871868 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_action/twitter_reply.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_action/twitter_reply.coffee @@ -71,7 +71,7 @@ class TwitterReply exclude = true # exclude own screen_name - if recipientScreenName is "@#{@ticket.preferences.channel_screen_name}".toLowerCase() + if recipientScreenName is "@#{ticket.preferences.channel_screen_name}".toLowerCase() exclude = true if exclude is false diff --git a/app/assets/javascripts/app/controllers/widget/ticket_stats.coffee b/app/assets/javascripts/app/controllers/widget/ticket_stats.coffee index 7445e8294..67d8b4b5b 100644 --- a/app/assets/javascripts/app/controllers/widget/ticket_stats.coffee +++ b/app/assets/javascripts/app/controllers/widget/ticket_stats.coffee @@ -70,6 +70,7 @@ class App.TicketStats extends App.Controller render: (data) => if !data data = @data + return if !data user_total = 0 if data.user.open_ids && data.user.closed_ids diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index 0bdcfd6df..22f8f319f 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -40,7 +40,7 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX if channel.status_in == 'error' message = "Channel: #{channel.area} in " %w(host user uid).each do |key| - next if !channel.options[key] || channel.options[key].empty? + next if channel.options[key].blank? message += "key:#{channel.options[key]};" end issues.push "#{message} #{channel.last_log_in}" @@ -53,7 +53,7 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX next if channel.status_out != 'error' message = "Channel: #{channel.area} out " %w(host user uid).each do |key| - next if !channel.options[key] || channel.options[key].empty? + next if channel.options[key].blank? message += "key:#{channel.options[key]};" end issues.push "#{message} #{channel.last_log_out}" @@ -89,7 +89,7 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX token = Setting.get('monitoring_token') - if issues.empty? + if issues.blank? result = { healthy: true, message: 'success', diff --git a/app/controllers/user_access_token_controller.rb b/app/controllers/user_access_token_controller.rb index 16def0e98..8b1f5aeec 100644 --- a/app/controllers/user_access_token_controller.rb +++ b/app/controllers/user_access_token_controller.rb @@ -45,10 +45,10 @@ class UserAccessTokenController < ApplicationController if Setting.get('api_token_access') == false raise Exceptions::UnprocessableEntity, 'API token access disabled!' end - if params[:label].empty? + if params[:label].blank? raise Exceptions::UnprocessableEntity, 'Need label!' end - token = Token.create( + token = Token.create!( action: 'api', label: params[:label], persistent: true, @@ -66,7 +66,7 @@ class UserAccessTokenController < ApplicationController def destroy token = Token.find_by(action: 'api', user_id: current_user.id, id: params[:id]) raise Exceptions::UnprocessableEntity, 'Unable to find api token!' if !token - token.destroy + token.destroy! render json: {}, status: :ok end diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 8b97388d6..9496572dd 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -615,10 +615,10 @@ returns if channel[:group_id] group = Group.lookup(id: channel[:group_id]) end - if !group || group && !group.active + if group.blank? || group.active == false group = Group.where(active: true).order('id ASC').first end - if !group + if group.blank? group = Group.first end title = mail[:subject] diff --git a/app/models/package.rb b/app/models/package.rb index f76c30326..221896a0e 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -44,7 +44,7 @@ returns: logger.error "File #{file['location']} is different" issues[file['location']] = 'changed' end - return nil if issues.empty? + return nil if issues.blank? issues end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index d630dbce1..e930201ae 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1031,9 +1031,7 @@ perform changes on ticket if key == 'ticket.action' next if value['value'].blank? next if value['value'] != 'delete' - - destroy - + destroy! next end diff --git a/lib/enrichment/clearbit/organization.rb b/lib/enrichment/clearbit/organization.rb index 7b095afa5..2477acd80 100644 --- a/lib/enrichment/clearbit/organization.rb +++ b/lib/enrichment/clearbit/organization.rb @@ -13,7 +13,6 @@ module Enrichment def synced? return false if !@config - # TODO UserInfo.current_user_id = 1 return false if !mapping? @@ -74,7 +73,7 @@ module Enrichment return false if @user.organization_id # can't create organization without name - return false if @current_changes[:name].empty? + return false if @current_changes[:name].blank? organization = create_current @@ -95,7 +94,7 @@ module Enrichment object: organization, current_changes: @current_changes, ) - organization.save + organization.save! ExternalSync.create( source: @source, @@ -127,10 +126,10 @@ module Enrichment ) organization.updated_by_id = 1 - organization.save + organization.save! @external_organization.last_payload = @payload - @external_organization.save + @external_organization.save! organization end diff --git a/lib/enrichment/clearbit/user.rb b/lib/enrichment/clearbit/user.rb index 57d39350b..85f509abe 100644 --- a/lib/enrichment/clearbit/user.rb +++ b/lib/enrichment/clearbit/user.rb @@ -12,7 +12,6 @@ module Enrichment return false if !@config return false if @local_user.email.blank? - # TODO UserInfo.current_user_id = 1 return false if !mapping?