Commit a378995f by muzaffaryousaf Committed by Andy Armstrong

If user is not above age limit, show restricted learner profile.

TNL-1658
parent 67848ff6
...@@ -149,3 +149,19 @@ class LearnerProfilePage(FieldsMixin, PageObject): ...@@ -149,3 +149,19 @@ class LearnerProfilePage(FieldsMixin, PageObject):
EmptyPromise(lambda: self.field_is_visible('country'), 'Country field is visible').fulfill() EmptyPromise(lambda: self.field_is_visible('country'), 'Country field is visible').fulfill()
EmptyPromise(lambda: self.field_is_visible('language_proficiencies'), 'Language field is visible').fulfill() EmptyPromise(lambda: self.field_is_visible('language_proficiencies'), 'Language field is visible').fulfill()
EmptyPromise(lambda: self.field_is_visible('bio'), 'About Me field is visible').fulfill() EmptyPromise(lambda: self.field_is_visible('bio'), 'About Me field is visible').fulfill()
@property
def profile_forced_private_message(self):
"""
Returns age limit message.
"""
self.wait_for_ajax()
return self.q(css='#u-field-message-account_privacy').text[0]
@property
def age_limit_message_present(self):
"""
Check if age limit message is present.
"""
self.wait_for_ajax()
return self.q(css='#u-field-message-account_privacy').visible
...@@ -226,6 +226,7 @@ class AccountSettingsPageTest(WebAppTest): ...@@ -226,6 +226,7 @@ class AccountSettingsPageTest(WebAppTest):
""" """
Test behaviour of "Year of Birth" field. Test behaviour of "Year of Birth" field.
""" """
self.assertEqual(self.account_settings_page.value_for_dropdown_field('year_of_birth', ''), '')
self._test_dropdown_field( self._test_dropdown_field(
u'year_of_birth', u'year_of_birth',
u'Year of Birth', u'Year of Birth',
......
...@@ -52,6 +52,9 @@ class LearnerProfilePageTest(WebAppTest): ...@@ -52,6 +52,9 @@ class LearnerProfilePageTest(WebAppTest):
self.other_profile_page = LearnerProfilePage(self.browser, self.USER_2_NAME) self.other_profile_page = LearnerProfilePage(self.browser, self.USER_2_NAME)
self.set_birth_year(self.MY_USER, birth_year='1990')
self.set_birth_year(self.OTHER_USER, birth_year='1990')
def authenticate_as_user(self, user): def authenticate_as_user(self, user):
""" """
Auto authenticate a user. Auto authenticate a user.
...@@ -69,11 +72,13 @@ class LearnerProfilePageTest(WebAppTest): ...@@ -69,11 +72,13 @@ class LearnerProfilePageTest(WebAppTest):
profile_page.value_for_dropdown_field('country', 'United Kingdom') profile_page.value_for_dropdown_field('country', 'United Kingdom')
profile_page.value_for_textarea_field('bio', 'Nothing Special') profile_page.value_for_textarea_field('bio', 'Nothing Special')
def visit_my_profile_page(self, user, privacy=None): def visit_my_profile_page(self, user, privacy=None, authenticate=True):
""" """
Visits a users profile page. Visits a users profile page.
""" """
self.authenticate_as_user(user) if authenticate:
self.authenticate_as_user(user)
self.my_profile_page.visit() self.my_profile_page.visit()
self.my_profile_page.wait_for_page() self.my_profile_page.wait_for_page()
...@@ -92,10 +97,6 @@ class LearnerProfilePageTest(WebAppTest): ...@@ -92,10 +97,6 @@ class LearnerProfilePageTest(WebAppTest):
self.other_profile_page.wait_for_page() self.other_profile_page.wait_for_page()
if user is self.OTHER_USER and privacy is not None: if user is self.OTHER_USER and privacy is not None:
self.account_settings_page.visit()
self.account_settings_page.wait_for_page()
self.assertEqual(self.account_settings_page.value_for_dropdown_field('year_of_birth', '1980'), '1980')
self.other_profile_page.visit() self.other_profile_page.visit()
self.other_profile_page.wait_for_page() self.other_profile_page.wait_for_page()
self.other_profile_page.privacy = privacy self.other_profile_page.privacy = privacy
...@@ -103,6 +104,25 @@ class LearnerProfilePageTest(WebAppTest): ...@@ -103,6 +104,25 @@ class LearnerProfilePageTest(WebAppTest):
if privacy == self.PRIVACY_PUBLIC: if privacy == self.PRIVACY_PUBLIC:
self.set_pubilc_profile_fields_data(self.other_profile_page) self.set_pubilc_profile_fields_data(self.other_profile_page)
def set_birth_year(self, user, birth_year):
"""
Set birth year for `user` to the specified value.
"""
self.authenticate_as_user(user)
self.account_settings_page.visit()
self.account_settings_page.wait_for_page()
self.assertEqual(self.account_settings_page.value_for_dropdown_field('year_of_birth', birth_year), birth_year)
def verify_profile_forced_private_message(self, birth_year, message=None):
"""
Verify age limit messages for a user.
"""
self.set_birth_year(self.MY_USER, birth_year=birth_year)
self.visit_my_profile_page(self.MY_USER, authenticate=False)
self.assertTrue(self.my_profile_page.privacy_field_visible)
self.assertEqual(self.my_profile_page.age_limit_message_present, message is not None)
self.assertIn(message, self.my_profile_page.profile_forced_private_message)
def test_dashboard_learner_profile_link(self): def test_dashboard_learner_profile_link(self):
""" """
Scenario: Verify that my profile link is present on dashboard page and we can navigate to correct page. Scenario: Verify that my profile link is present on dashboard page and we can navigate to correct page.
...@@ -212,7 +232,7 @@ class LearnerProfilePageTest(WebAppTest): ...@@ -212,7 +232,7 @@ class LearnerProfilePageTest(WebAppTest):
""" """
Test behaviour of a textarea field. Test behaviour of a textarea field.
""" """
self.visit_my_profile_page(self.MY_USER, privacy=self.PRIVACY_PUBLIC) self.visit_my_profile_page(self.MY_USER, privacy=self.PRIVACY_PUBLIC, )
self.my_profile_page.value_for_textarea_field(field_id, new_value) self.my_profile_page.value_for_textarea_field(field_id, new_value)
self.assertEqual(self.my_profile_page.get_non_editable_mode_value(field_id), displayed_value) self.assertEqual(self.my_profile_page.get_non_editable_mode_value(field_id), displayed_value)
...@@ -305,3 +325,26 @@ class LearnerProfilePageTest(WebAppTest): ...@@ -305,3 +325,26 @@ class LearnerProfilePageTest(WebAppTest):
self.my_profile_page.make_field_editable('bio') self.my_profile_page.make_field_editable('bio')
self.assertTrue(self.my_profile_page.mode_for_field('bio'), 'edit') self.assertTrue(self.my_profile_page.mode_for_field('bio'), 'edit')
def test_birth_year_not_set(self):
"""
Verify message if birth year is not set.
Given that I am a registered user.
And birth year is not set for the user.
And i visit my profile page.
Then i should see message `Your profile is disabled because you haven't filled in your Year of Birth.`
"""
message = "You must specify your birth year before you can share your full profile."
self.verify_profile_forced_private_message('', message=message)
def test_user_is_under_age(self):
"""
Verify message if user is under age.
Given that I am a registered user.
And birth year is set so that age is less than 13.
And i visit my profile page.
Then i should see message `You must be over 13 to share a full profile.`
"""
self.verify_profile_forced_private_message('2010', message='You must be over 13 to share a full profile.')
...@@ -15,7 +15,8 @@ define(['underscore'], function(_) { ...@@ -15,7 +15,8 @@ define(['underscore'], function(_) {
country: '0', country: '0',
language: '0', language: '0',
bio: "About the student", bio: "About the student",
language_proficiencies: [{code: '1'}] language_proficiencies: [{code: '1'}],
requires_parental_consent: true
}; };
var USER_PREFERENCES_DATA = { var USER_PREFERENCES_DATA = {
......
...@@ -35,7 +35,7 @@ define(['underscore'], function(_) { ...@@ -35,7 +35,7 @@ define(['underscore'], function(_) {
expect(privacyFieldElement.length).toBe(0); expect(privacyFieldElement.length).toBe(0);
} else { } else {
expect(privacyFieldElement.length).toBe(1); expect(privacyFieldElement.length).toBe(1);
expectProfileElementContainsField(privacyFieldElement, learnerProfileView.options.accountPrivacyFieldView) expectProfileElementContainsField(privacyFieldElement, learnerProfileView.options.accountPrivacyFieldView);
} }
}; };
......
...@@ -24,25 +24,24 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -24,25 +24,24 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
TemplateHelpers.installTemplate('templates/student_profile/learner_profile'); TemplateHelpers.installTemplate('templates/student_profile/learner_profile');
}); });
it("show loading error when UserAccountModel fails to load", function() { var createProfilePage = function(ownProfile) {
return LearnerProfilePage({
requests = AjaxHelpers.requests(this);
var context = LearnerProfilePage({
'accounts_api_url': Helpers.USER_ACCOUNTS_API_URL, 'accounts_api_url': Helpers.USER_ACCOUNTS_API_URL,
'preferences_api_url': Helpers.USER_PREFERENCES_API_URL, 'preferences_api_url': Helpers.USER_PREFERENCES_API_URL,
'own_profile': true, 'own_profile': ownProfile,
'account_settings_page_url': Helpers.USER_ACCOUNTS_API_URL, 'account_settings_page_url': Helpers.USER_ACCOUNTS_API_URL,
'country_options': Helpers.FIELD_OPTIONS, 'country_options': Helpers.FIELD_OPTIONS,
'language_options': Helpers.FIELD_OPTIONS, 'language_options': Helpers.FIELD_OPTIONS,
'has_preferences_access': true 'has_preferences_access': true
}), })
learnerProfileView = context.learnerProfileView; };
Helpers.expectLoadingIndicatorIsVisible(learnerProfileView, true); it("show loading error when UserAccountModel fails to load", function() {
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
LearnerProfileHelpers.expectProfileSectionsNotToBeRendered(learnerProfileView);
requests = AjaxHelpers.requests(this);
var context = createProfilePage(true),
learnerProfileView = context.learnerProfileView;
var userAccountRequest = requests[0]; var userAccountRequest = requests[0];
expect(userAccountRequest.method).toBe('GET'); expect(userAccountRequest.method).toBe('GET');
...@@ -59,21 +58,9 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -59,21 +58,9 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
requests = AjaxHelpers.requests(this); requests = AjaxHelpers.requests(this);
var context = LearnerProfilePage({ var context = createProfilePage(true),
'accounts_api_url': Helpers.USER_ACCOUNTS_API_URL,
'preferences_api_url': Helpers.USER_PREFERENCES_API_URL,
'own_profile': true,
'account_settings_page_url': Helpers.USER_ACCOUNTS_API_URL,
'country_options': Helpers.FIELD_OPTIONS,
'language_options': Helpers.FIELD_OPTIONS,
'has_preferences_access': true
}),
learnerProfileView = context.learnerProfileView; learnerProfileView = context.learnerProfileView;
Helpers.expectLoadingIndicatorIsVisible(learnerProfileView, true);
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
LearnerProfileHelpers.expectProfileSectionsNotToBeRendered(learnerProfileView);
var userAccountRequest = requests[0]; var userAccountRequest = requests[0];
expect(userAccountRequest.method).toBe('GET'); expect(userAccountRequest.method).toBe('GET');
expect(userAccountRequest.url).toBe(Helpers.USER_ACCOUNTS_API_URL); expect(userAccountRequest.url).toBe(Helpers.USER_ACCOUNTS_API_URL);
...@@ -97,21 +84,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -97,21 +84,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
requests = AjaxHelpers.requests(this); requests = AjaxHelpers.requests(this);
var context = LearnerProfilePage({ var context = createProfilePage(true),
'accounts_api_url': Helpers.USER_ACCOUNTS_API_URL, learnerProfileView = context.learnerProfileView;
'preferences_api_url': Helpers.USER_PREFERENCES_API_URL,
'own_profile': true,
'account_settings_page_url': Helpers.USER_ACCOUNTS_API_URL,
'country_options': Helpers.FIELD_OPTIONS,
'language_options': Helpers.FIELD_OPTIONS,
'has_preferences_access': true
});
var learnerProfileView = context.learnerProfileView;
Helpers.expectLoadingIndicatorIsVisible(learnerProfileView, true);
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
LearnerProfileHelpers.expectProfileSectionsNotToBeRendered(learnerProfileView);
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA); AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA); AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
...@@ -124,27 +98,48 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -124,27 +98,48 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
requests = AjaxHelpers.requests(this); requests = AjaxHelpers.requests(this);
var context = LearnerProfilePage({ var context = createProfilePage(true),
'accounts_api_url': Helpers.USER_ACCOUNTS_API_URL,
'preferences_api_url': Helpers.USER_PREFERENCES_API_URL,
'own_profile': true,
'account_settings_page_url': Helpers.USER_ACCOUNTS_API_URL,
'country_options': Helpers.FIELD_OPTIONS,
'language_options': Helpers.FIELD_OPTIONS,
'has_preferences_access': true
}),
learnerProfileView = context.learnerProfileView; learnerProfileView = context.learnerProfileView;
Helpers.expectLoadingIndicatorIsVisible(learnerProfileView, true); var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false); accountSettingsData['year_of_birth'] = 1989;
LearnerProfileHelpers.expectProfileSectionsNotToBeRendered(learnerProfileView); accountSettingsData['requires_parental_consent'] = false;
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA); AjaxHelpers.respondWithJson(requests, accountSettingsData);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA); AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
// sets the profile for full view. // sets the profile for full view.
context.accountPreferencesModel.set({account_privacy: 'all_users'}); context.accountPreferencesModel.set({account_privacy: 'all_users'});
LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, false) LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, false)
}); });
it("renders the limited profile for undefined 'year_of_birth'", function() {
requests = AjaxHelpers.requests(this);
var context = createProfilePage(true),
learnerProfileView = context.learnerProfileView;
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView)
});
it("renders the limited profile for under 13 users", function() {
requests = AjaxHelpers.requests(this);
var context = createProfilePage(true),
learnerProfileView = context.learnerProfileView;
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
accountSettingsData['requires_parental_consent'] = true;
AjaxHelpers.respondWithJson(requests, accountSettingsData);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView)
});
}); });
}); });
...@@ -12,12 +12,15 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j ...@@ -12,12 +12,15 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
AccountPreferencesModel, LearnerProfileFields, LearnerProfileView, AccountSettingsFieldViews) { AccountPreferencesModel, LearnerProfileFields, LearnerProfileView, AccountSettingsFieldViews) {
'use strict'; 'use strict';
describe("edx.user.LearnerProfileView", function (options) { describe("edx.user.LearnerProfileView", function () {
var createLearnerProfileView = function (ownProfile, accountPrivacy, profileIsPublic) { var createLearnerProfileView = function (ownProfile, accountPrivacy, profileIsPublic) {
var accountSettingsModel = new UserAccountModel(); var accountSettingsModel = new UserAccountModel();
accountSettingsModel.set(Helpers.USER_ACCOUNTS_DATA); var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
accountSettingsData['year_of_birth'] = 1989;
accountSettingsData['requires_parental_consent'] = false;
accountSettingsModel.set(accountSettingsData);
accountSettingsModel.set({'profile_is_public': profileIsPublic}); accountSettingsModel.set({'profile_is_public': profileIsPublic});
var accountPreferencesModel = new AccountPreferencesModel(); var accountPreferencesModel = new AccountPreferencesModel();
......
...@@ -37,9 +37,13 @@ ...@@ -37,9 +37,13 @@
this.set({'profile_is_public': profileIsPublic}, { silent: true }); this.set({'profile_is_public': profileIsPublic}, { silent: true });
return response; return response;
},
isAboveMinimumAge: function() {
var isBirthDefined = !(_.isUndefined(this.get('year_of_birth')) || _.isNull(this.get('year_of_birth')));
return isBirthDefined && !(this.get("requires_parental_consent"));
} }
}); });
return UserAccountModel; return UserAccountModel;
}) })
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
render: function () { render: function () {
this._super(); this._super();
this.message(); this.message();
this.updateFieldValue();
return this; return this;
}, },
...@@ -30,6 +31,13 @@ ...@@ -30,6 +31,13 @@
this._super(''); this._super('');
} }
return this._super(); return this._super();
},
updateFieldValue: function() {
if (!this.isAboveMinimumAge) {
this.$('.u-field-value select').val('private');
this.disableField(true);
}
} }
}); });
......
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
}, },
showFullProfile: function () { showFullProfile: function () {
var isAboveMinimumAge = this.options.accountSettingsModel.isAboveMinimumAge();
if (this.options.own_profile) { if (this.options.own_profile) {
return this.options.preferencesModel.get('account_privacy') === 'all_users'; return isAboveMinimumAge && this.options.preferencesModel.get('account_privacy') === 'all_users';
} else { } else {
return this.options.accountSettingsModel.get('profile_is_public'); return this.options.accountSettingsModel.get('profile_is_public');
} }
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
var fieldView = this.options.accountPrivacyFieldView; var fieldView = this.options.accountPrivacyFieldView;
fieldView.profileIsPrivate = (!this.options.accountSettingsModel.get('year_of_birth')); fieldView.profileIsPrivate = (!this.options.accountSettingsModel.get('year_of_birth'));
fieldView.requiresParentalConsent = (this.options.accountSettingsModel.get('requires_parental_consent')); fieldView.requiresParentalConsent = (this.options.accountSettingsModel.get('requires_parental_consent'));
fieldView.isAboveMinimumAge = this.options.accountSettingsModel.isAboveMinimumAge();
fieldView.undelegateEvents(); fieldView.undelegateEvents();
this.$('.wrapper-profile-field-account-privacy').append(fieldView.render().el); this.$('.wrapper-profile-field-account-privacy').append(fieldView.render().el);
fieldView.delegateEvents(); fieldView.delegateEvents();
......
...@@ -370,6 +370,10 @@ ...@@ -370,6 +370,10 @@
if (this.editable === 'toggle') { if (this.editable === 'toggle') {
this.showDisplayMode(true); this.showDisplayMode(true);
} }
},
disableField: function(disable) {
this.$('.u-field-value select').prop('disabled', disable);
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment