Skip to content

Commit 27448fe

Browse files
Copilotggazzo
andauthored
chore: replace getLoggedInUser with this.user in API endpoints (#38858)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ggazzo <5263975+ggazzo@users.noreply.github.com>
1 parent 0de0f36 commit 27448fe

File tree

7 files changed

+5
-33
lines changed

7 files changed

+5
-33
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { API } from '../api';
2-
import { getLoggedInUser } from '../helpers/getLoggedInUser';
32
import { getServerInfo } from '../lib/getServerInfo';
43

54
API.default.addRoute(
65
'info',
76
{ authRequired: false },
87
{
98
async get() {
10-
const user = await getLoggedInUser(this.request);
11-
return API.v1.success(await getServerInfo(user?._id));
9+
return API.v1.success(await getServerInfo(this.userId));
1210
},
1311
},
1412
);

apps/meteor/app/api/server/helpers/getLoggedInUser.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

apps/meteor/app/api/server/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import './ajv';
22
import './helpers/composeRoomWithLastMessage';
3-
import './helpers/getLoggedInUser';
43
import './helpers/getPaginationItems';
54
import './helpers/getUserFromParams';
65
import './helpers/getUserInfo';

apps/meteor/app/api/server/v1/channels.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMes
5454
import { API } from '../api';
5555
import { addUserToFileObj } from '../helpers/addUserToFileObj';
5656
import { composeRoomWithLastMessage } from '../helpers/composeRoomWithLastMessage';
57-
import { getLoggedInUser } from '../helpers/getLoggedInUser';
5857
import { getPaginationItems } from '../helpers/getPaginationItems';
5958
import { getUserFromParams, getUserListFromParams } from '../helpers/getUserFromParams';
6059

@@ -1147,9 +1146,7 @@ API.v1.addRoute(
11471146
return API.v1.failure('Channel does not exists');
11481147
}
11491148

1150-
const user = await getLoggedInUser(this.request);
1151-
1152-
if (!room || !user || !(await canAccessRoomAsync(room, user))) {
1149+
if (!(await canAccessRoomAsync(room, this.user))) {
11531150
throw new Meteor.Error('error-not-allowed', 'Not Allowed');
11541151
}
11551152

apps/meteor/app/api/server/v1/commands.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { executeSlashCommandPreview } from '../../../lib/server/methods/executeS
88
import { getSlashCommandPreviews } from '../../../lib/server/methods/getSlashCommandPreviews';
99
import { slashCommands } from '../../../utils/server/slashCommand';
1010
import { API } from '../api';
11-
import { getLoggedInUser } from '../helpers/getLoggedInUser';
1211
import { getPaginationItems } from '../helpers/getPaginationItems';
1312

1413
API.v1.addRoute(
@@ -248,7 +247,6 @@ API.v1.addRoute(
248247
// Expects these query params: command: 'giphy', params: 'mine', roomId: 'value'
249248
async get() {
250249
const query = this.queryParams;
251-
const user = await getLoggedInUser(this.request);
252250

253251
if (typeof query.command !== 'string') {
254252
return API.v1.failure('You must provide a command to get the previews from.');
@@ -267,7 +265,7 @@ API.v1.addRoute(
267265
return API.v1.failure('The command provided does not exist (or is disabled).');
268266
}
269267

270-
if (!(await canAccessRoomIdAsync(query.roomId, user?._id))) {
268+
if (!(await canAccessRoomIdAsync(query.roomId, this.userId))) {
271269
return API.v1.forbidden();
272270
}
273271

apps/meteor/app/api/server/v1/groups.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMes
3434
import { API } from '../api';
3535
import { addUserToFileObj } from '../helpers/addUserToFileObj';
3636
import { composeRoomWithLastMessage } from '../helpers/composeRoomWithLastMessage';
37-
import { getLoggedInUser } from '../helpers/getLoggedInUser';
3837
import { getPaginationItems } from '../helpers/getPaginationItems';
3938
import { getUserFromParams, getUserListFromParams } from '../helpers/getUserFromParams';
4039

@@ -839,12 +838,7 @@ API.v1.addRoute(
839838
return API.v1.failure('Group does not exists');
840839
}
841840

842-
const user = await getLoggedInUser(this.request);
843-
if (!user) {
844-
return API.v1.failure('User does not exists');
845-
}
846-
847-
if (!(await canAccessRoomAsync(room, user))) {
841+
if (!(await canAccessRoomAsync(room, this.user))) {
848842
throw new Meteor.Error('error-not-allowed', 'Not Allowed');
849843
}
850844

apps/meteor/app/api/server/v1/misc.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { getBaseUserFields } from '../../../utils/server/functions/getBaseUserFi
2929
import { isSMTPConfigured } from '../../../utils/server/functions/isSMTPConfigured';
3030
import { getURL } from '../../../utils/server/getURL';
3131
import { API } from '../api';
32-
import { getLoggedInUser } from '../helpers/getLoggedInUser';
3332
import { getPaginationItems } from '../helpers/getPaginationItems';
3433
import { getUserFromParams } from '../helpers/getUserFromParams';
3534
import { getUserInfo } from '../helpers/getUserInfo';
@@ -244,7 +243,7 @@ API.v1.addRoute(
244243
text = `#${channel}`;
245244
break;
246245
case 'user':
247-
if (settings.get('API_Shield_user_require_auth') && !(await getLoggedInUser(this.request))) {
246+
if (settings.get('API_Shield_user_require_auth') && !this.user) {
248247
return API.v1.failure('You must be logged in to do this.');
249248
}
250249
const user = await getUserFromParams(this.queryParams);

0 commit comments

Comments
 (0)