Merge pull request #2407 from Bilb/fix-mod-can-delete-messages

fix: allow non admin mods to delete message for deletion
pull/2408/head
Audric Ackermann 3 years ago committed by GitHub
commit 415fd2f0e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,6 +29,11 @@ window.sessionFeatureFlags = {
useTestNet: Boolean( useTestNet: Boolean(
process.env.NODE_APP_INSTANCE && process.env.NODE_APP_INSTANCE.includes('testnet') process.env.NODE_APP_INSTANCE && process.env.NODE_APP_INSTANCE.includes('testnet')
), ),
debug: {
debugFileServerRequests: false,
debugNonSnodeRequests: false,
debugOnionRequests: false,
},
}; };
window.versionInfo = { window.versionInfo = {

@ -245,8 +245,9 @@ const doDeleteSelectedMessagesInSOGS = async (
//#region open group v2 deletion //#region open group v2 deletion
// Get our Moderator status // Get our Moderator status
const isAdmin = conversation.isAdmin(ourDevicePubkey); const isAdmin = conversation.isAdmin(ourDevicePubkey);
const isModerator = conversation.isModerator(ourDevicePubkey);
if (!isAllOurs && !isAdmin) { if (!isAllOurs && !(isAdmin || isModerator)) {
ToastUtils.pushMessageDeleteForbidden(); ToastUtils.pushMessageDeleteForbidden();
window.inboxStore?.dispatch(resetSelectedMessageIds()); window.inboxStore?.dispatch(resetSelectedMessageIds());
return; return;

@ -73,12 +73,18 @@ export const downloadFileFromFileServer = async (
return null; return null;
} }
const urlToGet = `${POST_GET_FILE_ENDPOINT}/${fileId}`;
if (window.sessionFeatureFlags?.debug.debugFileServerRequests) {
window.log.info(`about to try to download fsv2: "${urlToGet}"`);
}
const result = await OnionSending.getBinaryViaOnionV4FromFileServer({ const result = await OnionSending.getBinaryViaOnionV4FromFileServer({
abortSignal: new AbortController().signal, abortSignal: new AbortController().signal,
endpoint: `${POST_GET_FILE_ENDPOINT}/${fileId}`, endpoint: urlToGet,
method: 'GET', method: 'GET',
}); });
if (window.sessionFeatureFlags?.debug.debugFileServerRequests) {
window.log.info(`download fsv2: "${urlToGet} got result:`, JSON.stringify(result));
}
if (!result) { if (!result) {
return null; return null;
} }

@ -782,6 +782,16 @@ async function sendOnionRequestHandlingSnodeEject({
abortSignal, abortSignal,
useV4, useV4,
}); });
if (window.sessionFeatureFlags?.debug.debugOnionRequests) {
window.log.info(
`sendOnionRequestHandlingSnodeEject: sendOnionRequestNoRetries: useV4:${useV4} destSnodeX25519:${destSnodeX25519}; \nfinalDestOptions:${JSON.stringify(
finalDestOptions
)}; \nfinalRelayOptions:${JSON.stringify(finalRelayOptions)}\n\n result: ${JSON.stringify(
result
)}`
);
}
response = result.response; response = result.response;
if ( if (
!isEmpty(finalRelayOptions) && !isEmpty(finalRelayOptions) &&

@ -102,6 +102,13 @@ const sendViaOnionV4ToNonSnodeWithRetries = async (
} }
const payloadObj = buildSendViaOnionPayload(url, fetchOptions); const payloadObj = buildSendViaOnionPayload(url, fetchOptions);
if (window.sessionFeatureFlags?.debug.debugNonSnodeRequests) {
window.log.info(
'sendViaOnionV4ToNonSnodeWithRetries: buildSendViaOnionPayload returned ',
JSON.stringify(payloadObj)
);
}
// if protocol is forced to 'http:' => just use http (without the ':'). // if protocol is forced to 'http:' => just use http (without the ':').
// otherwise use https as protocol (this is the default) // otherwise use https as protocol (this is the default)
const forcedHttp = url.protocol === PROTOCOLS.HTTP; const forcedHttp = url.protocol === PROTOCOLS.HTTP;
@ -121,7 +128,12 @@ const sendViaOnionV4ToNonSnodeWithRetries = async (
result = await pRetry( result = await pRetry(
async () => { async () => {
const pathNodes = await OnionSending.getOnionPathForSending(); const pathNodes = await OnionSending.getOnionPathForSending();
if (window.sessionFeatureFlags?.debug.debugNonSnodeRequests) {
window.log.info(
'sendViaOnionV4ToNonSnodeWithRetries: getOnionPathForSending returned',
JSON.stringify(pathNodes)
);
}
if (!pathNodes) { if (!pathNodes) {
throw new Error('getOnionPathForSending is emtpy'); throw new Error('getOnionPathForSending is emtpy');
} }
@ -140,6 +152,12 @@ const sendViaOnionV4ToNonSnodeWithRetries = async (
useV4: true, useV4: true,
throwErrors, throwErrors,
}); });
if (window.sessionFeatureFlags?.debug.debugNonSnodeRequests) {
window.log.info(
'sendViaOnionV4ToNonSnodeWithRetries: sendOnionRequestHandlingSnodeEject returned: ',
JSON.stringify(onionV4Response)
);
}
if (abortSignal?.aborted) { if (abortSignal?.aborted) {
// if the request was aborted, we just want to stop retries. // if the request was aborted, we just want to stop retries.
@ -175,6 +193,12 @@ const sendViaOnionV4ToNonSnodeWithRetries = async (
bodyBinary: decodedV4?.bodyBinary || null, bodyBinary: decodedV4?.bodyBinary || null,
}; };
} }
if (foundStatusCode === 404) {
// this is most likely that a 404 won't fix itself. So just stop right here retries by throwing a non retryable error
throw new pRetry.AbortError(
`Got 404 while sendViaOnionV4ToNonSnodeWithRetries with url:${url}. Stopping retries`
);
}
// we consider those cases as an error, and trigger a retry (if possible), by throwing a non-abortable error // we consider those cases as an error, and trigger a retry (if possible), by throwing a non-abortable error
throw new Error( throw new Error(
`sendViaOnionV4ToNonSnodeWithRetries failed with status code: ${foundStatusCode}. Retrying...` `sendViaOnionV4ToNonSnodeWithRetries failed with status code: ${foundStatusCode}. Retrying...`
@ -419,6 +443,9 @@ async function getBinaryViaOnionV4FromFileServer(sendOptions: {
} }
const builtUrl = new URL(`${fileServerURL}${endpoint}`); const builtUrl = new URL(`${fileServerURL}${endpoint}`);
if (window.sessionFeatureFlags?.debug.debugFileServerRequests) {
window.log.info(`getBinaryViaOnionV4FromFileServer fsv2: "${builtUrl} `);
}
const res = await OnionSending.sendViaOnionV4ToNonSnodeWithRetries( const res = await OnionSending.sendViaOnionV4ToNonSnodeWithRetries(
fileServerPubKey, fileServerPubKey,
builtUrl, builtUrl,
@ -432,6 +459,12 @@ async function getBinaryViaOnionV4FromFileServer(sendOptions: {
abortSignal abortSignal
); );
if (window.sessionFeatureFlags?.debug.debugFileServerRequests) {
window.log.info(
`getBinaryViaOnionV4FromFileServer fsv2: "${builtUrl}; got:`,
JSON.stringify(res)
);
}
return res as OnionV4BinarySnodeResponse; return res as OnionV4BinarySnodeResponse;
} }

5
ts/window.d.ts vendored

@ -38,6 +38,11 @@ declare global {
sessionFeatureFlags: { sessionFeatureFlags: {
useOnionRequests: boolean; useOnionRequests: boolean;
useTestNet: boolean; useTestNet: boolean;
debug: {
debugFileServerRequests: boolean;
debugNonSnodeRequests: boolean;
debugOnionRequests: boolean;
};
}; };
SessionSnodeAPI: SessionSnodeAPI; SessionSnodeAPI: SessionSnodeAPI;
onLogin: any; onLogin: any;

Loading…
Cancel
Save