From e39d89ecd9119f69f464d92a16d59d77cc746081 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 11 Nov 2019 15:48:33 -0500 Subject: [PATCH] REFACTOR: Remove `InputValidation` which was simply an `Ember.Object` --- .../controllers/admin-web-hooks-show.js.es6 | 8 ++++---- app/assets/javascripts/application.js | 1 - app/assets/javascripts/discourse-loader.js | 9 +++++++++ .../components/composer-editor.js.es6 | 4 ++-- .../discourse/components/composer-title.js.es6 | 4 ++-- .../groups-form-profile-fields.js.es6 | 6 +++--- .../discourse/controllers/composer.js.es6 | 6 +++--- .../controllers/create-account.js.es6 | 12 ++++++------ .../discourse/controllers/feature-topic.js.es6 | 6 +++--- .../controllers/preferences/email.js.es6 | 4 ++-- .../discourse/mixins/name-validation.js.es6 | 6 +++--- .../mixins/password-validation.js.es6 | 16 ++++++++-------- .../mixins/user-fields-validation.js.es6 | 5 ++--- .../mixins/username-validation.js.es6 | 18 +++++++++--------- .../discourse/models/input-validation.js.es6 | 2 -- .../controllers/poll-ui-builder.js.es6 | 8 ++++---- 16 files changed, 60 insertions(+), 55 deletions(-) delete mode 100644 app/assets/javascripts/discourse/models/input-validation.js.es6 diff --git a/app/assets/javascripts/admin/controllers/admin-web-hooks-show.js.es6 b/app/assets/javascripts/admin/controllers/admin-web-hooks-show.js.es6 index b07806f6fa8..4ba34034f35 100644 --- a/app/assets/javascripts/admin/controllers/admin-web-hooks-show.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-web-hooks-show.js.es6 @@ -5,7 +5,7 @@ import { inject } from "@ember/controller"; import Controller from "@ember/controller"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { extractDomainFromUrl } from "discourse/lib/utilities"; -import InputValidation from "discourse/models/input-validation"; +import EmberObject from "@ember/object"; export default Controller.extend({ adminWebHooks: inject(), @@ -41,14 +41,14 @@ export default Controller.extend({ secretValidation(secret) { if (!isEmpty(secret)) { if (secret.indexOf(" ") !== -1) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("admin.web_hooks.secret_invalid") }); } if (secret.length < 12) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("admin.web_hooks.secret_too_short") }); @@ -59,7 +59,7 @@ export default Controller.extend({ @discourseComputed("model.wildcard_web_hook", "model.web_hook_event_types.[]") eventTypeValidation(isWildcard, eventTypes) { if (!isWildcard && isEmpty(eventTypes)) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("admin.web_hooks.event_type_missing") }); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 6dbb9e815ca..35cc29acce0 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -47,7 +47,6 @@ //= require ./discourse/models/badge //= require ./discourse/models/permission-type //= require ./discourse/models/user-action-group -//= require ./discourse/models/input-validation //= require ./discourse/models/trust-level //= require ./discourse/lib/search //= require ./discourse/lib/user-search diff --git a/app/assets/javascripts/discourse-loader.js b/app/assets/javascripts/discourse-loader.js index 876aca44ce2..d5112d026e2 100644 --- a/app/assets/javascripts/discourse-loader.js +++ b/app/assets/javascripts/discourse-loader.js @@ -220,6 +220,15 @@ var define, requirejs; function requireFrom(name, origin) { name = transformForAliases(name); + + if (name === "discourse/models/input-validation") { + // eslint-disable-next-line no-console + console.log( + "input-validation has been removed and should be replaced with `@ember/object`" + ); + return Ember.Object; + } + var mod = EMBER_MODULES[name] || registry[name]; if (!mod) { throw new Error( diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6 index 75f8edd4f0e..d997c3f4f67 100644 --- a/app/assets/javascripts/discourse/components/composer-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6 @@ -26,7 +26,7 @@ import Composer from "discourse/models/composer"; import { load, LOADING_ONEBOX_CSS_CLASS } from "pretty-text/oneboxer"; import { applyInlineOneboxes } from "pretty-text/inline-oneboxer"; import { ajax } from "discourse/lib/ajax"; -import InputValidation from "discourse/models/input-validation"; +import EmberObject from "@ember/object"; import { findRawTemplate } from "discourse/lib/raw-templates"; import { iconHTML } from "discourse-common/lib/icon-library"; import { @@ -246,7 +246,7 @@ export default Component.extend({ } if (reason) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason, lastShownAt: lastValidatedAt diff --git a/app/assets/javascripts/discourse/components/composer-title.js.es6 b/app/assets/javascripts/discourse/components/composer-title.js.es6 index da012442f71..2eb06cb0711 100644 --- a/app/assets/javascripts/discourse/components/composer-title.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-title.js.es6 @@ -7,12 +7,12 @@ import { default as discourseComputed, observes } from "discourse-common/utils/decorators"; -import InputValidation from "discourse/models/input-validation"; import { load } from "pretty-text/oneboxer"; import { lookupCache } from "pretty-text/oneboxer-cache"; import { ajax } from "discourse/lib/ajax"; import afterTransition from "discourse/lib/after-transition"; import ENV from "discourse-common/config/environment"; +import EmberObject from "@ember/object"; export default Component.extend({ classNames: ["title-input"], @@ -60,7 +60,7 @@ export default Component.extend({ } if (reason) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason, lastShownAt: lastValidatedAt diff --git a/app/assets/javascripts/discourse/components/groups-form-profile-fields.js.es6 b/app/assets/javascripts/discourse/components/groups-form-profile-fields.js.es6 index 03ea2d8e143..9074ef2d637 100644 --- a/app/assets/javascripts/discourse/components/groups-form-profile-fields.js.es6 +++ b/app/assets/javascripts/discourse/components/groups-form-profile-fields.js.es6 @@ -6,8 +6,8 @@ import { observes } from "discourse-common/utils/decorators"; import Group from "discourse/models/group"; -import InputValidation from "discourse/models/input-validation"; import discourseDebounce from "discourse/lib/debounce"; +import EmberObject from "@ember/object"; export default Component.extend({ disableSave: null, @@ -74,7 +74,7 @@ export default Component.extend({ if (response.available) { this.set( validationName, - InputValidation.create({ + EmberObject.create({ ok: true, reason: I18n.t("admin.groups.new.name.available") }) @@ -101,6 +101,6 @@ export default Component.extend({ const options = { failed: true }; if (reason) options.reason = reason; - this.set("basicNameValidation", InputValidation.create(options)); + this.set("basicNameValidation", EmberObject.create(options)); } }); diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index 51d4b3202ef..e3d5ae3c0d7 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -19,7 +19,6 @@ import { observes, on } from "discourse-common/utils/decorators"; -import InputValidation from "discourse/models/input-validation"; import { getOwner } from "discourse-common/lib/get-owner"; import { escapeExpression, @@ -32,6 +31,7 @@ import { shortDate } from "discourse/lib/formatter"; import { SAVE_LABELS, SAVE_ICONS } from "discourse/models/composer"; import { Promise } from "rsvp"; import ENV from "discourse-common/config/environment"; +import EmberObject from "@ember/object"; function loadDraft(store, opts) { opts = opts || {}; @@ -1063,7 +1063,7 @@ export default Controller.extend({ @discourseComputed("model.categoryId", "lastValidatedAt") categoryValidation(categoryId, lastValidatedAt) { if (!this.siteSettings.allow_uncategorized_topics && !categoryId) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("composer.error.category_missing"), lastShownAt: lastValidatedAt @@ -1079,7 +1079,7 @@ export default Controller.extend({ category && category.minimum_required_tags > tagsArray.length ) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("composer.error.tags_missing", { count: category.minimum_required_tags diff --git a/app/assets/javascripts/discourse/controllers/create-account.js.es6 b/app/assets/javascripts/discourse/controllers/create-account.js.es6 index 96abb66d22e..ae431f3c37a 100644 --- a/app/assets/javascripts/discourse/controllers/create-account.js.es6 +++ b/app/assets/javascripts/discourse/controllers/create-account.js.es6 @@ -10,13 +10,13 @@ import { on } from "discourse-common/utils/decorators"; import { emailValid } from "discourse/lib/utilities"; -import InputValidation from "discourse/models/input-validation"; import PasswordValidation from "discourse/mixins/password-validation"; import UsernameValidation from "discourse/mixins/username-validation"; import NameValidation from "discourse/mixins/name-validation"; import UserFieldsValidation from "discourse/mixins/user-fields-validation"; import { userPath } from "discourse/lib/url"; import { findAll } from "discourse/models/login-method"; +import EmberObject from "@ember/object"; export default Controller.extend( ModalFunctionality, @@ -110,13 +110,13 @@ export default Controller.extend( emailValidation(email, rejectedEmails) { // If blank, fail without a reason if (isEmpty(email)) { - return InputValidation.create({ + return EmberObject.create({ failed: true }); } if (rejectedEmails.includes(email)) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.email.invalid") }); @@ -126,7 +126,7 @@ export default Controller.extend( this.get("authOptions.email") === email && this.get("authOptions.email_valid") ) { - return InputValidation.create({ + return EmberObject.create({ ok: true, reason: I18n.t("user.email.authenticated", { provider: this.authProviderDisplayName( @@ -137,13 +137,13 @@ export default Controller.extend( } if (emailValid(email)) { - return InputValidation.create({ + return EmberObject.create({ ok: true, reason: I18n.t("user.email.ok") }); } - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.email.invalid") }); diff --git a/app/assets/javascripts/discourse/controllers/feature-topic.js.es6 b/app/assets/javascripts/discourse/controllers/feature-topic.js.es6 index 3535e355cec..8fb459a1458 100644 --- a/app/assets/javascripts/discourse/controllers/feature-topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/feature-topic.js.es6 @@ -4,7 +4,7 @@ import Controller from "@ember/controller"; import { ajax } from "discourse/lib/ajax"; import ModalFunctionality from "discourse/mixins/modal-functionality"; import { categoryLinkHTML } from "discourse/helpers/category-link"; -import InputValidation from "discourse/models/input-validation"; +import EmberObject from "@ember/object"; export default Controller.extend(ModalFunctionality, { topicController: inject("topic"), @@ -79,7 +79,7 @@ export default Controller.extend(ModalFunctionality, { @discourseComputed("pinDisabled") pinInCategoryValidation(pinDisabled) { if (pinDisabled) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("topic.feature_topic.pin_validation") }); @@ -89,7 +89,7 @@ export default Controller.extend(ModalFunctionality, { @discourseComputed("pinGloballyDisabled") pinGloballyValidation(pinGloballyDisabled) { if (pinGloballyDisabled) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("topic.feature_topic.pin_validation") }); diff --git a/app/assets/javascripts/discourse/controllers/preferences/email.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/email.js.es6 index 94a13ae5961..413638e0db2 100644 --- a/app/assets/javascripts/discourse/controllers/preferences/email.js.es6 +++ b/app/assets/javascripts/discourse/controllers/preferences/email.js.es6 @@ -2,7 +2,7 @@ import discourseComputed from "discourse-common/utils/decorators"; import { empty, or } from "@ember/object/computed"; import Controller from "@ember/controller"; import { propertyEqual } from "discourse/lib/computed"; -import InputValidation from "discourse/models/input-validation"; +import EmberObject from "@ember/object"; import { emailValid } from "discourse/lib/utilities"; export default Controller.extend({ @@ -43,7 +43,7 @@ export default Controller.extend({ @discourseComputed("invalidEmail") emailValidation(invalidEmail) { if (invalidEmail) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.email.invalid") }); diff --git a/app/assets/javascripts/discourse/mixins/name-validation.js.es6 b/app/assets/javascripts/discourse/mixins/name-validation.js.es6 index e447f9fcb69..b2594c97fec 100644 --- a/app/assets/javascripts/discourse/mixins/name-validation.js.es6 +++ b/app/assets/javascripts/discourse/mixins/name-validation.js.es6 @@ -1,7 +1,7 @@ import { isEmpty } from "@ember/utils"; -import InputValidation from "discourse/models/input-validation"; import { default as discourseComputed } from "discourse-common/utils/decorators"; import Mixin from "@ember/object/mixin"; +import EmberObject from "@ember/object"; export default Mixin.create({ @discourseComputed() @@ -17,9 +17,9 @@ export default Mixin.create({ @discourseComputed("accountName") nameValidation() { if (this.siteSettings.full_name_required && isEmpty(this.accountName)) { - return InputValidation.create({ failed: true }); + return EmberObject.create({ failed: true }); } - return InputValidation.create({ ok: true }); + return EmberObject.create({ ok: true }); } }); diff --git a/app/assets/javascripts/discourse/mixins/password-validation.js.es6 b/app/assets/javascripts/discourse/mixins/password-validation.js.es6 index ec665cdbe6e..b313368f521 100644 --- a/app/assets/javascripts/discourse/mixins/password-validation.js.es6 +++ b/app/assets/javascripts/discourse/mixins/password-validation.js.es6 @@ -1,7 +1,7 @@ import { isEmpty } from "@ember/utils"; -import InputValidation from "discourse/models/input-validation"; import { default as discourseComputed } from "discourse-common/utils/decorators"; import Mixin from "@ember/object/mixin"; +import EmberObject from "@ember/object"; export default Mixin.create({ rejectedPasswords: null, @@ -43,11 +43,11 @@ export default Mixin.create({ passwordMinLength ) { if (!passwordRequired) { - return InputValidation.create({ ok: true }); + return EmberObject.create({ ok: true }); } if (rejectedPasswords.includes(password)) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: this.rejectedPasswordsMessages.get(password) || @@ -57,33 +57,33 @@ export default Mixin.create({ // If blank, fail without a reason if (isEmpty(password)) { - return InputValidation.create({ failed: true }); + return EmberObject.create({ failed: true }); } // If too short if (password.length < passwordMinLength) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.password.too_short") }); } if (!isEmpty(accountUsername) && password === accountUsername) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.password.same_as_username") }); } if (!isEmpty(accountEmail) && password === accountEmail) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.password.same_as_email") }); } // Looks good! - return InputValidation.create({ + return EmberObject.create({ ok: true, reason: I18n.t("user.password.ok") }); diff --git a/app/assets/javascripts/discourse/mixins/user-fields-validation.js.es6 b/app/assets/javascripts/discourse/mixins/user-fields-validation.js.es6 index e535043a2d2..782ceca03d2 100644 --- a/app/assets/javascripts/discourse/mixins/user-fields-validation.js.es6 +++ b/app/assets/javascripts/discourse/mixins/user-fields-validation.js.es6 @@ -1,6 +1,5 @@ import { isEmpty } from "@ember/utils"; import EmberObject from "@ember/object"; -import InputValidation from "discourse/models/input-validation"; import { on, default as discourseComputed @@ -36,9 +35,9 @@ export default Mixin.create({ return !val || isEmpty(val); }); if (anyEmpty) { - return InputValidation.create({ failed: true }); + return EmberObject.create({ failed: true }); } } - return InputValidation.create({ ok: true }); + return EmberObject.create({ ok: true }); } }); diff --git a/app/assets/javascripts/discourse/mixins/username-validation.js.es6 b/app/assets/javascripts/discourse/mixins/username-validation.js.es6 index 31186525f14..7845c45a580 100644 --- a/app/assets/javascripts/discourse/mixins/username-validation.js.es6 +++ b/app/assets/javascripts/discourse/mixins/username-validation.js.es6 @@ -1,9 +1,9 @@ import { isEmpty } from "@ember/utils"; -import InputValidation from "discourse/models/input-validation"; import discourseDebounce from "discourse/lib/debounce"; import { setting } from "discourse/lib/computed"; import { default as discourseComputed } from "discourse-common/utils/decorators"; import Mixin from "@ember/object/mixin"; +import EmberObject from "@ember/object"; export default Mixin.create({ uniqueUsernameValidation: null, @@ -32,7 +32,7 @@ export default Mixin.create({ this.set("uniqueUsernameValidation", null); if (accountUsername && accountUsername === this.prefilledUsername) { - return InputValidation.create({ + return EmberObject.create({ ok: true, reason: I18n.t("user.username.prefilled") }); @@ -40,12 +40,12 @@ export default Mixin.create({ // If blank, fail without a reason if (isEmpty(accountUsername)) { - return InputValidation.create({ failed: true }); + return EmberObject.create({ failed: true }); } // If too short if (accountUsername.length < this.siteSettings.min_username_length) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.username.too_short") }); @@ -53,7 +53,7 @@ export default Mixin.create({ // If too long if (accountUsername.length > this.maxUsernameLength) { - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.username.too_long") }); @@ -61,7 +61,7 @@ export default Mixin.create({ this.checkUsernameAvailability(); // Let's check it out asynchronously - return InputValidation.create({ + return EmberObject.create({ failed: true, reason: I18n.t("user.username.checking") }); @@ -87,7 +87,7 @@ export default Mixin.create({ } return this.set( "uniqueUsernameValidation", - InputValidation.create({ + EmberObject.create({ ok: true, reason: I18n.t("user.username.available") }) @@ -96,7 +96,7 @@ export default Mixin.create({ if (result.suggestion) { return this.set( "uniqueUsernameValidation", - InputValidation.create({ + EmberObject.create({ failed: true, reason: I18n.t("user.username.not_available", result) }) @@ -104,7 +104,7 @@ export default Mixin.create({ } else { return this.set( "uniqueUsernameValidation", - InputValidation.create({ + EmberObject.create({ failed: true, reason: result.errors ? result.errors.join(" ") diff --git a/app/assets/javascripts/discourse/models/input-validation.js.es6 b/app/assets/javascripts/discourse/models/input-validation.js.es6 deleted file mode 100644 index c7120db8465..00000000000 --- a/app/assets/javascripts/discourse/models/input-validation.js.es6 +++ /dev/null @@ -1,2 +0,0 @@ -import EmberObject from "@ember/object"; -export default EmberObject.extend(); diff --git a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 index fdb7e0498e1..14d9073e9e3 100644 --- a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 +++ b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 @@ -3,7 +3,7 @@ import { default as computed, observes } from "ember-addons/ember-computed-decorators"; -import InputValidation from "discourse/models/input-validation"; +import EmberObject from "@ember/object"; export default Controller.extend({ regularPollType: "regular", @@ -260,7 +260,7 @@ export default Controller.extend({ }; } - return InputValidation.create(options); + return EmberObject.create(options); }, @computed("pollStep") @@ -274,7 +274,7 @@ export default Controller.extend({ }; } - return InputValidation.create(options); + return EmberObject.create(options); }, @computed("disableInsert") @@ -288,7 +288,7 @@ export default Controller.extend({ }; } - return InputValidation.create(options); + return EmberObject.create(options); }, _comboboxOptions(start_index, end_index) {