Merge branch 'develop' of github.com:martini/zammad into develop

This commit is contained in:
Felix Niklas 2016-02-04 18:20:52 +01:00
commit 1024b4889c
7 changed files with 130 additions and 70 deletions

View file

@ -21,6 +21,7 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
fail "Can't find ticket.preferences for Ticket.find(#{record.ticket_id})" if !ticket.preferences
fail "Can't find ticket.preferences['channel_id'] for Ticket.find(#{record.ticket_id})" if !ticket.preferences['channel_id']
channel = Channel.lookup(id: ticket.preferences['channel_id'])
fail "No such channel id #{ticket.preferences['channel_id']}" if !channel
fail "Channel.find(#{channel.id}) isn't a twitter channel!" if channel.options[:adapter] !~ /\Atwitter/i
tweet = channel.deliver(
type: type['name'],

View file

@ -38,7 +38,7 @@ class Ticket < ApplicationModel
close_time_in_min: true,
close_time_diff_in_min: true,
update_time_escal_date: true,
updtate_time_sla_time: true,
update_time_sla_time: true,
update_time_in_min: true,
update_time_diff_in_min: true,
last_contact: true,

View file

@ -51,7 +51,7 @@ class CreateTicket < ActiveRecord::Migration
t.column :close_time_in_min, :integer, null: true
t.column :close_time_diff_in_min, :integer, null: true
t.column :update_time_escal_date, :timestamp, null: true
t.column :updtate_time_sla_time, :timestamp, null: true
t.column :update_time_sla_time, :timestamp, null: true
t.column :update_time_in_min, :integer, null: true
t.column :update_time_diff_in_min, :integer, null: true
t.column :last_contact, :timestamp, null: true

View file

@ -0,0 +1,6 @@
class UpdtateTimeSlaTime < ActiveRecord::Migration
def up
return if !Ticket.column_names.include?('updtate_time_sla_time')
rename_column :tickets, :updtate_time_sla_time, :update_time_sla_time
end
end

View file

@ -34,7 +34,7 @@ class TwitterBrowserTest < TestCase
end
twitter_customer_token_secret = ENV['TWITTER_BT_CUSTOMER_TOKEN_SECRET']
hash = "#sweetcheck#{hash_gen}"
hash = "#sweet#{hash_gen}"
@browser = browser_instance
login(
@ -197,7 +197,7 @@ class TwitterBrowserTest < TestCase
config.access_token_secret = twitter_customer_token_secret
end
text = "Today... #{hash} #{hash_gen}"
text = "Today #{rand_word}... #{hash} #{hash_gen}"
tweet = client.update(
text,
)
@ -253,7 +253,7 @@ class TwitterBrowserTest < TestCase
ticket_update(
data: {
body: "@dzucker6 reply #{re_hash} #{rand(999_999)}",
body: "@dzucker6 #{rand_word} reply #{re_hash} #{rand(999_999)}",
},
)
sleep 20
@ -277,4 +277,26 @@ class TwitterBrowserTest < TestCase
(0...10).map { ('a'..'z').to_a[rand(26)] }.join + rand(999).to_s
end
def rand_word
words = [
'dog',
'cat',
'house',
'home',
'yesterday',
'tomorrow',
'new york',
'berlin',
'coffee script',
'java script',
'bob smith',
'be open',
'really nice',
'stay tuned',
'be a good boy',
'invent new things',
]
words[rand(words.length)]
end
end

View file

@ -26,24 +26,33 @@ class TwitterTest < ActiveSupport::TestCase
consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
# armin_theo (is system and is following marion_bauer)
if !ENV['TWITTER_SYSTEM_LOGIN']
fail "ERROR: Need TWITTER_SYSTEM_LOGIN - hint TWITTER_SYSTEM_LOGIN='@system'"
end
if !ENV['TWITTER_SYSTEM_TOKEN']
fail "ERROR: Need TWITTER_SYSTEM_TOKEN - hint TWITTER_SYSTEM_TOKEN='1234'"
end
if !ENV['TWITTER_SYSTEM_TOKEN_SECRET']
fail "ERROR: Need TWITTER_SYSTEM_TOKEN_SECRET - hint TWITTER_SYSTEM_TOKEN_SECRET='1234'"
end
armin_theo_token = ENV['TWITTER_SYSTEM_TOKEN']
armin_theo_token_secret = ENV['TWITTER_SYSTEM_TOKEN_SECRET']
system_login = ENV['TWITTER_SYSTEM_LOGIN']
system_login_without_at = system_login[1, system_login.length]
system_token = ENV['TWITTER_SYSTEM_TOKEN']
system_token_secret = ENV['TWITTER_SYSTEM_TOKEN_SECRET']
# me_bauer (is customer and is following armin_theo)
if !ENV['TWITTER_CUSTOMER_LOGIN']
fail "ERROR: Need CUSTOMER_LOGIN - hint TWITTER_CUSTOMER_LOGIN='@customer'"
end
if !ENV['TWITTER_CUSTOMER_TOKEN']
fail "ERROR: Need CUSTOMER_TOKEN - hint TWITTER_CUSTOMER_TOKEN='1234'"
end
if !ENV['TWITTER_CUSTOMER_TOKEN_SECRET']
fail "ERROR: Need CUSTOMER_TOKEN_SECRET - hint TWITTER_CUSTOMER_TOKEN_SECRET='1234'"
end
me_bauer_token = ENV['TWITTER_CUSTOMER_TOKEN']
me_bauer_token_secret = ENV['TWITTER_CUSTOMER_TOKEN_SECRET']
customer_login = ENV['TWITTER_CUSTOMER_LOGIN']
customer_token = ENV['TWITTER_CUSTOMER_TOKEN']
customer_token_secret = ENV['TWITTER_CUSTOMER_TOKEN_SECRET']
# add channel
current = Channel.where(area: 'Twitter::Account')
@ -55,11 +64,11 @@ class TwitterTest < ActiveSupport::TestCase
auth: {
consumer_key: consumer_key,
consumer_secret: consumer_secret,
oauth_token: armin_theo_token,
oauth_token_secret: armin_theo_token_secret,
oauth_token: system_token,
oauth_token_secret: system_token_secret,
},
user: {
screen_name: '@armin_theo',
screen_name: system_login,
id: '1234',
},
sync: {
@ -69,7 +78,7 @@ class TwitterTest < ActiveSupport::TestCase
group_id: 2,
},
{
term: '#citheo24',
term: '#zarepl24',
group_id: 1,
},
],
@ -90,7 +99,7 @@ class TwitterTest < ActiveSupport::TestCase
hash = '#citheo42' + rand(999_999).to_s
user = User.find(2)
text = "Today the weather is really nice... #{hash}"
text = "Today the weather is really #{rand_word}... #{hash}"
ticket = Ticket.create(
title: text[0, 40],
customer_id: user.id,
@ -114,19 +123,19 @@ class TwitterTest < ActiveSupport::TestCase
created_by_id: 1,
)
assert(article, "outbound article created, text: #{text}")
assert_equal('@armin_theo', article.from, 'ticket article from')
assert_equal(system_login, article.from, 'ticket article from')
assert_equal('', article.to, 'ticket article to')
# reply by me_bauer
client = Twitter::REST::Client.new do |config|
config.consumer_key = consumer_key
config.consumer_secret = consumer_secret
config.access_token = me_bauer_token
config.access_token_secret = me_bauer_token_secret
config.access_token = customer_token
config.access_token_secret = customer_token_secret
end
tweet_found = false
client.user_timeline('armin_theo').each { |tweet|
client.user_timeline(system_login_without_at).each { |tweet|
next if tweet.id.to_s != article.message_id.to_s
tweet_found = true
@ -134,7 +143,7 @@ class TwitterTest < ActiveSupport::TestCase
}
assert(tweet_found, "found outbound '#{text}' tweet '#{article.message_id}'")
reply_text = '@armin_theo on my side the weather is nice, too! 😍😍😍 #weather' + rand(999_999).to_s
reply_text = "#{system_login} on my side the weather is nice, too! 😍😍😍 #weather#{rand(999_999)}"
tweet = client.update(
reply_text,
{
@ -155,8 +164,8 @@ class TwitterTest < ActiveSupport::TestCase
}
assert(article, "article tweet '#{tweet.id}' imported")
assert_equal('@me_bauer', article.from, 'ticket article from')
assert_equal('@armin_theo', article.to, 'ticket article to')
assert_equal(customer_login, article.from, 'ticket article from')
assert_equal(system_login, article.to, 'ticket article to')
assert_equal(tweet.id.to_s, article.message_id, 'ticket article inbound message_id')
assert_equal(2, article.ticket.articles.count, 'ticket article inbound count')
assert_equal(reply_text.utf8_to_3bytesutf8, ticket.articles.last.body, 'ticket article inbound body')
@ -174,12 +183,12 @@ class TwitterTest < ActiveSupport::TestCase
client = Twitter::REST::Client.new do |config|
config.consumer_key = consumer_key
config.consumer_secret = consumer_secret
config.access_token = me_bauer_token
config.access_token_secret = me_bauer_token_secret
config.access_token = customer_token
config.access_token_secret = customer_token_secret
end
hash = '#citheo24 #' + hash_gen
text = "Today... #{hash}"
hash = "#zarepl24 ##{hash_gen}"
text = "Today #{rand_word}... #{hash}"
tweet = client.update(
text,
)
@ -195,13 +204,13 @@ class TwitterTest < ActiveSupport::TestCase
break if article
sleep 20
}
assert(article, "Can't find tweet id #{tweet.id}")
assert_equal('@me_bauer', article.from, 'ticket article from')
assert(article, "Can't find tweet id #{tweet.id}/#{text}")
assert_equal(customer_login, article.from, 'ticket article from')
assert_equal(nil, article.to, 'ticket article to')
ticket = article.ticket
# send reply
reply_text = '@me_bauer on my side #weather' + hash_gen
reply_text = "#{customer_login} on my side #weather#{hash_gen}"
article = Ticket::Article.create(
ticket_id: ticket.id,
body: reply_text,
@ -212,11 +221,11 @@ class TwitterTest < ActiveSupport::TestCase
created_by_id: 1,
)
assert(article, "outbound article created, text: #{reply_text}")
assert_equal('@armin_theo', article.from, 'ticket article from')
assert_equal('@me_bauer', article.to, 'ticket article to')
assert_equal(system_login, article.from, 'ticket article from')
assert_equal(customer_login, article.to, 'ticket article to')
sleep 5
tweet_found = false
client.user_timeline('armin_theo').each { |local_tweet|
client.user_timeline(system_login_without_at).each { |local_tweet|
sleep 10
next if local_tweet.id.to_s != article.message_id.to_s
tweet_found = true
@ -237,8 +246,8 @@ class TwitterTest < ActiveSupport::TestCase
client = Twitter::REST::Client.new do |config|
config.consumer_key = consumer_key
config.consumer_secret = consumer_secret
config.access_token = armin_theo_token
config.access_token_secret = armin_theo_token_secret
config.access_token = system_token
config.access_token_secret = system_token_secret
end
dms = client.direct_messages(count: 100)
dms.each {|dm|
@ -247,17 +256,17 @@ class TwitterTest < ActiveSupport::TestCase
client = Twitter::REST::Client.new(
consumer_key: consumer_key,
consumer_secret: consumer_secret,
access_token: me_bauer_token,
access_token_secret: me_bauer_token_secret
access_token: customer_token,
access_token_secret: customer_token_secret
)
dms = client.direct_messages(count: 100)
dms.each {|dm|
client.destroy_direct_message(dm.id)
}
hash = '#citheo44' + hash_gen
text = 'How about the details? ' + hash
hash = "#citheo44 #{hash_gen}"
text = "How about #{rand_word} the details? #{hash}"
dm = client.create_direct_message(
'armin_theo',
system_login_without_at,
text,
)
assert(dm, "dm with ##{hash} created")
@ -275,8 +284,8 @@ class TwitterTest < ActiveSupport::TestCase
}
assert(article, "inbound article '#{text}' created")
assert_equal('@me_bauer', article.from, 'ticket article from')
assert_equal('@armin_theo', article.to, 'ticket article to')
assert_equal(customer_login, article.from, 'ticket article from')
assert_equal(system_login, article.to, 'ticket article to')
ticket = article.ticket
assert(ticket, 'ticket of inbound article exists')
assert(ticket.articles, 'ticket.articles exists')
@ -286,8 +295,8 @@ class TwitterTest < ActiveSupport::TestCase
# reply via ticket
outbound_article = Ticket::Article.create(
ticket_id: ticket.id,
to: 'me_bauer',
body: 'Will call you later!',
to: customer_login,
body: "Will call you later #{rand_word}!",
type: Ticket::Article::Type.find_by(name: 'twitter direct-message'),
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
internal: false,
@ -296,14 +305,14 @@ class TwitterTest < ActiveSupport::TestCase
)
assert(outbound_article, 'outbound article created')
assert_equal(2, outbound_article.ticket.articles.count, 'ticket article outbound count')
assert_equal('@armin_theo', outbound_article.from, 'ticket article from')
assert_equal('@me_bauer', outbound_article.to, 'ticket article to')
assert_equal(system_login, outbound_article.from, 'ticket article from')
assert_equal(customer_login, outbound_article.to, 'ticket article to')
ticket.state = Ticket::State.find_by(name: 'pending reminder')
ticket.save
text = 'Ok. ' + hash
text = "#{rand_word}. #{hash}"
dm = client.create_direct_message(
'armin_theo',
system_login_without_at,
text,
)
assert(dm, "second dm with ##{hash} created")
@ -321,8 +330,8 @@ class TwitterTest < ActiveSupport::TestCase
}
assert(article, "inbound article '#{text}' created")
assert_equal('@me_bauer', article.from, 'ticket article inbound from')
assert_equal('@armin_theo', article.to, 'ticket article inbound to')
assert_equal(customer_login, article.from, 'ticket article inbound from')
assert_equal(system_login, article.to, 'ticket article inbound to')
assert_equal(article.ticket.id, ticket.id, 'still the same ticket')
ticket = article.ticket
assert(ticket, 'ticket of inbound article exists')
@ -334,9 +343,9 @@ class TwitterTest < ActiveSupport::TestCase
ticket.state = Ticket::State.find_by(name: 'closed')
ticket.save
text = 'Thanks for your call . I just have one question. ' + hash
text = "Thanks #{rand_word} for your call. I just have one question. #{hash}"
dm = client.create_direct_message(
'armin_theo',
system_login_without_at,
text,
)
assert(dm, "third dm with ##{hash} created")
@ -353,9 +362,9 @@ class TwitterTest < ActiveSupport::TestCase
sleep 15
}
assert(article, "inbound article '#{text}' created")
assert_equal('@me_bauer', article.from, 'ticket article inbound from')
assert_equal('@armin_theo', article.to, 'ticket article inbound to')
assert(article, "inbound article '#{text}' created with dm id #{dm.id}")
assert_equal(customer_login, article.from, 'ticket article inbound from')
assert_equal(system_login, article.to, 'ticket article inbound to')
ticket = article.ticket
assert(ticket, 'ticket of inbound article exists')
assert(ticket.articles, 'ticket.articles exists')
@ -379,11 +388,11 @@ class TwitterTest < ActiveSupport::TestCase
client = Twitter::REST::Client.new do |config|
config.consumer_key = consumer_key
config.consumer_secret = consumer_secret
config.access_token = me_bauer_token
config.access_token_secret = me_bauer_token_secret
config.access_token = customer_token
config.access_token_secret = customer_token_secret
end
hash = '#citheo24 #' + hash_gen
text = "Today... #{hash}"
hash = '#zarepl24 #' + hash_gen
text = "Today... #{rand_word} #{hash}"
tweet = client.update(
text,
)
@ -395,18 +404,18 @@ class TwitterTest < ActiveSupport::TestCase
sleep 15
}
assert(article)
assert_equal('@me_bauer', article.from, 'ticket article from')
assert_equal(customer_login, article.from, 'ticket article from')
assert_equal(nil, article.to, 'ticket article to')
# new tweet II - by me_bauer
client = Twitter::REST::Client.new do |config|
config.consumer_key = consumer_key
config.consumer_secret = consumer_secret
config.access_token = me_bauer_token
config.access_token_secret = me_bauer_token_secret
config.access_token = customer_token
config.access_token_secret = customer_token_secret
end
hash = '#citheo24 #' + rand(999_999).to_s
text = "Today...2 #{hash}"
hash = '#zarepl24 #' + rand(999_999).to_s
text = "Today... #{rand_word} #{hash}"
tweet = client.update(
text,
)
@ -419,20 +428,20 @@ class TwitterTest < ActiveSupport::TestCase
sleep 15
}
assert(article)
assert_equal('@me_bauer', article.from, 'ticket article from')
assert_equal(customer_login, article.from, 'ticket article from')
assert_equal(nil, article.to, 'ticket article to')
# get dm via stream
client = Twitter::REST::Client.new(
consumer_key: consumer_key,
consumer_secret: consumer_secret,
access_token: me_bauer_token,
access_token_secret: me_bauer_token_secret
access_token: customer_token,
access_token_secret: customer_token_secret
)
hash = '#citheo44' + rand(999_999).to_s
text = 'How about the details? ' + hash
text = "How about the #{rand_word}? " + hash
dm = client.create_direct_message(
'armin_theo',
system_login_without_at,
text,
)
assert(dm, "dm with ##{hash} created")
@ -445,8 +454,8 @@ class TwitterTest < ActiveSupport::TestCase
sleep 10
}
assert(article, "inbound article '#{text}' created")
assert_equal('@me_bauer', article.from, 'ticket article from')
assert_equal('@armin_theo', article.to, 'ticket article to')
assert_equal(customer_login, article.from, 'ticket article from')
assert_equal(system_login, article.to, 'ticket article to')
end
@ -454,4 +463,26 @@ class TwitterTest < ActiveSupport::TestCase
rand(999).to_s + (0...10).map { ('a'..'z').to_a[rand(26)] }.join
end
def rand_word
words = [
'dog',
'cat',
'house',
'home',
'yesterday',
'tomorrow',
'new york',
'berlin',
'coffee script',
'java script',
'bob smith',
'be open',
'really nice',
'stay tuned',
'be a good boy',
'invent new things',
]
words[rand(words.length)]
end
end

View file

@ -447,7 +447,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
close_time_in_min
close_time_diff_in_min
update_time_escal_date
updtate_time_sla_time
update_time_sla_time
update_time_in_min
update_time_diff_in_min
last_contact