refactor: move from canDeleteMessage to canDeleteMessageAsync (#28480)

pull/28481/head^2
Guilherme Gazzo 3 years ago committed by GitHub
parent 04fadcc565
commit 0b300d100f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/meteor/app/api/server/default/info.ts
  2. 5
      apps/meteor/app/authorization/server/functions/canDeleteMessage.ts
  3. 4
      apps/meteor/app/lib/server/methods/deleteMessage.ts

@ -5,10 +5,10 @@ API.default.addRoute(
'info',
{ authRequired: false },
{
get() {
async get() {
const user = this.getLoggedInUser();
return API.v1.success(Promise.await(getServerInfo(user?._id)));
return API.v1.success(await getServerInfo(user?._id));
},
},
);

@ -9,7 +9,7 @@ const elapsedTime = (ts: number): number => {
return Math.round(dif / 1000 / 60);
};
const canDeleteMessageAsync = async (uid: string, { u, rid, ts }: { u: IUser; rid: string; ts: number }): Promise<boolean> => {
export const canDeleteMessageAsync = async (uid: string, { u, rid, ts }: { u: IUser; rid: string; ts: number }): Promise<boolean> => {
const forceDelete = await hasPermissionAsync(uid, 'force-delete-message', rid);
if (forceDelete) {
@ -52,6 +52,3 @@ const canDeleteMessageAsync = async (uid: string, { u, rid, ts }: { u: IUser; ri
return true;
};
export const canDeleteMessage = (uid: string, { u, rid, ts }: { u: IUser; rid: string; ts: number }): boolean =>
Promise.await(canDeleteMessageAsync(uid, { u, rid, ts }));

@ -3,7 +3,7 @@ import { Match, check } from 'meteor/check';
import type { IMessage, IUser } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { canDeleteMessage } from '../../../authorization/server/functions/canDeleteMessage';
import { canDeleteMessageAsync } from '../../../authorization/server/functions/canDeleteMessage';
import { Messages } from '../../../models/server';
import { deleteMessage } from '../functions';
@ -41,7 +41,7 @@ Meteor.methods<ServerMethods>({
},
});
if (!originalMessage || !canDeleteMessage(uid, originalMessage)) {
if (!originalMessage || !(await canDeleteMessageAsync(uid, originalMessage))) {
throw new Meteor.Error('error-action-not-allowed', 'Not allowed', {
method: 'deleteMessage',
action: 'Delete_message',

Loading…
Cancel
Save