Hide search boxes in private team-sets for non-privileged users (#24444)
This commit is contained in:
@@ -45,9 +45,10 @@ define([
|
||||
}),
|
||||
topicOptions = typeof topicMaxTeamSize !== 'undefined' ?
|
||||
{max_team_size: topicMaxTeamSize} : {},
|
||||
topic = isInstructorManagedTopic ?
|
||||
TeamSpecHelpers.createMockInstructorManagedTopic(topicOptions) :
|
||||
TeamSpecHelpers.createMockTopic(topicOptions);
|
||||
topic;
|
||||
|
||||
topicOptions.type = isInstructorManagedTopic ? 'public_managed' : 'open';
|
||||
topic = TeamSpecHelpers.createMockTopic(topicOptions);
|
||||
|
||||
return new TeamProfileHeaderActionsView(
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ define([
|
||||
context: options.context || TeamSpecHelpers.testContext,
|
||||
model: teamModel,
|
||||
topic: isInstructorManagedTopic ?
|
||||
TeamSpecHelpers.createMockInstructorManagedTopic() :
|
||||
TeamSpecHelpers.createMockTopic({type: 'public_managed'}) :
|
||||
TeamSpecHelpers.createMockTopic(),
|
||||
setFocusToHeaderFunc: function() {
|
||||
$('.teams-content').focus();
|
||||
|
||||
@@ -313,7 +313,7 @@ define([
|
||||
AjaxHelpers.expectNoRequests(requests);
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
var setUpTopicTab = function() {
|
||||
teamsTabView = createTeamsTabView();
|
||||
teamsTabView.browseTopic(TeamSpecHelpers.testTopicID);
|
||||
verifyTeamsRequest({
|
||||
@@ -322,15 +322,17 @@ define([
|
||||
});
|
||||
AjaxHelpers.respondWithJson(requests, {});
|
||||
AjaxHelpers.respondWithJson(requests, { count: 0 });
|
||||
});
|
||||
};
|
||||
|
||||
it('can search teams', function() {
|
||||
setUpTopicTab();
|
||||
performSearch();
|
||||
expect(teamsTabView.$('.page-title').text()).toBe('Team Search');
|
||||
expect(teamsTabView.$('.page-description').text()).toBe('Showing results for "foo"');
|
||||
});
|
||||
|
||||
it('can clear a search', function() {
|
||||
setUpTopicTab();
|
||||
// Perform a search
|
||||
performSearch();
|
||||
|
||||
@@ -348,6 +350,7 @@ define([
|
||||
});
|
||||
|
||||
it('can navigate back to all teams from a search', function() {
|
||||
setUpTopicTab();
|
||||
// Perform a search
|
||||
performSearch();
|
||||
|
||||
@@ -365,6 +368,7 @@ define([
|
||||
});
|
||||
|
||||
it('does not switch to showing results when the search returns an error', function() {
|
||||
setUpTopicTab();
|
||||
// Perform a search but respond with a 500
|
||||
teamsTabView.$('.search-field').val('foo');
|
||||
teamsTabView.$('.action-search').click();
|
||||
@@ -375,6 +379,51 @@ define([
|
||||
expect(teamsTabView.$('.page-description').text()).toBe('Test description 1');
|
||||
expect(teamsTabView.$('.search-field').val(), 'foo');
|
||||
});
|
||||
|
||||
it('shows a search box in non-private team-sets', function() {
|
||||
setUpTopicTab();
|
||||
expect(teamsTabView.$('.search-field')).toExist();
|
||||
});
|
||||
|
||||
it('does not show a search box in private team-sets for non-privileged users', function() {
|
||||
teamsTabView = createTeamsTabView({
|
||||
topics: {
|
||||
results: TeamSpecHelpers.createMockTopic({type: 'private_managed'})
|
||||
}
|
||||
});
|
||||
|
||||
teamsTabView.browseTopic(TeamSpecHelpers.testTopicID);
|
||||
|
||||
verifyTeamsRequest({
|
||||
order_by: 'last_activity_at',
|
||||
text_search: ''
|
||||
});
|
||||
AjaxHelpers.respondWithJson(requests, {});
|
||||
|
||||
expect(teamsTabView.$('.search-field')).not.toExist();
|
||||
});
|
||||
|
||||
it('shows a search box in private team-sets for privileged users', function() {
|
||||
teamsTabView = createTeamsTabView({
|
||||
topics: {
|
||||
results: TeamSpecHelpers.createMockTopic({type: 'private_managed'})
|
||||
},
|
||||
userInfo: TeamSpecHelpers.createMockUserInfo({
|
||||
privileged: true,
|
||||
staff: true
|
||||
})
|
||||
});
|
||||
|
||||
teamsTabView.browseTopic(TeamSpecHelpers.testTopicID);
|
||||
|
||||
verifyTeamsRequest({
|
||||
order_by: 'last_activity_at',
|
||||
text_search: ''
|
||||
});
|
||||
AjaxHelpers.respondWithJson(requests, {});
|
||||
|
||||
expect(teamsTabView.$('.search-field')).toExist();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ define([
|
||||
topicTeamsView = new TopicTeamsView({
|
||||
el: '.teams-container',
|
||||
model: isInstructorManagedTopic ?
|
||||
TeamSpecHelpers.createMockInstructorManagedTopic() : TeamSpecHelpers.createMockTopic(),
|
||||
TeamSpecHelpers.createMockTopic({type: 'public_managed'}) : TeamSpecHelpers.createMockTopic(),
|
||||
collection: options.teams || TeamSpecHelpers.createMockTeams({results: []}),
|
||||
context: _.extend({}, TeamSpecHelpers.testContext, options)
|
||||
});
|
||||
|
||||
@@ -7,13 +7,12 @@ define([
|
||||
], function(Backbone, _, TeamCollection, TopicCollection, TopicModel) {
|
||||
'use strict';
|
||||
var createMockPostResponse, createMockDiscussionResponse, createAnnotatedContentInfo, createMockThreadResponse,
|
||||
createMockTopicData, createMockTopicCollection, createMockTopic, createMockInstructorManagedTopic,
|
||||
createMockTopicData, createMockTopicCollection, createMockTopic,
|
||||
createMockContext,
|
||||
testContext,
|
||||
testCourseID = 'course/1',
|
||||
testUser = 'testUser',
|
||||
testTopicID = 'test-topic-1',
|
||||
testInstructorManagedTopicID = 'test-instructor-managed-topic-1',
|
||||
testTeamDiscussionID = '12345',
|
||||
teamEvents = _.clone(Backbone.Events),
|
||||
testCountries = [
|
||||
@@ -283,18 +282,6 @@ define([
|
||||
));
|
||||
};
|
||||
|
||||
createMockInstructorManagedTopic = function(options) {
|
||||
return new TopicModel(_.extend(
|
||||
{
|
||||
id: testInstructorManagedTopicID,
|
||||
name: 'Test Instructor Managed Topic 1',
|
||||
description: 'Test instructor managed topic description 1',
|
||||
type: 'public_managed'
|
||||
},
|
||||
options
|
||||
));
|
||||
};
|
||||
|
||||
testContext = {
|
||||
courseID: testCourseID,
|
||||
topics: {
|
||||
@@ -362,7 +349,6 @@ define([
|
||||
createMockUserInfo: createMockUserInfo,
|
||||
createMockContext: createMockContext,
|
||||
createMockTopic: createMockTopic,
|
||||
createMockInstructorManagedTopic: createMockInstructorManagedTopic,
|
||||
createMockPostResponse: createMockPostResponse,
|
||||
createMockDiscussionResponse: createMockDiscussionResponse,
|
||||
createAnnotatedContentInfo: createAnnotatedContentInfo,
|
||||
|
||||
@@ -387,11 +387,12 @@
|
||||
collection: collection,
|
||||
showSortControls: options.showSortControls
|
||||
}),
|
||||
searchFieldView = new SearchFieldView({
|
||||
type: 'teams',
|
||||
label: gettext('Search teams'),
|
||||
collection: collection
|
||||
}),
|
||||
searchFieldView = this.shouldShowSearch(topic) ?
|
||||
new SearchFieldView({
|
||||
type: 'teams',
|
||||
label: gettext('Search teams'),
|
||||
collection: collection
|
||||
}) : null,
|
||||
viewWithHeader = this.createViewWithHeader({
|
||||
subject: topic,
|
||||
mainView: teamsView,
|
||||
@@ -504,6 +505,13 @@
|
||||
return this.context.hasOpenTopic || this.context.hasPublicManagedTopic;
|
||||
},
|
||||
|
||||
shouldShowSearch: function(topic) {
|
||||
if (topic && topic.get('type') === 'private_managed') {
|
||||
return this.context.userInfo.privileged || this.context.userInfo.staff;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
getTeamsTabViewDescription: function() {
|
||||
if (this.context.hasOpenTopic) {
|
||||
return gettext(
|
||||
|
||||
Reference in New Issue
Block a user