FIX: disable New Topic button if filtered to a tag and a category that you don't have permission to post in

This commit is contained in:
Neil Lalonde 2017-12-15 13:42:23 -05:00
parent 065c155f81
commit e73556f48f
3 changed files with 22 additions and 7 deletions

View File

@ -1,3 +1,4 @@
import { default as computed } from 'ember-addons/ember-computed-decorators';
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection"; import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
import { default as NavItem, extraNavItemProperties, customNavItemHref } from 'discourse/models/nav-item'; import { default as NavItem, extraNavItemProperties, customNavItemHref } from 'discourse/models/nav-item';
@ -60,6 +61,11 @@ export default Ember.Controller.extend(BulkTopicSelection, {
categories: Ember.computed.alias('site.categoriesList'), categories: Ember.computed.alias('site.categoriesList'),
@computed('canCreateTopic', 'category', 'canCreateTopicOnCategory')
createTopicDisabled(canCreateTopic, category, canCreateTopicOnCategory) {
return !canCreateTopic || (category && !canCreateTopicOnCategory);
},
queryParams: ['order', 'ascending', 'status', 'state', 'search', 'max_posts', 'q'], queryParams: ['order', 'ascending', 'status', 'state', 'search', 'max_posts', 'q'],
navItems: function() { navItems: function() {

View File

@ -1,6 +1,7 @@
import Composer from 'discourse/models/composer'; import Composer from 'discourse/models/composer';
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
import { findTopicList } from 'discourse/routes/build-topic-route'; import { findTopicList } from 'discourse/routes/build-topic-route';
import PermissionType from 'discourse/models/permission-type';
export default Discourse.Route.extend({ export default Discourse.Route.extend({
navMode: 'latest', navMode: 'latest',
@ -62,8 +63,10 @@ export default Discourse.Route.extend({
} else { } else {
params.filter = `tags/c/${categorySlug}/${tag_id}/l/${filter}`; params.filter = `tags/c/${categorySlug}/${tag_id}/l/${filter}`;
} }
if (category) {
this.set('category', category); category.setupGroupsAndPermissions();
this.set('category', category);
}
} else if (this.get("additionalTags")) { } else if (this.get("additionalTags")) {
params.filter = `tags/intersection/${tag_id}/${this.get('additionalTags').join('/')}`; params.filter = `tags/intersection/${tag_id}/${this.get('additionalTags').join('/')}`;
this.set('category', null); this.set('category', null);
@ -72,10 +75,13 @@ export default Discourse.Route.extend({
this.set('category', null); this.set('category', null);
} }
return findTopicList(this.store, this.topicTrackingState, params.filter, params, {}).then(function(list) { return findTopicList(this.store, this.topicTrackingState, params.filter, params, {}).then((list) => {
controller.set('list', list); controller.setProperties({
controller.set('canCreateTopic', list.get('can_create_topic')); list: list,
controller.set('loading', false); canCreateTopic: list.get('can_create_topic'),
loading: false,
canCreateTopicOnCategory: this.get('category.permission') === PermissionType.FULL
});
}); });
}, },

View File

@ -15,7 +15,10 @@
{{d-button action="deleteTag" icon="trash-o" class="admin-tag btn-danger"}} {{d-button action="deleteTag" icon="trash-o" class="admin-tag btn-danger"}}
{{d-button action="renameTag" actionParam=tag icon="pencil" class="admin-tag"}} {{d-button action="renameTag" actionParam=tag icon="pencil" class="admin-tag"}}
{{else}} {{else}}
{{create-topic-button canCreateTopic=canCreateTopic action=(route-action "createTopic")}} {{create-topic-button
canCreateTopic=canCreateTopic
disabled=createTopicDisabled
action=(route-action "createTopic")}}
{{/if}} {{/if}}
{{#if showTagFilter}} {{#if showTagFilter}}