mirror of
https://github.com/discourse/discourse.git
synced 2025-04-29 02:54:34 +08:00
DEV: Plugin api function to add saveable user fields (#10774)
This commit is contained in:
parent
ecfca965f2
commit
d8bf2810ff
@ -61,6 +61,10 @@ import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
|
|||||||
import { addFeaturedLinkMetaDecorator } from "discourse/lib/render-topic-featured-link";
|
import { addFeaturedLinkMetaDecorator } from "discourse/lib/render-topic-featured-link";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
import { addAdvancedSearchOptions } from "discourse/components/search-advanced-options";
|
import { addAdvancedSearchOptions } from "discourse/components/search-advanced-options";
|
||||||
|
import {
|
||||||
|
addSaveableUserField,
|
||||||
|
addSaveableUserOptionField,
|
||||||
|
} from "discourse/models/user";
|
||||||
|
|
||||||
// If you add any methods to the API ensure you bump up this number
|
// If you add any methods to the API ensure you bump up this number
|
||||||
const PLUGIN_API_VERSION = "0.11.0";
|
const PLUGIN_API_VERSION = "0.11.0";
|
||||||
@ -1207,6 +1211,13 @@ class PluginApi {
|
|||||||
addAdvancedSearchOptions(options) {
|
addAdvancedSearchOptions(options) {
|
||||||
addAdvancedSearchOptions(options);
|
addAdvancedSearchOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addSaveableUserField(fieldName) {
|
||||||
|
addSaveableUserField(fieldName);
|
||||||
|
}
|
||||||
|
addSaveableUserOptionField(fieldName) {
|
||||||
|
addSaveableUserOptionField(fieldName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _pluginv01;
|
let _pluginv01;
|
||||||
|
@ -41,6 +41,68 @@ export const SECOND_FACTOR_METHODS = {
|
|||||||
|
|
||||||
const isForever = (dt) => moment().diff(dt, "years") < -500;
|
const isForever = (dt) => moment().diff(dt, "years") < -500;
|
||||||
|
|
||||||
|
let userFields = [
|
||||||
|
"bio_raw",
|
||||||
|
"website",
|
||||||
|
"location",
|
||||||
|
"name",
|
||||||
|
"title",
|
||||||
|
"locale",
|
||||||
|
"custom_fields",
|
||||||
|
"user_fields",
|
||||||
|
"muted_usernames",
|
||||||
|
"ignored_usernames",
|
||||||
|
"allowed_pm_usernames",
|
||||||
|
"profile_background_upload_url",
|
||||||
|
"card_background_upload_url",
|
||||||
|
"muted_tags",
|
||||||
|
"tracked_tags",
|
||||||
|
"watched_tags",
|
||||||
|
"watching_first_post_tags",
|
||||||
|
"date_of_birth",
|
||||||
|
"primary_group_id",
|
||||||
|
];
|
||||||
|
|
||||||
|
export function addSaveableUserField(fieldName) {
|
||||||
|
userFields.push(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
let userOptionFields = [
|
||||||
|
"mailing_list_mode",
|
||||||
|
"mailing_list_mode_frequency",
|
||||||
|
"external_links_in_new_tab",
|
||||||
|
"email_digests",
|
||||||
|
"email_in_reply_to",
|
||||||
|
"email_messages_level",
|
||||||
|
"email_level",
|
||||||
|
"email_previous_replies",
|
||||||
|
"color_scheme_id",
|
||||||
|
"dark_scheme_id",
|
||||||
|
"dynamic_favicon",
|
||||||
|
"enable_quoting",
|
||||||
|
"enable_defer",
|
||||||
|
"automatically_unpin_topics",
|
||||||
|
"digest_after_minutes",
|
||||||
|
"new_topic_duration_minutes",
|
||||||
|
"auto_track_topics_after_msecs",
|
||||||
|
"notification_level_when_replying",
|
||||||
|
"like_notification_frequency",
|
||||||
|
"include_tl0_in_digests",
|
||||||
|
"theme_ids",
|
||||||
|
"allow_private_messages",
|
||||||
|
"enable_allowed_pm_users",
|
||||||
|
"homepage_id",
|
||||||
|
"hide_profile_and_presence",
|
||||||
|
"text_size",
|
||||||
|
"title_count_mode",
|
||||||
|
"timezone",
|
||||||
|
"skip_new_user_tips",
|
||||||
|
];
|
||||||
|
|
||||||
|
export function addSaveableUserOptionField(fieldName) {
|
||||||
|
userOptionFields.push(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
const User = RestModel.extend({
|
const User = RestModel.extend({
|
||||||
hasPMs: gt("private_messages_stats.all", 0),
|
hasPMs: gt("private_messages_stats.all", 0),
|
||||||
hasStartedPMs: gt("private_messages_stats.mine", 0),
|
hasStartedPMs: gt("private_messages_stats.mine", 0),
|
||||||
@ -267,64 +329,10 @@ const User = RestModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
save(fields) {
|
save(fields) {
|
||||||
let userFields = [
|
|
||||||
"bio_raw",
|
|
||||||
"website",
|
|
||||||
"location",
|
|
||||||
"name",
|
|
||||||
"title",
|
|
||||||
"locale",
|
|
||||||
"custom_fields",
|
|
||||||
"user_fields",
|
|
||||||
"muted_usernames",
|
|
||||||
"ignored_usernames",
|
|
||||||
"allowed_pm_usernames",
|
|
||||||
"profile_background_upload_url",
|
|
||||||
"card_background_upload_url",
|
|
||||||
"muted_tags",
|
|
||||||
"tracked_tags",
|
|
||||||
"watched_tags",
|
|
||||||
"watching_first_post_tags",
|
|
||||||
"date_of_birth",
|
|
||||||
"primary_group_id",
|
|
||||||
];
|
|
||||||
|
|
||||||
const data = this.getProperties(
|
const data = this.getProperties(
|
||||||
userFields.filter((uf) => !fields || fields.indexOf(uf) !== -1)
|
userFields.filter((uf) => !fields || fields.indexOf(uf) !== -1)
|
||||||
);
|
);
|
||||||
|
|
||||||
let userOptionFields = [
|
|
||||||
"mailing_list_mode",
|
|
||||||
"mailing_list_mode_frequency",
|
|
||||||
"external_links_in_new_tab",
|
|
||||||
"email_digests",
|
|
||||||
"email_in_reply_to",
|
|
||||||
"email_messages_level",
|
|
||||||
"email_level",
|
|
||||||
"email_previous_replies",
|
|
||||||
"color_scheme_id",
|
|
||||||
"dark_scheme_id",
|
|
||||||
"dynamic_favicon",
|
|
||||||
"enable_quoting",
|
|
||||||
"enable_defer",
|
|
||||||
"automatically_unpin_topics",
|
|
||||||
"digest_after_minutes",
|
|
||||||
"new_topic_duration_minutes",
|
|
||||||
"auto_track_topics_after_msecs",
|
|
||||||
"notification_level_when_replying",
|
|
||||||
"like_notification_frequency",
|
|
||||||
"include_tl0_in_digests",
|
|
||||||
"theme_ids",
|
|
||||||
"allow_private_messages",
|
|
||||||
"enable_allowed_pm_users",
|
|
||||||
"homepage_id",
|
|
||||||
"hide_profile_and_presence",
|
|
||||||
"text_size",
|
|
||||||
"title_count_mode",
|
|
||||||
"timezone",
|
|
||||||
"skip_new_user_tips",
|
|
||||||
];
|
|
||||||
|
|
||||||
if (fields) {
|
if (fields) {
|
||||||
userOptionFields = userOptionFields.filter(
|
userOptionFields = userOptionFields.filter(
|
||||||
(uo) => fields.indexOf(uo) !== -1
|
(uo) => fields.indexOf(uo) !== -1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user