Skip to content

Commit

Permalink
channels.delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed May 9, 2022
1 parent af443ef commit a41e119
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 28 deletions.
23 changes: 1 addition & 22 deletions apps/meteor/app/api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,6 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'channels.delete',
{ authRequired: true },
{
post() {
const room = findChannelByIdOrName({
params: this.requestParams(),
checkedArchived: false,
});

Meteor.runAsUser(this.userId, () => {
Meteor.call('eraseRoom', room._id);
});

return API.v1.success();
},
},
);

API.v1.addRoute(
'channels.files',
{ authRequired: true },
Expand Down Expand Up @@ -419,9 +400,7 @@ API.v1.addRoute(
return API.v1.failure('invalid-user-invite-list', 'Cannot invite if no users are provided');
}

Meteor.runAsUser(this.userId, () => {
Meteor.call('addUsersToRoom', { rid: findResult._id, users: users.map((u) => u.username) });
});
Meteor.call('addUsersToRoom', { rid: findResult._id, users: users.map((u) => u.username) });

return API.v1.success({
channel: findChannelByIdOrName({ params: this.requestParams(), userId: this.userId }),
Expand Down
22 changes: 22 additions & 0 deletions apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isChannelsModeratorsProps,
isChannelsConvertToTeamProps,
isChannelsSetReadOnlyProps,
isChannelsDeleteProps,
} from '@rocket.chat/rest-typings';

import { Rooms, Subscriptions, Messages } from '../../../models/server';
Expand Down Expand Up @@ -444,6 +445,27 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'channels.delete',
{ authRequired: true },
{
post() {
if (!isChannelsDeleteProps(this.bodyParams)) {
throw new Meteor.Error('error-invalid-params', isChannelsDeleteProps.errors?.map((error: any) => error.message).join('\n '));
}
const { roomId } = this.bodyParams;
const room = findChannelByIdOrName({
params: { roomId },
checkedArchived: false,
});

Meteor.call('eraseRoom', room._id);

return API.v1.success();
},
},
);

API.v1.addRoute(
'channels.convertToTeam',
{ authRequired: true },
Expand Down
2 changes: 1 addition & 1 deletion packages/rest-typings/src/helpers/PaginatedRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export type PaginatedRequest<T = {}, S extends string = string> = {
offset?: number;
sort?: `{ "${S}": ${1 | -1} }` | string;
/* deprecated */
query: string;
query?: string;
} & T;
1 change: 1 addition & 0 deletions packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export * from './v1/channels/ChannelsGetAllUserMentionsByChannelProps';
export * from './v1/channels/ChannelsModeratorsProps';
export * from './v1/channels/ChannelsConvertToTeamProps';
export * from './v1/channels/ChannelsSetReadOnlyProps';
export * from './v1/channels/ChannelsDeleteProps';
export * from './v1/oauthapps';
export * from './helpers/PaginatedRequest';
export * from './helpers/PaginatedResult';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const channelsAddAllPropsSchema = {
additionalProperties: false,
},
],
additionalProperties: false,
};

export const isChannelsAddAllProps = ajv.compile<ChannelsAddAllProps>(channelsAddAllPropsSchema);
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const channelsArchivePropsSchema = {
additionalProperties: false,
},
],
additionalProperties: false,
};

export const isChannelsArchiveProps = ajv.compile<ChannelsArchiveProps>(channelsArchivePropsSchema);
18 changes: 18 additions & 0 deletions packages/rest-typings/src/v1/channels/ChannelsDeleteProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Ajv from 'ajv';

const ajv = new Ajv();

export type ChannelsDeleteProps = { roomId: string };

const channelsDeletePropsSchema = {
type: 'object',
properties: {
roomId: {
type: 'string',
},
},
required: ['roomId'],
additionalProperties: false,
};

export const isChannelsDeleteProps = ajv.compile<ChannelsDeleteProps>(channelsDeletePropsSchema);
2 changes: 2 additions & 0 deletions packages/rest-typings/src/v1/channels/ChannelsHistoryProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const channelsHistoryPropsSchema = {
type: 'string',
},
},
required: ['roomId'],
additionalProperties: false,
};

export const isChannelsHistoryProps = ajv.compile<ChannelsHistoryProps>(channelsHistoryPropsSchema);
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const channelsRolesPropsSchema = {
additionalProperties: false,
},
],
additionalProperties: false,
};

export const isChannelsRolesProps = ajv.compile<ChannelsRolesProps>(channelsRolesPropsSchema);
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const channelsSetReadOnlyPropsSchema = {
readOnly: { type: 'boolean' },
},
required: ['roomId', 'readOnly'],
additionalProperties: false,
};

export const isChannelsSetReadOnlyProps = ajv.compile<ChannelsSetReadOnlyProps>(channelsSetReadOnlyPropsSchema);
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const channelsUnarchivePropsSchema = {
additionalProperties: false,
},
],
additionalProperties: false,
};

export const isChannelsUnarchiveProps = ajv.compile<ChannelsUnarchiveProps>(channelsUnarchivePropsSchema);
2 changes: 1 addition & 1 deletion packages/rest-typings/src/v1/channels/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export type ChannelsEndpoints = {
POST: (params: { roomId: string; userId: string }) => {};
};
'channels.delete': {
POST: (params: { roomId: string }) => {};
POST: (params: { roomId: string }) => void;
};
'channels.leave': {
POST: (params: { roomId: string }) => {};
Expand Down

0 comments on commit a41e119

Please sign in to comment.