Skip to content
Snippets Groups Projects
Commit 8ff9fd84 authored by Andy Armstrong's avatar Andy Armstrong
Browse files

Obey learner profile default visibility

parent 6b91ab4e
No related branches found
No related tags found
No related merge requests found
Showing
with 107 additions and 71 deletions
......@@ -63,7 +63,7 @@ class LearnerProfilePage(FieldsMixin, PageObject):
Arguments:
privacy (str): 'all_users' or 'private'
"""
self.wait_for_element_visibility('select#u-field-select-account_privacy', 'Privacy dropdown is visiblie')
self.wait_for_element_visibility('select#u-field-select-account_privacy', 'Privacy dropdown is visible')
if privacy != self.privacy:
self.q(css=PROFILE_VISIBILITY_SELECTOR.format(privacy)).first.click()
......
......@@ -111,6 +111,19 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
self.assertEqual(profile_page.age_limit_message_present, message is not None)
self.assertIn(message, profile_page.profile_forced_private_message)
def test_profile_defaults_to_public(self):
"""
Scenario: Verify that a new user's profile defaults to public.
Given that I am a new user.
When I go to my profile page.
Then I see that the profile visibility is set to public.
"""
username, user_id = self.log_in_as_unique_user()
profile_page = self.visit_profile_page(username)
self.assertTrue(profile_page.privacy_field_visible)
self.assertEquals(profile_page.privacy, self.PRIVACY_PUBLIC)
def assert_default_image_has_public_access(self, profile_page):
"""
Assert that profile image has public access.
......@@ -514,6 +527,27 @@ class DifferentUserLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
self.assertEqual(profile_page.visible_fields, self.PRIVATE_PROFILE_FIELDS)
self.verify_profile_page_view_event(different_user_id, visibility=self.PRIVACY_PRIVATE)
def test_different_user_under_age(self):
"""
Scenario: Verify that desired fields are shown when looking at a different user's private profile.
Given that I am a registered user.
And I visit an under age user's profile page.
Then I shouldn't see the profile visibility selector dropdown.
Then I see some of the profile fields are shown.
"""
under_age_birth_year = datetime.now().year - 10
different_username, different_user_id = self._initialize_different_user(
privacy=self.PRIVACY_PUBLIC,
birth_year=under_age_birth_year
)
self.log_in_as_unique_user()
profile_page = self.visit_profile_page(different_username)
self.assertFalse(profile_page.privacy_field_visible)
self.assertEqual(profile_page.visible_fields, self.PRIVATE_PROFILE_FIELDS)
self.verify_profile_page_view_event(different_user_id, visibility=self.PRIVACY_PRIVATE)
def test_different_user_public_profile(self):
"""
Scenario: Verify that desired fields are shown when looking at a different user's public profile.
......@@ -534,7 +568,7 @@ class DifferentUserLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
self.assertEqual(profile_page.editable_fields, [])
self.verify_profile_page_view_event(different_user_id, visibility=self.PRIVACY_PUBLIC)
def _initialize_different_user(self, privacy=None):
def _initialize_different_user(self, privacy=None, birth_year=None):
"""
Initialize the profile page for a different test user
"""
......@@ -545,6 +579,10 @@ class DifferentUserLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
privacy = self.PRIVACY_PUBLIC
self.visit_profile_page(username, privacy=privacy)
# Set the user's year of birth
if birth_year:
self.set_birth_year(birth_year)
# Log the user out
LogoutPage(self.browser).visit()
......
......@@ -69,6 +69,7 @@ def learner_profile_context(logged_in_username, profile_username, user_is_staff)
'data': {
'profile_user_id': profile_user.id,
'default_public_account_fields': settings.ACCOUNT_VISIBILITY_CONFIGURATION['public_fields'],
'default_visibility': settings.ACCOUNT_VISIBILITY_CONFIGURATION['default_visibility'],
'accounts_api_url': reverse("accounts_api", kwargs={'username': profile_username}),
'preferences_api_url': reverse('preferences_api', kwargs={'username': profile_username}),
'profile_image_upload_url': reverse('profile_image_upload', kwargs={'username': profile_username}),
......
......@@ -13,19 +13,19 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var FIELDS_DATA = {
'country': {
'options': Helpers.FIELD_OPTIONS,
'options': Helpers.FIELD_OPTIONS
}, 'gender': {
'options': Helpers.FIELD_OPTIONS,
'options': Helpers.FIELD_OPTIONS
}, 'language': {
'options': Helpers.FIELD_OPTIONS,
'options': Helpers.FIELD_OPTIONS
}, 'level_of_education': {
'options': Helpers.FIELD_OPTIONS,
'options': Helpers.FIELD_OPTIONS
}, 'password': {
'url': '/password_reset',
'url': '/password_reset'
}, 'year_of_birth': {
'options': Helpers.FIELD_OPTIONS,
'options': Helpers.FIELD_OPTIONS
}, 'preferred_language': {
'options': Helpers.FIELD_OPTIONS,
'options': Helpers.FIELD_OPTIONS
}
};
......@@ -98,7 +98,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
expect(request.method).toBe('GET');
expect(request.url).toBe(Helpers.USER_ACCOUNTS_API_URL);
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.createAccountSettingsData());
Helpers.expectLoadingIndicatorIsVisible(accountSettingsView, true);
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
Helpers.expectSettingsSectionsButNotFieldsToBeRendered(accountSettingsView);
......@@ -126,8 +126,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
Helpers.expectSettingsSectionsButNotFieldsToBeRendered(accountSettingsView);
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.createAccountSettingsData());
AjaxHelpers.respondWithJson(requests, Helpers.createUserPreferencesData());
Helpers.expectLoadingIndicatorIsVisible(accountSettingsView, false);
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
......@@ -143,8 +143,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
);
var accountSettingsView = context.accountSettingsView;
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.createAccountSettingsData());
AjaxHelpers.respondWithJson(requests, Helpers.createUserPreferencesData());
var sectionsData = accountSettingsView.options.sectionsData;
......
......@@ -13,7 +13,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var createAccountSettingsView = function () {
var model = new UserAccountModel();
model.set(Helpers.USER_ACCOUNTS_DATA);
model.set(Helpers.createAccountSettingsData());
var sectionsData = [
{
......
......@@ -11,25 +11,33 @@ define(['underscore'], function(_) {
has_image: true
};
var USER_ACCOUNTS_DATA = {
var DEFAULT_ACCOUNT_SETTINGS_DATA = {
username: 'student',
name: 'Student',
email: 'student@edx.org',
level_of_education: '0',
gender: '0',
year_of_birth: '0',
country: '0',
language: '0',
level_of_education: '',
gender: '',
year_of_birth: '3', // Note: test birth year range is a string from 0-3
requires_parental_consent: false,
country: '',
language: '',
bio: "About the student",
language_proficiencies: [{code: '1'}],
requires_parental_consent: true,
profile_image: PROFILE_IMAGE
};
var USER_PREFERENCES_DATA = {
var createAccountSettingsData = function(options) {
return _.extend(_.extend({}, DEFAULT_ACCOUNT_SETTINGS_DATA), options);
};
var DEFAULT_USER_PREFERENCES_DATA = {
'pref-lang': '2'
};
var createUserPreferencesData = function(options) {
return _.extend(_.extend({}, DEFAULT_USER_PREFERENCES_DATA), options);
};
var FIELD_OPTIONS = [
['0', 'Option 0'],
['1', 'Option 1'],
......@@ -63,7 +71,6 @@ define(['underscore'], function(_) {
expect(fieldTitle).toBe(view.options.title);
if ('fieldValue' in view) {
expect(view.model.get(view.options.valueAttribute)).toBeTruthy();
expect(view.fieldValue()).toBe(view.modelValue());
} else if (view.fieldType === 'link') {
expect($(element).find('a').length).toBe(1);
......@@ -107,8 +114,8 @@ define(['underscore'], function(_) {
IMAGE_MAX_BYTES: IMAGE_MAX_BYTES,
IMAGE_MIN_BYTES: IMAGE_MIN_BYTES,
PROFILE_IMAGE: PROFILE_IMAGE,
USER_ACCOUNTS_DATA: USER_ACCOUNTS_DATA,
USER_PREFERENCES_DATA: USER_PREFERENCES_DATA,
createAccountSettingsData: createAccountSettingsData,
createUserPreferencesData: createUserPreferencesData,
FIELD_OPTIONS: FIELD_OPTIONS,
expectLoadingIndicatorIsVisible: expectLoadingIndicatorIsVisible,
expectLoadingErrorIsVisible: expectLoadingErrorIsVisible,
......
......@@ -99,7 +99,7 @@ define([
{value: "", name: "--"},
{value: "p", name: "Doctorate"},
{value: "m", name: "Master's or professional degree"},
{value: "b", name: "Bachelor's degree"},
{value: "b", name: "Bachelor's degree"}
],
required: false,
instructions: 'Select your education level.',
......@@ -115,7 +115,7 @@ define([
{value: "", name: "--"},
{value: "m", name: "Male"},
{value: "f", name: "Female"},
{value: "o", name: "Other"},
{value: "o", name: "Other"}
],
required: false,
instructions: 'Select your gender.',
......@@ -131,7 +131,7 @@ define([
{value: "", name: "--"},
{value: 1900, name: "1900"},
{value: 1950, name: "1950"},
{value: 2014, name: "2014"},
{value: 2014, name: "2014"}
],
required: false,
instructions: 'Select your year of birth.',
......
......@@ -10,8 +10,6 @@ define(['underscore'], function(_) {
}
if ('fieldValue' in view || 'imageUrl' in view) {
expect(view.model.get(view.options.valueAttribute)).toBeTruthy();
if ('imageUrl' in view) {
expect($($element.find('.image-frame')[0]).attr('src')).toBe(view.imageUrl());
} else if (view.fieldValue()) {
......@@ -111,6 +109,5 @@ define(['underscore'], function(_) {
expectLimitedProfileSectionsAndFieldsToBeRendered: expectLimitedProfileSectionsAndFieldsToBeRendered,
expectProfileSectionsAndFieldsToBeRendered: expectProfileSectionsAndFieldsToBeRendered,
expectProfileSectionsNotToBeRendered: expectProfileSectionsNotToBeRendered
};
});
......@@ -28,7 +28,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
});
var createProfilePage = function(ownProfile) {
return LearnerProfilePage({
return new LearnerProfilePage({
'accounts_api_url': Helpers.USER_ACCOUNTS_API_URL,
'preferences_api_url': Helpers.USER_PREFERENCES_API_URL,
'own_profile': ownProfile,
......@@ -39,7 +39,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
'profile_image_max_bytes': Helpers.IMAGE_MAX_BYTES,
'profile_image_min_bytes': Helpers.IMAGE_MIN_BYTES,
'profile_image_upload_url': Helpers.IMAGE_UPLOAD_API_URL,
'profile_image_remove_url': Helpers.IMAGE_REMOVE_API_URL
'profile_image_remove_url': Helpers.IMAGE_REMOVE_API_URL,
'default_visibility': 'all_users'
});
};
......@@ -72,7 +73,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
expect(userAccountRequest.method).toBe('GET');
expect(userAccountRequest.url).toBe(Helpers.USER_ACCOUNTS_API_URL);
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.createAccountSettingsData());
Helpers.expectLoadingIndicatorIsVisible(learnerProfileView, true);
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
LearnerProfileHelpers.expectProfileSectionsNotToBeRendered(learnerProfileView);
......@@ -87,20 +88,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
LearnerProfileHelpers.expectProfileSectionsNotToBeRendered(learnerProfileView);
});
it("renders the limited profile after models are successfully fetched", 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);
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
});
it("renders the full profile after models are successfully fetched", function() {
requests = AjaxHelpers.requests(this);
......@@ -108,12 +95,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var context = createProfilePage(true),
learnerProfileView = context.learnerProfileView;
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
accountSettingsData.year_of_birth = 1989;
accountSettingsData.requires_parental_consent = false;
AjaxHelpers.respondWithJson(requests, accountSettingsData);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.createAccountSettingsData());
AjaxHelpers.respondWithJson(requests, Helpers.createUserPreferencesData());
// sets the profile for full view.
context.accountPreferencesModel.set({account_privacy: 'all_users'});
......@@ -127,8 +110,11 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var context = createProfilePage(true),
learnerProfileView = context.learnerProfileView;
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
AjaxHelpers.respondWithJson(requests, Helpers.createAccountSettingsData({
year_of_birth: '',
requires_parental_consent: true
}));
AjaxHelpers.respondWithJson(requests, Helpers.createUserPreferencesData());
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
});
......@@ -140,11 +126,11 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
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);
AjaxHelpers.respondWithJson(requests, Helpers.createAccountSettingsData({
year_of_birth: new Date().getFullYear() - 10,
requires_parental_consent: true
}));
AjaxHelpers.respondWithJson(requests, Helpers.createUserPreferencesData());
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
});
......
......@@ -19,10 +19,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
var createLearnerProfileView = function (ownProfile, accountPrivacy, profileIsPublic) {
var accountSettingsModel = new UserAccountModel();
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
accountSettingsData.year_of_birth = 1989;
accountSettingsData.requires_parental_consent = false;
accountSettingsModel.set(accountSettingsData);
accountSettingsModel.set(Helpers.createAccountSettingsData());
accountSettingsModel.set({'profile_is_public': profileIsPublic});
accountSettingsModel.set({'profile_image': Helpers.PROFILE_IMAGE});
......@@ -76,7 +73,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
editable: editable,
showMessages: false,
iconName: 'fa-map-marker',
placeholderValue: 'Add country',
placeholderValue: '',
valueAttribute: "country",
options: Helpers.FIELD_OPTIONS,
helpMessage: ''
......
......@@ -15,8 +15,13 @@
return function (options) {
var learnerProfileElement = $('.wrapper-profile');
var accountPreferencesModel = new AccountPreferencesModel();
var defaultVisibility = options.default_visibility;
var AccountPreferencesModelWithDefaults = AccountPreferencesModel.extend({
defaults: {
account_privacy: defaultVisibility
}
});
var accountPreferencesModel = new AccountPreferencesModelWithDefaults();
accountPreferencesModel.url = options.preferences_api_url;
var accountSettingsModel = new AccountSettingsModel({
......@@ -70,7 +75,7 @@
editable: editable,
showMessages: false,
iconName: 'fa-map-marker',
placeholderValue: gettext('Add country'),
placeholderValue: '',
valueAttribute: "country",
options: options.country_options,
helpMessage: ''
......@@ -143,7 +148,12 @@
// Fetch the preferences model if the user has access
if (options.has_preferences_access) {
accountPreferencesModel.fetch({
success: showLearnerProfileView,
success: function() {
if (accountSettingsModel.get('requires_parental_consent')) {
accountPreferencesModel.set('account_privacy', 'private');
}
showLearnerProfileView();
},
error: showLoadingError
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment