diff --git a/packages/mattermost-redux/src/action_types/general.js b/packages/mattermost-redux/src/action_types/general.js index 44bfa7033239..0e6175ab09fe 100644 --- a/packages/mattermost-redux/src/action_types/general.js +++ b/packages/mattermost-redux/src/action_types/general.js @@ -26,6 +26,11 @@ export default keyMirror({ CLIENT_LICENSE_FAILURE: null, CLIENT_LICENSE_RECEIVED: null, + RECEIVED_DATA_RETENTION_POLICY: null, + DATA_RETENTION_POLICY_REQUEST: null, + DATA_RETENTION_POLICY_SUCCESS: null, + DATA_RETENTION_POLICY_FAILURE: null, + LOG_CLIENT_ERROR_REQUEST: null, LOG_CLIENT_ERROR_SUCCESS: null, LOG_CLIENT_ERROR_FAILURE: null, diff --git a/packages/mattermost-redux/src/actions/general.js b/packages/mattermost-redux/src/actions/general.js index 916d75353fee..3d7809e103bd 100644 --- a/packages/mattermost-redux/src/actions/general.js +++ b/packages/mattermost-redux/src/actions/general.js @@ -81,6 +81,34 @@ export function getClientConfig() { }; } +export function getDataRetentionPolicy() { + return async (dispatch, getState) => { + dispatch({type: GeneralTypes.DATA_RETENTION_POLICY_REQUEST}, getState); + + let data; + try { + data = await Client4.getDataRetentionPolicy(); + } catch (error) { + forceLogoutIfNecessary(error, dispatch); + dispatch(batchActions([ + { + type: GeneralTypes.DATA_RETENTION_POLICY_FAILURE, + error + }, + logError(error)(dispatch) + ]), getState); + return {error}; + } + + dispatch(batchActions([ + {type: GeneralTypes.RECEIVED_DATA_RETENTION_POLICY, data}, + {type: GeneralTypes.DATA_RETENTION_POLICY_SUCCESS} + ])); + + return {data}; + }; +} + export function getLicenseConfig() { return bindClientFunc( Client4.getClientLicenseOld, @@ -147,6 +175,7 @@ export function setUrl(url) { export default { getPing, getClientConfig, + getDataRetentionPolicy, getLicenseConfig, logClientError, setAppState, diff --git a/packages/mattermost-redux/src/client/client4.js b/packages/mattermost-redux/src/client/client4.js index 5689d0df9150..f218f07beb6a 100644 --- a/packages/mattermost-redux/src/client/client4.js +++ b/packages/mattermost-redux/src/client/client4.js @@ -202,6 +202,10 @@ export default class Client4 { return `${this.getBrandRoute()}/image?t=${timestamp}`; } + getDataRetentionRoute() { + return `${this.getBaseRoute()}/data_retention`; + } + getJobsRoute() { return `${this.getBaseRoute()}/jobs`; } @@ -1699,6 +1703,14 @@ export default class Client4 { return `${this.getEmojiRoute(id)}/image`; }; + // Data Retention + getDataRetentionPolicy = () => { + return this.doFetch( + `${this.getDataRetentionRoute()}/policy`, + {method: 'get'} + ); + }; + // Jobs Routes getJob = async (id) => { diff --git a/packages/mattermost-redux/src/reducers/entities/general.js b/packages/mattermost-redux/src/reducers/entities/general.js index 54c0b2fd3665..0f215786fa02 100644 --- a/packages/mattermost-redux/src/reducers/entities/general.js +++ b/packages/mattermost-redux/src/reducers/entities/general.js @@ -37,6 +37,17 @@ function credentials(state = {}, action) { } } +function dataRetentionPolicy(state = {}, action) { + switch (action.type) { + case GeneralTypes.RECEIVED_DATA_RETENTION_POLICY: + return action.data; + case UserTypes.LOGOUT_SUCCESS: + return {}; + default: + return state; + } +} + function deviceToken(state = '', action) { switch (action.type) { case GeneralTypes.RECEIVED_APP_DEVICE_TOKEN: @@ -72,6 +83,7 @@ export default combineReducers({ appState, credentials, config, + dataRetentionPolicy, deviceToken, license, serverVersion diff --git a/packages/mattermost-redux/src/reducers/requests/general.js b/packages/mattermost-redux/src/reducers/requests/general.js index a2e1c200067d..88ea78050d3b 100644 --- a/packages/mattermost-redux/src/reducers/requests/general.js +++ b/packages/mattermost-redux/src/reducers/requests/general.js @@ -30,6 +30,16 @@ function config(state = initialRequestState(), action) { ); } +function dataRetentionPolicy(state = initialRequestState(), action) { + return handleRequest( + GeneralTypes.DATA_RETENTION_POLICY_REQUEST, + GeneralTypes.DATA_RETENTION_POLICY_SUCCESS, + GeneralTypes.DATA_RETENTION_POLICY_FAILURE, + state, + action + ); +} + function license(state = initialRequestState(), action) { return handleRequest( GeneralTypes.CLIENT_LICENSE_REQUEST, @@ -57,6 +67,7 @@ function websocket(state = initialRequestState(), action) { export default combineReducers({ server, config, + dataRetentionPolicy, license, websocket }); diff --git a/packages/mattermost-redux/src/store/initial_state.js b/packages/mattermost-redux/src/store/initial_state.js index 188c202a990f..952155f8c11d 100644 --- a/packages/mattermost-redux/src/store/initial_state.js +++ b/packages/mattermost-redux/src/store/initial_state.js @@ -7,6 +7,7 @@ const state = { appState: false, credentials: {}, config: {}, + dataRetentionPolicy: {}, deviceToken: '', license: {}, serverVersion: '' @@ -148,6 +149,10 @@ const state = { status: 'not_started', error: null }, + dataRetentionPolicy: { + status: 'not_started', + error: null + }, license: { status: 'not_started', error: null diff --git a/packages/mattermost-redux/test/actions/general.test.js b/packages/mattermost-redux/test/actions/general.test.js index 9bea76637e9e..96c3f595544d 100644 --- a/packages/mattermost-redux/test/actions/general.test.js +++ b/packages/mattermost-redux/test/actions/general.test.js @@ -98,4 +98,23 @@ describe('Actions.General', () => { const {serverVersion} = store.getState().entities.general; assert.deepEqual(serverVersion, version); }); + + it('getDataRetentionPolicy', async () => { + const responseData = { + message_deletion_enabled: true, + file_deletion_enabled: false, + message_retention_cutoff: Date.now(), + file_retention_cutoff: 0 + }; + + nock(Client4.getBaseRoute()). + get('/data_retention/policy'). + query(true). + reply(200, responseData); + + await Actions.getDataRetentionPolicy()(store.dispatch, store.getState); + await TestHelper.wait(100); + const {dataRetentionPolicy} = store.getState().entities.general; + assert.deepEqual(dataRetentionPolicy, responseData); + }); });