mattermost-mobile/app/client/rest/general.ts
Anurag Shivarathri 2cd2ddbf5f
MM-33580 Granular Data Retention (#5330)
* Unable to open previews from search, pinned and mentions

* Granular data retention initialised

* Added server version check, logic to remove posts & test cases

* Restructured reducer & runs the job only one time a day

* Updated minimum server version with 5.36

* Reverting client.ts changes

* Added client rest calls & removed config check for data retention enabled or not & fixed test case

* Added check for license

* Update app/actions/views/login.js

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Update app/store/middlewares/helpers.js

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Update app/store/middlewares/helpers.js

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Fixed lint error

* Update app/client/rest/general.ts

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Update app/client/rest/general.ts

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Added redux migration

* Updated server version to 5.37

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-07-15 18:47:48 +05:30

122 lines
4.1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Config} from '@mm-redux/types/config';
import {GlobalDataRetentionPolicy, ChannelDataRetentionPolicy, TeamDataRetentionPolicy} from '@mm-redux/types/data_retention';
import {Role} from '@mm-redux/types/roles';
import {Dictionary} from '@mm-redux/types/utilities';
import {buildQueryString} from '@mm-redux/utils/helpers';
import {PER_PAGE_DEFAULT} from './constants';
import ClientError from './error';
export interface ClientGeneralMix {
getOpenGraphMetadata: (url: string) => Promise<any>;
ping: () => Promise<any>;
logClientError: (message: string, level?: string) => Promise<any>;
getClientConfigOld: () => Promise<Config>;
getClientLicenseOld: () => Promise<any>;
getTimezones: () => Promise<string[]>;
getGlobalDataRetentionPolicy: () => Promise<GlobalDataRetentionPolicy[]>;
getTeamDataRetentionPolicies: (userId: string, page?: number, perPage?: number) => Promise<{
policies: TeamDataRetentionPolicy[];
total_count: number;
}>;
getChannelDataRetentionPolicies: (userId: string, page?: number, perPage?: number) => Promise<{
policies: ChannelDataRetentionPolicy[];
total_count: number;
}>;
getRolesByNames: (rolesNames: string[]) => Promise<Role[]>;
getRedirectLocation: (urlParam: string) => Promise<Dictionary<string>>;
}
const ClientGeneral = (superclass: any) => class extends superclass {
getOpenGraphMetadata = async (url: string) => {
return this.doFetch(
`${this.getBaseRoute()}/opengraph`,
{method: 'post', body: JSON.stringify({url})},
);
};
ping = async () => {
return this.doFetch(
`${this.getBaseRoute()}/system/ping?time=${Date.now()}`,
{method: 'get'},
);
};
logClientError = async (message: string, level = 'ERROR') => {
const url = `${this.getBaseRoute()}/logs`;
if (!this.enableLogging) {
throw new ClientError(this.getUrl(), {
message: 'Logging disabled.',
url,
});
}
return this.doFetch(
url,
{method: 'post', body: JSON.stringify({message, level})},
);
};
getClientConfigOld = async () => {
return this.doFetch(
`${this.getBaseRoute()}/config/client?format=old`,
{method: 'get'},
);
};
getClientLicenseOld = async () => {
return this.doFetch(
`${this.getBaseRoute()}/license/client?format=old`,
{method: 'get'},
);
};
getTimezones = async () => {
return this.doFetch(
`${this.getTimezonesRoute()}`,
{method: 'get'},
);
};
getGlobalDataRetentionPolicy = () => {
return this.doFetch(
`${this.getDataRetentionRoute()}/policy`,
{method: 'get'},
);
};
getTeamDataRetentionPolicies = (userId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {
return this.doFetch(
`${this.getBaseRoute()}/users/${userId}/data_retention/team_policies${buildQueryString({page, per_page: perPage})}`,
{method: 'get'},
);
};
getChannelDataRetentionPolicies = (userId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {
return this.doFetch(
`${this.getBaseRoute()}/users/${userId}/data_retention/channel_policies${buildQueryString({page, per_page: perPage})}`,
{method: 'get'},
);
};
getRolesByNames = async (rolesNames: string[]) => {
return this.doFetch(
`${this.getRolesRoute()}/names`,
{method: 'post', body: JSON.stringify(rolesNames)},
);
};
getRedirectLocation = async (urlParam: string) => {
if (!urlParam.length) {
return Promise.resolve();
}
const url = `${this.getRedirectLocationRoute()}${buildQueryString({url: urlParam})}`;
return this.doFetch(url, {method: 'get'});
};
};
export default ClientGeneral;