Skip to content

Commit

Permalink
Added unlock feature + fixed locked feature
Browse files Browse the repository at this point in the history
  • Loading branch information
aka001 committed Feb 18, 2015
1 parent 69e1405 commit ea83d91
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/controllers/admin/users_controller.rb
Expand Up @@ -13,6 +13,12 @@ def lock_account
redirect_to user_search_path, notice: t("admins.user_search.account_locking_scheduled", name: u.username)
end

def unlock_account
u = User.find(close_account_params)
u.unlock_account!
redirect_to user_search_path, notice: t("admins.user_search.account_unlocking_scheduled", name: u.username)
end

private

def close_account_params
Expand Down
8 changes: 7 additions & 1 deletion app/models/user.rb
Expand Up @@ -457,7 +457,13 @@ def close_account!
end

def lock_account!
self.save(:locked_at => Time.now)
self.locked_at = Time.now
self.save
end

def unlock_account!
self.locked_at = nil
self.save
end

def clear_account!
Expand Down
6 changes: 4 additions & 2 deletions app/views/admins/_user_entry.haml
Expand Up @@ -25,8 +25,10 @@
%li= link_to t('admins.user_search.close_account'), admin_close_account_path(user), method: :post, data: { confirm: t('admins.user_search.are_you_sure') }, class: 'btn btn-danger btn-mini'

- unless user.locked_at
%li= link_to t('admins.user_search.lock_account'), admin_close_account_path(user), method: :post, data: { confirm: t('admins.user_search.are_you_sure_lock_account') }, class: 'btn btn-danger btn-mini'

%li= link_to t('admins.user_search.lock_account'), admin_lock_account_path(user), method: :post, data: { confirm: t('admins.user_search.are_you_sure_lock_account') }, class: 'btn btn-danger btn-mini'
- if user.locked_at
%li= link_to t('admins.user_search.unlock_account'), admin_unlock_account_path(user), method: :post, data: { confirm: t('admins.user_search.are_you_sure_unlock_account') }, class: 'btn btn-danger btn-mini'

%div.row
%div.span5
%dl.dl-horizontal
Expand Down
2 changes: 2 additions & 0 deletions config/locales/diaspora/en.yml
Expand Up @@ -115,8 +115,10 @@ en:
close_account: "close account"
are_you_sure: "Are you sure you want to close this account?"
are_you_sure_lock_account: "Are you sure you want to lock this account?"
are_you_sure_unlock_account: "Are you sure you want to unlock this account?"
account_closing_scheduled: "The account of %{name} is scheduled to be closed. It will be processed in a few moments..."
account_locking_scheduled: "The account of %{name} is scheduled to be locked. It will be processed in a few moments..."
account_unlocking_scheduled: "The account of %{name} is scheduled to be unlocked. It will be processed in a few moments..."
email_to: "Email to Invite"
under_13: "Show users that are under 13 (COPPA)"
users:
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -139,6 +139,8 @@

namespace :admin do
post 'users/:id/close_account' => 'users#close_account', :as => 'close_account'
post 'users/:id/lock_account' => 'users#lock_account', :as => 'lock_account'
post 'users/:id/unlock_account' => 'users#unlock_account', :as => 'unlock_account'
end

resource :profile, :only => [:edit, :update]
Expand Down

0 comments on commit ea83d91

Please sign in to comment.