Skip to content

Commit

Permalink
feat: merge from centosadmin
Browse files Browse the repository at this point in the history
  • Loading branch information
RexQian committed Jan 26, 2017
2 parents 7306eb4 + b3732cd commit 69c115c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.2

* Add reset 2fa for admin.

# 1.3.1

* Add timeout handling for SMS command
Expand Down Expand Up @@ -26,7 +30,7 @@

# 1.2.1

* add `requires_redmine_plugin :redmine_telegram_common`,
* add `requires_redmine_plugin :redmine_telegram_common`,
* add defer plugin dependency check patch for load `redmine_telegram_common` before `redmine_2fa` loaded. Extracted from [here](https://github.com/michaelkrupp-redmine/redmine_pluginloader). [Redmine issue](http://www.redmine.org/issues/6324#change-73605).

# 1.2.0
Expand Down
11 changes: 8 additions & 3 deletions app/controllers/second_authentications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ class SecondAuthenticationsController < ApplicationController
unloadable

def destroy
User.current.reset_second_auth
flash[:notice] = l(:notice_2fa_reset)
redirect_to my_account_path
user = User.find(params[:id])
if User.current.admin? || user == User.current
user.reset_second_auth
flash[:notice] = l(:notice_2fa_reset)
redirect_to(:back)
else
render_403
end
end
end
7 changes: 7 additions & 0 deletions app/views/second_authentications/_link_to_reset.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script type="text/javascript">
$(document).ready(function($) {
if($(".controller-users.action-edit").length > 0) {
$($("#content .contextual")[0]).append('<%= j render 'second_authentications/reset', user: @user %>');
}
});
</script>
2 changes: 1 addition & 1 deletion app/views/second_authentications/_reset.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% if user.two_factor_authenticable? or user.ignore_2fa? %>
<%= link_to l(:link_2fa_reset), second_authentication_reset_path, method: :delete, class: 'icon icon-not-ok' %>
<%= link_to l(:link_2fa_reset), second_authentication_reset_path(user), method: :delete, class: 'icon icon-not-ok' %>
<% end %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# 2FA management

delete 'reset', to: 'second_authentications#destroy', as: 'second_authentication_reset'
delete 'users/:id/reset', to: 'second_authentications#destroy', as: 'second_authentication_reset'

# 2FA step

Expand Down
3 changes: 2 additions & 1 deletion lib/redmine_2fa/hooks/view_my_account_contextual_hook.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Redmine2FA
module Hooks
class ViewMyAccountContextualHook < Redmine::Hook::ViewListener
render_on :view_my_account_contextual, partial: 'second_authentications/reset'
render_on :view_my_account_contextual, partial: 'second_authentications/reset', user: @user
render_on :view_users_form, partial: 'second_authentications/link_to_reset'
end
end
end

0 comments on commit 69c115c

Please sign in to comment.