FEATURE: display associated accounts in admin user

This commit is contained in:
Sam 2014-09-25 15:50:54 +10:00
parent d31322ea56
commit c248d28c38
6 changed files with 51 additions and 1 deletions

View file

@ -40,6 +40,11 @@
{{/unless}}
</div>
<div class='display-row associations'>
<div class='field'>{{i18n user.associated_accounts}}</div>
<div class='value'>{{associated_accounts}}</div>
</div>
<div class='display-row'>
<div class='field'>{{i18n user.avatar.title}}</div>
<div class='value'>{{avatar content imageSize="large"}}</div>

View file

@ -41,6 +41,7 @@ class User < ActiveRecord::Base
has_one :facebook_user_info, dependent: :destroy
has_one :twitter_user_info, dependent: :destroy
has_one :github_user_info, dependent: :destroy
has_one :google_user_info, dependent: :destroy
has_one :oauth2_user_info, dependent: :destroy
has_one :user_stat, dependent: :destroy
has_one :user_profile, dependent: :destroy, inverse_of: :user
@ -633,6 +634,31 @@ class User < ActiveRecord::Base
user_stat.try(:first_post_created_at)
end
def associated_accounts
result = []
if twitter_user_info
result << "Twitter(#{twitter_user_info.screen_name})"
end
if facebook_user_info
result << "Facebook(#{facebook_user_info.username})"
end
if google_user_info
result << "Google(#{google_user_info.email})"
end
if github_user_info
result << "Github(#{github_user_info.screen_name})"
end
user_open_ids.each do |oid|
result << "OpenID #{oid.url[0..20]}...(#{oid.email})"
end
result.empty? ? I18n.t("user.no_accounts_associated") : result.join(", ")
end
protected
def badge_grant

View file

@ -24,7 +24,8 @@ class AdminUserSerializer < BasicUserSerializer
:can_activate,
:can_deactivate,
:blocked,
:time_read
:time_read,
:associated_accounts
has_one :single_sign_on_record, serializer: SingleSignOnRecordSerializer, embed: :objects

View file

@ -490,6 +490,7 @@ en:
ok: "Your password looks good."
instructions: "At least %{count} characters."
associated_accounts: "Associated accounts"
ip_address:
title: "Last IP Address"
registration_ip_address:

View file

@ -1108,6 +1108,7 @@ en:
password_too_long: "Passwords are limited to 200 characters."
user:
no_accounts_associated: "No accounts associated"
username:
short: "must be at least %{min} characters"
long: "must be no more than %{max} characters"

View file

@ -405,6 +405,22 @@ describe User do
end
end
describe 'associated_accounts' do
it 'should correctly find social associations' do
user = Fabricate(:user)
user.associated_accounts.should == I18n.t("user.no_accounts_associated")
TwitterUserInfo.create(user_id: user.id, screen_name: "sam", twitter_user_id: 1)
FacebookUserInfo.create(user_id: user.id, username: "sam", facebook_user_id: 1)
GoogleUserInfo.create(user_id: user.id, email: "sam@sam.com", google_user_id: 1)
GithubUserInfo.create(user_id: user.id, screen_name: "sam", github_user_id: 1)
user.reload
user.associated_accounts.should == "Twitter(sam), Facebook(sam), Google(sam@sam.com), Github(sam)"
end
end
describe 'name heuristics' do
it 'is able to guess a decent name from an email' do
User.suggest_name('sam.saffron@gmail.com').should == 'Sam Saffron'