Skip to content

Commit

Permalink
FEATURE: display associated accounts in admin user
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Sep 25, 2014
1 parent d31322e commit c248d28
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
26 changes: 26 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -633,6 +634,31 @@ def first_post_created_at
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
Expand Down
3 changes: 2 additions & 1 deletion app/serializers/admin_user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,22 @@
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'
Expand Down

0 comments on commit c248d28

Please sign in to comment.