mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
Add ability to give users a title. Show them under usernames beside posts. Needs love from a designer.
This commit is contained in:
parent
a86b35c873
commit
b2d300fe0b
12 changed files with 93 additions and 2 deletions
|
@ -6,4 +6,21 @@
|
|||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.AdminUserController = Discourse.ObjectController.extend({});
|
||||
Discourse.AdminUserController = Discourse.ObjectController.extend({
|
||||
editingTitle: false,
|
||||
|
||||
toggleTitleEdit: function() {
|
||||
this.set('editingTitle', !this.editingTitle);
|
||||
},
|
||||
|
||||
saveTitle: function() {
|
||||
Discourse.ajax("/users/" + this.get('username').toLowerCase(), {
|
||||
data: {title: this.get('title')},
|
||||
type: 'PUT'
|
||||
}).then(null, function(e){
|
||||
bootbox.alert(Em.String.i18n("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body}));
|
||||
});
|
||||
|
||||
this.toggleTitleEdit();
|
||||
}
|
||||
});
|
|
@ -27,6 +27,25 @@
|
|||
<div class='value'>{{avatar content imageSize="large"}}</div>
|
||||
</div>
|
||||
|
||||
<div class='display-row'>
|
||||
<div class='field'>{{i18n user.title.title}}</div>
|
||||
<div class='value'>
|
||||
{{#if editingTitle}}
|
||||
{{textField value=title autofocus="autofocus"}}
|
||||
{{else}}
|
||||
<span {{action toggleTitleEdit}}>{{title}} </span>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class='controls'>
|
||||
{{#if editingTitle}}
|
||||
<button class='btn' {{action saveTitle}}>{{i18n admin.user.save_title}}</button>
|
||||
<a href="#" {{action toggleTitleEdit}}>Cancel</a>
|
||||
{{else}}
|
||||
<button class='btn' {{action toggleTitleEdit}}>{{i18n admin.user.edit_title}}</button>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='display-row' style='height: 50px'>
|
||||
<div class='field'>{{i18n user.ip_address.title}}</div>
|
||||
<div class='value'>{{ip_address}}</div>
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
<div {{bindAttr class=":contents byTopicCreator:topic-creator"}}>
|
||||
<a href='{{unbound usernameUrl}}'>{{avatar this imageSize="large"}}</a>
|
||||
<h3 {{bindAttr class="staff new_user"}}><a href='{{unbound usernameUrl}}'>{{breakUp username}}</a></h3>
|
||||
{{#if user_title}}<div class="user-title">{{user_title}}</div>{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -370,6 +370,16 @@
|
|||
.score {
|
||||
font-size: 12px;
|
||||
}
|
||||
.user-title {
|
||||
font-size: 12px;
|
||||
padding: 0 3px;
|
||||
background-color: #ddd;
|
||||
border-radius: 5px;
|
||||
margin-top: 2px;
|
||||
border: solid 1px #ccc;
|
||||
font-weight: bold;
|
||||
color: #555;
|
||||
}
|
||||
}
|
||||
}
|
||||
.reply-to-tab {
|
||||
|
|
|
@ -48,6 +48,7 @@ class UsersController < ApplicationController
|
|||
u.digest_after_days = params[:digest_after_days] || u.digest_after_days
|
||||
u.auto_track_topics_after_msecs = params[:auto_track_topics_after_msecs].to_i if params[:auto_track_topics_after_msecs]
|
||||
u.new_topic_duration_minutes = params[:new_topic_duration_minutes].to_i if params[:new_topic_duration_minutes]
|
||||
u.title = params[:title] || u.title if guardian.can_grant_title?(u)
|
||||
|
||||
[:email_digests, :email_direct, :email_private_messages,
|
||||
:external_links_in_new_tab, :enable_quoting, :dynamic_favicon].each do |i|
|
||||
|
|
|
@ -12,6 +12,7 @@ class AdminUserSerializer < BasicUserSerializer
|
|||
:trust_level,
|
||||
:flag_level,
|
||||
:username,
|
||||
:title,
|
||||
:avatar_template,
|
||||
:topics_entered,
|
||||
:posts_read_count,
|
||||
|
|
|
@ -33,6 +33,7 @@ class PostSerializer < ApplicationSerializer
|
|||
:read,
|
||||
:username,
|
||||
:name,
|
||||
:user_title,
|
||||
:reply_to_user,
|
||||
:bookmarked,
|
||||
:raw,
|
||||
|
@ -128,6 +129,10 @@ class PostSerializer < ApplicationSerializer
|
|||
object.user.name
|
||||
end
|
||||
|
||||
def user_title
|
||||
object.user.title
|
||||
end
|
||||
|
||||
def trust_level
|
||||
object.user.trust_level
|
||||
end
|
||||
|
|
|
@ -14,7 +14,8 @@ class UserSerializer < BasicUserSerializer
|
|||
:bio_excerpt,
|
||||
:trust_level,
|
||||
:moderator,
|
||||
:admin
|
||||
:admin,
|
||||
:title
|
||||
|
||||
has_one :invited_by, embed: :object, serializer: BasicUserSerializer
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ en:
|
|||
yes_value: "Yes"
|
||||
of_value: "of"
|
||||
generic_error: "Sorry, an error has occurred."
|
||||
generic_error_with_reason: "An error occured: %{error}"
|
||||
log_in: "Log In"
|
||||
age: "Age"
|
||||
last_post: "Last Post"
|
||||
|
@ -294,6 +295,8 @@ en:
|
|||
avatar:
|
||||
title: "Avatar"
|
||||
instructions: "We use <a href='https://gravatar.com' target='_blank'>Gravatar</a> for avatars based on your email"
|
||||
title:
|
||||
title: "Title"
|
||||
|
||||
filters:
|
||||
all: "All"
|
||||
|
@ -1166,6 +1169,8 @@ en:
|
|||
admin: "Admin?"
|
||||
blocked: "Blocked?"
|
||||
show_admin_profile: "Admin"
|
||||
edit_title: "Edit Title"
|
||||
save_title: "Save Title"
|
||||
refresh_browsers: "Force browser refresh"
|
||||
show_public_profile: "Show Public Profile"
|
||||
impersonate: 'Impersonate'
|
||||
|
|
5
db/migrate/20130625201113_add_title_to_users.rb
Normal file
5
db/migrate/20130625201113_add_title_to_users.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddTitleToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :title, :string
|
||||
end
|
||||
end
|
|
@ -133,6 +133,10 @@ class Guardian
|
|||
can_administer?(user) && not(user.moderator?)
|
||||
end
|
||||
|
||||
def can_grant_title?(user)
|
||||
user && is_staff?
|
||||
end
|
||||
|
||||
def can_block_user?(user)
|
||||
user && is_staff? && not(user.staff?)
|
||||
end
|
||||
|
|
|
@ -937,5 +937,27 @@ describe Guardian do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'can_grant_title?' do
|
||||
it 'is false without a logged in user' do
|
||||
Guardian.new(nil).can_grant_title?(user).should be_false
|
||||
end
|
||||
|
||||
it 'is false for regular users' do
|
||||
Guardian.new(user).can_grant_title?(user).should be_false
|
||||
end
|
||||
|
||||
it 'is true for moderators' do
|
||||
Guardian.new(moderator).can_grant_title?(user).should be_true
|
||||
end
|
||||
|
||||
it 'is true for admins' do
|
||||
Guardian.new(admin).can_grant_title?(user).should be_true
|
||||
end
|
||||
|
||||
it 'is false without a user to look at' do
|
||||
Guardian.new(admin).can_grant_title?(nil).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue