Commit 5461e33b authored by Harshil Sharma's avatar Harshil Sharma Committed by Jesse Hallam

Refactored to rename "service terms" to "terms of service" (#671)

* #143 refactored 'service terms' to 'terms of service'

* 124 Renamed EnableCustomServiceTerms feature flag to EnableCustomTermsOfService

* 124 reverted version

* reverted package lock

* #124 renamed selectot from 'service terms' to 'terms of service'
parent 680174a1
......@@ -117,17 +117,17 @@ export default keyMirror({
SWITCH_LOGIN_SUCCESS: null,
SWITCH_LOGIN_FAILURE: null,
GET_SERVICE_TERMS_REQUEST: null,
GET_SERVICE_TERMS_SUCCESS: null,
GET_SERVICE_TERMS_FAILURE: null,
GET_TERMS_OF_SERVICE_REQUEST: null,
GET_TERMS_OF_SERVICE_SUCCESS: null,
GET_TERMS_OF_SERVICE_FAILURE: null,
CREATE_SERVICE_TERMS_REQUEST: null,
CREATE_SERVICE_TERMS_SUCCESS: null,
CREATE_SERVICE_TERMS_FAILURE: null,
CREATE_TERMS_OF_SERVICE_REQUEST: null,
CREATE_TERMS_OF_SERVICE_SUCCESS: null,
CREATE_TERMS_OF_SERVICE_FAILURE: null,
UPDATE_SERVICE_TERMS_STATUS_REQUEST: null,
UPDATE_SERVICE_TERMS_STATUS_SUCCESS: null,
UPDATE_SERVICE_TERMS_STATUS_FAILURE: null,
UPDATE_TERMS_OF_SERVICE_STATUS_REQUEST: null,
UPDATE_TERMS_OF_SERVICE_STATUS_SUCCESS: null,
UPDATE_TERMS_OF_SERVICE_STATUS_FAILURE: null,
CREATE_USER_ACCESS_TOKEN_REQUEST: null,
CREATE_USER_ACCESS_TOKEN_SUCCESS: null,
......
......@@ -9,7 +9,7 @@ import {Client4} from 'client';
import {logError} from './errors';
import {bindClientFunc, forceLogoutIfNecessary} from './helpers';
import {getServiceTerms, createServiceTerms} from './users';
import {getTermsOfService, createTermsOfService} from './users';
import {batchActions} from 'redux-batched-actions';
import type {ActionFunc} from '../types/actions';
......@@ -51,14 +51,14 @@ export function getConfig(): ActionFunc {
return {error};
}
if (config.SupportSettings && config.SupportSettings.CustomServiceTermsEnabled) {
const result = await dispatch(getServiceTerms());
if (config.SupportSettings && config.SupportSettings.CustomTermsOfServiceEnabled) {
const result = await dispatch(getTermsOfService());
if (result.error) {
return {error: result.error};
}
if (result.data) {
config.SupportSettings.CustomServiceTermsText = result.data.text;
config.SupportSettings.CustomTermsOfServiceText = result.data.text;
}
}
dispatch(batchActions([
......@@ -78,9 +78,9 @@ export function getConfig(): ActionFunc {
export function updateConfig(config: Object): ActionFunc {
return async (dispatch, getState) => {
const stateConfig = getState().entities.admin.config;
if (config.SupportSettings && config.SupportSettings.CustomServiceTermsEnabled) {
if (stateConfig.SupportSettings.CustomServiceTermsText !== config.SupportSettings.CustomServiceTermsText) {
const result = await dispatch(createServiceTerms(config.SupportSettings.CustomServiceTermsText));
if (config.SupportSettings && config.SupportSettings.CustomTermsOfServiceEnabled) {
if (stateConfig.SupportSettings.CustomTermsOfServiceText !== config.SupportSettings.CustomTermsOfServiceText) {
const result = await dispatch(createTermsOfService(config.SupportSettings.CustomTermsOfServiceText));
if (result.error) {
return result;
}
......@@ -88,7 +88,7 @@ export function updateConfig(config: Object): ActionFunc {
}
if (config.SupportSettings && typeof config.SupportSettings === 'object') {
Reflect.deleteProperty(config.SupportSettings, 'CustomServiceTermsText');
Reflect.deleteProperty(config.SupportSettings, 'CustomTermsOfServiceText');
}
return await dispatch(bindClientFunc(
Client4.updateConfig,
......
......@@ -610,14 +610,14 @@ export function getMe() {
};
}
export function updateServiceTermsStatus(serviceTermsId, accepted) {
export function updateTermsOfServiceStatus(termsOfServiceId, accepted) {
return async (dispatch, getState) => {
const response = await dispatch(bindClientFunc(
Client4.updateServiceTermsStatus,
UserTypes.UPDATE_SERVICE_TERMS_STATUS_REQUEST,
UserTypes.UPDATE_SERVICE_TERMS_STATUS_SUCCESS,
UserTypes.UPDATE_SERVICE_TERMS_STATUS_FAILURE,
serviceTermsId,
Client4.updateTermsOfServiceStatus,
UserTypes.UPDATE_TERMS_OF_SERVICE_STATUS_REQUEST,
UserTypes.UPDATE_TERMS_OF_SERVICE_STATUS_SUCCESS,
UserTypes.UPDATE_TERMS_OF_SERVICE_STATUS_FAILURE,
termsOfServiceId,
accepted
));
const {data, error} = response;
......@@ -625,7 +625,7 @@ export function updateServiceTermsStatus(serviceTermsId, accepted) {
const currentUser = getCurrentUser(getState());
dispatch({
type: UserTypes.RECEIVED_ME,
data: Object.assign({}, currentUser, {accepted_service_terms_id: accepted ? serviceTermsId : null}),
data: Object.assign({}, currentUser, {accepted_terms_of_service_id: accepted ? termsOfServiceId : null}),
});
return {data};
}
......@@ -633,21 +633,21 @@ export function updateServiceTermsStatus(serviceTermsId, accepted) {
};
}
export function getServiceTerms() {
export function getTermsOfService() {
return bindClientFunc(
Client4.getServiceTerms,
UserTypes.GET_SERVICE_TERMS_REQUEST,
UserTypes.GET_SERVICE_TERMS_SUCCESS,
UserTypes.GET_SERVICE_TERMS_FAILURE,
Client4.getTermsOfService,
UserTypes.GET_TERMS_OF_SERVICE_REQUEST,
UserTypes.GET_TERMS_OF_SERVICE_SUCCESS,
UserTypes.GET_TERMS_OF_SERVICE_FAILURE,
);
}
export function createServiceTerms(text) {
export function createTermsOfService(text) {
return bindClientFunc(
Client4.createServiceTerms,
UserTypes.CREATE_SERVICE_TERMS_REQUEST,
UserTypes.CREATE_SERVICE_TERMS_SUCCESS,
UserTypes.CREATE_SERVICE_TERMS_FAILURE,
Client4.createTermsOfService,
UserTypes.CREATE_TERMS_OF_SERVICE_REQUEST,
UserTypes.CREATE_TERMS_OF_SERVICE_SUCCESS,
UserTypes.CREATE_TERMS_OF_SERVICE_FAILURE,
text,
);
}
......@@ -1582,9 +1582,9 @@ export default {
switchOAuthToEmail,
switchEmailToLdap,
switchLdapToEmail,
getServiceTerms,
createServiceTerms,
updateServiceTermsStatus,
getTermsOfService,
createTermsOfService,
updateTermsOfServiceStatus,
createUserAccessToken,
getUserAccessToken,
getUserAccessTokensForUser,
......
......@@ -413,21 +413,21 @@ export default class Client4 {
);
}
updateServiceTermsStatus = async (serviceTermsId, accepted) => {
updateTermsOfServiceStatus = async (termsOfServiceId, accepted) => {
return this.doFetch(
`${this.getUserRoute('me')}/terms_of_service`,
{method: 'post', body: JSON.stringify({serviceTermsId, accepted})}
{method: 'post', body: JSON.stringify({termsOfServiceId, accepted})}
);
}
getServiceTerms = async () => {
getTermsOfService = async () => {
return this.doFetch(
`${this.getBaseRoute()}/terms_of_service`,
{method: 'get'}
);
}
createServiceTerms = async (text) => {
createTermsOfService = async (text) => {
return this.doFetch(
`${this.getBaseRoute()}/terms_of_service`,
{method: 'post', body: JSON.stringify({text})}
......
......@@ -318,31 +318,31 @@ function switchLogin(state: RequestStatusType = initialRequestState(), action: G
);
}
function updateServiceTermsStatus(state: RequestStatusType = initialRequestState(), action: GenericAction): RequestStatusType {
function updateTermsOfServiceStatus(state: RequestStatusType = initialRequestState(), action: GenericAction): RequestStatusType {
return handleRequest(
UserTypes.UPDATE_SERVICE_TERMS_STATUS_REQUEST,
UserTypes.UPDATE_SERVICE_TERMS_STATUS_SUCCESS,
UserTypes.UPDATE_SERVICE_TERMS_STATUS_FAILURE,
UserTypes.UPDATE_TERMS_OF_SERVICE_STATUS_REQUEST,
UserTypes.UPDATE_TERMS_OF_SERVICE_STATUS_SUCCESS,
UserTypes.UPDATE_TERMS_OF_SERVICE_STATUS_FAILURE,
state,
action
);
}
function getServiceTerms(state: RequestStatusType = initialRequestState(), action: GenericAction): RequestStatusType {
function getTermsOfService(state: RequestStatusType = initialRequestState(), action: GenericAction): RequestStatusType {
return handleRequest(
UserTypes.GET_SERVICE_TERMS_REQUEST,
UserTypes.GET_SERVICE_TERMS_SUCCESS,
UserTypes.GET_SERVICE_TERMS_FAILURE,
UserTypes.GET_TERMS_OF_SERVICE_REQUEST,
UserTypes.GET_TERMS_OF_SERVICE_SUCCESS,
UserTypes.GET_TERMS_OF_SERVICE_FAILURE,
state,
action
);
}
function createServiceTerms(state: RequestStatusType = initialRequestState(), action: GenericAction): RequestStatusType {
function createTermsOfService(state: RequestStatusType = initialRequestState(), action: GenericAction): RequestStatusType {
return handleRequest(
UserTypes.CREATE_SERVICE_TERMS_REQUEST,
UserTypes.CREATE_SERVICE_TERMS_SUCCESS,
UserTypes.CREATE_SERVICE_TERMS_FAILURE,
UserTypes.CREATE_TERMS_OF_SERVICE_REQUEST,
UserTypes.CREATE_TERMS_OF_SERVICE_SUCCESS,
UserTypes.CREATE_TERMS_OF_SERVICE_FAILURE,
state,
action
);
......@@ -427,9 +427,9 @@ export default combineReducers({
verifyEmail,
passwordReset,
switchLogin,
getServiceTerms,
createServiceTerms,
updateServiceTermsStatus,
getTermsOfService,
createTermsOfService,
updateTermsOfServiceStatus,
createUserAccessToken,
getUserAccessToken,
revokeUserAccessToken,
......
......@@ -344,13 +344,13 @@ function removeCurrentUserFromList(profiles, currentUserId) {
}
}
export const showCustomTerms = createSelector(
export const shouldShowTermsOfService = createSelector(
getConfig,
getCurrentUser,
getLicense,
(config, user, license) => {
// Defaults to false if the setting doesn't exist
return Boolean(license.IsLicensed === 'true' && config.EnableCustomServiceTerms === 'true' && user && config.CustomServiceTermsId !== user.accepted_service_terms_id);
return Boolean(license.IsLicensed === 'true' && config.EnableCustomTermsOfService === 'true' && user && config.CustomTermsOfServiceId !== user.accepted_terms_of_service_id);
}
);
......
......@@ -115,7 +115,7 @@ describe('Actions.Users', () => {
});
});
it('getServiceTerms', async () => {
it('getTermsOfService', async () => {
if (TestHelper.isLiveServer()) {
console.log('Skipping mock-only test');
return;
......@@ -132,19 +132,19 @@ describe('Actions.Users', () => {
get('/terms_of_service').
reply(200, response);
await Actions.getServiceTerms()(store.dispatch, store.getState);
await Actions.getTermsOfService()(store.dispatch, store.getState);
const request = store.getState().requests.users.getServiceTerms;
const request = store.getState().requests.users.getTermsOfService;
if (request.status === RequestStatus.FAILURE) {
throw new Error(JSON.stringify(request.error));
}
});
it('updateServiceTermsStatus accept terms', async () => {
it('updateTermsOfServiceStatus accept terms', async () => {
const user = TestHelper.basicUser;
nock(Client4.getUsersRoute()).
post('').
reply(201, {...TestHelper.fakeUserWithId(), accepted_service_terms_id: 1});
reply(201, {...TestHelper.fakeUserWithId(), accepted_terms_of_service_id: 1});
TestHelper.mockLogin();
await Actions.login(user.email, 'password1')(store.dispatch, store.getState);
......@@ -153,9 +153,9 @@ describe('Actions.Users', () => {
post('/users/me/terms_of_service').
reply(200, OK_RESPONSE);
await Actions.updateServiceTermsStatus(1, true)(store.dispatch, store.getState);
await Actions.updateTermsOfServiceStatus(1, true)(store.dispatch, store.getState);
const request = store.getState().requests.users.updateServiceTermsStatus;
const request = store.getState().requests.users.updateTermsOfServiceStatus;
if (request.status === RequestStatus.FAILURE) {
throw new Error(JSON.stringify(request.error));
......@@ -165,14 +165,14 @@ describe('Actions.Users', () => {
assert.ok(currentUserId);
assert.ok(profiles[currentUserId]);
assert.equal(profiles[currentUserId].accepted_service_terms_id, 1);
assert.equal(profiles[currentUserId].accepted_terms_of_service_id, 1);
});
it('updateServiceTermsStatus reject terms', async () => {
it('updateTermsOfServiceStatus reject terms', async () => {
const user = TestHelper.basicUser;
nock(Client4.getUsersRoute()).
post('').
reply(201, {...TestHelper.fakeUserWithId(), accepted_service_terms_id: 0});
reply(201, {...TestHelper.fakeUserWithId(), accepted_terms_of_service_id: 0});
TestHelper.mockLogin();
await Actions.login(user.email, 'password1')(store.dispatch, store.getState);
......@@ -181,9 +181,9 @@ describe('Actions.Users', () => {
post('/users/me/terms_of_service').
reply(200, OK_RESPONSE);
await Actions.updateServiceTermsStatus(1, false)(store.dispatch, store.getState);
await Actions.updateTermsOfServiceStatus(1, false)(store.dispatch, store.getState);
const request = store.getState().requests.users.updateServiceTermsStatus;
const request = store.getState().requests.users.updateTermsOfServiceStatus;
if (request.status === RequestStatus.FAILURE) {
throw new Error(JSON.stringify(request.error));
......@@ -193,7 +193,7 @@ describe('Actions.Users', () => {
assert.ok(currentUserId);
assert.ok(profiles[currentUserId]);
assert.notEqual(profiles[currentUserId].accepted_service_terms_id, 1);
assert.notEqual(profiles[currentUserId].accepted_terms_of_service_id, 1);
});
it('logout', async () => {
......
......@@ -339,14 +339,14 @@ describe('Selectors.Users', () => {
});
});
it('showCustomTerms', () => {
it('shouldShowTermsOfService', () => {
const userId = 1234;
assert.equal(Selectors.showCustomTerms({
assert.equal(Selectors.shouldShowTermsOfService({
entities: {
general: {
config: {
CustomServiceTermsId: '1',
EnableCustomServiceTerms: 'true',
CustomTermsOfServiceId: '1',
EnableCustomTermsOfService: 'true',
},
license: {
IsLicensed: 'true',
......@@ -355,18 +355,18 @@ describe('Selectors.Users', () => {
users: {
currentUserId: userId,
profiles: {
[userId]: {id: userId, username: 'user', first_name: 'First', last_name: 'Last', accepted_service_terms_id: '0'},
[userId]: {id: userId, username: 'user', first_name: 'First', last_name: 'Last', accepted_terms_of_service_id: '0'},
},
},
},
}), true);
assert.equal(Selectors.showCustomTerms({
assert.equal(Selectors.shouldShowTermsOfService({
entities: {
general: {
config: {
CustomServiceTermsId: '1',
EnableCustomServiceTerms: 'false',
CustomTermsOfServiceId: '1',
EnableCustomTermsOfService: 'false',
},
license: {
IsLicensed: 'true',
......@@ -375,18 +375,18 @@ describe('Selectors.Users', () => {
users: {
currentUserId: userId,
profiles: {
[userId]: {id: userId, username: 'user', first_name: 'First', last_name: 'Last', accepted_service_terms_id: '1'},
[userId]: {id: userId, username: 'user', first_name: 'First', last_name: 'Last', accepted_terms_of_service_id: '1'},
},
},
},
}), false);
assert.equal(Selectors.showCustomTerms({
assert.equal(Selectors.shouldShowTermsOfService({
entities: {
general: {
config: {
CustomServiceTermsId: '1',
EnableCustomServiceTerms: 'true',
CustomTermsOfServiceId: '1',
EnableCustomTermsOfService: 'true',
},
license: {
IsLicensed: 'false',
......@@ -395,18 +395,18 @@ describe('Selectors.Users', () => {
users: {
currentUserId: userId,
profiles: {
[userId]: {id: userId, username: 'user', first_name: 'First', last_name: 'Last', accepted_service_terms_id: '1'},
[userId]: {id: userId, username: 'user', first_name: 'First', last_name: 'Last', accepted_terms_of_service_id: '1'},
},
},
},
}), false);
assert.equal(Selectors.showCustomTerms({
assert.equal(Selectors.shouldShowTermsOfService({
entities: {
general: {
config: {
CustomServiceTermsId: '1',
EnableCustomServiceTerms: 'true',
CustomTermsOfServiceId: '1',
EnableCustomTermsOfService: 'true',
},
license: {
IsLicensed: 'true',
......@@ -415,18 +415,18 @@ describe('Selectors.Users', () => {
users: {
currentUserId: userId,
profiles: {
[userId]: {id: userId, username: 'user', first_name: 'First', last_name: 'Last', accepted_service_terms_id: '1'},
[userId]: {id: userId, username: 'user', first_name: 'First', last_name: 'Last', accepted_terms_of_service_id: '1'},
},
},
},
}), false);
assert.equal(Selectors.showCustomTerms({
assert.equal(Selectors.shouldShowTermsOfService({
entities: {
general: {
config: {
CustomServiceTermsId: '1',
EnableCustomServiceTerms: 'true',
CustomTermsOfServiceId: '1',
EnableCustomTermsOfService: 'true',
},
license: {
IsLicensed: 'true',
......
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