Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Add data retention client/reducer/action (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum authored and hmhealey committed Aug 28, 2020
1 parent af3dbec commit 3dabc48
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/mattermost-redux/src/action_types/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions packages/mattermost-redux/src/actions/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -147,6 +175,7 @@ export function setUrl(url) {
export default {
getPing,
getClientConfig,
getDataRetentionPolicy,
getLicenseConfig,
logClientError,
setAppState,
Expand Down
12 changes: 12 additions & 0 deletions packages/mattermost-redux/src/client/client4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}
Expand Down Expand Up @@ -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) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/mattermost-redux/src/reducers/entities/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -72,6 +83,7 @@ export default combineReducers({
appState,
credentials,
config,
dataRetentionPolicy,
deviceToken,
license,
serverVersion
Expand Down
11 changes: 11 additions & 0 deletions packages/mattermost-redux/src/reducers/requests/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,6 +67,7 @@ function websocket(state = initialRequestState(), action) {
export default combineReducers({
server,
config,
dataRetentionPolicy,
license,
websocket
});
5 changes: 5 additions & 0 deletions packages/mattermost-redux/src/store/initial_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const state = {
appState: false,
credentials: {},
config: {},
dataRetentionPolicy: {},
deviceToken: '',
license: {},
serverVersion: ''
Expand Down Expand Up @@ -148,6 +149,10 @@ const state = {
status: 'not_started',
error: null
},
dataRetentionPolicy: {
status: 'not_started',
error: null
},
license: {
status: 'not_started',
error: null
Expand Down
19 changes: 19 additions & 0 deletions packages/mattermost-redux/test/actions/general.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 3dabc48

Please sign in to comment.