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

fix: resetIrcConnection not requiring user logged #33994

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
Commits
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
11 changes: 11 additions & 0 deletions apps/meteor/app/irc/server/methods/resetIrcConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Settings } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { settings } from '../../../settings/server';
import Bridge from '../irc-bridge';
Expand All @@ -16,8 +17,18 @@ declare module '@rocket.chat/ddp-client' {
Meteor.methods<ServerMethods>({
async resetIrcConnection() {
const ircEnabled = Boolean(settings.get('IRC_Enabled'));
const uid = Meteor.userId();

if (!uid) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'resetIrcConnection' });
}

if (!(await hasPermissionAsync(uid, 'edit-privileged-setting'))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'resetIrcConnection' });
}

const updatedLastPingValue = await Settings.updateValueById('IRC_Bridge_Last_Ping', new Date(0), { upsert: true });

if (updatedLastPingValue.modifiedCount || updatedLastPingValue.upsertedCount) {
void notifyOnSettingChangedById('IRC_Bridge_Last_Ping');
}
Expand Down
Loading