Skip to content

Commit

Permalink
[BREAK] remove unused endpoints and restify others (#25889)
Browse files Browse the repository at this point in the history
<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
  [NEW] For new features
  [IMPROVE] For an improvement (performance or little improvements) in existing features
  [FIX] For bug fixes that affect the end-user
  [BREAK] For pull requests including breaking changes
  Chore: For small tasks
  Doc: For documentation
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. 
  - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc
  - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat
  - Lint and unit tests pass locally with my changes
  - I have added tests that prove my fix is effective or that my feature works (if applicable)
  - I have added necessary documentation (if applicable)
  - Any dependent changes have been merged and published in downstream modules
-->

## Proposed changes (including videos or screenshots)
<!-- CHANGELOG -->
<!--
  Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
  If it fixes a bug or resolves a feature request, be sure to link to that issue below.
  This description will appear in the release notes if we accept the contribution.
-->

<!-- END CHANGELOG -->

## Issue(s)
<!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 -->

## Steps to test or reproduce
<!-- Mention how you would reproduce the bug if not mentioned on the issue page already. Also mention which screens are going to have the changes if applicable -->

## Further comments
<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->


Co-authored-by: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com>
  • Loading branch information
KevLehman and murtaza98 committed Jun 29, 2022
1 parent bbd3f10 commit a7f3789
Show file tree
Hide file tree
Showing 46 changed files with 326 additions and 520 deletions.
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
50 changes: 0 additions & 50 deletions apps/meteor/ee/app/livechat-enterprise/server/api/departments.js
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

0 comments on commit a7f3789

Please sign in to comment.