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
|
@ -6,4 +6,21 @@
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module 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 class='value'>{{avatar content imageSize="large"}}</div>
|
||||||
</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='display-row' style='height: 50px'>
|
||||||
<div class='field'>{{i18n user.ip_address.title}}</div>
|
<div class='field'>{{i18n user.ip_address.title}}</div>
|
||||||
<div class='value'>{{ip_address}}</div>
|
<div class='value'>{{ip_address}}</div>
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
<div {{bindAttr class=":contents byTopicCreator:topic-creator"}}>
|
<div {{bindAttr class=":contents byTopicCreator:topic-creator"}}>
|
||||||
<a href='{{unbound usernameUrl}}'>{{avatar this imageSize="large"}}</a>
|
<a href='{{unbound usernameUrl}}'>{{avatar this imageSize="large"}}</a>
|
||||||
<h3 {{bindAttr class="staff new_user"}}><a href='{{unbound usernameUrl}}'>{{breakUp username}}</a></h3>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -370,6 +370,16 @@
|
||||||
.score {
|
.score {
|
||||||
font-size: 12px;
|
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 {
|
.reply-to-tab {
|
||||||
|
|
|
@ -48,6 +48,7 @@ class UsersController < ApplicationController
|
||||||
u.digest_after_days = params[:digest_after_days] || u.digest_after_days
|
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.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.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,
|
[:email_digests, :email_direct, :email_private_messages,
|
||||||
:external_links_in_new_tab, :enable_quoting, :dynamic_favicon].each do |i|
|
:external_links_in_new_tab, :enable_quoting, :dynamic_favicon].each do |i|
|
||||||
|
|
|
@ -12,6 +12,7 @@ class AdminUserSerializer < BasicUserSerializer
|
||||||
:trust_level,
|
:trust_level,
|
||||||
:flag_level,
|
:flag_level,
|
||||||
:username,
|
:username,
|
||||||
|
:title,
|
||||||
:avatar_template,
|
:avatar_template,
|
||||||
:topics_entered,
|
:topics_entered,
|
||||||
:posts_read_count,
|
:posts_read_count,
|
||||||
|
|
|
@ -33,6 +33,7 @@ class PostSerializer < ApplicationSerializer
|
||||||
:read,
|
:read,
|
||||||
:username,
|
:username,
|
||||||
:name,
|
:name,
|
||||||
|
:user_title,
|
||||||
:reply_to_user,
|
:reply_to_user,
|
||||||
:bookmarked,
|
:bookmarked,
|
||||||
:raw,
|
:raw,
|
||||||
|
@ -128,6 +129,10 @@ class PostSerializer < ApplicationSerializer
|
||||||
object.user.name
|
object.user.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_title
|
||||||
|
object.user.title
|
||||||
|
end
|
||||||
|
|
||||||
def trust_level
|
def trust_level
|
||||||
object.user.trust_level
|
object.user.trust_level
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,8 @@ class UserSerializer < BasicUserSerializer
|
||||||
:bio_excerpt,
|
:bio_excerpt,
|
||||||
:trust_level,
|
:trust_level,
|
||||||
:moderator,
|
:moderator,
|
||||||
:admin
|
:admin,
|
||||||
|
:title
|
||||||
|
|
||||||
has_one :invited_by, embed: :object, serializer: BasicUserSerializer
|
has_one :invited_by, embed: :object, serializer: BasicUserSerializer
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ en:
|
||||||
yes_value: "Yes"
|
yes_value: "Yes"
|
||||||
of_value: "of"
|
of_value: "of"
|
||||||
generic_error: "Sorry, an error has occurred."
|
generic_error: "Sorry, an error has occurred."
|
||||||
|
generic_error_with_reason: "An error occured: %{error}"
|
||||||
log_in: "Log In"
|
log_in: "Log In"
|
||||||
age: "Age"
|
age: "Age"
|
||||||
last_post: "Last Post"
|
last_post: "Last Post"
|
||||||
|
@ -294,6 +295,8 @@ en:
|
||||||
avatar:
|
avatar:
|
||||||
title: "Avatar"
|
title: "Avatar"
|
||||||
instructions: "We use <a href='https://gravatar.com' target='_blank'>Gravatar</a> for avatars based on your email"
|
instructions: "We use <a href='https://gravatar.com' target='_blank'>Gravatar</a> for avatars based on your email"
|
||||||
|
title:
|
||||||
|
title: "Title"
|
||||||
|
|
||||||
filters:
|
filters:
|
||||||
all: "All"
|
all: "All"
|
||||||
|
@ -1166,6 +1169,8 @@ en:
|
||||||
admin: "Admin?"
|
admin: "Admin?"
|
||||||
blocked: "Blocked?"
|
blocked: "Blocked?"
|
||||||
show_admin_profile: "Admin"
|
show_admin_profile: "Admin"
|
||||||
|
edit_title: "Edit Title"
|
||||||
|
save_title: "Save Title"
|
||||||
refresh_browsers: "Force browser refresh"
|
refresh_browsers: "Force browser refresh"
|
||||||
show_public_profile: "Show Public Profile"
|
show_public_profile: "Show Public Profile"
|
||||||
impersonate: 'Impersonate'
|
impersonate: 'Impersonate'
|
||||||
|
|
|
@ -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?)
|
can_administer?(user) && not(user.moderator?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_grant_title?(user)
|
||||||
|
user && is_staff?
|
||||||
|
end
|
||||||
|
|
||||||
def can_block_user?(user)
|
def can_block_user?(user)
|
||||||
user && is_staff? && not(user.staff?)
|
user && is_staff? && not(user.staff?)
|
||||||
end
|
end
|
||||||
|
|
|
@ -937,5 +937,27 @@ describe Guardian do
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue