Skip to content

Commit

Permalink
Merge pull request #10 from centosadmin/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vladislav-yashin authored Aug 8, 2018
2 parents f4ce2c4 + b7909db commit 386de8b
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 48 deletions.
4 changes: 2 additions & 2 deletions app/workers/issue_chat_message_sender_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class IssueChatMessageSenderWorker
period: 1
}

def perform(im_id, platform_name, message)
Redmine2chat.platforms[platform_name].send_message(im_id, message)
def perform(im_id, platform_name, message, params = {})
Redmine2chat.platforms[platform_name].send_message(im_id, message, params)
end
end
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ en:

error_editing_issue: Failed to edit the issue. Perhaps you entered the wrong data or you do not have the access.
warning_editing_issue: Field %{field} already has the requested value.
notes_saved: Notes saved successfully
hot: Assigned to you issues with recent activity
me: Assigned to you issues
deadline: Assigned to you issues with expired deadline
Expand Down Expand Up @@ -139,7 +140,7 @@ en:
messages:
hello: "Hello, everybody! This is a chat for issue: %{issue_url}"
closed_from_issue: chat was closed from issue
closed_automaticaly: chat was closed automatically
closed_automatically: chat was closed automatically
close_notification: "The issue of this chat is closed. Chat will automatically disbanded after %{time_in_words}."
archive:
joined: joined the chat
Expand Down
3 changes: 2 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ru:

error_editing_issue: Не удалось отредактировать задачу. Возможно вы ввели неверные данные или у вас нет необходимого доступа.
warning_editing_issue: Поле %{field} уже имеет запрашиваемое значение.
notes_saved: Примечания успешно добавлены
hot: Назначенные вам задачи с активностью за последние сутки
me: Назначенные вам задачи
deadline: Назначенные вам задачи с просроченным дедлайном
Expand Down Expand Up @@ -139,7 +140,7 @@ ru:
messages:
hello: "Всем привет! Это чат для задачи: %{issue_url}"
closed_from_issue: Чат закрыт из задачи.
closed_automaticaly: Чат закрыт автоматически.
closed_automatically: Чат закрыт автоматически.
close_notification: "Задача по этому чату закрыта. Чат будет автоматически расформирован через %{time_in_words}."
archive:
joined: присоединился к чату
Expand Down
2 changes: 2 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
RedmineBots::Slack::Bot.register_commands Redmine2chat::Platforms::Slack::Commands::Me,
Redmine2chat::Platforms::Slack::Commands::Spent,
Redmine2chat::Platforms::Slack::Commands::Yspent

RedmineBots::Telegram.update_manager.add_handler(->(message) { Redmine2chat::Telegram::Bot.new(message).call if message.is_a?(::Telegram::Bot::Types::Message) })
end

Rails.application.config.eager_load_paths += Dir.glob("#{Rails.application.config.root}/plugins/redmine_2chat/{lib,app/workers,app/models,app/controllers}")
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine2chat/platforms/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def close_chat(im_id, message)
robot_client.channels_archive(channel: im_id)
end

def send_message(im_id, message)
def send_message(im_id, message, **)
robot_client.chat_postMessage(channel: im_id, text: message)
end

Expand Down
16 changes: 3 additions & 13 deletions lib/redmine2chat/platforms/telegram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ module Utils
end

class Telegram
def initialize
RedmineBots::Telegram.update_manager.add_handler(method(:handle_message))
end

def icon_path
'/plugin_assets/redmine_2chat/images/telegram-icon.png'
end
Expand All @@ -34,20 +30,14 @@ def close_chat(im_id, message)
Utils.get_chat_link.(im_id)
end

def send_message(im_id, message)
def send_message(im_id, message, params = {})
message_params = {
chat_id: im_id,
message: Nokogiri::HTML::DocumentFragment.parse(message).to_html,
message: message,
bot_token: RedmineBots::Telegram.bot_token
}
}.merge(params)

RedmineBots::Telegram::Bot::MessageSender.call(message_params)
end

private

def handle_message(message)
Redmine2chat::Telegram::Bot.new(message).call if message.is_a?(::Telegram::Bot::Types::Message)
end
end
end
2 changes: 1 addition & 1 deletion lib/redmine2chat/telegram/bot/group_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def new_chat_members

def can_manage_chat?(telegram_user)
telegram_account = TelegramAccount.find_by(telegram_id: telegram_user.id)
telegram_account && telegram_account.user && telegram_account.user.allowed_to?(:manage_telegram_chat, issue.project)
telegram_account && telegram_account.user && telegram_account.user.allowed_to?(:manage_chat, issue.project)
end

def edit_group_admin(telegram_user, is_admin = true)
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine2chat/telegram/commands/base_bot_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def arguments_help
end

def send_message(text, params = {})
IssueChatMessageSenderWorker.perform_async(chat_id, 'telegram', text)
IssueChatMessageSenderWorker.perform_async(chat_id, 'telegram', text, params)
end

def account
Expand Down
16 changes: 4 additions & 12 deletions lib/redmine2chat/telegram/commands/edit_issue_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ class EditIssueCommand < BaseBotCommand

PER_PAGE = 10

EDITABLES = [
'project',
'tracker',
'subject',
'status',
'priority',
'assigned_to',
'start_date',
'due_date',
'estimated_hours',
'done_ratio']
EDITABLES = %w(project tracker subject status priority assigned_to start_date due_date estimated_hours done_ratio notes)

def execute
return unless account.present?
Expand Down Expand Up @@ -109,6 +99,8 @@ def execute_step_5
if journal.present?
if journal.details.any?
send_message(details_to_strings(journal.details).join("\n"))
elsif attr == 'notes'
send_message(I18n.t('redmine_2chat.bot.notes_saved'))
else
send_message(I18n.t('redmine_2chat.bot.warning_editing_issue', field: attr))
end
Expand Down Expand Up @@ -233,7 +225,7 @@ def make_keyboard(items)
Telegram::Bot::Types::ReplyKeyboardMarkup.new(
keyboard: items_with_cancel.each_slice(2).to_a,
one_time_keyboard: true,
resize_keyboard: true)
resize_keyboard: true).to_json
end

def issue
Expand Down
4 changes: 2 additions & 2 deletions lib/redmine2chat/telegram/commands/issue_chat_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def issue
end

def create_issue_chat
if account.user.allowed_to?(:create_telegram_chat, issue.project)
if account.user.allowed_to?(:create_chat, issue.project)
return unless plugin_module_enabled?

creating_chat_message = I18n.t('redmine_2chat.bot.creating_chat')
Expand All @@ -37,7 +37,7 @@ def create_issue_chat
end

def close_issue_chat
if account.user.allowed_to?(:close_telegram_chat, issue.project)
if account.user.allowed_to?(:close_chat, issue.project)
CloseChat.(issue)
message_text = I18n.t('redmine_2chat.bot.chat.destroyed')
send_message(message_text)
Expand Down
28 changes: 14 additions & 14 deletions test/integration/redmine_2chat/commands/edit_issue_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ class Redmine2chat::Telegram::Commands::EditIssueCommandTest < ActiveSupport::Te
I18n.t('redmine_2chat.bot.edit_issue.select_param'),
I18n.t('redmine_2chat.bot.edit_issue.cancel_hint')
].join(' ')
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns(nil)
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns({})
Redmine2chat::Telegram::Commands::BaseBotCommand.any_instance
.expects(:send_message)
.with(text, reply_markup: nil)
.with(text, reply_markup: '{}')
Redmine2chat::Telegram::Commands::EditIssueCommand.new(command).execute
end

it 'offers to select project' do
command = Telegram::Bot::Types::Message.new(command_params.merge(text: '/issue project'))
text = I18n.t('redmine_2chat.bot.new_issue.choice_project_without_page')
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns(nil)
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns({})
Redmine2chat::Telegram::Commands::BaseBotCommand.any_instance
.expects(:send_message)
.with(text, reply_markup: nil)
.with(text, reply_markup: '{}')
Redmine2chat::Telegram::Commands::EditIssueCommand.new(command).execute
end

Expand All @@ -80,11 +80,11 @@ class Redmine2chat::Telegram::Commands::EditIssueCommandTest < ActiveSupport::Te
I18n.t('redmine_2chat.bot.edit_issue.cancel_hint')
].join(' ')

Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns('markup')
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns({})

Redmine2chat::Telegram::Commands::BaseBotCommand.any_instance
.expects(:send_message)
.with(text_2, reply_markup: 'markup')
.with(text_2, reply_markup: '{}')

Redmine2chat::Telegram::Commands::EditIssueCommand.new(command).execute
end
Expand All @@ -109,11 +109,11 @@ class Redmine2chat::Telegram::Commands::EditIssueCommandTest < ActiveSupport::Te
I18n.t('redmine_2chat.bot.edit_issue.cancel_hint')
].join(' ')

Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns('markup')
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns({})

Redmine2chat::Telegram::Commands::BaseBotCommand.any_instance
.expects(:send_message)
.with(text_2, reply_markup: 'markup')
.with(text_2, reply_markup: '{}')

Redmine2chat::Telegram::Commands::EditIssueCommand.new(command).execute
end
Expand Down Expand Up @@ -143,11 +143,11 @@ class Redmine2chat::Telegram::Commands::EditIssueCommandTest < ActiveSupport::Te
I18n.t('redmine_2chat.bot.edit_issue.cancel_hint')
].join(' ')

Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns('markup')
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns({})

Redmine2chat::Telegram::Commands::BaseBotCommand.any_instance
.expects(:send_message)
.with(text_2, reply_markup: 'markup')
.with(text_2, reply_markup: '{}')

Redmine2chat::Telegram::Commands::EditIssueCommand.new(command).execute
end
Expand Down Expand Up @@ -175,10 +175,10 @@ class Redmine2chat::Telegram::Commands::EditIssueCommandTest < ActiveSupport::Te
I18n.t('redmine_2chat.bot.edit_issue.select_param'),
I18n.t('redmine_2chat.bot.edit_issue.cancel_hint')
].join(' ')
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns(nil)
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns({})
Redmine2chat::Telegram::Commands::BaseBotCommand.any_instance
.expects(:send_message)
.with(text, reply_markup: nil)
.with(text, reply_markup: '{}')
Redmine2chat::Telegram::Commands::EditIssueCommand.new(command).execute
end

Expand All @@ -203,10 +203,10 @@ class Redmine2chat::Telegram::Commands::EditIssueCommandTest < ActiveSupport::Te
it 'offerts to send new value for editing param' do
command = Telegram::Bot::Types::Message.new(command_params.merge(text: 'status'))
text = I18n.t('redmine_2chat.bot.edit_issue.select_status')
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns(nil)
Telegram::Bot::Types::ReplyKeyboardMarkup.expects(:new).returns({})
Redmine2chat::Telegram::Commands::BaseBotCommand.any_instance
.expects(:send_message)
.with(text, reply_markup: nil)
.with(text, reply_markup: '{}')
Redmine2chat::Telegram::Commands::EditIssueCommand.new(command).execute
end

Expand Down

0 comments on commit 386de8b

Please sign in to comment.