about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/resets_controller.rb18
-rw-r--r--app/views/admin/accounts/show.html.haml20
-rw-r--r--config/routes.rb1
-rw-r--r--spec/controllers/admin/resets_controller_spec.rb16
4 files changed, 47 insertions, 8 deletions
diff --git a/app/controllers/admin/resets_controller.rb b/app/controllers/admin/resets_controller.rb
new file mode 100644
index 000000000..6db648403
--- /dev/null
+++ b/app/controllers/admin/resets_controller.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+module Admin
+  class ResetsController < BaseController
+    before_action :set_account
+
+    def create
+      @account.user.send_reset_password_instructions
+      redirect_to admin_accounts_path
+    end
+
+    private
+
+    def set_account
+      @account = Account.find(params[:account_id])
+    end
+  end
+end
diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml
index 6d2a4d123..07dcc7f46 100644
--- a/app/views/admin/accounts/show.html.haml
+++ b/app/views/admin/accounts/show.html.haml
@@ -61,12 +61,16 @@
         = surround '(', ')' do
           = number_to_human_size @account.media_attachments.sum('file_file_size')
 
-- if @account.silenced?
-  = link_to t('admin.accounts.undo_silenced'), admin_account_silence_path(@account.id), method: :delete, class: 'button'
-- else
-  = link_to t('admin.accounts.silence'), admin_account_silence_path(@account.id), method: :post, class: 'button'
+%div{ style: 'float: right' }
+  = link_to t('admin.accounts.reset_password'), admin_account_reset_path(@account.id), method: :create, class: 'button'
 
-- if @account.suspended?
-  = link_to t('admin.accounts.undo_suspension'), admin_account_suspension_path(@account.id), method: :delete, class: 'button'
-- else
-  = link_to t('admin.accounts.perform_full_suspension'), admin_account_suspension_path(@account.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button'
+%div{ style: 'float: left' }
+  - if @account.silenced?
+    = link_to t('admin.accounts.undo_silenced'), admin_account_silence_path(@account.id), method: :delete, class: 'button'
+  - else
+    = link_to t('admin.accounts.silence'), admin_account_silence_path(@account.id), method: :post, class: 'button'
+
+  - if @account.suspended?
+    = link_to t('admin.accounts.undo_suspension'), admin_account_suspension_path(@account.id), method: :delete, class: 'button'
+  - else
+    = link_to t('admin.accounts.perform_full_suspension'), admin_account_suspension_path(@account.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button'
diff --git a/config/routes.rb b/config/routes.rb
index 8dcd4b330..31909a4f4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -86,6 +86,7 @@ Rails.application.routes.draw do
     end
 
     resources :accounts, only: [:index, :show] do
+      resource :reset, only: [:create]
       resource :silence, only: [:create, :destroy]
       resource :suspension, only: [:create, :destroy]
     end
diff --git a/spec/controllers/admin/resets_controller_spec.rb b/spec/controllers/admin/resets_controller_spec.rb
new file mode 100644
index 000000000..283ab029f
--- /dev/null
+++ b/spec/controllers/admin/resets_controller_spec.rb
@@ -0,0 +1,16 @@
+require 'rails_helper'
+
+describe Admin::ResetsController do
+  let(:account) { Fabricate(:account, user: Fabricate(:user)) }
+  before do
+    sign_in Fabricate(:user, admin: true), scope: :user
+  end
+
+  describe 'POST #create' do
+    it 'redirects to admin accounts page' do
+      post :create, params: { account_id: account.id }
+
+      expect(response).to redirect_to(admin_accounts_path)
+    end
+  end
+end