Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
Этот коммит содержится в:
3
Makefile
3
Makefile
@@ -56,7 +56,7 @@ GO_LINKER_FLAGS ?= -ldflags \
|
|||||||
# GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not
|
# GOOS/GOARCH of the build host, used to determine whether we're cross-compiling or not
|
||||||
BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"
|
BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"
|
||||||
|
|
||||||
PLATFORM_FILES="./main.go"
|
PLATFORM_FILES="./cmd/mattermost/main.go"
|
||||||
|
|
||||||
# Output paths
|
# Output paths
|
||||||
DIST_ROOT=dist
|
DIST_ROOT=dist
|
||||||
@@ -504,6 +504,7 @@ clean: stop-docker ## Clean up everything except persistant server data.
|
|||||||
rm -f *.test
|
rm -f *.test
|
||||||
rm -f imports/imports.go
|
rm -f imports/imports.go
|
||||||
rm -f cmd/platform/cprofile*.out
|
rm -f cmd/platform/cprofile*.out
|
||||||
|
rm -f cmd/mattermost/cprofile*.out
|
||||||
|
|
||||||
nuke: clean clean-docker ## Clean plus removes persistant server data.
|
nuke: clean clean-docker ## Clean plus removes persistant server data.
|
||||||
@echo BOOM
|
@echo BOOM
|
||||||
|
|||||||
@@ -4,25 +4,25 @@ dist: | check-style test package
|
|||||||
build-linux:
|
build-linux:
|
||||||
@echo Build Linux amd64
|
@echo Build Linux amd64
|
||||||
ifeq ($(BUILDER_GOOS_GOARCH),"linux_amd64")
|
ifeq ($(BUILDER_GOOS_GOARCH),"linux_amd64")
|
||||||
env GOOS=linux GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./
|
env GOOS=linux GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./...
|
||||||
else
|
else
|
||||||
env GOOS=linux GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/linux_amd64/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./
|
env GOOS=linux GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./...
|
||||||
endif
|
endif
|
||||||
|
|
||||||
build-osx:
|
build-osx:
|
||||||
@echo Build OSX amd64
|
@echo Build OSX amd64
|
||||||
ifeq ($(BUILDER_GOOS_GOARCH),"darwin_amd64")
|
ifeq ($(BUILDER_GOOS_GOARCH),"darwin_amd64")
|
||||||
env GOOS=darwin GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./
|
env GOOS=darwin GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./...
|
||||||
else
|
else
|
||||||
env GOOS=darwin GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/darwin_amd64/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./
|
env GOOS=darwin GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./...
|
||||||
endif
|
endif
|
||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
@echo Build Windows amd64
|
@echo Build Windows amd64
|
||||||
ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64")
|
ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64")
|
||||||
env GOOS=windows GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/platform.exe $(GOFLAGS) $(GO_LINKER_FLAGS) ./
|
env GOOS=windows GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./...
|
||||||
else
|
else
|
||||||
env GOOS=windows GOARCH=amd64 $(GO) build -i -o $(GOPATH)/bin/windows_amd64/platform.exe $(GOFLAGS) $(GO_LINKER_FLAGS) ./
|
env GOOS=windows GOARCH=amd64 $(GO) install -i $(GOFLAGS) $(GO_LINKER_FLAGS) ./...
|
||||||
endif
|
endif
|
||||||
|
|
||||||
build: build-linux build-windows build-osx
|
build: build-linux build-windows build-osx
|
||||||
@@ -76,35 +76,43 @@ endif
|
|||||||
@# Make osx package
|
@# Make osx package
|
||||||
@# Copy binary
|
@# Copy binary
|
||||||
ifeq ($(BUILDER_GOOS_GOARCH),"darwin_amd64")
|
ifeq ($(BUILDER_GOOS_GOARCH),"darwin_amd64")
|
||||||
|
cp $(GOPATH)/bin/mattermost $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
||||||
cp $(GOPATH)/bin/platform $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
cp $(GOPATH)/bin/platform $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
||||||
else
|
else
|
||||||
|
cp $(GOPATH)/bin/darwin_amd64/mattermost $(DIST_PATH)/bin # from cross-compiled bin dir
|
||||||
cp $(GOPATH)/bin/darwin_amd64/platform $(DIST_PATH)/bin # from cross-compiled bin dir
|
cp $(GOPATH)/bin/darwin_amd64/platform $(DIST_PATH)/bin # from cross-compiled bin dir
|
||||||
endif
|
endif
|
||||||
@# Package
|
@# Package
|
||||||
tar -C dist -czf $(DIST_PATH)-$(BUILD_TYPE_NAME)-osx-amd64.tar.gz mattermost
|
tar -C dist -czf $(DIST_PATH)-$(BUILD_TYPE_NAME)-osx-amd64.tar.gz mattermost
|
||||||
@# Cleanup
|
@# Cleanup
|
||||||
|
rm -f $(DIST_PATH)/bin/mattermost
|
||||||
rm -f $(DIST_PATH)/bin/platform
|
rm -f $(DIST_PATH)/bin/platform
|
||||||
|
|
||||||
@# Make windows package
|
@# Make windows package
|
||||||
@# Copy binary
|
@# Copy binary
|
||||||
ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64")
|
ifeq ($(BUILDER_GOOS_GOARCH),"windows_amd64")
|
||||||
|
cp $(GOPATH)/bin/mattermost.exe $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
||||||
cp $(GOPATH)/bin/platform.exe $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
cp $(GOPATH)/bin/platform.exe $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
||||||
else
|
else
|
||||||
|
cp $(GOPATH)/bin/windows_amd64/mattermost.exe $(DIST_PATH)/bin # from cross-compiled bin dir
|
||||||
cp $(GOPATH)/bin/windows_amd64/platform.exe $(DIST_PATH)/bin # from cross-compiled bin dir
|
cp $(GOPATH)/bin/windows_amd64/platform.exe $(DIST_PATH)/bin # from cross-compiled bin dir
|
||||||
endif
|
endif
|
||||||
@# Package
|
@# Package
|
||||||
cd $(DIST_ROOT) && zip -9 -r -q -l mattermost-$(BUILD_TYPE_NAME)-windows-amd64.zip mattermost && cd ..
|
cd $(DIST_ROOT) && zip -9 -r -q -l mattermost-$(BUILD_TYPE_NAME)-windows-amd64.zip mattermost && cd ..
|
||||||
@# Cleanup
|
@# Cleanup
|
||||||
|
rm -f $(DIST_PATH)/bin/mattermost.exe
|
||||||
rm -f $(DIST_PATH)/bin/platform.exe
|
rm -f $(DIST_PATH)/bin/platform.exe
|
||||||
|
|
||||||
@# Make linux package
|
@# Make linux package
|
||||||
@# Copy binary
|
@# Copy binary
|
||||||
ifeq ($(BUILDER_GOOS_GOARCH),"linux_amd64")
|
ifeq ($(BUILDER_GOOS_GOARCH),"linux_amd64")
|
||||||
|
cp $(GOPATH)/bin/mattermost $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
||||||
cp $(GOPATH)/bin/platform $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
cp $(GOPATH)/bin/platform $(DIST_PATH)/bin # from native bin dir, not cross-compiled
|
||||||
else
|
else
|
||||||
|
cp $(GOPATH)/bin/linux_amd64/mattermost $(DIST_PATH)/bin # from cross-compiled bin dir
|
||||||
cp $(GOPATH)/bin/linux_amd64/platform $(DIST_PATH)/bin # from cross-compiled bin dir
|
cp $(GOPATH)/bin/linux_amd64/platform $(DIST_PATH)/bin # from cross-compiled bin dir
|
||||||
endif
|
endif
|
||||||
@# Package
|
@# Package
|
||||||
tar -C dist -czf $(DIST_PATH)-$(BUILD_TYPE_NAME)-linux-amd64.tar.gz mattermost
|
tar -C dist -czf $(DIST_PATH)-$(BUILD_TYPE_NAME)-linux-amd64.tar.gz mattermost
|
||||||
@# Don't clean up native package so dev machines will have an unzipped package available
|
@# Don't clean up native package so dev machines will have an unzipped package available
|
||||||
@#rm -f $(DIST_PATH)/bin/platform
|
@#rm -f $(DIST_PATH)/bin/mattermost
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -128,11 +127,11 @@ func init() {
|
|||||||
ModifyChannelCmd,
|
ModifyChannelCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
cmd.RootCmd.AddCommand(ChannelCmd)
|
RootCmd.AddCommand(ChannelCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createChannelCmdF(command *cobra.Command, args []string) error {
|
func createChannelCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -182,7 +181,7 @@ func createChannelCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeChannelUsersCmdF(command *cobra.Command, args []string) error {
|
func removeChannelUsersCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -207,16 +206,16 @@ func removeChannelUsersCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
func removeUserFromChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
|
func removeUserFromChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
cmd.CommandPrintErrorln("Can't find user '" + userArg + "'")
|
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := a.RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
if err := a.RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addChannelUsersCmdF(command *cobra.Command, args []string) error {
|
func addChannelUsersCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -241,16 +240,16 @@ func addChannelUsersCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
func addUserToChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
|
func addUserToChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
cmd.CommandPrintErrorln("Can't find user '" + userArg + "'")
|
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, err := a.AddUserToChannel(user, channel); err != nil {
|
if _, err := a.AddUserToChannel(user, channel); err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to add '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
CommandPrintErrorln("Unable to add '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func archiveChannelsCmdF(command *cobra.Command, args []string) error {
|
func archiveChannelsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -263,11 +262,11 @@ func archiveChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
channels := getChannelsFromChannelArgs(a, args)
|
channels := getChannelsFromChannelArgs(a, args)
|
||||||
for i, channel := range channels {
|
for i, channel := range channels {
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if result := <-a.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
|
if result := <-a.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to archive channel '" + channel.Name + "' error: " + result.Err.Error())
|
CommandPrintErrorln("Unable to archive channel '" + channel.Name + "' error: " + result.Err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +274,7 @@ func archiveChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func deleteChannelsCmdF(command *cobra.Command, args []string) error {
|
func deleteChannelsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -288,7 +287,7 @@ func deleteChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
confirmFlag, _ := command.Flags().GetBool("confirm")
|
confirmFlag, _ := command.Flags().GetBool("confirm")
|
||||||
if !confirmFlag {
|
if !confirmFlag {
|
||||||
var confirm string
|
var confirm string
|
||||||
cmd.CommandPrettyPrintln("Are you sure you want to delete the channels specified? All data will be permanently deleted? (YES/NO): ")
|
CommandPrettyPrintln("Are you sure you want to delete the channels specified? All data will be permanently deleted? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
@@ -298,13 +297,13 @@ func deleteChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
channels := getChannelsFromChannelArgs(a, args)
|
channels := getChannelsFromChannelArgs(a, args)
|
||||||
for i, channel := range channels {
|
for i, channel := range channels {
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := deleteChannel(a, channel); err != nil {
|
if err := deleteChannel(a, channel); err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + err.Error())
|
CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("Deleted channel '" + channel.Name + "'")
|
CommandPrettyPrintln("Deleted channel '" + channel.Name + "'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,7 +315,7 @@ func deleteChannel(a *app.App, channel *model.Channel) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func moveChannelsCmdF(command *cobra.Command, args []string) error {
|
func moveChannelsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -340,14 +339,14 @@ func moveChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
channels := getChannelsFromChannelArgs(a, args[1:])
|
channels := getChannelsFromChannelArgs(a, args[1:])
|
||||||
for i, channel := range channels {
|
for i, channel := range channels {
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
originTeamID := channel.TeamId
|
originTeamID := channel.TeamId
|
||||||
if err := moveChannel(a, team, channel, user); err != nil {
|
if err := moveChannel(a, team, channel, user); err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to move channel '" + channel.Name + "' error: " + err.Error())
|
CommandPrintErrorln("Unable to move channel '" + channel.Name + "' error: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("Moved channel '" + channel.Name + "' to " + team.Name + "(" + team.Id + ") from " + originTeamID + ".")
|
CommandPrettyPrintln("Moved channel '" + channel.Name + "' to " + team.Name + "(" + team.Id + ") from " + originTeamID + ".")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +367,7 @@ func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *mod
|
|||||||
if webhook.ChannelId == channel.Id {
|
if webhook.ChannelId == channel.Id {
|
||||||
webhook.TeamId = team.Id
|
webhook.TeamId = team.Id
|
||||||
if result := <-a.Srv.Store.Webhook().UpdateIncoming(webhook); result.Err != nil {
|
if result := <-a.Srv.Store.Webhook().UpdateIncoming(webhook); result.Err != nil {
|
||||||
cmd.CommandPrintErrorln("Failed to move incoming webhook '" + webhook.Id + "' to new team.")
|
CommandPrintErrorln("Failed to move incoming webhook '" + webhook.Id + "' to new team.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,7 +380,7 @@ func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *mod
|
|||||||
if webhook.ChannelId == channel.Id {
|
if webhook.ChannelId == channel.Id {
|
||||||
webhook.TeamId = team.Id
|
webhook.TeamId = team.Id
|
||||||
if result := <-a.Srv.Store.Webhook().UpdateOutgoing(webhook); result.Err != nil {
|
if result := <-a.Srv.Store.Webhook().UpdateOutgoing(webhook); result.Err != nil {
|
||||||
cmd.CommandPrintErrorln("Failed to move outgoing webhook '" + webhook.Id + "' to new team.")
|
CommandPrintErrorln("Failed to move outgoing webhook '" + webhook.Id + "' to new team.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,7 +390,7 @@ func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listChannelsCmdF(command *cobra.Command, args []string) error {
|
func listChannelsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -404,19 +403,19 @@ func listChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
teams := getTeamsFromTeamArgs(a, args)
|
teams := getTeamsFromTeamArgs(a, args)
|
||||||
for i, team := range teams {
|
for i, team := range teams {
|
||||||
if team == nil {
|
if team == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if result := <-a.Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
|
if result := <-a.Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to list channels for '" + args[i] + "'")
|
CommandPrintErrorln("Unable to list channels for '" + args[i] + "'")
|
||||||
} else {
|
} else {
|
||||||
channels := result.Data.([]*model.Channel)
|
channels := result.Data.([]*model.Channel)
|
||||||
|
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
if channel.DeleteAt > 0 {
|
if channel.DeleteAt > 0 {
|
||||||
cmd.CommandPrettyPrintln(channel.Name + " (archived)")
|
CommandPrettyPrintln(channel.Name + " (archived)")
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln(channel.Name)
|
CommandPrettyPrintln(channel.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,7 +425,7 @@ func listChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func restoreChannelsCmdF(command *cobra.Command, args []string) error {
|
func restoreChannelsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -439,11 +438,11 @@ func restoreChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
channels := getChannelsFromChannelArgs(a, args)
|
channels := getChannelsFromChannelArgs(a, args)
|
||||||
for i, channel := range channels {
|
for i, channel := range channels {
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if result := <-a.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
|
if result := <-a.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to restore channel '" + args[i] + "'")
|
CommandPrintErrorln("Unable to restore channel '" + args[i] + "'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,7 +450,7 @@ func restoreChannelsCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func modifyChannelCmdF(command *cobra.Command, args []string) error {
|
func modifyChannelCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/api4"
|
"github.com/mattermost/mattermost-server/api4"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -19,13 +18,13 @@ func TestJoinChannel(t *testing.T) {
|
|||||||
|
|
||||||
channel := th.CreatePublicChannel()
|
channel := th.CreatePublicChannel()
|
||||||
|
|
||||||
cmd.CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
||||||
|
|
||||||
// Joining twice should succeed
|
// Joining twice should succeed
|
||||||
cmd.CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
||||||
|
|
||||||
// should fail because channel does not exist
|
// should fail because channel does not exist
|
||||||
require.Error(t, cmd.RunCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name+"asdf", th.BasicUser2.Email))
|
require.Error(t, RunCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name+"asdf", th.BasicUser2.Email))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoveChannel(t *testing.T) {
|
func TestRemoveChannel(t *testing.T) {
|
||||||
@@ -34,15 +33,15 @@ func TestRemoveChannel(t *testing.T) {
|
|||||||
|
|
||||||
channel := th.CreatePublicChannel()
|
channel := th.CreatePublicChannel()
|
||||||
|
|
||||||
cmd.CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
||||||
|
|
||||||
// should fail because channel does not exist
|
// should fail because channel does not exist
|
||||||
require.Error(t, cmd.RunCommand(t, "channel", "remove", th.BasicTeam.Name+":doesnotexist", th.BasicUser2.Email))
|
require.Error(t, RunCommand(t, "channel", "remove", th.BasicTeam.Name+":doesnotexist", th.BasicUser2.Email))
|
||||||
|
|
||||||
cmd.CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
||||||
|
|
||||||
// Leaving twice should succeed
|
// Leaving twice should succeed
|
||||||
cmd.CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
CheckCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMoveChannel(t *testing.T) {
|
func TestMoveChannel(t *testing.T) {
|
||||||
@@ -63,12 +62,12 @@ func TestMoveChannel(t *testing.T) {
|
|||||||
origin := team1.Name + ":" + channel.Name
|
origin := team1.Name + ":" + channel.Name
|
||||||
dest := team2.Name
|
dest := team2.Name
|
||||||
|
|
||||||
cmd.CheckCommand(t, "channel", "add", origin, adminEmail)
|
CheckCommand(t, "channel", "add", origin, adminEmail)
|
||||||
|
|
||||||
// should fail with nill because errors are logged instead of returned when a channel does not exist
|
// should fail with nill because errors are logged instead of returned when a channel does not exist
|
||||||
require.Nil(t, cmd.RunCommand(t, "channel", "move", dest, team1.Name+":doesnotexist", "--username", adminUsername))
|
require.Nil(t, RunCommand(t, "channel", "move", dest, team1.Name+":doesnotexist", "--username", adminUsername))
|
||||||
|
|
||||||
cmd.CheckCommand(t, "channel", "move", dest, origin, "--username", adminUsername)
|
CheckCommand(t, "channel", "move", dest, origin, "--username", adminUsername)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListChannels(t *testing.T) {
|
func TestListChannels(t *testing.T) {
|
||||||
@@ -78,7 +77,7 @@ func TestListChannels(t *testing.T) {
|
|||||||
channel := th.CreatePublicChannel()
|
channel := th.CreatePublicChannel()
|
||||||
th.Client.Must(th.Client.DeleteChannel(channel.Id))
|
th.Client.Must(th.Client.DeleteChannel(channel.Id))
|
||||||
|
|
||||||
output := cmd.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
|
output := CheckCommand(t, "channel", "list", th.BasicTeam.Name)
|
||||||
|
|
||||||
if !strings.Contains(string(output), "town-square") {
|
if !strings.Contains(string(output), "town-square") {
|
||||||
t.Fatal("should have channels")
|
t.Fatal("should have channels")
|
||||||
@@ -96,10 +95,10 @@ func TestRestoreChannel(t *testing.T) {
|
|||||||
channel := th.CreatePublicChannel()
|
channel := th.CreatePublicChannel()
|
||||||
th.Client.Must(th.Client.DeleteChannel(channel.Id))
|
th.Client.Must(th.Client.DeleteChannel(channel.Id))
|
||||||
|
|
||||||
cmd.CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
|
CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
|
||||||
|
|
||||||
// restoring twice should succeed
|
// restoring twice should succeed
|
||||||
cmd.CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
|
CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateChannel(t *testing.T) {
|
func TestCreateChannel(t *testing.T) {
|
||||||
@@ -109,8 +108,8 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
id := model.NewId()
|
id := model.NewId()
|
||||||
name := "name" + id
|
name := "name" + id
|
||||||
|
|
||||||
cmd.CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name)
|
CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name)
|
||||||
|
|
||||||
name = name + "-private"
|
name = name + "-private"
|
||||||
cmd.CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--private", "--name", name)
|
CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--private", "--name", name)
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
package cmd
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -29,11 +28,11 @@ func init() {
|
|||||||
CommandCmd.AddCommand(
|
CommandCmd.AddCommand(
|
||||||
CommandMoveCmd,
|
CommandMoveCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(CommandCmd)
|
RootCmd.AddCommand(CommandCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveCommandCmdF(command *cobra.Command, args []string) error {
|
func moveCommandCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -49,16 +48,16 @@ func moveCommandCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands := getCommandsFromCommandArgs(a, args[1:])
|
commands := getCommandsFromCommandArgs(a, args[1:])
|
||||||
cmd.CommandPrintErrorln(commands)
|
CommandPrintErrorln(commands)
|
||||||
for i, command := range commands {
|
for i, command := range commands {
|
||||||
if command == nil {
|
if command == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find command '" + args[i+1] + "'")
|
CommandPrintErrorln("Unable to find command '" + args[i+1] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := moveCommand(a, team, command); err != nil {
|
if err := moveCommand(a, team, command); err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to move command '" + command.Trigger + "' error: " + err.Error())
|
CommandPrintErrorln("Unable to move command '" + command.Trigger + "' error: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("Moved command '" + command.Trigger + "'")
|
CommandPrettyPrintln("Moved command '" + command.Trigger + "'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -30,7 +29,7 @@ func init() {
|
|||||||
ConfigCmd.AddCommand(
|
ConfigCmd.AddCommand(
|
||||||
ValidateConfigCmd,
|
ValidateConfigCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(ConfigCmd)
|
RootCmd.AddCommand(ConfigCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func configValidateCmdF(command *cobra.Command, args []string) error {
|
func configValidateCmdF(command *cobra.Command, args []string) error {
|
||||||
@@ -63,6 +62,6 @@ func configValidateCmdF(command *cobra.Command, args []string) error {
|
|||||||
return errors.New(utils.T(err.Id))
|
return errors.New(utils.T(err.Id))
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("The document is valid")
|
CommandPrettyPrintln("The document is valid")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,8 +41,8 @@ func TestConfigFlag(t *testing.T) {
|
|||||||
defer os.Chdir(prevDir)
|
defer os.Chdir(prevDir)
|
||||||
os.Chdir(dir)
|
os.Chdir(dir)
|
||||||
|
|
||||||
require.Error(t, cmd.RunCommand(t, "version"))
|
require.Error(t, RunCommand(t, "version"))
|
||||||
cmd.CheckCommand(t, "--config", "foo.json", "version")
|
CheckCommand(t, "--config", "foo.json", "version")
|
||||||
cmd.CheckCommand(t, "--config", "./foo.json", "version")
|
CheckCommand(t, "--config", "./foo.json", "version")
|
||||||
cmd.CheckCommand(t, "--config", configPath, "version")
|
CheckCommand(t, "--config", configPath, "version")
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@@ -26,6 +25,6 @@ func TestConfigValidate(t *testing.T) {
|
|||||||
config.SetDefaults()
|
config.SetDefaults()
|
||||||
require.NoError(t, ioutil.WriteFile(path, []byte(config.ToJson()), 0600))
|
require.NoError(t, ioutil.WriteFile(path, []byte(config.ToJson()), 0600))
|
||||||
|
|
||||||
assert.Error(t, cmd.RunCommand(t, "--config", "foo.json", "config", "validate"))
|
assert.Error(t, RunCommand(t, "--config", "foo.json", "config", "validate"))
|
||||||
assert.NoError(t, cmd.RunCommand(t, "--config", path, "config", "validate"))
|
assert.NoError(t, RunCommand(t, "--config", path, "config", "validate"))
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExecCommand(t *testing.T) {
|
func TestExecCommand(t *testing.T) {
|
||||||
if filter := flag.Lookup("test.run").Value.String(); filter != "ExecCommand" {
|
if filter := flag.Lookup("test.run").Value.String(); filter != "ExecCommand" {
|
||||||
t.Skip("use -run ExecCommand to execute a command via the test executable")
|
t.Skip("use -run ExecCommand to execute a command via the test executable")
|
||||||
}
|
}
|
||||||
cmd.RootCmd.SetArgs(flag.Args())
|
RootCmd.SetArgs(flag.Args())
|
||||||
require.NoError(t, cmd.RootCmd.Execute())
|
require.NoError(t, RootCmd.Execute())
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,11 +42,11 @@ func init() {
|
|||||||
BulkImportCmd,
|
BulkImportCmd,
|
||||||
SlackImportCmd,
|
SlackImportCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(ImportCmd)
|
RootCmd.AddCommand(ImportCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func slackImportCmdF(command *cobra.Command, args []string) error {
|
func slackImportCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -73,17 +72,17 @@ func slackImportCmdF(command *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
|
CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
|
||||||
|
|
||||||
a.SlackImport(fileReader, fileInfo.Size(), team.Id)
|
a.SlackImport(fileReader, fileInfo.Size(), team.Id)
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("Finished Slack Import.")
|
CommandPrettyPrintln("Finished Slack Import.")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func bulkImportCmdF(command *cobra.Command, args []string) error {
|
func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -115,29 +114,29 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
|||||||
defer fileReader.Close()
|
defer fileReader.Close()
|
||||||
|
|
||||||
if apply && validate {
|
if apply && validate {
|
||||||
cmd.CommandPrettyPrintln("Use only one of --apply or --validate.")
|
CommandPrettyPrintln("Use only one of --apply or --validate.")
|
||||||
return nil
|
return nil
|
||||||
} else if apply && !validate {
|
} else if apply && !validate {
|
||||||
cmd.CommandPrettyPrintln("Running Bulk Import. This may take a long time.")
|
CommandPrettyPrintln("Running Bulk Import. This may take a long time.")
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("Running Bulk Import Data Validation.")
|
CommandPrettyPrintln("Running Bulk Import Data Validation.")
|
||||||
cmd.CommandPrettyPrintln("** This checks the validity of the entities in the data file, but does not persist any changes **")
|
CommandPrettyPrintln("** This checks the validity of the entities in the data file, but does not persist any changes **")
|
||||||
cmd.CommandPrettyPrintln("Use the --apply flag to perform the actual data import.")
|
CommandPrettyPrintln("Use the --apply flag to perform the actual data import.")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("")
|
CommandPrettyPrintln("")
|
||||||
|
|
||||||
if err, lineNumber := a.BulkImport(fileReader, !apply, workers); err != nil {
|
if err, lineNumber := a.BulkImport(fileReader, !apply, workers); err != nil {
|
||||||
cmd.CommandPrettyPrintln(err.Error())
|
CommandPrettyPrintln(err.Error())
|
||||||
if lineNumber != 0 {
|
if lineNumber != 0 {
|
||||||
cmd.CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
|
CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
if apply {
|
if apply {
|
||||||
cmd.CommandPrettyPrintln("Finished Bulk Import.")
|
CommandPrettyPrintln("Finished Bulk Import.")
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
|
CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
package cmd
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitDBCommandContextCobra(cmd *cobra.Command) (*app.App, error) {
|
func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
|
||||||
config, err := cmd.Flags().GetString("config")
|
config, err := command.Flags().GetString("config")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/mlog"
|
"github.com/mattermost/mattermost-server/mlog"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -23,7 +22,7 @@ func init() {
|
|||||||
JobserverCmd.Flags().Bool("nojobs", false, "Do not run jobs on this jobserver.")
|
JobserverCmd.Flags().Bool("nojobs", false, "Do not run jobs on this jobserver.")
|
||||||
JobserverCmd.Flags().Bool("noschedule", false, "Do not schedule jobs from this jobserver.")
|
JobserverCmd.Flags().Bool("noschedule", false, "Do not schedule jobs from this jobserver.")
|
||||||
|
|
||||||
cmd.RootCmd.AddCommand(JobserverCmd)
|
RootCmd.AddCommand(JobserverCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func jobserverCmdF(command *cobra.Command, args []string) {
|
func jobserverCmdF(command *cobra.Command, args []string) {
|
||||||
@@ -32,7 +31,7 @@ func jobserverCmdF(command *cobra.Command, args []string) {
|
|||||||
noSchedule, _ := command.Flags().GetBool("noschedule")
|
noSchedule, _ := command.Flags().GetBool("noschedule")
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
a, err := cmd.InitDBCommandContext("config.json")
|
a, err := InitDBCommandContext("config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -36,11 +35,11 @@ func init() {
|
|||||||
LdapSyncCmd,
|
LdapSyncCmd,
|
||||||
LdapIdMigrate,
|
LdapIdMigrate,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(LdapCmd)
|
RootCmd.AddCommand(LdapCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ldapSyncCmdF(command *cobra.Command, args []string) error {
|
func ldapSyncCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -49,9 +48,9 @@ func ldapSyncCmdF(command *cobra.Command, args []string) error {
|
|||||||
if ldapI := a.Ldap; ldapI != nil {
|
if ldapI := a.Ldap; ldapI != nil {
|
||||||
job, err := ldapI.StartSynchronizeJob(true)
|
job, err := ldapI.StartSynchronizeJob(true)
|
||||||
if err != nil || job.Status == model.JOB_STATUS_ERROR || job.Status == model.JOB_STATUS_CANCELED {
|
if err != nil || job.Status == model.JOB_STATUS_ERROR || job.Status == model.JOB_STATUS_CANCELED {
|
||||||
cmd.CommandPrintErrorln("ERROR: AD/LDAP Synchronization please check the server logs")
|
CommandPrintErrorln("ERROR: AD/LDAP Synchronization please check the server logs")
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("SUCCESS: AD/LDAP Synchronization Complete")
|
CommandPrettyPrintln("SUCCESS: AD/LDAP Synchronization Complete")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +58,7 @@ func ldapSyncCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ldapIdMigrateCmdF(command *cobra.Command, args []string) error {
|
func ldapIdMigrateCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -68,9 +67,9 @@ func ldapIdMigrateCmdF(command *cobra.Command, args []string) error {
|
|||||||
toAttribute := args[0]
|
toAttribute := args[0]
|
||||||
if ldapI := a.Ldap; ldapI != nil {
|
if ldapI := a.Ldap; ldapI != nil {
|
||||||
if err := ldapI.MigrateIDAttribute(toAttribute); err != nil {
|
if err := ldapI.MigrateIDAttribute(toAttribute); err != nil {
|
||||||
cmd.CommandPrintErrorln("ERROR: AD/LDAP IdAttribute migration failed! Error: " + err.Error())
|
CommandPrintErrorln("ERROR: AD/LDAP IdAttribute migration failed! Error: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("SUCCESS: AD/LDAP IdAttribute migration complete. You can now change your IdAttribute to: " + toAttribute)
|
CommandPrettyPrintln("SUCCESS: AD/LDAP IdAttribute migration complete. You can now change your IdAttribute to: " + toAttribute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,11 +25,11 @@ var UploadLicenseCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
LicenseCmd.AddCommand(UploadLicenseCmd)
|
LicenseCmd.AddCommand(UploadLicenseCmd)
|
||||||
cmd.RootCmd.AddCommand(LicenseCmd)
|
RootCmd.AddCommand(LicenseCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadLicenseCmdF(command *cobra.Command, args []string) error {
|
func uploadLicenseCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -49,7 +48,7 @@ func uploadLicenseCmdF(command *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("Uploaded license file")
|
CommandPrettyPrintln("Uploaded license file")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -27,11 +26,11 @@ func init() {
|
|||||||
MessageExportCmd.Flags().String("format", "actiance", "The format to export data in")
|
MessageExportCmd.Flags().String("format", "actiance", "The format to export data in")
|
||||||
MessageExportCmd.Flags().Int64("exportFrom", -1, "The timestamp of the earliest post to export, expressed in seconds since the unix epoch.")
|
MessageExportCmd.Flags().Int64("exportFrom", -1, "The timestamp of the earliest post to export, expressed in seconds since the unix epoch.")
|
||||||
MessageExportCmd.Flags().Int("timeoutSeconds", -1, "The maximum number of seconds to wait for the job to complete before timing out.")
|
MessageExportCmd.Flags().Int("timeoutSeconds", -1, "The maximum number of seconds to wait for the job to complete before timing out.")
|
||||||
cmd.RootCmd.AddCommand(MessageExportCmd)
|
RootCmd.AddCommand(MessageExportCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func messageExportCmdF(command *cobra.Command, args []string) error {
|
func messageExportCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -72,9 +71,9 @@ func messageExportCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
job, err := messageExportI.StartSynchronizeJob(ctx, startTime)
|
job, err := messageExportI.StartSynchronizeJob(ctx, startTime)
|
||||||
if err != nil || job.Status == model.JOB_STATUS_ERROR || job.Status == model.JOB_STATUS_CANCELED {
|
if err != nil || job.Status == model.JOB_STATUS_ERROR || job.Status == model.JOB_STATUS_CANCELED {
|
||||||
cmd.CommandPrintErrorln("ERROR: Message export job failed. Please check the server logs")
|
CommandPrintErrorln("ERROR: Message export job failed. Please check the server logs")
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("SUCCESS: Message export job complete")
|
CommandPrettyPrintln("SUCCESS: Message export job complete")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
)
|
)
|
||||||
@@ -25,7 +24,7 @@ func TestMessageExportNotEnabled(t *testing.T) {
|
|||||||
defer os.RemoveAll(filepath.Dir(configPath))
|
defer os.RemoveAll(filepath.Dir(configPath))
|
||||||
|
|
||||||
// should fail fast because the feature isn't enabled
|
// should fail fast because the feature isn't enabled
|
||||||
require.Error(t, cmd.RunCommand(t, "--config", configPath, "export"))
|
require.Error(t, RunCommand(t, "--config", configPath, "export"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageExportInvalidFormat(t *testing.T) {
|
func TestMessageExportInvalidFormat(t *testing.T) {
|
||||||
@@ -33,7 +32,7 @@ func TestMessageExportInvalidFormat(t *testing.T) {
|
|||||||
defer os.RemoveAll(filepath.Dir(configPath))
|
defer os.RemoveAll(filepath.Dir(configPath))
|
||||||
|
|
||||||
// should fail fast because format isn't supported
|
// should fail fast because format isn't supported
|
||||||
require.Error(t, cmd.RunCommand(t, "--config", configPath, "--format", "not_actiance", "export"))
|
require.Error(t, RunCommand(t, "--config", configPath, "--format", "not_actiance", "export"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageExportNegativeExportFrom(t *testing.T) {
|
func TestMessageExportNegativeExportFrom(t *testing.T) {
|
||||||
@@ -41,7 +40,7 @@ func TestMessageExportNegativeExportFrom(t *testing.T) {
|
|||||||
defer os.RemoveAll(filepath.Dir(configPath))
|
defer os.RemoveAll(filepath.Dir(configPath))
|
||||||
|
|
||||||
// should fail fast because export from must be a valid timestamp
|
// should fail fast because export from must be a valid timestamp
|
||||||
require.Error(t, cmd.RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "-1", "export"))
|
require.Error(t, RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "-1", "export"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageExportNegativeTimeoutSeconds(t *testing.T) {
|
func TestMessageExportNegativeTimeoutSeconds(t *testing.T) {
|
||||||
@@ -49,7 +48,7 @@ func TestMessageExportNegativeTimeoutSeconds(t *testing.T) {
|
|||||||
defer os.RemoveAll(filepath.Dir(configPath))
|
defer os.RemoveAll(filepath.Dir(configPath))
|
||||||
|
|
||||||
// should fail fast because timeout seconds must be a positive int
|
// should fail fast because timeout seconds must be a positive int
|
||||||
require.Error(t, cmd.RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "0", "--timeoutSeconds", "-1", "export"))
|
require.Error(t, RunCommand(t, "--config", configPath, "--format", "actiance", "--exportFrom", "0", "--timeoutSeconds", "-1", "export"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTempConfig(t *testing.T, isMessageExportEnabled bool) string {
|
func writeTempConfig(t *testing.T, isMessageExportEnabled bool) string {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
package cmd
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -54,11 +53,11 @@ func init() {
|
|||||||
ExportPermissionsCmd,
|
ExportPermissionsCmd,
|
||||||
ImportPermissionsCmd,
|
ImportPermissionsCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(PermissionsCmd)
|
RootCmd.AddCommand(PermissionsCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetPermissionsCmdF(command *cobra.Command, args []string) error {
|
func resetPermissionsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -66,13 +65,13 @@ func resetPermissionsCmdF(command *cobra.Command, args []string) error {
|
|||||||
confirmFlag, _ := command.Flags().GetBool("confirm")
|
confirmFlag, _ := command.Flags().GetBool("confirm")
|
||||||
if !confirmFlag {
|
if !confirmFlag {
|
||||||
var confirm string
|
var confirm string
|
||||||
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
|
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
}
|
}
|
||||||
cmd.CommandPrettyPrintln("Are you sure you want to reset the permissions system? All data related to the permissions system will be permanently deleted and all users will revert to having the default permissions. (YES/NO): ")
|
CommandPrettyPrintln("Are you sure you want to reset the permissions system? All data related to the permissions system will be permanently deleted and all users will revert to having the default permissions. (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
@@ -83,13 +82,13 @@ func resetPermissionsCmdF(command *cobra.Command, args []string) error {
|
|||||||
return errors.New(err.Error())
|
return errors.New(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("Permissions system successfully reset")
|
CommandPrettyPrintln("Permissions system successfully reset")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportPermissionsCmdF(command *cobra.Command, args []string) error {
|
func exportPermissionsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -107,7 +106,7 @@ func exportPermissionsCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func importPermissionsCmdF(command *cobra.Command, args []string) error {
|
func importPermissionsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,11 +20,11 @@ var ResetCmd = &cobra.Command{
|
|||||||
func init() {
|
func init() {
|
||||||
ResetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.")
|
ResetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.")
|
||||||
|
|
||||||
cmd.RootCmd.AddCommand(ResetCmd)
|
RootCmd.AddCommand(ResetCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetCmdF(command *cobra.Command, args []string) error {
|
func resetCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -34,13 +33,13 @@ func resetCmdF(command *cobra.Command, args []string) error {
|
|||||||
confirmFlag, _ := command.Flags().GetBool("confirm")
|
confirmFlag, _ := command.Flags().GetBool("confirm")
|
||||||
if !confirmFlag {
|
if !confirmFlag {
|
||||||
var confirm string
|
var confirm string
|
||||||
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
|
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
}
|
}
|
||||||
cmd.CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ")
|
CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
@@ -48,7 +47,7 @@ func resetCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a.Srv.Store.DropAllTables()
|
a.Srv.Store.DropAllTables()
|
||||||
cmd.CommandPrettyPrintln("Database successfully reset")
|
CommandPrettyPrintln("Database successfully reset")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,11 +38,11 @@ func init() {
|
|||||||
MakeSystemAdminCmd,
|
MakeSystemAdminCmd,
|
||||||
MakeMemberCmd,
|
MakeMemberCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(RolesCmd)
|
RootCmd.AddCommand(RolesCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeSystemAdminCmdF(command *cobra.Command, args []string) error {
|
func makeSystemAdminCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -88,7 +87,7 @@ func makeSystemAdminCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeMemberCmdF(command *cobra.Command, args []string) error {
|
func makeMemberCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/api4"
|
"github.com/mattermost/mattermost-server/api4"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,7 +14,7 @@ func TestAssignRole(t *testing.T) {
|
|||||||
th := api4.Setup().InitBasic()
|
th := api4.Setup().InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
cmd.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
|
CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
|
||||||
|
|
||||||
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
|
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
@@ -26,7 +25,7 @@ func TestAssignRole(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CheckCommand(t, "roles", "member", th.BasicUser.Email)
|
CheckCommand(t, "roles", "member", th.BasicUser.Email)
|
||||||
|
|
||||||
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
|
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
package cmd
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -23,4 +23,6 @@ var RootCmd = &cobra.Command{
|
|||||||
func init() {
|
func init() {
|
||||||
RootCmd.PersistentFlags().StringP("config", "c", "config.json", "Configuration file to use.")
|
RootCmd.PersistentFlags().StringP("config", "c", "config.json", "Configuration file to use.")
|
||||||
RootCmd.PersistentFlags().Bool("disableconfigwatch", false, "When set config.json will not be loaded from disk when the file is changed.")
|
RootCmd.PersistentFlags().Bool("disableconfigwatch", false, "When set config.json will not be loaded from disk when the file is changed.")
|
||||||
|
RootCmd.PersistentFlags().Bool("platform", false, "This flag signifies that the user tried to start the command from the platform binary, so we can log a mssage")
|
||||||
|
RootCmd.PersistentFlags().MarkHidden("platform")
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
|
|
||||||
"github.com/icrowley/fake"
|
"github.com/icrowley/fake"
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,7 +41,7 @@ func init() {
|
|||||||
SampleDataCmd.Flags().IntP("workers", "w", 2, "How many workers to run during the import.")
|
SampleDataCmd.Flags().IntP("workers", "w", 2, "How many workers to run during the import.")
|
||||||
SampleDataCmd.Flags().String("profile-images", "", "Optional. Path to folder with images to randomly pick as user profile image.")
|
SampleDataCmd.Flags().String("profile-images", "", "Optional. Path to folder with images to randomly pick as user profile image.")
|
||||||
SampleDataCmd.Flags().StringP("bulk", "b", "", "Optional. Path to write a JSONL bulk file instead of loading into the database.")
|
SampleDataCmd.Flags().StringP("bulk", "b", "", "Optional. Path to write a JSONL bulk file instead of loading into the database.")
|
||||||
cmd.RootCmd.AddCommand(SampleDataCmd)
|
RootCmd.AddCommand(SampleDataCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sliceIncludes(vs []string, t string) bool {
|
func sliceIncludes(vs []string, t string) bool {
|
||||||
@@ -130,7 +129,7 @@ func randomMessage(users []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sampleDataCmdF(command *cobra.Command, args []string) error {
|
func sampleDataCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/api4"
|
"github.com/mattermost/mattermost-server/api4"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,11 +15,11 @@ func TestSampledataBadParameters(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
// should fail because you need at least 1 worker
|
// should fail because you need at least 1 worker
|
||||||
require.Error(t, cmd.RunCommand(t, "sampledata", "--workers", "0"))
|
require.Error(t, RunCommand(t, "sampledata", "--workers", "0"))
|
||||||
|
|
||||||
// should fail because you have more team memberships than teams
|
// should fail because you have more team memberships than teams
|
||||||
require.Error(t, cmd.RunCommand(t, "sampledata", "--teams", "10", "--teams-memberships", "11"))
|
require.Error(t, RunCommand(t, "sampledata", "--teams", "10", "--teams-memberships", "11"))
|
||||||
|
|
||||||
// should fail because you have more channel memberships than channels per team
|
// should fail because you have more channel memberships than channels per team
|
||||||
require.Error(t, cmd.RunCommand(t, "sampledata", "--channels-per-team", "10", "--channel-memberships", "11"))
|
require.Error(t, RunCommand(t, "sampledata", "--channels-per-team", "10", "--channel-memberships", "11"))
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
"github.com/mattermost/mattermost-server/api4"
|
"github.com/mattermost/mattermost-server/api4"
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/manualtesting"
|
"github.com/mattermost/mattermost-server/manualtesting"
|
||||||
"github.com/mattermost/mattermost-server/mlog"
|
"github.com/mattermost/mattermost-server/mlog"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
@@ -37,8 +36,8 @@ var serverCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmd.RootCmd.AddCommand(serverCmd)
|
RootCmd.AddCommand(serverCmd)
|
||||||
cmd.RootCmd.RunE = serverCmdF
|
RootCmd.RunE = serverCmdF
|
||||||
}
|
}
|
||||||
|
|
||||||
func serverCmdF(command *cobra.Command, args []string) error {
|
func serverCmdF(command *cobra.Command, args []string) error {
|
||||||
@@ -48,12 +47,13 @@ func serverCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disableConfigWatch, _ := command.Flags().GetBool("disableconfigwatch")
|
disableConfigWatch, _ := command.Flags().GetBool("disableconfigwatch")
|
||||||
|
usedPlatform, _ := command.Flags().GetBool("platform")
|
||||||
|
|
||||||
interruptChan := make(chan os.Signal, 1)
|
interruptChan := make(chan os.Signal, 1)
|
||||||
return runServer(config, disableConfigWatch, interruptChan)
|
return runServer(config, disableConfigWatch, usedPlatform, interruptChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runServer(configFileLocation string, disableConfigWatch bool, interruptChan chan os.Signal) error {
|
func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform bool, interruptChan chan os.Signal) error {
|
||||||
options := []app.Option{app.ConfigFile(configFileLocation)}
|
options := []app.Option{app.ConfigFile(configFileLocation)}
|
||||||
if disableConfigWatch {
|
if disableConfigWatch {
|
||||||
options = append(options, app.DisableConfigWatch)
|
options = append(options, app.DisableConfigWatch)
|
||||||
@@ -69,6 +69,9 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan
|
|||||||
utils.TestConnection(a.Config())
|
utils.TestConnection(a.Config())
|
||||||
|
|
||||||
pwd, _ := os.Getwd()
|
pwd, _ := os.Getwd()
|
||||||
|
if usedPlatform {
|
||||||
|
mlog.Error("The platform binary has been deprecated, please switch to using the mattermost binary.")
|
||||||
|
}
|
||||||
mlog.Info(fmt.Sprintf("Current version is %v (%v/%v/%v/%v)", model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise))
|
mlog.Info(fmt.Sprintf("Current version is %v (%v/%v/%v/%v)", model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise))
|
||||||
mlog.Info(fmt.Sprintf("Enterprise Enabled: %v", model.BuildEnterpriseReady))
|
mlog.Info(fmt.Sprintf("Enterprise Enabled: %v", model.BuildEnterpriseReady))
|
||||||
mlog.Info(fmt.Sprintf("Current working directory is %v", pwd))
|
mlog.Info(fmt.Sprintf("Current working directory is %v", pwd))
|
||||||
@@ -52,7 +52,7 @@ func TestRunServerSuccess(t *testing.T) {
|
|||||||
th := SetupServerTest()
|
th := SetupServerTest()
|
||||||
defer th.TearDownServerTest()
|
defer th.TearDownServerTest()
|
||||||
|
|
||||||
err := runServer(th.configPath, th.disableConfigWatch, th.interruptChan)
|
err := runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ func TestRunServerInvalidConfigFile(t *testing.T) {
|
|||||||
os.Chmod(unreadableConfigFile.Name(), 0200)
|
os.Chmod(unreadableConfigFile.Name(), 0200)
|
||||||
defer os.Remove(unreadableConfigFile.Name())
|
defer os.Remove(unreadableConfigFile.Name())
|
||||||
|
|
||||||
err = runServer(unreadableConfigFile.Name(), th.disableConfigWatch, th.interruptChan)
|
err = runServer(unreadableConfigFile.Name(), th.disableConfigWatch, false, th.interruptChan)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ func TestRunServerSystemdNotification(t *testing.T) {
|
|||||||
}(socketReader)
|
}(socketReader)
|
||||||
|
|
||||||
// Start and stop the server
|
// Start and stop the server
|
||||||
err = runServer(th.configPath, th.disableConfigWatch, th.interruptChan)
|
err = runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Ensure the notification has been sent on the socket and is correct
|
// Ensure the notification has been sent on the socket and is correct
|
||||||
@@ -131,6 +131,6 @@ func TestRunServerNoSystemd(t *testing.T) {
|
|||||||
os.Unsetenv("NOTIFY_SOCKET")
|
os.Unsetenv("NOTIFY_SOCKET")
|
||||||
defer os.Setenv("NOTIFY_SOCKET", originalSocket)
|
defer os.Setenv("NOTIFY_SOCKET", originalSocket)
|
||||||
|
|
||||||
err := runServer(th.configPath, th.disableConfigWatch, th.interruptChan)
|
err := runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -75,11 +74,11 @@ func init() {
|
|||||||
DeleteTeamsCmd,
|
DeleteTeamsCmd,
|
||||||
ListTeamsCmd,
|
ListTeamsCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(TeamCmd)
|
RootCmd.AddCommand(TeamCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTeamCmdF(command *cobra.Command, args []string) error {
|
func createTeamCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -116,7 +115,7 @@ func createTeamCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeUsersCmdF(command *cobra.Command, args []string) error {
|
func removeUsersCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -141,16 +140,16 @@ func removeUsersCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
func removeUserFromTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
|
func removeUserFromTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
cmd.CommandPrintErrorln("Can't find user '" + userArg + "'")
|
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := a.LeaveTeam(team, user, ""); err != nil {
|
if err := a.LeaveTeam(team, user, ""); err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error())
|
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addUsersCmdF(command *cobra.Command, args []string) error {
|
func addUsersCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -175,16 +174,16 @@ func addUsersCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
func addUserToTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
|
func addUserToTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
cmd.CommandPrintErrorln("Can't find user '" + userArg + "'")
|
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := a.JoinUserToTeam(team, user, ""); err != nil {
|
if err := a.JoinUserToTeam(team, user, ""); err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to add '" + userArg + "' to " + team.Name)
|
CommandPrintErrorln("Unable to add '" + userArg + "' to " + team.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteTeamsCmdF(command *cobra.Command, args []string) error {
|
func deleteTeamsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -197,13 +196,13 @@ func deleteTeamsCmdF(command *cobra.Command, args []string) error {
|
|||||||
confirmFlag, _ := command.Flags().GetBool("confirm")
|
confirmFlag, _ := command.Flags().GetBool("confirm")
|
||||||
if !confirmFlag {
|
if !confirmFlag {
|
||||||
var confirm string
|
var confirm string
|
||||||
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
|
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
}
|
}
|
||||||
cmd.CommandPrettyPrintln("Are you sure you want to delete the teams specified? All data will be permanently deleted? (YES/NO): ")
|
CommandPrettyPrintln("Are you sure you want to delete the teams specified? All data will be permanently deleted? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
@@ -213,13 +212,13 @@ func deleteTeamsCmdF(command *cobra.Command, args []string) error {
|
|||||||
teams := getTeamsFromTeamArgs(a, args)
|
teams := getTeamsFromTeamArgs(a, args)
|
||||||
for i, team := range teams {
|
for i, team := range teams {
|
||||||
if team == nil {
|
if team == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := deleteTeam(a, team); err != nil {
|
if err := deleteTeam(a, team); err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to delete team '" + team.Name + "' error: " + err.Error())
|
CommandPrintErrorln("Unable to delete team '" + team.Name + "' error: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
cmd.CommandPrettyPrintln("Deleted team '" + team.Name + "'")
|
CommandPrettyPrintln("Deleted team '" + team.Name + "'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +230,7 @@ func deleteTeam(a *app.App, team *model.Team) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listTeamsCmdF(command *cobra.Command, args []string) error {
|
func listTeamsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -243,7 +242,7 @@ func listTeamsCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, team := range teams {
|
for _, team := range teams {
|
||||||
cmd.CommandPrettyPrintln(team.Name)
|
CommandPrettyPrintln(team.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/api4"
|
"github.com/mattermost/mattermost-server/api4"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ func TestCreateTeam(t *testing.T) {
|
|||||||
name := "name" + id
|
name := "name" + id
|
||||||
displayName := "Name " + id
|
displayName := "Name " + id
|
||||||
|
|
||||||
cmd.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
|
CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
|
||||||
|
|
||||||
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
|
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
|
||||||
|
|
||||||
@@ -33,7 +32,7 @@ func TestJoinTeam(t *testing.T) {
|
|||||||
th := api4.Setup().InitSystemAdmin().InitBasic()
|
th := api4.Setup().InitSystemAdmin().InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
cmd.CheckCommand(t, "team", "add", th.BasicTeam.Name, th.BasicUser.Email)
|
CheckCommand(t, "team", "add", th.BasicTeam.Name, th.BasicUser.Email)
|
||||||
|
|
||||||
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ func TestLeaveTeam(t *testing.T) {
|
|||||||
th := api4.Setup().InitBasic()
|
th := api4.Setup().InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
cmd.CheckCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email)
|
CheckCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email)
|
||||||
|
|
||||||
profiles := th.Client.Must(th.Client.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
profiles := th.Client.Must(th.Client.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
||||||
|
|
||||||
@@ -88,9 +87,9 @@ func TestListTeams(t *testing.T) {
|
|||||||
name := "name" + id
|
name := "name" + id
|
||||||
displayName := "Name " + id
|
displayName := "Name " + id
|
||||||
|
|
||||||
cmd.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
|
CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
|
||||||
|
|
||||||
output := cmd.CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
|
output := CheckCommand(t, "team", "list", th.BasicTeam.Name, th.BasicUser.Email)
|
||||||
|
|
||||||
if !strings.Contains(string(output), name) {
|
if !strings.Contains(string(output), name) {
|
||||||
t.Fatal("should have the created team")
|
t.Fatal("should have the created team")
|
||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/api4"
|
"github.com/mattermost/mattermost-server/api4"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
"github.com/mattermost/mattermost-server/wsapi"
|
"github.com/mattermost/mattermost-server/wsapi"
|
||||||
@@ -43,11 +42,11 @@ func init() {
|
|||||||
RunWebClientTestsCmd,
|
RunWebClientTestsCmd,
|
||||||
RunServerForWebClientTestsCmd,
|
RunServerForWebClientTestsCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(TestCmd)
|
RootCmd.AddCommand(TestCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func webClientTestsCmdF(command *cobra.Command, args []string) error {
|
func webClientTestsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -68,7 +67,7 @@ func webClientTestsCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error {
|
func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -103,14 +102,14 @@ func setupClientTests(cfg *model.Config) {
|
|||||||
func executeTestCommand(command *exec.Cmd) {
|
func executeTestCommand(command *exec.Cmd) {
|
||||||
cmdOutPipe, err := command.StdoutPipe()
|
cmdOutPipe, err := command.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.CommandPrintErrorln("Failed to run tests")
|
CommandPrintErrorln("Failed to run tests")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdErrOutPipe, err := command.StderrPipe()
|
cmdErrOutPipe, err := command.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.CommandPrintErrorln("Failed to run tests")
|
CommandPrintErrorln("Failed to run tests")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -130,7 +129,7 @@ func executeTestCommand(command *exec.Cmd) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if err := command.Run(); err != nil {
|
if err := command.Run(); err != nil {
|
||||||
cmd.CommandPrintErrorln("Client Tests failed")
|
CommandPrintErrorln("Client Tests failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -104,7 +103,7 @@ var MigrateAuthCmd = &cobra.Command{
|
|||||||
Short: "Mass migrate user accounts authentication type",
|
Short: "Mass migrate user accounts authentication type",
|
||||||
Long: `Migrates accounts from one authentication provider to another. For example, you can upgrade your authentication provider from email to ldap.`,
|
Long: `Migrates accounts from one authentication provider to another. For example, you can upgrade your authentication provider from email to ldap.`,
|
||||||
Example: " user migrate_auth email saml users.json",
|
Example: " user migrate_auth email saml users.json",
|
||||||
Args: func(cmd *cobra.Command, args []string) error {
|
Args: func(command *cobra.Command, args []string) error {
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
return errors.New("Auth migration requires at least 2 arguments.")
|
return errors.New("Auth migration requires at least 2 arguments.")
|
||||||
}
|
}
|
||||||
@@ -119,7 +118,7 @@ var MigrateAuthCmd = &cobra.Command{
|
|||||||
return errors.New("Ldap migration requires 3 arguments.")
|
return errors.New("Ldap migration requires 3 arguments.")
|
||||||
}
|
}
|
||||||
|
|
||||||
autoFlag, _ := cmd.Flags().GetBool("auto")
|
autoFlag, _ := command.Flags().GetBool("auto")
|
||||||
|
|
||||||
if toAuth == "saml" && autoFlag {
|
if toAuth == "saml" && autoFlag {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
@@ -245,11 +244,11 @@ Global Flags:
|
|||||||
VerifyUserCmd,
|
VerifyUserCmd,
|
||||||
SearchUserCmd,
|
SearchUserCmd,
|
||||||
)
|
)
|
||||||
cmd.RootCmd.AddCommand(UserCmd)
|
RootCmd.AddCommand(UserCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func userActivateCmdF(command *cobra.Command, args []string) error {
|
func userActivateCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -270,7 +269,7 @@ func changeUsersActiveStatus(a *app.App, userArgs []string, active bool) {
|
|||||||
err := changeUserActiveStatus(a, user, userArgs[i], active)
|
err := changeUserActiveStatus(a, user, userArgs[i], active)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.CommandPrintErrorln(err.Error())
|
CommandPrintErrorln(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,7 +289,7 @@ func changeUserActiveStatus(a *app.App, user *model.User, userArg string, activa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func userDeactivateCmdF(command *cobra.Command, args []string) error {
|
func userDeactivateCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -306,7 +305,7 @@ func userDeactivateCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func userCreateCmdF(command *cobra.Command, args []string) error {
|
func userCreateCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -346,13 +345,13 @@ func userCreateCmdF(command *cobra.Command, args []string) error {
|
|||||||
a.UpdateUserRoles(ruser.Id, "system_user system_admin", false)
|
a.UpdateUserRoles(ruser.Id, "system_user system_admin", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("Created User")
|
CommandPrettyPrintln("Created User")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func userInviteCmdF(command *cobra.Command, args []string) error {
|
func userInviteCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -372,7 +371,7 @@ func userInviteCmdF(command *cobra.Command, args []string) error {
|
|||||||
err := inviteUser(a, email, team, args[i+1])
|
err := inviteUser(a, email, team, args[i+1])
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.CommandPrintErrorln(err.Error())
|
CommandPrintErrorln(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,13 +385,13 @@ func inviteUser(a *app.App, email string, team *model.Team, teamArg string) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
a.SendInviteEmails(team, "Administrator", invites, *a.Config().ServiceSettings.SiteURL)
|
a.SendInviteEmails(team, "Administrator", invites, *a.Config().ServiceSettings.SiteURL)
|
||||||
cmd.CommandPrettyPrintln("Invites may or may not have been sent.")
|
CommandPrettyPrintln("Invites may or may not have been sent.")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetUserPasswordCmdF(command *cobra.Command, args []string) error {
|
func resetUserPasswordCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -416,7 +415,7 @@ func resetUserPasswordCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateUserEmailCmdF(command *cobra.Command, args []string) error {
|
func updateUserEmailCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -451,7 +450,7 @@ func updateUserEmailCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resetUserMfaCmdF(command *cobra.Command, args []string) error {
|
func resetUserMfaCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -477,7 +476,7 @@ func resetUserMfaCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func deleteUserCmdF(command *cobra.Command, args []string) error {
|
func deleteUserCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -490,13 +489,13 @@ func deleteUserCmdF(command *cobra.Command, args []string) error {
|
|||||||
confirmFlag, _ := command.Flags().GetBool("confirm")
|
confirmFlag, _ := command.Flags().GetBool("confirm")
|
||||||
if !confirmFlag {
|
if !confirmFlag {
|
||||||
var confirm string
|
var confirm string
|
||||||
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
|
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
}
|
}
|
||||||
cmd.CommandPrettyPrintln("Are you sure you want to permanently delete the specified users? (YES/NO): ")
|
CommandPrettyPrintln("Are you sure you want to permanently delete the specified users? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
@@ -519,7 +518,7 @@ func deleteUserCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func deleteAllUsersCommandF(command *cobra.Command, args []string) error {
|
func deleteAllUsersCommandF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -532,13 +531,13 @@ func deleteAllUsersCommandF(command *cobra.Command, args []string) error {
|
|||||||
confirmFlag, _ := command.Flags().GetBool("confirm")
|
confirmFlag, _ := command.Flags().GetBool("confirm")
|
||||||
if !confirmFlag {
|
if !confirmFlag {
|
||||||
var confirm string
|
var confirm string
|
||||||
cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
|
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
}
|
}
|
||||||
cmd.CommandPrettyPrintln("Are you sure you want to permanently delete all user accounts? (YES/NO): ")
|
CommandPrettyPrintln("Are you sure you want to permanently delete all user accounts? (YES/NO): ")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
|
||||||
@@ -549,7 +548,7 @@ func deleteAllUsersCommandF(command *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("All user accounts successfully deleted.")
|
CommandPrettyPrintln("All user accounts successfully deleted.")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -562,7 +561,7 @@ func migrateAuthCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func migrateAuthToLdapCmdF(command *cobra.Command, args []string) error {
|
func migrateAuthToLdapCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -592,14 +591,14 @@ func migrateAuthToLdapCmdF(command *cobra.Command, args []string) error {
|
|||||||
return errors.New("Error while migrating users: " + err.Error())
|
return errors.New("Error while migrating users: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("Successfully migrated accounts.")
|
CommandPrettyPrintln("Successfully migrated accounts.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func migrateAuthToSamlCmdF(command *cobra.Command, args []string) error {
|
func migrateAuthToSamlCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -630,7 +629,7 @@ func migrateAuthToSamlCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
if autoFlag && !dryRunFlag {
|
if autoFlag && !dryRunFlag {
|
||||||
var confirm string
|
var confirm string
|
||||||
cmd.CommandPrettyPrintln("You are about to perform an automatic \"" + fromAuth + " to saml\" migration. This must only be done if your current Mattermost users with " + fromAuth + " auth have the same username and email in your SAML service. Otherwise, provide the usernames and emails from your SAML Service using the \"users file\" without the \"--auto\" option.\n\nDo you want to proceed with automatic migration anyway? (YES/NO):")
|
CommandPrettyPrintln("You are about to perform an automatic \"" + fromAuth + " to saml\" migration. This must only be done if your current Mattermost users with " + fromAuth + " auth have the same username and email in your SAML service. Otherwise, provide the usernames and emails from your SAML Service using the \"users file\" without the \"--auto\" option.\n\nDo you want to proceed with automatic migration anyway? (YES/NO):")
|
||||||
fmt.Scanln(&confirm)
|
fmt.Scanln(&confirm)
|
||||||
|
|
||||||
if confirm != "YES" {
|
if confirm != "YES" {
|
||||||
@@ -648,14 +647,14 @@ func migrateAuthToSamlCmdF(command *cobra.Command, args []string) error {
|
|||||||
return errors.New("Error while migrating users: " + err.Error())
|
return errors.New("Error while migrating users: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("Successfully migrated accounts.")
|
CommandPrettyPrintln("Successfully migrated accounts.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyUserCmdF(command *cobra.Command, args []string) error {
|
func verifyUserCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -669,11 +668,11 @@ func verifyUserCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
for i, user := range users {
|
for i, user := range users {
|
||||||
if user == nil {
|
if user == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find user '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find user '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if cresult := <-a.Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil {
|
if cresult := <-a.Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil {
|
||||||
cmd.CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error())
|
CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,7 +680,7 @@ func verifyUserCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func searchUserCmdF(command *cobra.Command, args []string) error {
|
func searchUserCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -695,21 +694,21 @@ func searchUserCmdF(command *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
for i, user := range users {
|
for i, user := range users {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
cmd.CommandPrettyPrintln("------------------------------")
|
CommandPrettyPrintln("------------------------------")
|
||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
cmd.CommandPrintErrorln("Unable to find user '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find user '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandPrettyPrintln("id: " + user.Id)
|
CommandPrettyPrintln("id: " + user.Id)
|
||||||
cmd.CommandPrettyPrintln("username: " + user.Username)
|
CommandPrettyPrintln("username: " + user.Username)
|
||||||
cmd.CommandPrettyPrintln("nickname: " + user.Nickname)
|
CommandPrettyPrintln("nickname: " + user.Nickname)
|
||||||
cmd.CommandPrettyPrintln("position: " + user.Position)
|
CommandPrettyPrintln("position: " + user.Position)
|
||||||
cmd.CommandPrettyPrintln("first_name: " + user.FirstName)
|
CommandPrettyPrintln("first_name: " + user.FirstName)
|
||||||
cmd.CommandPrettyPrintln("last_name: " + user.LastName)
|
CommandPrettyPrintln("last_name: " + user.LastName)
|
||||||
cmd.CommandPrettyPrintln("email: " + user.Email)
|
CommandPrettyPrintln("email: " + user.Email)
|
||||||
cmd.CommandPrettyPrintln("auth_service: " + user.AuthService)
|
CommandPrettyPrintln("auth_service: " + user.AuthService)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/api4"
|
"github.com/mattermost/mattermost-server/api4"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -20,9 +19,9 @@ func TestCreateUserWithTeam(t *testing.T) {
|
|||||||
email := "success+" + id + "@simulator.amazonses.com"
|
email := "success+" + id + "@simulator.amazonses.com"
|
||||||
username := "name" + id
|
username := "name" + id
|
||||||
|
|
||||||
cmd.CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
|
CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
|
||||||
|
|
||||||
cmd.CheckCommand(t, "team", "add", th.BasicTeam.Id, email)
|
CheckCommand(t, "team", "add", th.BasicTeam.Id, email)
|
||||||
|
|
||||||
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ func TestCreateUserWithoutTeam(t *testing.T) {
|
|||||||
email := "success+" + id + "@simulator.amazonses.com"
|
email := "success+" + id + "@simulator.amazonses.com"
|
||||||
username := "name" + id
|
username := "name" + id
|
||||||
|
|
||||||
cmd.CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
|
CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
|
||||||
|
|
||||||
if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil {
|
if result := <-th.App.Srv.Store.User().GetByEmail(email); result.Err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
@@ -64,7 +63,7 @@ func TestResetPassword(t *testing.T) {
|
|||||||
th := api4.Setup().InitBasic()
|
th := api4.Setup().InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
cmd.CheckCommand(t, "user", "password", th.BasicUser.Email, "password2")
|
CheckCommand(t, "user", "password", th.BasicUser.Email, "password2")
|
||||||
|
|
||||||
th.Client.Logout()
|
th.Client.Logout()
|
||||||
th.BasicUser.Password = "password2"
|
th.BasicUser.Password = "password2"
|
||||||
@@ -76,10 +75,10 @@ func TestMakeUserActiveAndInactive(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
// first inactivate the user
|
// first inactivate the user
|
||||||
cmd.CheckCommand(t, "user", "deactivate", th.BasicUser.Email)
|
CheckCommand(t, "user", "deactivate", th.BasicUser.Email)
|
||||||
|
|
||||||
// activate the inactive user
|
// activate the inactive user
|
||||||
cmd.CheckCommand(t, "user", "activate", th.BasicUser.Email)
|
CheckCommand(t, "user", "activate", th.BasicUser.Email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChangeUserEmail(t *testing.T) {
|
func TestChangeUserEmail(t *testing.T) {
|
||||||
@@ -88,7 +87,7 @@ func TestChangeUserEmail(t *testing.T) {
|
|||||||
|
|
||||||
newEmail := model.NewId() + "@mattermost-test.com"
|
newEmail := model.NewId() + "@mattermost-test.com"
|
||||||
|
|
||||||
cmd.CheckCommand(t, "user", "email", th.BasicUser.Username, newEmail)
|
CheckCommand(t, "user", "email", th.BasicUser.Username, newEmail)
|
||||||
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err == nil {
|
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err == nil {
|
||||||
t.Fatal("should've updated to the new email")
|
t.Fatal("should've updated to the new email")
|
||||||
}
|
}
|
||||||
@@ -102,21 +101,21 @@ func TestChangeUserEmail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// should fail because using an invalid email
|
// should fail because using an invalid email
|
||||||
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, "wrong$email.com"))
|
require.Error(t, RunCommand(t, "user", "email", th.BasicUser.Username, "wrong$email.com"))
|
||||||
|
|
||||||
// should fail because missing one parameter
|
// should fail because missing one parameter
|
||||||
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username))
|
require.Error(t, RunCommand(t, "user", "email", th.BasicUser.Username))
|
||||||
|
|
||||||
// should fail because missing both parameters
|
// should fail because missing both parameters
|
||||||
require.Error(t, cmd.RunCommand(t, "user", "email"))
|
require.Error(t, RunCommand(t, "user", "email"))
|
||||||
|
|
||||||
// should fail because have more than 2 parameters
|
// should fail because have more than 2 parameters
|
||||||
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, "new@email.com", "extra!"))
|
require.Error(t, RunCommand(t, "user", "email", th.BasicUser.Username, "new@email.com", "extra!"))
|
||||||
|
|
||||||
// should fail because user not found
|
// should fail because user not found
|
||||||
require.Error(t, cmd.RunCommand(t, "user", "email", "invalidUser", newEmail))
|
require.Error(t, RunCommand(t, "user", "email", "invalidUser", newEmail))
|
||||||
|
|
||||||
// should fail because email already in use
|
// should fail because email already in use
|
||||||
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, th.BasicUser2.Email))
|
require.Error(t, RunCommand(t, "user", "email", th.BasicUser.Username, th.BasicUser2.Email))
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/store"
|
"github.com/mattermost/mattermost-server/store"
|
||||||
"github.com/mattermost/mattermost-server/store/sqlstore"
|
"github.com/mattermost/mattermost-server/store/sqlstore"
|
||||||
@@ -19,11 +18,11 @@ var VersionCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmd.RootCmd.AddCommand(VersionCmd)
|
RootCmd.AddCommand(VersionCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func versionCmdF(command *cobra.Command, args []string) error {
|
func versionCmdF(command *cobra.Command, args []string) error {
|
||||||
a, err := cmd.InitDBCommandContextCobra(command)
|
a, err := InitDBCommandContextCobra(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -34,12 +33,12 @@ func versionCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printVersion(a *app.App) {
|
func printVersion(a *app.App) {
|
||||||
cmd.CommandPrintln("Version: " + model.CurrentVersion)
|
CommandPrintln("Version: " + model.CurrentVersion)
|
||||||
cmd.CommandPrintln("Build Number: " + model.BuildNumber)
|
CommandPrintln("Build Number: " + model.BuildNumber)
|
||||||
cmd.CommandPrintln("Build Date: " + model.BuildDate)
|
CommandPrintln("Build Date: " + model.BuildDate)
|
||||||
cmd.CommandPrintln("Build Hash: " + model.BuildHash)
|
CommandPrintln("Build Hash: " + model.BuildHash)
|
||||||
cmd.CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady)
|
CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady)
|
||||||
if supplier, ok := a.Srv.Store.(*store.LayeredStore).DatabaseLayer.(*sqlstore.SqlSupplier); ok {
|
if supplier, ok := a.Srv.Store.(*store.LayeredStore).DatabaseLayer.(*sqlstore.SqlSupplier); ok {
|
||||||
cmd.CommandPrintln("DB Version: " + supplier.GetCurrentSchemaVersion())
|
CommandPrintln("DB Version: " + supplier.GetCurrentSchemaVersion())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,8 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVersion(t *testing.T) {
|
func TestVersion(t *testing.T) {
|
||||||
cmd.CheckCommand(t, "version")
|
CheckCommand(t, "version")
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/cmd"
|
"github.com/mattermost/mattermost-server/cmd/mattermost/commands"
|
||||||
_ "github.com/mattermost/mattermost-server/cmd/commands"
|
|
||||||
|
|
||||||
// Plugins
|
// Plugins
|
||||||
_ "github.com/mattermost/mattermost-server/model/gitlab"
|
_ "github.com/mattermost/mattermost-server/model/gitlab"
|
||||||
@@ -28,7 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := cmd.Run(os.Args[1:]); err != nil {
|
if err := commands.Run(os.Args[1:]); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
39
cmd/platform/main.go
Обычный файл
39
cmd/platform/main.go
Обычный файл
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func findMattermostBinary() string {
|
||||||
|
for _, file := range []string{"./mattermost", "../mattermost", "./bin/mattermost"} {
|
||||||
|
path, _ := filepath.Abs(file)
|
||||||
|
if stat, err := os.Stat(path); err == nil && !stat.IsDir() {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "./mattermost"
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Print angry message to use mattermost command directly
|
||||||
|
fmt.Println(`
|
||||||
|
------------------------------------ ERROR ------------------------------------------------
|
||||||
|
The platform binary has been deprecated, please switch to using the new mattermost binary.
|
||||||
|
The platform binary will be removed in a future version.
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
`)
|
||||||
|
|
||||||
|
// Execve the real MM binary
|
||||||
|
args := os.Args
|
||||||
|
args[0] = "mattermost"
|
||||||
|
args = append(args, "--platform")
|
||||||
|
if err := syscall.Exec(findMattermostBinary(), args, nil); err != nil {
|
||||||
|
fmt.Println("Could not start Mattermost, use the mattermost command directly.")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,7 +41,7 @@ func FindConfigFile(fileName string) (path string) {
|
|||||||
return fileName
|
return fileName
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, dir := range []string{"./config", "../config", "../../config", "."} {
|
for _, dir := range []string{"./config", "../config", "../../config", "../../../config", "."} {
|
||||||
path, _ := filepath.Abs(filepath.Join(dir, fileName))
|
path, _ := filepath.Abs(filepath.Join(dir, fileName))
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
return path
|
return path
|
||||||
@@ -53,7 +53,7 @@ func FindConfigFile(fileName string) (path string) {
|
|||||||
|
|
||||||
// FindDir looks for the given directory in nearby ancestors, falling back to `./` if not found.
|
// FindDir looks for the given directory in nearby ancestors, falling back to `./` if not found.
|
||||||
func FindDir(dir string) (string, bool) {
|
func FindDir(dir string) (string, bool) {
|
||||||
for _, parent := range []string{".", "..", "../.."} {
|
for _, parent := range []string{".", "..", "../..", "../../.."} {
|
||||||
foundDir, err := filepath.Abs(filepath.Join(parent, dir))
|
foundDir, err := filepath.Abs(filepath.Join(parent, dir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user