Skip to content

Commit

Permalink
Merge pull request oppia#931 from oppia/collections-backend
Browse files Browse the repository at this point in the history
Collections backend
BenHenning committed Oct 6, 2015
2 parents 38226d7 + d1b84d2 commit 2ecf34e
Showing 46 changed files with 6,520 additions and 968 deletions.
2 changes: 1 addition & 1 deletion core/controllers/admin.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
from core.domain import config_services
from core.domain import exp_services
from core.domain import recommendations_services
from core.domain import rights_manager
from core.domain import rte_component_registry
from core.domain import user_services
from core.platform import models
@@ -168,7 +169,6 @@ def post(self):
logging.info(
'[ADMIN] %s reloaded exploration %s' %
(self.user_id, exploration_id))
exp_services.delete_demo(unicode(exploration_id))
exp_services.load_demo(unicode(exploration_id))
elif self.payload.get('action') == 'clear_search_index':
exp_services.clear_search_index()
12 changes: 6 additions & 6 deletions core/controllers/base.py
Original file line number Diff line number Diff line change
@@ -388,12 +388,12 @@ def render_template(
'DEFAULT_LANGUAGE_CODE': feconf.ALL_LANGUAGE_CODES[0]['code'],
'DEV_MODE': feconf.DEV_MODE,
'DOMAIN_URL': '%s://%s' % (scheme, netloc),
'EXPLORATION_STATUS_PRIVATE': (
rights_manager.EXPLORATION_STATUS_PRIVATE),
'EXPLORATION_STATUS_PUBLIC': (
rights_manager.EXPLORATION_STATUS_PUBLIC),
'EXPLORATION_STATUS_PUBLICIZED': (
rights_manager.EXPLORATION_STATUS_PUBLICIZED),
'ACTIVITY_STATUS_PRIVATE': (
rights_manager.ACTIVITY_STATUS_PRIVATE),
'ACTIVITY_STATUS_PUBLIC': (
rights_manager.ACTIVITY_STATUS_PUBLIC),
'ACTIVITY_STATUS_PUBLICIZED': (
rights_manager.ACTIVITY_STATUS_PUBLICIZED),
'FULL_URL': '%s://%s/%s' % (scheme, netloc, path),
'INVALID_NAME_CHARS': feconf.INVALID_NAME_CHARS,
# TODO(sll): Consider including the obj_editor html directly as
56 changes: 35 additions & 21 deletions core/controllers/editor.py
Original file line number Diff line number Diff line change
@@ -130,7 +130,8 @@ def test_editor(self, exploration_id, escaped_state_name=None, **kwargs):
except:
raise self.PageNotFoundException

if not rights_manager.Actor(self.user_id).can_edit(exploration_id):
if not rights_manager.Actor(self.user_id).can_edit(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id):
raise self.UnauthorizedUserException(
'You do not have the credentials to edit this exploration.',
self.user_id)
@@ -172,14 +173,15 @@ def get(self, exploration_id):
exploration_id, strict=False)
if (exploration is None or
not rights_manager.Actor(self.user_id).can_view(
exploration_id)):
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id)):
self.redirect('/')
return

can_edit = (
bool(self.user_id) and
self.username not in config_domain.BANNED_USERNAMES.value and
rights_manager.Actor(self.user_id).can_edit(exploration_id))
rights_manager.Actor(self.user_id).can_edit(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id))

value_generators_js = VALUE_GENERATORS_JS.value

@@ -212,20 +214,27 @@ def get(self, exploration_id):
'INTERACTION_SPECS': interaction_registry.Registry.get_all_specs(),
'additional_angular_modules': additional_angular_modules,
'can_delete': rights_manager.Actor(
self.user_id).can_delete(exploration_id),
self.user_id).can_delete(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id),
'can_edit': can_edit,
'can_modify_roles': rights_manager.Actor(
self.user_id).can_modify_roles(exploration_id),
self.user_id).can_modify_roles(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id),
'can_publicize': rights_manager.Actor(
self.user_id).can_publicize(exploration_id),
'can_publish': rights_manager.Actor(self.user_id).can_publish(
exploration_id),
self.user_id).can_publicize(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id),
'can_publish': rights_manager.Actor(
self.user_id).can_publish(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id),
'can_release_ownership': rights_manager.Actor(
self.user_id).can_release_ownership(exploration_id),
self.user_id).can_release_ownership(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id),
'can_unpublicize': rights_manager.Actor(
self.user_id).can_unpublicize(exploration_id),
'can_unpublish': rights_manager.Actor(self.user_id).can_unpublish(
exploration_id),
self.user_id).can_unpublicize(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id),
'can_unpublish': rights_manager.Actor(
self.user_id).can_unpublish(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id),
'dependencies_html': jinja2.utils.Markup(dependencies_html),
'gadget_templates': jinja2.utils.Markup(gadget_templates),
'interaction_templates': jinja2.utils.Markup(
@@ -307,7 +316,8 @@ def _get_exploration_data(self, exploration_id, version=None):

def get(self, exploration_id):
"""Gets the data for the exploration overview page."""
if not rights_manager.Actor(self.user_id).can_view(exploration_id):
if not rights_manager.Actor(self.user_id).can_view(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id):
raise self.PageNotFoundException

version = self.request.get('v', default_value=None)
@@ -366,7 +376,7 @@ def delete(self, exploration_id):

exploration = exp_services.get_exploration_by_id(exploration_id)
can_delete = rights_manager.Actor(self.user_id).can_delete(
exploration.id)
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration.id)
if not can_delete:
raise self.UnauthorizedUserException(
'User %s does not have permissions to delete exploration %s' %
@@ -402,8 +412,9 @@ def put(self, exploration_id):
viewable_if_private = self.payload.get('viewable_if_private')

if new_member_username:
if not rights_manager.Actor(self.user_id).can_modify_roles(
exploration_id):
if not rights_manager.Actor(
self.user_id).can_modify_roles(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id):
raise self.UnauthorizedUserException(
'Only an owner of this exploration can add or change '
'roles.')
@@ -414,7 +425,7 @@ def put(self, exploration_id):
raise Exception(
'Sorry, we could not find the specified user.')

rights_manager.assign_role(
rights_manager.assign_role_for_exploration(
self.user_id, exploration_id, new_member_id, new_member_role)

elif is_public is not None:
@@ -455,10 +466,11 @@ def put(self, exploration_id):
except utils.ValidationError as e:
raise self.InvalidInputException(e)

rights_manager.release_ownership(self.user_id, exploration_id)
rights_manager.release_ownership_of_exploration(
self.user_id, exploration_id)

elif viewable_if_private is not None:
rights_manager.set_private_viewability(
rights_manager.set_private_viewability_of_exploration(
self.user_id, exploration_id, viewable_if_private)

else:
@@ -590,7 +602,8 @@ def get(self, exploration_id):
except:
raise self.PageNotFoundException

if not rights_manager.Actor(self.user_id).can_view(exploration_id):
if not rights_manager.Actor(self.user_id).can_view(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id):
raise self.PageNotFoundException

version = self.request.get('v', default_value=exploration.version)
@@ -625,7 +638,8 @@ def get(self, exploration_id):
except:
raise self.PageNotFoundException

if not rights_manager.Actor(self.user_id).can_view(exploration_id):
if not rights_manager.Actor(self.user_id).can_view(
rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id):
raise self.PageNotFoundException

version = self.request.get('v', default_value=exploration.version)
24 changes: 16 additions & 8 deletions core/controllers/editor_test.py
Original file line number Diff line number Diff line change
@@ -65,9 +65,14 @@ def assert_cannot_edit(self, response_body):

class EditorTest(BaseEditorControllerTest):

def setUp(self):
super(EditorTest, self).setUp()
exp_services.load_demo('0')
rights_manager.release_ownership_of_exploration(
feconf.SYSTEM_COMMITTER_ID, '0')

def test_editor_page(self):
"""Test access to editor pages for the sample exploration."""
exp_services.load_demo('0')

# Check that non-editors can access, but not edit, the editor page.
response = self.testapp.get('/create/0')
@@ -92,7 +97,7 @@ def test_editor_page(self):

def test_new_state_template(self):
"""Test the validity of the NEW_STATE_TEMPLATE."""
exp_services.load_demo('0')

exploration = exp_services.get_exploration_by_id('0')
exploration.add_states([feconf.DEFAULT_INIT_STATE_NAME])
new_state_dict = exploration.states[
@@ -102,7 +107,6 @@ def test_new_state_template(self):

def test_add_new_state_error_cases(self):
"""Test the error cases for adding a new state to an exploration."""
exp_services.load_demo('0')
CURRENT_VERSION = 1

self.login(self.EDITOR_EMAIL)
@@ -173,8 +177,6 @@ def _put_and_expect_400_error(payload):
self.logout()

def test_resolved_answers_handler(self):
exp_services.load_demo('0')

# In the reader perspective, submit the first multiple-choice answer,
# then submit 'blah' once, 'blah2' twice and 'blah3' three times.
# TODO(sll): Use the ExplorationPlayer in reader_test for this.
@@ -248,6 +250,8 @@ def _create_training_data(*arg):

# Load the fuzzy rules demo exploration.
exp_services.load_demo('16')
rights_manager.release_ownership_of_exploration(
feconf.SYSTEM_COMMITTER_ID, '16')

exploration_dict = self.get_json(
'%s/16' % feconf.EXPLORATION_INIT_URL_PREFIX)
@@ -476,7 +480,6 @@ class DownloadIntegrationTest(BaseEditorControllerTest):
""")

def test_exploration_download_handler_for_default_exploration(self):

self.login(self.EDITOR_EMAIL)
self.OWNER_ID = self.get_user_id_from_email(self.EDITOR_EMAIL)

@@ -592,7 +595,7 @@ def test_deletion_rights_for_unpublished_exploration(self):
UNPUBLISHED_EXP_ID, 'A title', 'A category')
exp_services.save_new_exploration(self.owner_id, exploration)

rights_manager.assign_role(
rights_manager.assign_role_for_exploration(
self.owner_id, UNPUBLISHED_EXP_ID, self.editor_id,
rights_manager.ROLE_EDITOR)

@@ -621,7 +624,7 @@ def test_deletion_rights_for_published_exploration(self):
PUBLISHED_EXP_ID, 'A title', 'A category')
exp_services.save_new_exploration(self.owner_id, exploration)

rights_manager.assign_role(
rights_manager.assign_role_for_exploration(
self.owner_id, PUBLISHED_EXP_ID, self.editor_id,
rights_manager.ROLE_EDITOR)
rights_manager.publish_exploration(self.owner_id, PUBLISHED_EXP_ID)
@@ -661,6 +664,8 @@ def setUp(self):
self.EXP_ID = '0'

exp_services.load_demo(self.EXP_ID)
rights_manager.release_ownership_of_exploration(
feconf.SYSTEM_COMMITTER_ID, self.EXP_ID)

self.login(self.EDITOR_EMAIL)

@@ -773,8 +778,11 @@ class ExplorationEditRightsTest(BaseEditorControllerTest):

def test_user_banning(self):
"""Test that banned users are banned."""

EXP_ID = '0'
exp_services.load_demo(EXP_ID)
rights_manager.release_ownership_of_exploration(
feconf.SYSTEM_COMMITTER_ID, EXP_ID)

# Sign-up new editors Joe and Sandra.
self.signup('joe@example.com', 'joe')
1 change: 0 additions & 1 deletion core/controllers/galleries.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@
from core.domain import exp_domain
from core.domain import exp_jobs
from core.domain import exp_services
from core.domain import rights_manager
from core.domain import user_services
from core.platform import models
(base_models, exp_models,) = models.Registry.import_models([
10 changes: 5 additions & 5 deletions core/controllers/galleries_test.py
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ def test_gallery_handler_demo_exploration(self):
'title': 'Welcome to Oppia!',
'language_code': 'en',
'objective': 'become familiar with Oppia\'s capabilities',
'status': rights_manager.EXPLORATION_STATUS_PUBLIC,
'status': rights_manager.ACTIVITY_STATUS_PUBLIC,
}, response_dict['explorations_list'][0])

# Publicize the demo exploration.
@@ -108,7 +108,7 @@ def test_gallery_handler_demo_exploration(self):
'title': 'A new title!',
'language_code': 'en',
'objective': 'become familiar with Oppia\'s capabilities',
'status': rights_manager.EXPLORATION_STATUS_PUBLICIZED,
'status': rights_manager.ACTIVITY_STATUS_PUBLICIZED,
}, response_dict['explorations_list'][0])

def test_gallery_handler_for_created_explorations(self):
@@ -163,15 +163,15 @@ def test_gallery_handler_for_created_explorations(self):
'title': 'Title B',
'language_code': 'en',
'objective': 'Objective B',
'status': rights_manager.EXPLORATION_STATUS_PUBLICIZED,
'status': rights_manager.ACTIVITY_STATUS_PUBLICIZED,
}, response_dict['explorations_list'][0])
self.assertDictContainsSubset({
'id': 'A',
'category': 'Category A',
'title': 'Title A',
'language_code': 'en',
'objective': 'Objective A',
'status': rights_manager.EXPLORATION_STATUS_PUBLIC,
'status': rights_manager.ACTIVITY_STATUS_PUBLIC,
}, response_dict['explorations_list'][1])

# Delete exploration A
@@ -186,7 +186,7 @@ def test_gallery_handler_for_created_explorations(self):
'title': 'Title B',
'language_code': 'en',
'objective': 'Objective B',
'status': rights_manager.EXPLORATION_STATUS_PUBLICIZED,
'status': rights_manager.ACTIVITY_STATUS_PUBLICIZED,
}, response_dict['explorations_list'][0])

def test_new_exploration_ids(self):
2 changes: 1 addition & 1 deletion core/controllers/home.py
Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ def get(self):

subscribed_summaries = (
exp_services.get_exploration_summaries_matching_ids(
subscription_services.get_activity_ids_subscribed_to(
subscription_services.get_exploration_ids_subscribed_to(
self.user_id)))

def _get_intro_card_color(category):
16 changes: 8 additions & 8 deletions core/controllers/home_test.py
Original file line number Diff line number Diff line change
@@ -99,27 +99,27 @@ def test_managers_can_see_explorations(self):
self.assertEqual(len(response['explorations_list']), 1)
self.assertEqual(
response['explorations_list'][0]['status'],
rights_manager.EXPLORATION_STATUS_PRIVATE)
rights_manager.ACTIVITY_STATUS_PRIVATE)

rights_manager.publish_exploration(self.owner_id, self.EXP_ID)
response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
self.assertEqual(len(response['explorations_list']), 1)
self.assertEqual(
response['explorations_list'][0]['status'],
rights_manager.EXPLORATION_STATUS_PUBLIC)
rights_manager.ACTIVITY_STATUS_PUBLIC)

rights_manager.publicize_exploration(self.owner_id, self.EXP_ID)
response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
self.assertEqual(len(response['explorations_list']), 1)
self.assertEqual(
response['explorations_list'][0]['status'],
rights_manager.EXPLORATION_STATUS_PUBLICIZED)
rights_manager.ACTIVITY_STATUS_PUBLICIZED)
self.logout()

def test_collaborators_can_see_explorations(self):
self.save_new_default_exploration(
self.EXP_ID, self.owner_id, title=self.EXP_TITLE)
rights_manager.assign_role(
rights_manager.assign_role_for_exploration(
self.owner_id, self.EXP_ID, self.collaborator_id,
rights_manager.ROLE_EDITOR)
self.set_admins([self.OWNER_EMAIL])
@@ -129,28 +129,28 @@ def test_collaborators_can_see_explorations(self):
self.assertEqual(len(response['explorations_list']), 1)
self.assertEqual(
response['explorations_list'][0]['status'],
rights_manager.EXPLORATION_STATUS_PRIVATE)
rights_manager.ACTIVITY_STATUS_PRIVATE)

rights_manager.publish_exploration(self.owner_id, self.EXP_ID)
response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
self.assertEqual(len(response['explorations_list']), 1)
self.assertEqual(
response['explorations_list'][0]['status'],
rights_manager.EXPLORATION_STATUS_PUBLIC)
rights_manager.ACTIVITY_STATUS_PUBLIC)

rights_manager.publicize_exploration(self.owner_id, self.EXP_ID)
response = self.get_json(self.MY_EXPLORATIONS_DATA_URL)
self.assertEqual(len(response['explorations_list']), 1)
self.assertEqual(
response['explorations_list'][0]['status'],
rights_manager.EXPLORATION_STATUS_PUBLICIZED)
rights_manager.ACTIVITY_STATUS_PUBLICIZED)

self.logout()

def test_viewer_cannot_see_explorations(self):
self.save_new_default_exploration(
self.EXP_ID, self.owner_id, title=self.EXP_TITLE)
rights_manager.assign_role(
rights_manager.assign_role_for_exploration(
self.owner_id, self.EXP_ID, self.viewer_id,
rights_manager.ROLE_VIEWER)
self.set_admins([self.OWNER_EMAIL])
Loading
Oops, something went wrong.

0 comments on commit 2ecf34e

Please sign in to comment.