forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the controllers for classroom page (oppia#7455)
* Made the infrastructural changes for classroom page * lint * added imports * made review changes * fix oppia#7431 * fix test * flipped flag * removed comment
- Loading branch information
Showing
21 changed files
with
661 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2018 The Oppia Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS-IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Controllers for the classroom page.""" | ||
from __future__ import absolute_import # pylint: disable=import-only-modules | ||
|
||
from constants import constants | ||
from core.controllers import acl_decorators | ||
from core.controllers import base | ||
from core.domain import config_domain | ||
from core.domain import topic_services | ||
import feconf | ||
|
||
|
||
class ClassroomPage(base.BaseHandler): | ||
"""Renders the classroom page.""" | ||
|
||
@acl_decorators.open_access | ||
def get(self, classroom_name): | ||
"""Handles GET requests.""" | ||
|
||
if not constants.ENABLE_NEW_STRUCTURE_PLAYERS: | ||
raise self.PageNotFoundException | ||
|
||
classroom_name_is_valid = False | ||
for classroom_dict in config_domain.TOPIC_IDS_FOR_CLASSROOM_PAGES.value: | ||
if classroom_dict['name'] == classroom_name: | ||
classroom_name_is_valid = True | ||
break | ||
|
||
if not classroom_name_is_valid: | ||
raise self.PageNotFoundException | ||
|
||
self.render_template('classroom-page.mainpage.html') | ||
|
||
|
||
class ClassroomDataHandler(base.BaseHandler): | ||
"""Manages the data that needs to be displayed to a learner on the classroom | ||
page. | ||
""" | ||
GET_HANDLER_ERROR_RETURN_TYPE = feconf.HANDLER_TYPE_JSON | ||
|
||
@acl_decorators.open_access | ||
def get(self, classroom_name): | ||
"""Handles GET requests.""" | ||
|
||
if not constants.ENABLE_NEW_STRUCTURE_PLAYERS: | ||
raise self.PageNotFoundException | ||
|
||
classroom_name_is_valid = False | ||
for classroom_dict in config_domain.TOPIC_IDS_FOR_CLASSROOM_PAGES.value: | ||
if classroom_dict['name'] == classroom_name: | ||
classroom_name_is_valid = True | ||
topic_ids = classroom_dict['topic_ids'] | ||
break | ||
|
||
if not classroom_name_is_valid: | ||
raise self.PageNotFoundException | ||
|
||
topic_summaries = topic_services.get_multi_topic_summaries(topic_ids) | ||
topic_summary_dicts = [summary.to_dict() for summary in topic_summaries] | ||
|
||
self.values.update({ | ||
'topic_summary_dicts': topic_summary_dicts | ||
}) | ||
self.render_json(self.values) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2018 The Oppia Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS-IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Tests for the classroom page.""" | ||
from __future__ import absolute_import # pylint: disable=import-only-modules | ||
|
||
from constants import constants | ||
from core.tests import test_utils | ||
import feconf | ||
|
||
|
||
class BaseClassroomControllerTests(test_utils.GenericTestBase): | ||
|
||
def setUp(self): | ||
"""Completes the sign-up process for the various users.""" | ||
super(BaseClassroomControllerTests, self).setUp() | ||
self.signup(self.NEW_USER_EMAIL, self.NEW_USER_USERNAME) | ||
self.user_id = self.get_user_id_from_email(self.NEW_USER_EMAIL) | ||
|
||
|
||
class ClassroomPageTests(BaseClassroomControllerTests): | ||
|
||
def test_any_user_can_access_classroom_page(self): | ||
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): | ||
response = self.get_html_response( | ||
'%s/%s' % (feconf.CLASSROOM_URL_PREFIX, 'Math')) | ||
self.assertIn('<classroom-page></classroom-page>', response) | ||
|
||
def test_no_user_can_access_invalid_classroom_page(self): | ||
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): | ||
self.get_html_response( | ||
'%s/%s' % ( | ||
feconf.CLASSROOM_URL_PREFIX, 'invalid_subject'), | ||
expected_status_int=404) | ||
|
||
def test_get_fails_when_new_structures_not_enabled(self): | ||
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', False): | ||
self.get_html_response( | ||
'%s/%s' % (feconf.CLASSROOM_URL_PREFIX, 'Math'), | ||
expected_status_int=404) | ||
|
||
|
||
class ClassroomDataHandlerTests(BaseClassroomControllerTests): | ||
|
||
def test_get(self): | ||
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): | ||
json_response = self.get_json( | ||
'%s/%s' % (feconf.CLASSROOM_DATA_HANDLER, 'Math')) | ||
expected_dict = { | ||
'topic_summary_dicts': [] | ||
} | ||
self.assertDictContainsSubset(expected_dict, json_response) | ||
|
||
def test_get_fails_for_invalid_classroom_name(self): | ||
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): | ||
self.get_json( | ||
'%s/%s' % ( | ||
feconf.CLASSROOM_DATA_HANDLER, 'invalid_subject'), | ||
expected_status_int=404) | ||
|
||
def test_get_fails_when_new_structures_not_enabled(self): | ||
with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', False): | ||
self.get_json( | ||
'%s/%s' % (feconf.CLASSROOM_DATA_HANDLER, 'Math'), | ||
expected_status_int=404) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/templates/dev/head/domain/classroom/ClassroomBackendApiService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2018 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Service to get topic data. | ||
*/ | ||
|
||
require('domain/utilities/UrlInterpolationService.ts'); | ||
|
||
require('domain/classroom/classroom-domain.constants.ajs.ts'); | ||
|
||
angular.module('oppia').factory('ClassroomBackendApiService', [ | ||
'$http', '$q', 'UrlInterpolationService', 'CLASSROOOM_DATA_URL_TEMPLATE', | ||
function($http, $q, UrlInterpolationService, CLASSROOOM_DATA_URL_TEMPLATE) { | ||
var classroomDataDict = null; | ||
var _fetchClassroomData = function( | ||
classroomName, successCallback, errorCallback) { | ||
var classroomDataUrl = UrlInterpolationService.interpolateUrl( | ||
CLASSROOOM_DATA_URL_TEMPLATE, { | ||
classroom_name: classroomName | ||
}); | ||
|
||
$http.get(classroomDataUrl).then(function(response) { | ||
classroomDataDict = angular.copy(response.data); | ||
if (successCallback) { | ||
successCallback(classroomDataDict); | ||
} | ||
}, function(errorResponse) { | ||
if (errorCallback) { | ||
errorCallback(errorResponse.data); | ||
} | ||
}); | ||
}; | ||
|
||
return { | ||
fetchClassroomData: function(classroomName) { | ||
return $q(function(resolve, reject) { | ||
_fetchClassroomData(classroomName, resolve, reject); | ||
}); | ||
} | ||
}; | ||
} | ||
]); |
Oops, something went wrong.