mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #5730 from techAPJ/enforce-tagging
FEATURE: enforce tagging on categories
This commit is contained in:
@@ -779,11 +779,19 @@ export default Ember.Controller.extend({
|
||||
|
||||
@computed('model.categoryId', 'lastValidatedAt')
|
||||
categoryValidation(categoryId, lastValidatedAt) {
|
||||
if( !this.siteSettings.allow_uncategorized_topics && !categoryId) {
|
||||
if(!this.siteSettings.allow_uncategorized_topics && !categoryId) {
|
||||
return InputValidation.create({ failed: true, reason: I18n.t('composer.error.category_missing'), lastShownAt: lastValidatedAt });
|
||||
}
|
||||
},
|
||||
|
||||
@computed('model.category', 'model.tags', 'lastValidatedAt')
|
||||
tagValidation(category, tags, lastValidatedAt) {
|
||||
const tagsArray = tags || [];
|
||||
if (this.site.get('can_tag_topics') && category && category.get('minimum_required_tags') > tagsArray.length) {
|
||||
return InputValidation.create({ failed: true, reason: I18n.t('composer.error.tags_missing', {count: category.get('minimum_required_tags')}), lastShownAt: lastValidatedAt });
|
||||
}
|
||||
},
|
||||
|
||||
collapse() {
|
||||
this._saveDraft();
|
||||
this.set('model.composeState', Composer.DRAFT);
|
||||
|
||||
@@ -108,7 +108,8 @@ const Category = RestModel.extend({
|
||||
num_featured_topics: this.get('num_featured_topics'),
|
||||
default_view: this.get('default_view'),
|
||||
subcategory_list_style: this.get('subcategory_list_style'),
|
||||
default_top_period: this.get('default_top_period')
|
||||
default_top_period: this.get('default_top_period'),
|
||||
minimum_required_tags: this.get('minimum_required_tags')
|
||||
},
|
||||
type: id ? 'PUT' : 'POST'
|
||||
});
|
||||
|
||||
@@ -105,6 +105,11 @@ const Composer = RestModel.extend({
|
||||
return categoryId ? this.site.categories.findBy('id', categoryId) : null;
|
||||
},
|
||||
|
||||
@computed('category')
|
||||
minimumRequiredTags(category) {
|
||||
return (category && category.get('minimum_required_tags') > 0) ? category.get('minimum_required_tags') : null;
|
||||
},
|
||||
|
||||
creatingTopic: Em.computed.equal('action', CREATE_TOPIC),
|
||||
creatingSharedDraft: Em.computed.equal('action', CREATE_SHARED_DRAFT),
|
||||
creatingPrivateMessage: Em.computed.equal('action', PRIVATE_MESSAGE),
|
||||
@@ -246,28 +251,41 @@ const Composer = RestModel.extend({
|
||||
return options;
|
||||
},
|
||||
|
||||
// whether to disable the post button
|
||||
cantSubmitPost: function() {
|
||||
@computed
|
||||
isStaffUser() {
|
||||
const currentUser = Discourse.User.current();
|
||||
return currentUser && currentUser.get('staff');
|
||||
},
|
||||
|
||||
@computed('loading', 'canEditTitle', 'titleLength', 'targetUsernames', 'replyLength', 'categoryId', 'missingReplyCharacters', 'tags', 'topicFirstPost', 'minimumRequiredTags', 'isStaffUser')
|
||||
cantSubmitPost(loading, canEditTitle, titleLength, targetUsernames, replyLength, categoryId, missingReplyCharacters, tags, topicFirstPost, minimumRequiredTags, isStaffUser) {
|
||||
|
||||
// can't submit while loading
|
||||
if (this.get('loading')) return true;
|
||||
if (loading) return true;
|
||||
|
||||
// title is required when
|
||||
// - creating a new topic/private message
|
||||
// - editing the 1st post
|
||||
if (this.get('canEditTitle') && !this.get('titleLengthValid')) return true;
|
||||
if (canEditTitle && !this.get('titleLengthValid')) return true;
|
||||
|
||||
// reply is always required
|
||||
if (this.get('missingReplyCharacters') > 0) return true;
|
||||
if (missingReplyCharacters > 0) return true;
|
||||
|
||||
if (this.site.get('can_tag_topics') && !isStaffUser && topicFirstPost && minimumRequiredTags) {
|
||||
const tagsArray = tags || [];
|
||||
if (tagsArray.length < minimumRequiredTags) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.get("privateMessage")) {
|
||||
// need at least one user when sending a PM
|
||||
return this.get('targetUsernames') && (this.get('targetUsernames').trim() + ',').indexOf(',') === 0;
|
||||
return targetUsernames && (targetUsernames.trim() + ',').indexOf(',') === 0;
|
||||
} else {
|
||||
// has a category? (when needed)
|
||||
return this.get('requiredCategoryMissing');
|
||||
}
|
||||
}.property('loading', 'canEditTitle', 'titleLength', 'targetUsernames', 'replyLength', 'categoryId', 'missingReplyCharacters'),
|
||||
},
|
||||
|
||||
@computed('canCategorize', 'categoryId')
|
||||
requiredCategoryMissing(canCategorize, categoryId) {
|
||||
|
||||
@@ -152,4 +152,13 @@
|
||||
</section>
|
||||
{{/unless}}
|
||||
|
||||
{{#if siteSettings.tagging_enabled}}
|
||||
<section class='field minimum-required-tags'>
|
||||
<label>
|
||||
{{i18n 'category.minimum_required_tags'}}
|
||||
{{text-field value=category.minimum_required_tags type="number"}}
|
||||
</label>
|
||||
</section>
|
||||
{{/if}}
|
||||
|
||||
{{plugin-outlet name="category-custom-settings" args=(hash category=category)}}
|
||||
|
||||
@@ -64,7 +64,8 @@
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if canEditTags}}
|
||||
{{mini-tag-chooser tags=model.tags tabindex="4" categoryId=model.categoryId}}
|
||||
{{mini-tag-chooser tags=model.tags tabindex="4" categoryId=model.categoryId minimum=model.minimumRequiredTags}}
|
||||
{{popup-input-tip validation=tagValidation}}
|
||||
{{/if}}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user