Skip to content

Commit

Permalink
Admin UI for confirming users (mastodon#2245)
Browse files Browse the repository at this point in the history
* Shows confirmed status in list.

* Adds ability to confirm users in admin UI.

* Added new english translations.

* Addresses feedback from mastodon#2245.

* More feedback.
  • Loading branch information
ashfurrow authored and Gargron committed Apr 23, 2017
1 parent 59b1de0 commit 723f25a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/controllers/admin/confirmations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Admin
class ConfirmationsController < BaseController
before_action :set_account

def create
@account.user.confirm
redirect_to admin_accounts_path
end

private

def set_account
@account = Account.find(params[:account_id])
end
end
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class User < ApplicationRecord
scope :admins, -> { where(admin: true) }
scope :confirmed, -> { where.not(confirmed_at: nil) }

def confirmed?
confirmed_at.present?
end

def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end
Expand Down
7 changes: 7 additions & 0 deletions app/views/admin/accounts/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
%tr
%th= t('admin.accounts.username')
%th= t('admin.accounts.domain')
%th= t('admin.accounts.confirmed')
%th= fa_icon 'paper-plane-o'
%th
%tbody
Expand All @@ -34,6 +35,12 @@
%td
- unless account.local?
= link_to account.domain, admin_accounts_path(by_domain: account.domain)
%td
- if account.local?
- if account.user.present? && account.user.confirmed?
%i.fa.fa-check
- else
%i.fa.fa-times
%td
- if account.local?
= t('admin.accounts.location.local')
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/accounts/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
- else
= link_to t('admin.accounts.silence'), admin_account_silence_path(@account.id), method: :post, class: 'button'

- unless @account.user.confirmed?
= link_to t('admin.accounts.confirm'), admin_account_confirmation_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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ en:
admin:
accounts:
are_you_sure: Are you sure?
confirm: Confirm
confirmed: Confirmed
display_name: Display name
domain: Domain
edit: Edit
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
resource :reset, only: [:create]
resource :silence, only: [:create, :destroy]
resource :suspension, only: [:create, :destroy]
resource :confirmation, only: [:create]
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@
end
end

describe '#confirmed?' do
it 'returns true when a confirmed_at is set' do
user = Fabricate.build(:user, confirmed_at: Time.now.utc)
expect(user.confirmed?).to be true
end

it 'returns false if a confirmed_at is nil' do
user = Fabricate.build(:user, confirmed_at: nil)
expect(user.confirmed?).to be false
end
end

describe 'whitelist' do
around(:each) do |example|
old_whitelist = Rails.configuration.x.email_whitelist
Expand Down

0 comments on commit 723f25a

Please sign in to comment.