Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAK] remove unused endpoints and restify others #25889

Merged
merged 21 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/meteor/app/livechat/imports/server/rest/departments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isLivechatDepartmentProps } from '@rocket.chat/rest-typings';
import { Match, check } from 'meteor/check';

import { API } from '../../../../api/server';
import { hasPermission } from '../../../../authorization/server';
import { hasPermission, hasAtLeastOnePermission } from '../../../../authorization/server';
import { LivechatDepartment, LivechatDepartmentAgents } from '../../../../models/server';
import { Livechat } from '../../../server/lib/Livechat';
import {
Expand All @@ -18,6 +18,10 @@ API.v1.addRoute(
{ authRequired: true, validateParams: isLivechatDepartmentProps },
{
async get() {
if (!hasAtLeastOnePermission(this.userId, ['view-livechat-departments', 'view-l-room'])) {
return API.v1.unauthorized();
}

const { offset, count } = this.getPaginationItems();
const { sort } = this.parseJsonQuery();

Expand Down Expand Up @@ -76,6 +80,10 @@ API.v1.addRoute(
{ authRequired: true },
{
async get() {
if (!hasAtLeastOnePermission(this.userId, ['view-livechat-departments', 'view-l-room'])) {
return API.v1.unauthorized();
}

check(this.urlParams, {
_id: String,
});
Expand Down
21 changes: 0 additions & 21 deletions apps/meteor/app/livechat/imports/server/rest/officeHour.js

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ import '../imports/server/rest/visitors.js';
import '../imports/server/rest/visitors.ts';
import '../imports/server/rest/dashboards.js';
import '../imports/server/rest/queue.js';
import '../imports/server/rest/officeHour.js';
import '../imports/server/rest/businessHours.js';
13 changes: 0 additions & 13 deletions apps/meteor/app/livechat/server/api/lib/officeHour.js

This file was deleted.

2 changes: 0 additions & 2 deletions apps/meteor/app/livechat/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import './methods/getAgentData';
import './methods/getAgentOverviewData';
import './methods/getAnalyticsChartData';
import './methods/getAnalyticsOverviewData';
import './methods/getInitialData';
import './methods/getNextAgent';
import './methods/getRoutingConfig';
import './methods/loadHistory';
Expand Down Expand Up @@ -61,7 +60,6 @@ import './methods/sendOfflineMessage';
import './methods/setCustomField';
import './methods/setDepartmentForVisitor';
import './methods/startVideoCall';
import './methods/startFileUploadRoom';
import './methods/transfer';
import './methods/webhookTest';
import './methods/setUpConnection';
Expand Down
112 changes: 0 additions & 112 deletions apps/meteor/app/livechat/server/methods/getInitialData.js

This file was deleted.

30 changes: 0 additions & 30 deletions apps/meteor/app/livechat/server/methods/startFileUploadRoom.js

This file was deleted.

2 changes: 1 addition & 1 deletion apps/meteor/client/components/Omnichannel/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Tags = ({
const t = useTranslation();
const forms = useFormsSubscription() as any;

const { value: tagsResult, phase: stateTags } = useEndpointData('/v1/livechat/tags.list');
const { value: tagsResult, phase: stateTags } = useEndpointData('/v1/livechat/tags');

// TODO: Refactor the formsSubscription to use components instead of hooks (since the only thing the hook does is return a component)
const { useCurrentChatTags } = forms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useDepartmentsByUnitsList = (
const [itemsList, setItemsList] = useState(() => new RecordList<ILivechatDepartmentRecord>());
const reload = useCallback(() => setItemsList(new RecordList<ILivechatDepartmentRecord>()), []);

const getDepartments = useEndpoint('GET', `/v1/livechat/departments.available-by-unit/${options.unitId || 'none'}`);
const getDepartments = useEndpoint('GET', `/v1/livechat/units/${options.unitId || 'none'}/departments/available`);

useComponentDidUpdate(() => {
options && reload();
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/hooks/useMonitorsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useMonitorsList = (
const [itemsList, setItemsList] = useState(() => new RecordList<ILivechatMonitorRecord>());
const reload = useCallback(() => setItemsList(new RecordList<ILivechatMonitorRecord>()), []);

const getMonitors = useEndpoint('GET', '/v1/livechat/monitors.list');
const getMonitors = useEndpoint('GET', '/v1/livechat/monitors');

useComponentDidUpdate(() => {
options && reload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React, { useMemo } from 'react';
import React from 'react';

import { useEndpointData } from '../../../../../hooks/useEndpointData';
import { AsyncStatePhase } from '../../../../../lib/asyncState';
Expand All @@ -11,14 +11,7 @@ import { FormSkeleton } from '../../Skeleton';

const PriorityField = ({ id }) => {
const t = useTranslation();
const {
value: data,
phase: state,
error,
} = useEndpointData(
'/v1/livechat/priorities.getOne',
useMemo(() => ({ priorityId: id }), [id]),
);
const { value: data, phase: state, error } = useEndpointData(`/v1/livechat/priorities/${id}`);
if (state === AsyncStatePhase.LOADING) {
return <FormSkeleton />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function RoomEdit({ room, visitor, reload, reloadInfo, close }) {
const [customFieldsError, setCustomFieldsError] = useState([]);

const { value: allCustomFields, phase: stateCustomFields } = useEndpointData('/v1/livechat/custom-fields');
const { value: prioritiesResult = {}, phase: statePriorities } = useEndpointData('/v1/livechat/priorities.list');
const { value: prioritiesResult = {}, phase: statePriorities } = useEndpointData('/v1/livechat/priorities');

const jsonConverterToValidFormat = (customFields) => {
const jsonObj = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { LivechatDepartmentAgents, CannedResponse, LivechatUnit } from '@rocket.chat/models';
import { LivechatDepartmentAgents, CannedResponse } from '@rocket.chat/models';

import { hasPermissionAsync } from '../../../../../app/authorization/server/functions/hasPermission';
import LivechatUnit from '../../../models/server/models/LivechatUnit';

export async function findAllCannedResponses({ userId }) {
if (!(await hasPermissionAsync(userId, 'view-canned-responses'))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Template.visitorEditCustomFieldsForm.onCreated(async function () {
if (priorityId) {
this.roomPriority.set(priorityId);
}
const { priorities } = await APIClient.get('/v1/livechat/priorities.list');
const { priorities } = await APIClient.get('/v1/livechat/priorities');
this.priorities.set(priorities);
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Template.visitorInfoCustomForm.onCreated(function () {
let priority;

if (priorityId) {
priority = await APIClient.get('/v1/livechat/priorities.getOne', { priorityId });
priority = await APIClient.get(`/v1/livechat/priorities/${priorityId}`);
}

this.priority.set(priority);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { API } from '../../../../../app/api/server';
import { findBusinessHours } from '../business-hour/lib/business-hour';

API.v1.addRoute(
'livechat/business-hours.list',
'livechat/business-hours',
{ authRequired: true },
{
async get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
findPercentageOfAbandonedRooms,
findAllAverageOfChatDurationTime,
} from '../../../../../app/livechat/server/lib/analytics/departments';
import { findAllDepartmentsAvailable, findAllDepartmentsByUnit } from '../lib/Department';

API.v1.addRoute(
'livechat/analytics/departments/amount-of-chats',
Expand Down Expand Up @@ -351,52 +350,3 @@ API.v1.addRoute(
},
},
);

API.v1.addRoute(
'livechat/departments.available-by-unit/:unitId',
{ authRequired: true },
{
get() {
check(this.urlParams, {
unitId: Match.Maybe(String),
});
const { offset, count } = this.getPaginationItems();
const { unitId } = this.urlParams;
const { text, onlyMyDepartments } = this.queryParams;

const { departments, total } = Promise.await(
findAllDepartmentsAvailable(this.userId, unitId, offset, count, text, onlyMyDepartments === 'true'),
);

return API.v1.success({
departments,
count: departments.length,
offset,
total,
});
},
},
);

API.v1.addRoute(
'livechat/departments.by-unit/:id',
{ authRequired: true },
{
async get() {
check(this.urlParams, {
id: String,
});
const { offset, count } = this.getPaginationItems();
const { id } = this.urlParams;

const { departments, total } = await findAllDepartmentsByUnit(id, offset, count);

return API.v1.success({
departments,
count: departments.length,
offset,
total,
});
},
},
);
Loading