mirror of
https://github.com/discourse/discourse.git
synced 2025-04-29 01:14:35 +08:00
FEATURE: Add a location field to a user's profile
This commit is contained in:
parent
1efa113bea
commit
7c22d738b6
@ -191,6 +191,7 @@ Discourse.User = Discourse.Model.extend({
|
|||||||
var data = this.getProperties('auto_track_topics_after_msecs',
|
var data = this.getProperties('auto_track_topics_after_msecs',
|
||||||
'bio_raw',
|
'bio_raw',
|
||||||
'website',
|
'website',
|
||||||
|
'location',
|
||||||
'name',
|
'name',
|
||||||
'locale',
|
'locale',
|
||||||
'email_digests',
|
'email_digests',
|
||||||
|
@ -127,10 +127,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">{{i18n user.location}}</label>
|
||||||
|
<div class="controls">
|
||||||
|
{{input type="text" value=location class="input-xxlarge"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{i18n user.website}}</label>
|
<label class="control-label">{{i18n user.website}}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{textField value=website classNames="input-xxlarge"}}
|
{{input type="text" value=website class="input-xxlarge"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -86,6 +86,9 @@
|
|||||||
|
|
||||||
<div class='secondary'>
|
<div class='secondary'>
|
||||||
<dl>
|
<dl>
|
||||||
|
{{#if location}}
|
||||||
|
<dt>{{i18n user.location}}</dt><dd>{{location}}</a></dd>
|
||||||
|
{{/if}}
|
||||||
{{#if websiteName}}
|
{{#if websiteName}}
|
||||||
<dt>{{i18n user.website}}</dt><dd><a {{bind-attr href="website"}} target="_blank">{{websiteName}}</a></dd>
|
<dt>{{i18n user.website}}</dt><dd><a {{bind-attr href="website"}} target="_blank">{{websiteName}}</a></dd>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -39,6 +39,7 @@ class User < ActiveRecord::Base
|
|||||||
has_one :github_user_info, dependent: :destroy
|
has_one :github_user_info, dependent: :destroy
|
||||||
has_one :oauth2_user_info, dependent: :destroy
|
has_one :oauth2_user_info, dependent: :destroy
|
||||||
has_one :user_stat, dependent: :destroy
|
has_one :user_stat, dependent: :destroy
|
||||||
|
has_one :user_profile, dependent: :destroy
|
||||||
has_one :single_sign_on_record, dependent: :destroy
|
has_one :single_sign_on_record, dependent: :destroy
|
||||||
belongs_to :approved_by, class_name: 'User'
|
belongs_to :approved_by, class_name: 'User'
|
||||||
belongs_to :primary_group, class_name: 'Group'
|
belongs_to :primary_group, class_name: 'Group'
|
||||||
@ -73,6 +74,7 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
after_create :create_email_token
|
after_create :create_email_token
|
||||||
after_create :create_user_stat
|
after_create :create_user_stat
|
||||||
|
after_create :create_user_profile
|
||||||
after_save :refresh_avatar
|
after_save :refresh_avatar
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
@ -656,6 +658,10 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_user_profile
|
||||||
|
UserProfile.create(user_id: id)
|
||||||
|
end
|
||||||
|
|
||||||
def create_user_stat
|
def create_user_stat
|
||||||
stat = UserStat.new(new_since: Time.now)
|
stat = UserStat.new(new_since: Time.now)
|
||||||
stat.user_id = id
|
stat.user_id = id
|
||||||
|
2
app/models/user_profile.rb
Normal file
2
app/models/user_profile.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class UserProfile < ActiveRecord::Base
|
||||||
|
end
|
@ -9,6 +9,7 @@ class UserSerializer < BasicUserSerializer
|
|||||||
:created_at,
|
:created_at,
|
||||||
:website,
|
:website,
|
||||||
:profile_background,
|
:profile_background,
|
||||||
|
:location,
|
||||||
:can_edit,
|
:can_edit,
|
||||||
:can_edit_username,
|
:can_edit_username,
|
||||||
:can_edit_email,
|
:can_edit_email,
|
||||||
@ -113,6 +114,13 @@ class UserSerializer < BasicUserSerializer
|
|||||||
scope.can_edit_name?(object)
|
scope.can_edit_name?(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def location
|
||||||
|
object.user_profile.try(:location)
|
||||||
|
end
|
||||||
|
def include_location?
|
||||||
|
location.present?
|
||||||
|
end
|
||||||
|
|
||||||
def stats
|
def stats
|
||||||
UserAction.stats(object.id, scope)
|
UserAction.stats(object.id, scope)
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,10 @@ class UserUpdater
|
|||||||
:disable_jump_reply
|
:disable_jump_reply
|
||||||
]
|
]
|
||||||
|
|
||||||
|
PROFILE_ATTR = [
|
||||||
|
:location
|
||||||
|
]
|
||||||
|
|
||||||
def initialize(actor, user)
|
def initialize(actor, user)
|
||||||
@user = user
|
@user = user
|
||||||
@guardian = Guardian.new(actor)
|
@guardian = Guardian.new(actor)
|
||||||
@ -55,8 +59,16 @@ class UserUpdater
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
user_profile = user.user_profile
|
||||||
|
PROFILE_ATTR.each do |attribute|
|
||||||
|
user_profile.send("#{attribute.to_s}=", attributes[attribute])
|
||||||
|
end
|
||||||
|
|
||||||
|
User.transaction do
|
||||||
|
user_profile.save
|
||||||
user.save
|
user.save
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -358,6 +358,7 @@ en:
|
|||||||
last_seen: "Seen"
|
last_seen: "Seen"
|
||||||
created: "Joined"
|
created: "Joined"
|
||||||
log_out: "Log Out"
|
log_out: "Log Out"
|
||||||
|
location: "Location"
|
||||||
website: "Web Site"
|
website: "Web Site"
|
||||||
email_settings: "Email"
|
email_settings: "Email"
|
||||||
email_digests:
|
email_digests:
|
||||||
|
14
db/migrate/20140527163207_create_user_profiles.rb
Normal file
14
db/migrate/20140527163207_create_user_profiles.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class CreateUserProfiles < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
create_table :user_profiles, id: false do |t|
|
||||||
|
t.references :user
|
||||||
|
t.string :location
|
||||||
|
end
|
||||||
|
execute "ALTER TABLE user_profiles ADD PRIMARY KEY (user_id)"
|
||||||
|
execute "INSERT INTO user_profiles (user_id) SELECT id FROM users"
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
drop_table :user_profiles
|
||||||
|
end
|
||||||
|
end
|
8
spec/models/user_profile_spec.rb
Normal file
8
spec/models/user_profile_spec.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe UserProfile do
|
||||||
|
it "is created automatically when a user is created" do
|
||||||
|
user = Fabricate(:evil_trout)
|
||||||
|
user.user_profile.should be_present
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user