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

[MM-47629] Don't crash when a run channel has been deleted #1908

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ describe('runs > run details page > run info', {testIsolation: true}, () => {
cy.url().should('include', `${testTeam.name}/channels/the-run-name`);
});
});

it('indicates when the channel has been deleted', () => {
cy.apiDeleteChannel(testRun.channel_id).then(() => {
cy.visit(`/playbooks/runs/${testRun.id}`);

// * Assert channel name
getOverviewEntry('channel').contains('Channel deleted');
});
});
});

describe('as viewer', () => {
Expand Down
7 changes: 4 additions & 3 deletions server/app/playbook_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,12 @@ func (s *PlaybookRunServiceImpl) GetPlaybookRunMetadata(playbookRunID string) (*
// Get main channel details
channel, err := s.pluginAPI.Channel.Get(playbookRun.ChannelID)
if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve channel id '%s'", playbookRun.ChannelID)
s.pluginAPI.Log.Warn("failed to retrieve channel id", "channel_id", playbookRun.ChannelID)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is the main core change: considering that a missing channel is not a big deal and we can continue the process without it.

channel = &model.Channel{}
}
team, err := s.pluginAPI.Team.Get(channel.TeamId)
team, err := s.pluginAPI.Team.Get(playbookRun.TeamID)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the run teamID because the channel might not exist

if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve team id '%s'", channel.TeamId)
return nil, errors.Wrapf(err, "failed to retrieve team id '%s'", playbookRun.TeamID)
}

numParticipants, err := s.store.GetHistoricalPlaybookRunParticipantsCount(playbookRun.ChannelID)
Expand Down
1 change: 1 addition & 0 deletions webapp/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"AG7PKJ": "Rename run",
"AML4RW": "Task assignments",
"AhY0vJ": "Leave and unfollow",
"AkyGP2": "Channel deleted",
"AoNLta": "There are no finished runs linked to this channel",
"Auj1ap": "Start a trial or upgrade your subscription.",
"B3Q5mz": "Trigger",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const PlaybookRunDetails = () => {
// we must force metadata refetch when participants change (leave&unfollow)
const [metadata, metadataResult] = useRunMetadata(playbookRun?.id, [JSON.stringify(playbookRun?.participant_ids)]);
const [statusUpdates] = useRunStatusUpdates(playbookRun?.id, [playbookRun?.status_posts.length]);
const [channel] = useChannel(playbookRun?.channel_id ?? '');
const [channel, channelResult] = useChannel(playbookRun?.channel_id ?? '');
const myUser = useSelector(getCurrentUser);
const {options, selectOption, eventsFilter, resetFilters} = useFilter();
const followState = useRunFollowers(metadata?.followers || []);
Expand Down Expand Up @@ -144,6 +144,8 @@ const PlaybookRunDetails = () => {
}
}, [urlHash]);

const channelDeleted = Boolean(channel?.delete_at) || channelResult.isErrorCode(404);

// not found or error
if (playbookRunResult.error !== null || metadataResult.error !== null) {
return <Redirect to={pluginErrorUrl(ErrorPageTypes.PLAYBOOK_RUNS)}/>;
Expand Down Expand Up @@ -176,6 +178,7 @@ const PlaybookRunDetails = () => {
role={role}
followState={followState}
channel={channel}
channelDeleted={channelDeleted}
onViewParticipants={() => RHS.open(RHSContent.RunParticipants, RHSParticipantsTitle, playbookRun.name, () => onViewInfo)}
onViewTimeline={() => RHS.open(RHSContent.RunTimeline, formatMessage({defaultMessage: 'Timeline'}), playbookRun.name, () => onViewInfo, false)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Props {
runMetadata?: Metadata;
role: Role;
channel: Channel | undefined | null;
channelDeleted: boolean;
followState: FollowState;
onViewParticipants: () => void;
onViewTimeline: () => void;
Expand All @@ -42,6 +43,7 @@ const RHSInfo = (props: Props) => {
onViewParticipants={props.onViewParticipants}
editable={editable}
channel={props.channel}
channelDeleted={props.channelDeleted}
followState={props.followState}
playbook={props.playbook}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ interface Props {
runMetadata?: Metadata;
editable: boolean;
channel: Channel | undefined | null;
channelDeleted: boolean;
followState: FollowState;
playbook?: PlaybookWithChecklist;
role: Role;
Expand All @@ -91,7 +92,7 @@ const StyledArrowIcon = styled(ArrowForwardIosIcon)`
margin-left: 7px;
`;

const RHSInfoOverview = ({run, role, channel, runMetadata, followState, editable, playbook, onViewParticipants}: Props) => {
const RHSInfoOverview = ({run, role, channel, channelDeleted, runMetadata, followState, editable, playbook, onViewParticipants}: Props) => {
const {formatMessage} = useIntl();
const addToast = useToaster().add;
const refreshLHS = useLHSRefresh();
Expand Down Expand Up @@ -197,24 +198,13 @@ const RHSInfoOverview = ({run, role, channel, runMetadata, followState, editable
icon={ProductChannelsIcon}
name={formatMessage({defaultMessage: 'Channel'})}
>
{channel && runMetadata ? <>
<ItemLink
to={`/${runMetadata.team_name}/channels/${channel.name}`}
data-testid='runinfo-channel-link'
>
<ItemContent >
{channel.display_name}
</ItemContent>
<OpenInNewIcon
size={14}
color={'var(--button-bg)'}
/>
</ItemLink>
</> : <ItemDisabledContent>
{role === Role.Participant ? <RequestJoinButton onClick={showRequestJoinConfirm}>{formatMessage({defaultMessage: 'Request to Join'})}</RequestJoinButton> : null}
<LockOutlineIcon size={20}/> {formatMessage({defaultMessage: 'Private'})}
</ItemDisabledContent>
}
<ChannelRow
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the channel row to it's own component because we started to have a lot of conditions.

channel={channel}
runMetadata={runMetadata}
channelDeleted={channelDeleted}
role={role}
onClickRequestJoin={showRequestJoinConfirm}
/>
</Item>
{RequestJoinModal}
</Section>
Expand Down Expand Up @@ -277,7 +267,7 @@ const ItemDisabledContent = styled(ItemContent)`
color: rgba(var(--center-channel-color-rgb), 0.64);
`;

const OverviewRow = styled.div<{onClick?: () => void}>`
const OverviewRow = styled.div<{ onClick?: () => void }>`
padding: 10px 24px;
height: 44px;
display: flex;
Expand Down Expand Up @@ -321,3 +311,47 @@ const ParticipantsContainer = styled.div`
flex-direction: row;
align-items: center;
`;

interface ChannelRowProps {
channel: Channel | undefined | null;
channelDeleted: boolean;
runMetadata?: Metadata;
role: Role;
onClickRequestJoin: () => void;
}

const ChannelRow = ({channel, runMetadata, channelDeleted, role, onClickRequestJoin}: ChannelRowProps) => {
const {formatMessage} = useIntl();

if (channelDeleted) {
return (
<ItemDisabledContent>
{formatMessage({defaultMessage: 'Channel deleted'})}
</ItemDisabledContent>
);
}

if (channel && runMetadata) {
return (
<ItemLink
to={`/${runMetadata.team_name}/channels/${channel.name}`}
data-testid='runinfo-channel-link'
>
<ItemContent >
{channel.display_name}
</ItemContent>
<OpenInNewIcon
size={14}
color={'var(--button-bg)'}
/>
</ItemLink>
);
}

return (
<ItemDisabledContent>
{role === Role.Participant ? <RequestJoinButton onClick={onClickRequestJoin}>{formatMessage({defaultMessage: 'Request to Join'})}</RequestJoinButton> : null}
<LockOutlineIcon size={20}/> {formatMessage({defaultMessage: 'Private'})}
</ItemDisabledContent>
);
};
Loading