diff --git a/Changelog.md b/Changelog.md index eda648117fbacd195ab359f3de6d6fc50d4cc350..b11c3d24395e57b33ea7a2ed6a760dbe09cedabc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -173,6 +173,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a * Make help sections linkable [#5667](https://github.com/diaspora/diaspora/pull/5667) * Add invitation link to contacts page [#5655](https://github.com/diaspora/diaspora/pull/5655) * Add year to notifications page [#5676](https://github.com/diaspora/diaspora/pull/5676) +* Give admins the ability to lock & unlock accounts [#5643](https://github.com/diaspora/diaspora/pull/5643) # 0.4.1.2 diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 5167cdee7c7f0fd9bae64edfcd81780d6af7a364..2163c3630086715d81b34e938aa8af48b2bad175 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -2,15 +2,22 @@ module Admin class UsersController < AdminController def close_account - u = User.find(close_account_params) + u = User.find(params[:id]) u.close_account! - redirect_to user_search_path, notice: t('admins.user_search.account_closing_scheduled', name: u.username) + redirect_to user_search_path, notice: t("admins.user_search.account_closing_scheduled", name: u.username) end - private + def lock_account + u = User.find(params[:id]) + u.lock_access! + redirect_to user_search_path, notice: t("admins.user_search.account_locking_scheduled", name: u.username) + end - def close_account_params - params.require(:id) + def unlock_account + u = User.find(params[:id]) + u.unlock_access! + redirect_to user_search_path, notice: t("admins.user_search.account_unlocking_scheduled", name: u.username) end + end end diff --git a/app/models/user.rb b/app/models/user.rb index 1fa150afb860a7fa958e48a304134a985dde52dc..7fb19c411e9460c0c9fd106f09d912c1adc73626 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -480,6 +480,10 @@ class User < ActiveRecord::Base AccountDeletion.create(:person => self.person) end + def closed_account? + self.person.closed_account + end + def clear_account! clearable_fields.each do |field| self[field] = nil diff --git a/app/views/admins/_user_entry.haml b/app/views/admins/_user_entry.haml index d6223f2ccd9eb2089e594840e774d2b7f823c4cb..5fa76beaa721e094f1ca56afd0e45ea81d12ec41 100644 --- a/app/views/admins/_user_entry.haml +++ b/app/views/admins/_user_entry.haml @@ -24,6 +24,12 @@ - unless user.person.closed_account %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.closed_account? + - unless user.access_locked? + %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' + - else + %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 diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index d31afd681a09e215050d8a223d03b2417ba4c946..04d3c2965131c9f08d037191a7da1b45092928f6 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -115,7 +115,12 @@ en: add_invites: "Add invites" 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" email_to: "Email to invite" under_13: "Show users that are under 13 (COPPA)" users: diff --git a/config/routes.rb b/config/routes.rb index 8aa59a909200b34e4727cb7e05a5b7aac8e51ceb..8eed61639eec8c74190d3a6e26642e90600f1df5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -143,6 +143,8 @@ Diaspora::Application.routes.draw do 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] diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index dc238d51ad03c39dc54d13f7ccd7aa21fa1b9926..c2653685378946d28dc28a66503004427689f762 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -19,4 +19,21 @@ describe Admin::UsersController, :type => :controller do end end + describe '#lock_account' do + it 'it locks the given account' do + other_user = FactoryGirl.create :user + other_user.lock_access! + expect(other_user.reload.access_locked?).to be_truthy + end + end + + describe '#unlock_account' do + it 'it unlocks the given account' do + other_user = FactoryGirl.create :user + other_user.lock_access! + other_user.unlock_access! + expect(other_user.reload.access_locked?).to be_falsey + end + end + end