Skip to content

Commit

Permalink
MM-38702: Include attachments by default (mattermost#543)
Browse files Browse the repository at this point in the history
Include attachments by default. Add a new flag to reverse
the logic.

https://mattermost.atlassian.net/browse/MM-38702
  • Loading branch information
agnivade authored Aug 17, 2022
1 parent eae1e37 commit 4e2542b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ issues:
- linters:
- goconst
text: "YES"

- linters:
- staticcheck
text: SA1019
15 changes: 9 additions & 6 deletions commands/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions commands/export_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
7 changes: 4 additions & 3 deletions commands/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions docs/mmctl_export_create.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 4e2542b

Please sign in to comment.