Skip to content

Commit

Permalink
Merge pull request #48 from centosadmin/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vladislav-yashin authored Mar 1, 2018
2 parents d715afe + ed62cf7 commit a711ed2
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 166 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.4.0

* Update telegram-bot-ruby
* Use bot from redmine_telegram_common
* Add link to bot in code instruction

# 1.3.4

* Add bot collision check
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
source 'https://rubygems.org'

gem 'telegram-bot-ruby', '<= 0.7.2'
gem 'active_model_otp'
gem 'rqrcode'

Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ Supports:
- HTTPS host - Telegram Bot Webhook needs to POST on HTTPS hosts.
- Ruby 2.3+

### Upgrade from 1.3.4 to 1.4.0+

From 1.4.0 redmine_2fa (as well as other Southbridge telegram plugins) is using bot from redmine_telegram_common.
In order to perform migration to single bot you should run `bundle exec rake telegram_common:migrate_to_single_bot`.
Bot token will be taken from one of installed Southbridge plugins in the following priority:

* redmine_chat_telegram
* redmine_intouch
* redmine_2fa

Also you should re-initialize bot on redmine_telegram_common settings page.

### Upgrade form 1.1.3 to 1.2.0+

Since version 1.2.0 this plugin uses [redmine_telegram_common](https://github.com/centosadmin/redmine_telegram_common) plugin.
Expand All @@ -31,10 +43,6 @@ Since 2.0 version, model `Redmine2FA::TelegramAccount` will be removed, also tab

### Important!!!

A bot for this plugin must be unique.

Otherwise, there may be conflicts if the same bot is used in other plug-in with update polling mode.

A bot can operate either via the web-hook, or through periodic polling.

This plugin uses web-hook mechanism, so be sure to use the HTTPS protocol.
Expand Down
12 changes: 10 additions & 2 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
- HTTPS - нужен для того, чтобы принимать сообщение от Telegram Bot API ([веб-хук](https://tlgrm.ru/docs/bots/api#setwebhook))
- Ruby 2.3+

### Обновление с 1.3.4 до 1.4.0+

Начиная с версии 1.4.0 redmine_2fa (так же, как и другие telegram-плагины от Southbridge) использует бота из redmine_telegram_common.
Чтобы произвести миграцию для использования единого бота, нужно выполнить команду `bundle exec rake telegram_common:migrate_to_single_bot`.
Token бота будет взят из одного из установленных плагинов от Southbridge в следующем приоритете:

* redmine_chat_telegram
* redmine_intouch
* redmine_2fa

### Обновление с 1.1.3 на 1.2.0+

Начиная с версии 1.2.0 это плагин использует [redmine_telegram_common](https://github
Expand All @@ -32,8 +42,6 @@

### Важно!!!

Бот для этого плагина должен быть уникальным. Иначе могут быть конфликты, если тот же бот используется в другом плагине в режиме опроса обновлений.

Бот может работать либо через web-hook либо через периодический опрос.

В этом плагине используется механизм web-hook, поэтому использование протокола HTTPS обязательно.
Expand Down
63 changes: 0 additions & 63 deletions app/controllers/otp_bot_controller.rb

This file was deleted.

21 changes: 0 additions & 21 deletions app/controllers/otp_bot_webhook_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/account/init_2fa/_telegram.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<tr class="instruction2FA telegramInstruction" style="<%= style %>">
<td colspan="3">
<%= t 'redmine_2fa.second_authentications.telegram.instruction_html', bot_name: Setting.plugin_redmine_2fa['bot_name'] %>
<%= t 'redmine_2fa.second_authentications.telegram.instruction_html', bot_name: Setting.plugin_redmine_telegram_common['bot_name'] %>
</td>
</tr>
2 changes: 1 addition & 1 deletion app/views/account/otp.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<tr id="otpCodeResentInstruction" style="display: none">
<td align="center" colspan="2">
<%= t('redmine_2fa.resend.instruction_html', timeout: 30) %>
<%= t('redmine_2fa.resend.instruction_html', timeout: 30, bot_name: Setting.plugin_redmine_telegram_common['bot_name']) %>
</td>
</tr>

Expand Down
44 changes: 0 additions & 44 deletions app/views/settings/_redmine_2fa.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,3 @@
</li>
<% end %>
</ul>

<h4>Telegram</h4>
<p>
<label for="settings_bot_token">Bot Token</label>
<%= text_field_tag 'settings[bot_token]', @settings['bot_token'], size: 50 %>
<% if (bot_collisions = TelegramCommon.bot_collisions).present? %>
<br>
<strong style="color: red"><%= t 'telegram_common.settings.bot_collision' %></strong>
<% bot_collisions.each do |collision| %>
<p>
<strong><%= collision.join(', ') %><strong>
</p>
<% end %>
<% end %>
</p>
<table style="width: 100%">
<tr>
<td style="width: 50%"><h3><%= t('redmine_2fa.settings.telegram.init.header') %></h3></td>
<td style="width: 50%"><h3><%= t('redmine_2fa.settings.telegram.reset.header') %></h3></td>
</tr>
<tr>
<td>
<%= t('redmine_2fa.settings.telegram.init.description_html') %>
</td>
<td>
<%= t('redmine_2fa.settings.telegram.reset.description_html') %>
</td>
</tr>
<tr>
<td>
<%= link_to otp_bot_init_path, method: 'post' do %>
<button type="button"><%= t('redmine_2fa.settings.telegram.init.button_text') %></button>
<% end %>
</td>
<td>
<%= link_to otp_bot_reset_path, method: 'delete' do %>
<button type="button"><%= t('redmine_2fa.settings.telegram.reset.button_text') %></button>
<% end %>
</td>
</tr>
</table>

<%= hidden_field_tag 'settings[bot_name]', @settings['bot_name'] %>
<%= hidden_field_tag 'settings[bot_id]', @settings['bot_id'] %>
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ en:
auth_code: 'Authorization code'
resend:
link: 'Resend code'
instruction_html: 'Code sent. Code resending possible after <span id="otpCodeResendTimer">%{timeout}</span> seconds.'
instruction_html: 'Code sent by <a href="https://telegram.me/%{bot_name}" target="_blank">%{bot_name}</a> (need to be in your contacts list).<br><br>Code resending is possible after 5 seconds <span id="otpCodeResendTimer">%{timeout}</span> секунд.'
notice:
auth_code:
invalid: 'Wrong authorization code'
Expand Down
2 changes: 1 addition & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ru:
auth_code: 'Код подтверждения'
resend:
link: 'Отправить повторно'
instruction_html: 'Код отправлен. Повторная отправка кода возможна через <span id="otpCodeResendTimer">%{timeout}</span> секунд.'
instruction_html: 'Код отправлен ботом <a href="https://telegram.me/%{bot_name}" target="_blank">%{bot_name}</a> (необходимо добавить в контакты).<br><br>Повторная отправка кода возможна через <span id="otpCodeResendTimer">%{timeout}</span> секунд.'
notice:
auth_code:
invalid: 'Неверный код подтверждения'
Expand Down
9 changes: 0 additions & 9 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
scope 'redmine_2fa' do
# Plugin settings

post 'bot/init' => 'otp_bot#create', as: 'otp_bot_init'
delete 'bot/reset' => 'otp_bot#destroy', as: 'otp_bot_reset'

# 2FA init
put 'mobile_phone/update', to: 'user_mobile_phone#update', as: 'user_mobile_phone_update'
post 'mobile_phone/confirm', to: 'user_mobile_phone#confirm', as: 'user_mobile_phone_confirm'
Expand All @@ -18,8 +13,4 @@

post 'otp_code/resend', to: 'otp_codes#create', as: 'resend_otp'
post 'otp_code/confirm', to: 'account#confirm_otp', as: 'confirm_otp'

# Telegram bot webhook

post 'bot/:token/update' => 'otp_bot_webhook#update'
end
7 changes: 5 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
require 'redmine_2fa'
require 'telegram/bot'

ActionDispatch::Callbacks.to_prepare do
# Rails 5.1/Rails 4
reloader = defined?(ActiveSupport::Reloader) ? ActiveSupport::Reloader : ActionDispatch::Reloader

reloader.to_prepare do
%w( /app/models/redmine_2fa/*.rb
/app/models/redmine_2fa/auth_source/*.rb
/lib/redmine_2fa/patches/account_controller_patch/*.rb
Expand All @@ -18,7 +21,7 @@

Redmine::Plugin.register :redmine_2fa do
name 'Redmine 2FA'
version '1.3.4'
version '1.4.0'
url 'https://github.com/centosadmin/redmine_2fa'
description 'Two-factor authorization for Redmine'
author 'Southbridge'
Expand Down
6 changes: 5 additions & 1 deletion lib/redmine_2fa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ def self.switched_off?
end

def self.bot_token
Setting.plugin_redmine_2fa['bot_token']
Setting.plugin_redmine_telegram_common['bot_token']
end

def self.logger
Logger.new(Rails.root.join('log', 'redmine_2fa', 'bot-update.log'))
end

def self.handle_message(message)
TelegramCommon::Bot.new(bot_token, message).call if message.is_a?(Telegram::Bot::Types::Message)
end

module Configuration
def self.configuration
Redmine::Configuration['redmine_2fa']
Expand Down
7 changes: 0 additions & 7 deletions test/integration/routing/otp_bot_test.rb

This file was deleted.

8 changes: 0 additions & 8 deletions test/integration/routing/otp_bot_webhook_test.rb

This file was deleted.

0 comments on commit a711ed2

Please sign in to comment.