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(core): Disallow deletion of default channel #3181

Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions packages/core/e2e/channel.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,26 @@ describe('Channels', () => {
expect(product!.channels.map(c => c.id)).toEqual(['T_1']);
});

it('Fail to delete the default channel', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

you did an e2e test, you are a good man

await adminClient.asSuperAdmin();

const defaultChannelId = (
await adminClient.query<Codegen.GetChannelsQuery, Codegen.GetChannelsQueryVariables>(GET_CHANNELS)
).channels.items.find(channel => channel.code === DEFAULT_CHANNEL_CODE)?.id;

expect(defaultChannelId).not.toBeUndefined();

const mutation = await adminClient.query<
Codegen.DeleteChannelMutation,
Codegen.DeleteChannelMutationVariables
>(DELETE_CHANNEL, { id: defaultChannelId! });

expect(mutation.deleteChannel).toEqual({
result: DeletionResult.NOT_DELETED,
message: 'The default Channel cannot be deleted',
});
});

describe('currencyCode support', () => {
beforeAll(async () => {
await adminClient.asSuperAdmin();
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/i18n/messages/de.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"error": {
"cannot-delete-role": "Die Rolle \"{ roleCode }\" kann nicht gelöscht werden",
"cannot-delete-default-channel": "Der Standardkanal kann nicht gelöscht werden",
"cannot-locate-customer-for-user": "Es konnte kein Kunde für den Nutzer gefunden werden",
"cannot-modify-role": "Die Rolle \"{ roleCode }\" kann nicht geändert werden",
"cannot-create-sales-for-active-order": "Es kann kein Sale für eine aktive Bestellung erstellt werden",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"available-currency-codes-must-include-default": "availableCurrencyCodes must include the defaultCurrencyCode ({ defaultCurrencyCode })",
"cannot-delete-role": "The role \"{ roleCode }\" cannot be deleted",
"cannot-delete-sole-superadmin": "The sole SuperAdmin cannot be deleted",
"cannot-delete-default-channel": "The default Channel cannot be deleted",
"cannot-locate-customer-for-user": "Cannot locate a Customer for the user",
"cannot-modify-role": "The role \"{ roleCode }\" cannot be modified",
"cannot-move-collection-into-self": "Cannot move a Collection into itself",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/service/services/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ export class ChannelService {

async delete(ctx: RequestContext, id: ID): Promise<DeletionResponse> {
const channel = await this.connection.getEntityOrThrow(ctx, Channel, id);
if (channel.code === DEFAULT_CHANNEL_CODE)
return {
result: DeletionResult.NOT_DELETED,
message: ctx.translate('error.cannot-delete-default-channel'),
};

const deletedChannel = new Channel(channel);
await this.connection.getRepository(ctx, Session).delete({ activeChannelId: id });
await this.connection.getRepository(ctx, Channel).delete(id);
Expand Down
Loading