mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:29:30 +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',
|
||||
'bio_raw',
|
||||
'website',
|
||||
'location',
|
||||
'name',
|
||||
'locale',
|
||||
'email_digests',
|
||||
|
|
|
@ -127,10 +127,17 @@
|
|||
</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">
|
||||
<label class="control-label">{{i18n user.website}}</label>
|
||||
<div class="controls">
|
||||
{{textField value=website classNames="input-xxlarge"}}
|
||||
{{input type="text" value=website class="input-xxlarge"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -86,6 +86,9 @@
|
|||
|
||||
<div class='secondary'>
|
||||
<dl>
|
||||
{{#if location}}
|
||||
<dt>{{i18n user.location}}</dt><dd>{{location}}</a></dd>
|
||||
{{/if}}
|
||||
{{#if websiteName}}
|
||||
<dt>{{i18n user.website}}</dt><dd><a {{bind-attr href="website"}} target="_blank">{{websiteName}}</a></dd>
|
||||
{{/if}}
|
||||
|
|
|
@ -39,6 +39,7 @@ class User < ActiveRecord::Base
|
|||
has_one :github_user_info, dependent: :destroy
|
||||
has_one :oauth2_user_info, dependent: :destroy
|
||||
has_one :user_stat, dependent: :destroy
|
||||
has_one :user_profile, dependent: :destroy
|
||||
has_one :single_sign_on_record, dependent: :destroy
|
||||
belongs_to :approved_by, class_name: 'User'
|
||||
belongs_to :primary_group, class_name: 'Group'
|
||||
|
@ -73,6 +74,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
after_create :create_email_token
|
||||
after_create :create_user_stat
|
||||
after_create :create_user_profile
|
||||
after_save :refresh_avatar
|
||||
|
||||
before_destroy do
|
||||
|
@ -656,6 +658,10 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def create_user_profile
|
||||
UserProfile.create(user_id: id)
|
||||
end
|
||||
|
||||
def create_user_stat
|
||||
stat = UserStat.new(new_since: Time.now)
|
||||
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,
|
||||
:website,
|
||||
:profile_background,
|
||||
:location,
|
||||
:can_edit,
|
||||
:can_edit_username,
|
||||
:can_edit_email,
|
||||
|
@ -113,6 +114,13 @@ class UserSerializer < BasicUserSerializer
|
|||
scope.can_edit_name?(object)
|
||||
end
|
||||
|
||||
def location
|
||||
object.user_profile.try(:location)
|
||||
end
|
||||
def include_location?
|
||||
location.present?
|
||||
end
|
||||
|
||||
def stats
|
||||
UserAction.stats(object.id, scope)
|
||||
end
|
||||
|
|
|
@ -18,6 +18,10 @@ class UserUpdater
|
|||
:disable_jump_reply
|
||||
]
|
||||
|
||||
PROFILE_ATTR = [
|
||||
:location
|
||||
]
|
||||
|
||||
def initialize(actor, user)
|
||||
@user = user
|
||||
@guardian = Guardian.new(actor)
|
||||
|
@ -55,7 +59,15 @@ class UserUpdater
|
|||
end
|
||||
end
|
||||
|
||||
user.save
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -358,6 +358,7 @@ en:
|
|||
last_seen: "Seen"
|
||||
created: "Joined"
|
||||
log_out: "Log Out"
|
||||
location: "Location"
|
||||
website: "Web Site"
|
||||
email_settings: "Email"
|
||||
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…
Reference in New Issue
Block a user