Skip to content

Commit

Permalink
Merge pull request #21771 from dukenv0307/fix/21212
Browse files Browse the repository at this point in the history
Fix user are able to flag their own comment
  • Loading branch information
tylerkaraszewski authored Jun 28, 2023
2 parents 3dc50e0 + 8353696 commit 98f7abc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
27 changes: 26 additions & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Onyx.connect({
},
});

let loginList;
Onyx.connect({
key: ONYXKEYS.LOGIN_LIST,
callback: (val) => (loginList = _.isEmpty(val) ? [] : _.keys(val)),
});

let preferredLocale = CONST.LOCALES.DEFAULT;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
Expand Down Expand Up @@ -220,7 +226,7 @@ function canEditReportAction(reportAction) {
*/
function canFlagReportAction(reportAction) {
return (
reportAction.actorEmail !== sessionEmail &&
!loginList.includes(reportAction.actorEmail) &&
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT &&
!ReportActionsUtils.isDeletedAction(reportAction) &&
!ReportActionsUtils.isCreatedTaskReportAction(reportAction)
Expand Down Expand Up @@ -2063,6 +2069,24 @@ function chatIncludesChronos(report) {
return report.participantAccountIDs && _.contains(report.participantAccountIDs, CONST.ACCOUNT_ID.CHRONOS);
}

/**
* Whether flag comment page should show
*
* @param {Object} reportAction
* @param {Object} report
* @returns {Boolean}
*/

function shouldShowFlagComment(reportAction, report) {
return (
canFlagReportAction(reportAction) &&
!isArchivedRoom(report) &&
!chatIncludesChronos(report) &&
!isConciergeChatReport(report.reportID) &&
reportAction.actorEmail !== CONST.EMAIL.CONCIERGE
);
}

/**
* @param {Object} report
* @param {String} report.lastReadTime
Expand Down Expand Up @@ -2319,6 +2343,7 @@ export {
findLastAccessedReport,
canEditReportAction,
canFlagReportAction,
shouldShowFlagComment,
canDeleteReportAction,
canLeaveRoom,
sortReportsByLastRead,
Expand Down
24 changes: 21 additions & 3 deletions src/pages/FlagCommentPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import CONST from '../CONST';
import * as ReportUtils from '../libs/ReportUtils';
import * as ReportActionsUtils from '../libs/ReportActionsUtils';
import * as Session from '../libs/actions/Session';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';
import FullscreenLoadingIndicator from '../components/FullscreenLoadingIndicator';

const propTypes = {
/** Array of report actions for this report */
Expand All @@ -39,12 +41,16 @@ const propTypes = {
}),
}).isRequired,

/** Indicates whether the report data is loading */
isLoadingReportData: PropTypes.bool,

...withLocalizePropTypes,
};

const defaultProps = {
reportActions: {},
report: {},
isLoadingReportData: true,
};

/**
Expand All @@ -61,6 +67,11 @@ function getReportID(route) {

function FlagCommentPage(props) {
let reportAction = props.reportActions[`${props.route.params.reportActionID.toString()}`];

// Handle threads if needed
if (reportAction === undefined || reportAction.reportActionID === undefined) {
reportAction = ReportActionsUtils.getParentReportAction(props.report);
}
const severities = [
{
severity: CONST.MODERATION.FLAG_SEVERITY_SPAM,
Expand Down Expand Up @@ -118,7 +129,6 @@ function FlagCommentPage(props) {
// Handle threads if needed
if (reportAction === undefined || reportAction.reportActionID === undefined) {
reportID = ReportUtils.getParentReport(props.report).reportID;
reportAction = ReportActionsUtils.getParentReportAction(props.report);
}
Report.flagComment(reportID, reportAction, severity);
Navigation.dismissModal();
Expand All @@ -137,10 +147,15 @@ function FlagCommentPage(props) {
/>
));

const shouldShowLoading = props.isLoadingReportData || props.report.isLoadingReportActions;
if (shouldShowLoading) {
return <FullscreenLoadingIndicator />;
}

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
{({safeAreaPaddingBottomStyle}) => (
<>
<FullPageNotFoundView shouldShow={!shouldShowLoading && !ReportUtils.shouldShowFlagComment(reportAction, props.report)}>
<HeaderWithBackButton title={props.translate('reportActionContextMenu.flagAsOffensive')} />
<ScrollView
contentContainerStyle={safeAreaPaddingBottomStyle}
Expand All @@ -154,7 +169,7 @@ function FlagCommentPage(props) {
<Text style={[styles.ph5, styles.textLabelSupporting, styles.mb1]}>{props.translate('moderation.chooseAReason')}</Text>
{severityMenuItems}
</ScrollView>
</>
</FullPageNotFoundView>
)}
</ScreenWrapper>
);
Expand All @@ -174,5 +189,8 @@ export default compose(
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`,
},
isLoadingReportData: {
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
},
}),
)(FlagCommentPage);

0 comments on commit 98f7abc

Please sign in to comment.