REFACTOR: Remove `InputValidation` which was simply an `Ember.Object`

This commit is contained in:
Robin Ward 2019-11-11 15:48:33 -05:00
parent 211410c3b9
commit e39d89ecd9
16 changed files with 60 additions and 55 deletions

View File

@ -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")
});

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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));
}
});

View File

@ -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

View File

@ -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")
});

View File

@ -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")
});

View File

@ -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")
});

View File

@ -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 });
}
});

View File

@ -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")
});

View File

@ -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 });
}
});

View File

@ -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(" ")

View File

@ -1,2 +0,0 @@
import EmberObject from "@ember/object";
export default EmberObject.extend();

View File

@ -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) {