FIX: category permissions weren't properly loaded when /categories is the homepage
FIX: don't scope to a specific category when creating a new topic from /categories
This commit is contained in:
parent
21f81979cb
commit
d5a2029026
|
@ -1,5 +1,7 @@
|
|||
import ComboboxView from 'discourse/components/combo-box';
|
||||
import { categoryBadgeHTML } from 'discourse/helpers/category-link';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import { observes, on } from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default ComboboxView.extend({
|
||||
classNames: ['combobox category-combobox'],
|
||||
|
@ -8,46 +10,34 @@ export default ComboboxView.extend({
|
|||
valueBinding: Ember.Binding.oneWay('source'),
|
||||
castInteger: true,
|
||||
|
||||
content: function() {
|
||||
let scopedCategoryId = this.get('scopedCategoryId');
|
||||
|
||||
@computed("scopedCategoryId", "categories")
|
||||
content(scopedCategoryId, categories) {
|
||||
// Always scope to the parent of a category, if present
|
||||
if (scopedCategoryId) {
|
||||
const scopedCat = Discourse.Category.findById(scopedCategoryId);
|
||||
scopedCategoryId = scopedCat.get('parent_category_id') || scopedCat.get('id');
|
||||
}
|
||||
|
||||
return this.get('categories').filter(function(c) {
|
||||
if (scopedCategoryId && (c.get('id') !== scopedCategoryId) && (c.get('parent_category_id') !== scopedCategoryId)) {
|
||||
return false;
|
||||
}
|
||||
return c.get('permission') === Discourse.PermissionType.FULL && !c.get('isUncategorizedCategory');
|
||||
return categories.filter(c => {
|
||||
if (scopedCategoryId && c.get('id') !== scopedCategoryId && c.get('parent_category_id') !== scopedCategoryId) { return false; }
|
||||
if (c.get('isUncategorizedCategory')) { return false; }
|
||||
return c.get('permission') === Discourse.PermissionType.FULL;
|
||||
});
|
||||
}.property('scopedCategoryId', 'categories'),
|
||||
},
|
||||
|
||||
_setCategories: function() {
|
||||
@on("init")
|
||||
@observes("site.sortedCategories")
|
||||
_updateCategories() {
|
||||
const categories = Discourse.SiteSettings.fixed_category_positions_on_create ?
|
||||
Discourse.Category.list() :
|
||||
Discourse.Category.listByActivity();
|
||||
this.set('categories', categories);
|
||||
},
|
||||
|
||||
if (!this.get('categories')) {
|
||||
this.set('automatic', true);
|
||||
}
|
||||
|
||||
this._updateCategories();
|
||||
|
||||
}.on('init'),
|
||||
|
||||
_updateCategories: function() {
|
||||
|
||||
if (this.get('automatic')) {
|
||||
this.set('categories',
|
||||
Discourse.SiteSettings.fixed_category_positions_on_create ?
|
||||
Discourse.Category.list() : Discourse.Category.listByActivity()
|
||||
);
|
||||
}
|
||||
}.observes('automatic', 'site.sortedCategories'),
|
||||
|
||||
none: function() {
|
||||
@computed("rootNone")
|
||||
none(rootNone) {
|
||||
if (Discourse.User.currentProp('staff') || Discourse.SiteSettings.allow_uncategorized_topics) {
|
||||
if (this.get('rootNone')) {
|
||||
if (rootNone) {
|
||||
return "category.none";
|
||||
} else {
|
||||
return Discourse.Category.findUncategorized();
|
||||
|
@ -55,10 +45,9 @@ export default ComboboxView.extend({
|
|||
} else {
|
||||
return 'category.choose';
|
||||
}
|
||||
}.property(),
|
||||
},
|
||||
|
||||
comboTemplate(item) {
|
||||
|
||||
let category;
|
||||
|
||||
// If we have no id, but text with the uncategorized name, we can use that badge.
|
||||
|
@ -79,16 +68,14 @@ export default ComboboxView.extend({
|
|||
result = categoryBadgeHTML(Discourse.Category.findById(parentCategoryId), {link: false}) + " " + result;
|
||||
}
|
||||
|
||||
result += " <span class='topic-count'>× " + category.get('topic_count') + "</span>";
|
||||
result += ` <span class='topic-count'>× ${category.get('topic_count')}</span>`;
|
||||
|
||||
const description = category.get('description');
|
||||
// TODO wtf how can this be null?;
|
||||
if (description && description !== 'null') {
|
||||
result += '<div class="category-desc">' +
|
||||
description.substr(0,200) +
|
||||
(description.length > 200 ? '…' : '') +
|
||||
'</div>';
|
||||
result += `<div class="category-desc">${description.substr(0, 200)}${description.length > 200 ? '…' : ''}</div>`;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ export default DiscoveryController.extend({
|
|||
withLogo: Em.computed.filterBy('model.categories', 'logo_url'),
|
||||
showPostsColumn: Em.computed.empty('withLogo'),
|
||||
|
||||
// this makes sure the composer isn't scoping to a specific category
|
||||
category: null,
|
||||
|
||||
actions: {
|
||||
|
||||
refresh() {
|
||||
|
|
|
@ -34,7 +34,7 @@ CategoryList.reopenClass({
|
|||
},
|
||||
|
||||
listForParent(store, category) {
|
||||
return Discourse.ajax('/categories.json?parent_category_id=' + category.get('id')).then((result) => {
|
||||
return Discourse.ajax(`/categories.json?parent_category_id=${category.get("id")}`).then(result => {
|
||||
return Discourse.CategoryList.create({
|
||||
categories: this.categoriesFrom(store, result),
|
||||
parentCategory: category
|
||||
|
@ -44,7 +44,7 @@ CategoryList.reopenClass({
|
|||
|
||||
list(store) {
|
||||
const getCategories = () => Discourse.ajax("/categories.json");
|
||||
return PreloadStore.getAndRemove("categories_list", getCategories).then((result) => {
|
||||
return PreloadStore.getAndRemove("categories_list", getCategories).then(result => {
|
||||
return Discourse.CategoryList.create({
|
||||
categories: this.categoriesFrom(store, result),
|
||||
can_create_category: result.category_list.can_create_category,
|
||||
|
|
|
@ -78,10 +78,16 @@ class CategoryList
|
|||
end
|
||||
|
||||
if latest_post_only?
|
||||
@categories = @categories.includes(:latest_post => {:topic => :last_poster} )
|
||||
@categories = @categories.includes(latest_post: { topic: :last_poster })
|
||||
end
|
||||
|
||||
@categories = @categories.to_a
|
||||
|
||||
allowed_topic_create = Set.new(Category.topic_create_allowed(@guardian).pluck(:id))
|
||||
@categories.each do |category|
|
||||
category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id)
|
||||
end
|
||||
|
||||
if @options[:parent_category_id].blank?
|
||||
subcategories = {}
|
||||
to_delete = Set.new
|
||||
|
|
|
@ -15,7 +15,7 @@ module TopicGuardian
|
|||
|
||||
def can_create_topic_on_category?(category)
|
||||
can_create_topic?(nil) &&
|
||||
(!category || Category.topic_create_allowed(self).where(:id => category.id).count == 1)
|
||||
(!category || Category.topic_create_allowed(self).where(id: category.id).count == 1)
|
||||
end
|
||||
|
||||
def can_create_post_on_topic?(topic)
|
||||
|
|
Loading…
Reference in New Issue