Skip to content

Commit

Permalink
Rename gallery to library throughout the codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlip committed May 4, 2016
1 parent 08bd01f commit b923cf3
Show file tree
Hide file tree
Showing 118 changed files with 772 additions and 945 deletions.
12 changes: 7 additions & 5 deletions core/controllers/admin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ def test_change_rights(self):
BOTH_MODERATOR_AND_ADMIN_EMAIL, BOTH_MODERATOR_AND_ADMIN_USERNAME)

# Navigate to any page. The role is not set.
self.testapp.get('/gallery').mustcontain(no=['/moderator', '/admin'])
self.testapp.get(feconf.LIBRARY_INDEX_URL).mustcontain(
no=['/moderator', '/admin'])

# Log in as a superadmin. This gives access to /admin.
self.login('superadmin@example.com', is_super_admin=True)
self.testapp.get('/gallery').mustcontain('/admin', no=['/moderator'])
self.testapp.get(feconf.LIBRARY_INDEX_URL).mustcontain(
'/admin', no=['/moderator'])

# Add a moderator, an admin, and a person with both roles, then log
# out.
Expand All @@ -154,20 +156,20 @@ def test_change_rights(self):

# Log in as a moderator.
self.login(self.MODERATOR_EMAIL)
self.testapp.get(feconf.GALLERY_URL).mustcontain(
self.testapp.get(feconf.LIBRARY_INDEX_URL).mustcontain(
'/moderator', no=['/admin'])
self.logout()

# Log in as an admin.
self.login(self.ADMIN_EMAIL)
self.testapp.get(feconf.GALLERY_URL).mustcontain(
self.testapp.get(feconf.LIBRARY_INDEX_URL).mustcontain(
'/moderator', no=['/admin'])
self.logout()

# Log in as a both-moderator-and-admin.
# Only '(Admin)' is shown in the navbar.
self.login(BOTH_MODERATOR_AND_ADMIN_EMAIL)
self.assertEqual(self.testapp.get('/').status_int, 302)
self.testapp.get(feconf.GALLERY_URL).mustcontain(
self.testapp.get(feconf.LIBRARY_INDEX_URL).mustcontain(
'/moderator', no=['/admin'])
self.logout()
31 changes: 16 additions & 15 deletions core/controllers/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def test_dev_indicator_appears_in_dev_and_not_in_production(self):
"""Test dev indicator appears in dev and not in production."""

with self.swap(feconf, 'DEV_MODE', True):
response = self.testapp.get('/gallery')
response = self.testapp.get(feconf.LIBRARY_INDEX_URL)
self.assertIn('<div class="oppia-dev-mode">', response.body)

with self.swap(feconf, 'DEV_MODE', False):
response = self.testapp.get('/gallery')
response = self.testapp.get(feconf.LIBRARY_INDEX_URL)
self.assertNotIn('<div class="oppia-dev-mode">', response.body)

def test_that_no_get_results_in_500_error(self):
Expand Down Expand Up @@ -79,16 +79,16 @@ def test_that_no_get_results_in_500_error(self):
def test_requests_for_invalid_paths(self):
"""Test that requests for invalid paths result in a 404 error."""

response = self.testapp.get('/gallery/extra', expect_errors=True)
response = self.testapp.get('/library/extra', expect_errors=True)
self.assertEqual(response.status_int, 404)

response = self.testapp.get('/gallery/data/extra', expect_errors=True)
response = self.testapp.get('/library/data/extra', expect_errors=True)
self.assertEqual(response.status_int, 404)

response = self.testapp.post('/gallery/extra', {}, expect_errors=True)
response = self.testapp.post('/library/extra', {}, expect_errors=True)
self.assertEqual(response.status_int, 404)

response = self.testapp.put('/gallery/extra', {}, expect_errors=True)
response = self.testapp.put('/library/extra', {}, expect_errors=True)
self.assertEqual(response.status_int, 404)

def test_redirect_in_both_logged_in_and_logged_out_states(self):
Expand Down Expand Up @@ -145,20 +145,20 @@ def _get_current_time(unused_cls):
types.MethodType(_get_current_time, base.CsrfTokenManager)):
# Create a token and check that it expires correctly.
token = base.CsrfTokenManager().create_csrf_token('uid', 'page')
self.assertTrue(
base.CsrfTokenManager.is_csrf_token_valid('uid', 'page', token))
self.assertTrue(base.CsrfTokenManager.is_csrf_token_valid(
'uid', 'page', token))

current_time = orig_time + 1
self.assertTrue(
base.CsrfTokenManager.is_csrf_token_valid('uid', 'page', token))
self.assertTrue(base.CsrfTokenManager.is_csrf_token_valid(
'uid', 'page', token))

current_time = orig_time + FORTY_EIGHT_HOURS_IN_SECS - PADDING
self.assertTrue(
base.CsrfTokenManager.is_csrf_token_valid('uid', 'page', token))
self.assertTrue(base.CsrfTokenManager.is_csrf_token_valid(
'uid', 'page', token))

current_time = orig_time + FORTY_EIGHT_HOURS_IN_SECS + PADDING
self.assertFalse(
base.CsrfTokenManager.is_csrf_token_valid('uid', 'page', token))
self.assertFalse(base.CsrfTokenManager.is_csrf_token_valid(
'uid', 'page', token))

# Check that the expiry of one token does not cause the other to
# expire.
Expand All @@ -182,7 +182,8 @@ def _get_current_time(unused_cls):
base.CsrfTokenManager.is_csrf_token_valid(
'uid', 'page2', token2))

current_time = orig_time + 100 + FORTY_EIGHT_HOURS_IN_SECS + PADDING
current_time = (
orig_time + 100 + FORTY_EIGHT_HOURS_IN_SECS + PADDING)
self.assertFalse(
base.CsrfTokenManager.is_csrf_token_valid(
'uid', 'page1', token1))
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
MODERATOR_REQUEST_FORUM_URL = config_domain.ConfigProperty(
'moderator_request_forum_url', {'type': 'unicode'},
'A link to the forum for nominating explorations to be featured '
'in the gallery',
'in the Oppia library',
default_value=MODERATOR_REQUEST_FORUM_URL_DEFAULT_VALUE)

DEFAULT_TWITTER_SHARE_MESSAGE_EDITOR = config_domain.ConfigProperty(
Expand Down
8 changes: 5 additions & 3 deletions core/controllers/editor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def test_untrained_answers_handler(self):
with self.swap(feconf, 'SHOW_TRAINABLE_UNRESOLVED_ANSWERS', True):
def _create_answer(value, count=1):
return {'value': value, 'count': count}

def _create_training_data(*arg):
return [_create_answer(value) for value in arg]

Expand Down Expand Up @@ -790,7 +791,7 @@ def test_user_banning(self):
# Joe logs in.
self.login('joe@example.com')

response = self.testapp.get(feconf.GALLERY_URL)
response = self.testapp.get(feconf.LIBRARY_INDEX_URL)
self.assertEqual(response.status_int, 200)
response = self.testapp.get('/create/%s' % exp_id)
self.assertEqual(response.status_int, 200)
Expand All @@ -800,8 +801,9 @@ def test_user_banning(self):
config_services.set_property(
feconf.SYSTEM_COMMITTER_ID, 'banned_usernames', ['joe'])

# Test that Joe is banned. (He can still access the gallery.)
response = self.testapp.get(feconf.GALLERY_URL, expect_errors=True)
# Test that Joe is banned. (He can still access the library page.)
response = self.testapp.get(
feconf.LIBRARY_INDEX_URL, expect_errors=True)
self.assertEqual(response.status_int, 200)
response = self.testapp.get('/create/%s' % exp_id, expect_errors=True)
self.assertEqual(response.status_int, 200)
Expand Down
119 changes: 110 additions & 9 deletions core/controllers/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Controllers for the user dashboard and for notifications."""
"""Controllers for the creator dashboard, notifications, and creating new
activities.
"""

from core.controllers import base
from core.domain import collection_domain
from core.domain import collection_services
from core.domain import config_domain
from core.domain import exp_domain
from core.domain import exp_services
from core.domain import feedback_services
from core.domain import subscription_services
Expand All @@ -24,6 +29,14 @@
import feconf
import utils

EXPLORATION_ID_KEY = 'explorationId'
COLLECTION_ID_KEY = 'collectionId'

ALLOW_YAML_FILE_UPLOAD = config_domain.ConfigProperty(
'allow_yaml_file_upload', {'type': 'bool'},
'Whether to allow exploration uploads via YAML.',
default_value=False)


class NotificationsDashboardPage(base.BaseHandler):
"""Page with notifications for the user."""
Expand All @@ -48,9 +61,7 @@ def get(self):
class NotificationsDashboardHandler(base.BaseHandler):
"""Provides data for the user notifications dashboard."""

# We use 'gallery' because the createExploration() modal makes a call
# there.
PAGE_NAME_FOR_CSRF = 'gallery'
PAGE_NAME_FOR_CSRF = 'dashboard'

def get(self):
"""Handles GET requests."""
Expand Down Expand Up @@ -97,9 +108,8 @@ def get(self):

class MyExplorationsPage(base.BaseHandler):
"""Page showing the user's explorations."""
# We use 'gallery' because the createExploration() modal makes a call
# there.
PAGE_NAME_FOR_CSRF = 'gallery'

PAGE_NAME_FOR_CSRF = 'dashboard'

@base.require_user
def get(self):
Expand All @@ -111,7 +121,9 @@ def get(self):
'nav_mode': feconf.NAV_MODE_HOME,
'can_create_collections': (
self.username in
config_domain.WHITELISTED_COLLECTION_EDITOR_USERNAMES.value)
config_domain.WHITELISTED_COLLECTION_EDITOR_USERNAMES.value
),
'allow_yaml_file_upload': ALLOW_YAML_FILE_UPLOAD.value,
})
self.render_template(
'dashboard/my_explorations.html', redirect_url_on_logout='/')
Expand Down Expand Up @@ -161,7 +173,7 @@ def _get_intro_card_color(category):
'community_owned': exp_summary.community_owned,
'is_editable': True,
'thumbnail_image_url': (
'/images/gallery/exploration_background_%s_small.png' %
'/images/library/exploration_background_%s_small.png' %
_get_intro_card_color(exp_summary.category)),
'ratings': exp_summary.ratings,
'num_open_threads': (
Expand Down Expand Up @@ -202,3 +214,92 @@ def get(self):
self.render_json({
'num_unseen_notifications': num_unseen_notifications,
})


class NewExploration(base.BaseHandler):
"""Creates a new exploration."""

PAGE_NAME_FOR_CSRF = 'dashboard'

@base.require_fully_signed_up
def post(self):
"""Handles POST requests."""
title = self.payload.get('title')
category = self.payload.get('category')
objective = self.payload.get('objective')
language_code = self.payload.get('language_code')

if not title:
raise self.InvalidInputException('No title supplied.')
if not category:
raise self.InvalidInputException('No category chosen.')
if not language_code:
raise self.InvalidInputException('No language chosen.')

new_exploration_id = exp_services.get_new_exploration_id()
exploration = exp_domain.Exploration.create_default_exploration(
new_exploration_id, title, category,
objective=objective, language_code=language_code)
exp_services.save_new_exploration(self.user_id, exploration)

self.render_json({
EXPLORATION_ID_KEY: new_exploration_id
})


class NewCollection(base.BaseHandler):
"""Creates a new collection."""

PAGE_NAME_FOR_CSRF = 'dashboard'

@base.require_fully_signed_up
def post(self):
"""Handles POST requests."""
title = self.payload.get('title')
category = self.payload.get('category')
objective = self.payload.get('objective')
# TODO(bhenning): Implement support for language codes in collections.

if not title:
raise self.InvalidInputException('No title supplied.')
if not category:
raise self.InvalidInputException('No category chosen.')

new_collection_id = collection_services.get_new_collection_id()
collection = collection_domain.Collection.create_default_collection(
new_collection_id, title, category, objective=objective)
collection_services.save_new_collection(self.user_id, collection)

self.render_json({
COLLECTION_ID_KEY: new_collection_id
})


class UploadExploration(base.BaseHandler):
"""Uploads a new exploration."""

PAGE_NAME_FOR_CSRF = 'dashboard'

@base.require_fully_signed_up
def post(self):
"""Handles POST requests."""
title = self.payload.get('title')
category = self.payload.get('category')
yaml_content = self.request.get('yaml_file')

if not title:
raise self.InvalidInputException('No title supplied.')
if not category:
raise self.InvalidInputException('No category chosen.')

new_exploration_id = exp_services.get_new_exploration_id()
if ALLOW_YAML_FILE_UPLOAD.value:
exp_services.save_new_exploration_from_yaml_and_assets(
self.user_id, yaml_content, title, category,
new_exploration_id, [])
self.render_json({
EXPLORATION_ID_KEY: new_exploration_id
})
else:
raise self.InvalidInputException(
'This server does not allow file uploads.')
43 changes: 43 additions & 0 deletions core/controllers/home_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

"""Tests for the user notification dashboard and 'my explorations' pages."""

from core.controllers import home
from core.domain import config_services
from core.domain import feedback_domain
from core.domain import feedback_services
from core.domain import rights_manager
Expand Down Expand Up @@ -256,3 +258,44 @@ def test_author_ids_are_handled_correctly(self):
self.assertEqual(
response['recent_notifications'][0]['author_username'], '')
self.assertNotIn('author_id', response['recent_notifications'][0])


class CreationButtonsTest(test_utils.GenericTestBase):

def setUp(self):
super(CreationButtonsTest, self).setUp()
self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)

def test_new_exploration_ids(self):
"""Test generation of exploration ids."""
self.login(self.EDITOR_EMAIL)

response = self.testapp.get('/my_explorations')
self.assertEqual(response.status_int, 200)
csrf_token = self.get_csrf_token_from_response(response)
exp_a_id = self.post_json(feconf.NEW_EXPLORATION_URL, {
'title': self.UNICODE_TEST_STRING,
'category': self.UNICODE_TEST_STRING,
'objective': 'Learn how to generate exploration ids.',
'language_code': feconf.DEFAULT_LANGUAGE_CODE
}, csrf_token)[home.EXPLORATION_ID_KEY]
self.assertEqual(len(exp_a_id), 12)

self.logout()

def test_exploration_upload_button(self):
"""Test that the exploration upload button appears when appropriate."""
self.login(self.EDITOR_EMAIL)

response = self.testapp.get('/my_explorations')
self.assertEqual(response.status_int, 200)
response.mustcontain(no=['ng-click="showUploadExplorationModal()"'])

config_services.set_property(
feconf.SYSTEM_COMMITTER_ID, 'allow_yaml_file_upload', True)

response = self.testapp.get('/my_explorations')
self.assertEqual(response.status_int, 200)
response.mustcontain('ng-click="showUploadExplorationModal()"')

self.logout()
Loading

0 comments on commit b923cf3

Please sign in to comment.