From 4e2542b9ae9e666b8d05a83cf9763b0e4ec36ece Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 17 Aug 2022 14:41:59 +0530 Subject: [PATCH] MM-38702: Include attachments by default (#543) Include attachments by default. Add a new flag to reverse the logic. https://mattermost.atlassian.net/browse/MM-38702 --- .golangci.yml | 4 ++++ commands/export.go | 15 +++++++++------ commands/export_e2e_test.go | 8 ++++---- commands/export_test.go | 7 ++++--- docs/mmctl_export_create.rst | 4 ++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 65be5ce61..c1db9f20e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -75,3 +75,7 @@ issues: - linters: - goconst text: "YES" + + - linters: + - staticcheck + text: SA1019 diff --git a/commands/export.go b/commands/export.go index b98498704..e608d5676 100644 --- a/commands/export.go +++ b/commands/export.go @@ -80,6 +80,10 @@ var ExportJobShowCmd = &cobra.Command{ func init() { ExportCreateCmd.Flags().Bool("attachments", false, "Set to true to include file attachments in the export file.") + _ = ExportCreateCmd.Flags().MarkHidden("attachments") + _ = ExportCreateCmd.Flags().MarkDeprecated("attachments", "the tool now includes attachments by default. The flag will be removed in a future version.") + + ExportCreateCmd.Flags().Bool("no-attachments", false, "Set to true to exclude file attachments in the export file.") ExportDownloadCmd.Flags().Bool("resume", false, "Set to true to resume an export download.") _ = ExportDownloadCmd.Flags().MarkHidden("resume") @@ -107,12 +111,11 @@ func init() { } func exportCreateCmdF(c client.Client, command *cobra.Command, args []string) error { - var data map[string]string - withAttachments, _ := command.Flags().GetBool("attachments") - if withAttachments { - data = map[string]string{ - "include_attachments": "true", - } + data := make(map[string]string) + + excludeAttachments, _ := command.Flags().GetBool("no-attachments") + if !excludeAttachments { + data["include_attachments"] = "true" } job, _, err := c.CreateJob(&model.Job{ diff --git a/commands/export_e2e_test.go b/commands/export_e2e_test.go index a4edf1828..e8f2ede32 100644 --- a/commands/export_e2e_test.go +++ b/commands/export_e2e_test.go @@ -145,21 +145,21 @@ func (s *MmctlE2ETestSuite) TestExportCreateCmdF() { s.Require().Nil(err) s.Require().Len(printer.GetLines(), 1) s.Require().Empty(printer.GetErrorLines()) - s.Require().Nil(printer.GetLines()[0].(*model.Job).Data) + s.Require().Equal("true", printer.GetLines()[0].(*model.Job).Data["include_attachments"]) }) - s.RunForSystemAdminAndLocal("MM-T3878 - create export with attachments", func(c client.Client) { + s.RunForSystemAdminAndLocal("MM-T3878 - create export without attachments", func(c client.Client) { printer.Clean() cmd := &cobra.Command{} - cmd.Flags().Bool("attachments", true, "") + cmd.Flags().Bool("no-attachments", true, "") err := exportCreateCmdF(c, cmd, nil) s.Require().Nil(err) s.Require().Len(printer.GetLines(), 1) s.Require().Empty(printer.GetErrorLines()) - s.Require().Equal("true", printer.GetLines()[0].(*model.Job).Data["include_attachments"]) + s.Require().Empty(printer.GetLines()[0].(*model.Job).Data) }) } diff --git a/commands/export_test.go b/commands/export_test.go index 2118a20a5..467cbaad5 100644 --- a/commands/export_test.go +++ b/commands/export_test.go @@ -18,6 +18,7 @@ func (s *MmctlUnitTestSuite) TestExportCreateCmdF() { printer.Clean() mockJob := &model.Job{ Type: model.JobTypeExportProcess, + Data: map[string]string{"include_attachments": "true"}, } s.client. @@ -33,11 +34,11 @@ func (s *MmctlUnitTestSuite) TestExportCreateCmdF() { s.Equal(mockJob, printer.GetLines()[0].(*model.Job)) }) - s.Run("create export with attachments", func() { + s.Run("create export without attachments", func() { printer.Clean() mockJob := &model.Job{ Type: model.JobTypeExportProcess, - Data: map[string]string{"include_attachments": "true"}, + Data: make(map[string]string), } s.client. @@ -47,7 +48,7 @@ func (s *MmctlUnitTestSuite) TestExportCreateCmdF() { Times(1) cmd := &cobra.Command{} - cmd.Flags().Bool("attachments", true, "") + cmd.Flags().Bool("no-attachments", true, "") err := exportCreateCmdF(s.client, cmd, nil) s.Require().Nil(err) diff --git a/docs/mmctl_export_create.rst b/docs/mmctl_export_create.rst index 5f97d0d44..3cb45e533 100644 --- a/docs/mmctl_export_create.rst +++ b/docs/mmctl_export_create.rst @@ -20,8 +20,8 @@ Options :: - --attachments Set to true to include file attachments in the export file. - -h, --help help for create + -h, --help help for create + --no-attachments Set to true to exclude file attachments in the export file. Options inherited from parent commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~