mirror of
https://github.com/discourse/discourse.git
synced 2026-08-14 06:55:03 -05:00
FEATURE: Support custom preferences for users, injected by plugins
This commit is contained in:
@@ -204,7 +204,8 @@ Discourse.User = Discourse.Model.extend({
|
|||||||
'external_links_in_new_tab',
|
'external_links_in_new_tab',
|
||||||
'mailing_list_mode',
|
'mailing_list_mode',
|
||||||
'enable_quoting',
|
'enable_quoting',
|
||||||
'disable_jump_reply');
|
'disable_jump_reply',
|
||||||
|
'custom_fields');
|
||||||
|
|
||||||
_.each(['muted','watched','tracked'], function(s){
|
_.each(['muted','watched','tracked'], function(s){
|
||||||
var cats = user.get(s + 'Categories').map(function(c){ return c.get('id')});
|
var cats = user.get(s + 'Categories').map(function(c){ return c.get('id')});
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ Discourse.TopicRoute = Discourse.Route.extend({
|
|||||||
// Use replaceState to update the URL once it changes
|
// Use replaceState to update the URL once it changes
|
||||||
postChangedRoute: Discourse.debounce(function(currentPost) {
|
postChangedRoute: Discourse.debounce(function(currentPost) {
|
||||||
// do nothing if we are transitioning to another route
|
// do nothing if we are transitioning to another route
|
||||||
if (this.get("isTransitioning")) { return; }
|
if (this.get("isTransitioning") || Discourse.TopicRoute.disableReplaceState) { return; }
|
||||||
|
|
||||||
var topic = this.modelFor('topic');
|
var topic = this.modelFor('topic');
|
||||||
if (topic && currentPost) {
|
if (topic && currentPost) {
|
||||||
|
|||||||
@@ -175,6 +175,7 @@
|
|||||||
{{preference-checkbox labelKey="user.enable_quoting" checked=enable_quoting}}
|
{{preference-checkbox labelKey="user.enable_quoting" checked=enable_quoting}}
|
||||||
{{preference-checkbox labelKey="user.dynamic_favicon" checked=dynamic_favicon}}
|
{{preference-checkbox labelKey="user.dynamic_favicon" checked=dynamic_favicon}}
|
||||||
{{preference-checkbox labelKey="user.disable_jump_reply" checked=disable_jump_reply}}
|
{{preference-checkbox labelKey="user.disable_jump_reply" checked=disable_jump_reply}}
|
||||||
|
{{view Discourse.CustomPreferences}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="control-group category">
|
<div class="control-group category">
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ Discourse.PreferencesView = Discourse.View.extend({
|
|||||||
uploading: false,
|
uploading: false,
|
||||||
uploadProgress: 0,
|
uploadProgress: 0,
|
||||||
|
|
||||||
|
customPreferences: function(){
|
||||||
|
}.property(),
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var $upload = $("#profile-background-input");
|
var $upload = $("#profile-background-input");
|
||||||
@@ -53,3 +56,29 @@ Discourse.PreferencesView = Discourse.View.extend({
|
|||||||
$("#profile-background-input").fileupload("destroy");
|
$("#profile-background-input").fileupload("destroy");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Discourse.PreferencesView.reopenClass({
|
||||||
|
registerCustomSection: function(viewClass){
|
||||||
|
var customSections = this.customSections;
|
||||||
|
if(!customSections){
|
||||||
|
customSections = Em.A();
|
||||||
|
this.customSections = customSections;
|
||||||
|
}
|
||||||
|
|
||||||
|
customSections.addObject(viewClass);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Discourse.CustomPreferences = Discourse.ContainerView.extend({
|
||||||
|
init: function(){
|
||||||
|
this._super();
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var sections = Discourse.PreferencesView.customSections;
|
||||||
|
if(sections){
|
||||||
|
sections.forEach(function(view){
|
||||||
|
self.pushObject(view.create({user: self.get('controller.model')}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ class UserSerializer < BasicUserSerializer
|
|||||||
:private_messages_stats,
|
:private_messages_stats,
|
||||||
:disable_jump_reply,
|
:disable_jump_reply,
|
||||||
:gravatar_avatar_upload_id,
|
:gravatar_avatar_upload_id,
|
||||||
:custom_avatar_upload_id
|
:custom_avatar_upload_id,
|
||||||
|
:custom_fields
|
||||||
|
|
||||||
def gravatar_avatar_upload_id
|
def gravatar_avatar_upload_id
|
||||||
object.user_avatar.try(:gravatar_upload_id)
|
object.user_avatar.try(:gravatar_upload_id)
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ class UserUpdater
|
|||||||
user_profile.send("#{attribute.to_s}=", attributes[attribute])
|
user_profile.send("#{attribute.to_s}=", attributes[attribute])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if fields = attributes[:custom_fields]
|
||||||
|
user.custom_fields = fields
|
||||||
|
end
|
||||||
|
|
||||||
User.transaction do
|
User.transaction do
|
||||||
user_profile.save
|
user_profile.save
|
||||||
user.save
|
user.save
|
||||||
|
|||||||
@@ -946,10 +946,14 @@ describe UsersController do
|
|||||||
user = Fabricate(:user, name: 'Billy Bob')
|
user = Fabricate(:user, name: 'Billy Bob')
|
||||||
log_in_user(user)
|
log_in_user(user)
|
||||||
|
|
||||||
put :update, username: user.username, name: 'Jim Tom'
|
put :update, username: user.username, name: 'Jim Tom', custom_fields: {test: :it}
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
expect(user.reload.name).to eq 'Jim Tom'
|
|
||||||
|
user.reload
|
||||||
|
|
||||||
|
expect(user.name).to eq 'Jim Tom'
|
||||||
|
expect(user.custom_fields['test']).to eq 'it'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns user JSON' do
|
it 'returns user JSON' do
|
||||||
|
|||||||
Reference in New Issue
Block a user