Этот коммит содержится в:
Ben Schumacher
2021-07-12 20:05:36 +02:00
коммит произвёл Claudio Costa
родитель 953eebdef4
Коммит 97ccf0bdf6
472 изменённых файлов: 9126 добавлений и 9132 удалений

Просмотреть файл

@@ -192,9 +192,9 @@ func createChannelCmdF(command *cobra.Command, args []string) error {
purpose, _ := command.Flags().GetString("purpose")
useprivate, _ := command.Flags().GetBool("private")
channelType := model.CHANNEL_OPEN
channelType := model.ChannelTypeOpen
if useprivate {
channelType = model.CHANNEL_PRIVATE
channelType = model.ChannelTypePrivate
}
team := getTeamFromTeamArg(a, teamArg)
@@ -487,7 +487,7 @@ func listChannelsCmdF(command *cobra.Command, args []string) error {
if channel.DeleteAt > 0 {
output += " (archived)"
}
if channel.Type == model.CHANNEL_PRIVATE {
if channel.Type == model.ChannelTypePrivate {
output += " (private)"
}
CommandPrettyPrintln(output)
@@ -552,13 +552,13 @@ func modifyChannelCmdF(command *cobra.Command, args []string) error {
return errors.New("Unable to find channel '" + args[0] + "'")
}
if !(channel.Type == model.CHANNEL_OPEN || channel.Type == model.CHANNEL_PRIVATE) {
if !(channel.Type == model.ChannelTypeOpen || channel.Type == model.ChannelTypePrivate) {
return errors.New("You can only change the type of public/private channels.")
}
channel.Type = model.CHANNEL_OPEN
channel.Type = model.ChannelTypeOpen
if private {
channel.Type = model.CHANNEL_PRIVATE
channel.Type = model.ChannelTypePrivate
}
user := getUserFromUserArg(a, username)
@@ -657,7 +657,7 @@ func searchChannelCmdF(command *cobra.Command, args []string) error {
if channel.DeleteAt > 0 {
output += " (archived)"
}
if channel.Type == model.CHANNEL_PRIVATE {
if channel.Type == model.ChannelTypePrivate {
output += " (private)"
}
CommandPrettyPrintln(output)

Просмотреть файл

@@ -156,7 +156,7 @@ func TestCreateChannel(t *testing.T) {
th.CheckCommand(t, "channel", "create", "--display_name", commonName, "--team", th.BasicTeam.Name, "--name", commonName)
channel, _ := th.App.Srv().Store.Channel().GetByName(team.Id, commonName, false)
assert.Equal(t, commonName, channel.Name)
assert.Equal(t, model.CHANNEL_OPEN, channel.Type)
assert.Equal(t, model.ChannelTypeOpen, channel.Type)
})
t.Run("should create private channel", func(t *testing.T) {
@@ -164,7 +164,7 @@ func TestCreateChannel(t *testing.T) {
th.CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name, "--private")
channel, _ := th.App.Srv().Store.Channel().GetByName(team.Id, name, false)
assert.Equal(t, name, channel.Name)
assert.Equal(t, model.CHANNEL_PRIVATE, channel.Type)
assert.Equal(t, model.ChannelTypePrivate, channel.Type)
})
t.Run("should create channel with header and purpose", func(t *testing.T) {
@@ -172,7 +172,7 @@ func TestCreateChannel(t *testing.T) {
th.CheckCommand(t, "channel", "create", "--display_name", name, "--team", th.BasicTeam.Name, "--name", name, "--header", "this is a header", "--purpose", "this is the purpose")
channel, _ := th.App.Srv().Store.Channel().GetByName(team.Id, name, false)
assert.Equal(t, name, channel.Name)
assert.Equal(t, model.CHANNEL_OPEN, channel.Type)
assert.Equal(t, model.ChannelTypeOpen, channel.Type)
assert.Equal(t, "this is a header", channel.Header)
assert.Equal(t, "this is the purpose", channel.Purpose)
})
@@ -321,7 +321,7 @@ func TestModifyChannel(t *testing.T) {
th.CheckCommand(t, "channel", "modify", "--public", th.BasicTeam.Name+":"+channel1.Name, "--username", th.BasicUser2.Email)
res, err := th.App.Srv().Store.Channel().Get(channel1.Id, false)
require.NoError(t, err)
assert.Equal(t, model.CHANNEL_OPEN, res.Type)
assert.Equal(t, model.ChannelTypeOpen, res.Type)
// should fail because user doesn't exist
require.Error(t, th.RunCommand(t, "channel", "modify", "--public", th.BasicTeam.Name+":"+channel2.Name, "--username", "idonotexist"))
@@ -332,7 +332,7 @@ func TestModifyChannel(t *testing.T) {
th.CheckCommand(t, "channel", "modify", "--private", th.BasicTeam.Name+":"+pchannel1.Name, "--username", th.BasicUser2.Email)
res, err = th.App.Srv().Store.Channel().Get(pchannel1.Id, false)
require.NoError(t, err)
assert.Equal(t, model.CHANNEL_PRIVATE, res.Type)
assert.Equal(t, model.ChannelTypePrivate, res.Type)
// should fail because user doesn't exist
require.Error(t, th.RunCommand(t, "channel", "modify", "--private", th.BasicTeam.Name+":"+pchannel2.Name, "--username", "idonotexist"))

Просмотреть файл

@@ -131,7 +131,7 @@ func createCommandCmdF(command *cobra.Command, args []string) error {
}
// check if creator has permission to create slash commands
if !a.HasPermissionToTeam(user.Id, team.Id, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
if !a.HasPermissionToTeam(user.Id, team.Id, model.PermissionManageSlashCommands) {
return errors.New("the creator must be a user who has permissions to manage slash commands")
}
@@ -332,7 +332,7 @@ func modifyCommandCmdF(command *cobra.Command, args []string) (cmdError error) {
}
// check if creator has permission to create slash commands
if !a.HasPermissionToTeam(user.Id, modifiedCommand.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
if !a.HasPermissionToTeam(user.Id, modifiedCommand.TeamId, model.PermissionManageSlashCommands) {
return errors.New("the creator must be a user who has permissions to manage slash commands")
}

Просмотреть файл

@@ -81,7 +81,7 @@ type TestPluginSettings struct {
}
func getDsn(driver string, source string) string {
if driver == model.DATABASE_DRIVER_MYSQL {
if driver == model.DatabaseDriverMysql {
return driver + "://" + source
}
return source

Просмотреть файл

@@ -133,7 +133,7 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error {
}
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.JobStatusError || job.Status == model.JobStatusCanceled {
CommandPrintErrorln("ERROR: Message export job failed. Please check the server logs")
} else {
CommandPrettyPrintln("SUCCESS: Message export job complete")
@@ -175,7 +175,7 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string)
if warningsCount == 0 {
CommandPrettyPrintln("SUCCESS: Your data was exported.")
} else {
if format == model.COMPLIANCE_EXPORT_TYPE_GLOBALRELAY || format == model.COMPLIANCE_EXPORT_TYPE_GLOBALRELAY_ZIP {
if format == model.ComplianceExportTypeGlobalrelay || format == model.ComplianceExportTypeGlobalrelayZip {
CommandPrettyPrintln(fmt.Sprintf("WARNING: %d warnings encountered, see logs for details.", warningsCount))
} else {
CommandPrettyPrintln(fmt.Sprintf("WARNING: %d warnings encountered, see warning.txt for details.", warningsCount))

Просмотреть файл

@@ -66,7 +66,7 @@ func extractContentCmdF(command *cobra.Command, args []string) error {
for {
opts := model.GetFileInfosOptions{
Since: since,
SortBy: model.FILEINFO_SORT_BY_CREATED,
SortBy: model.FileinfoSortByCreated,
IncludeDeleted: false,
}
fileInfos, err := a.Srv().Store.FileInfo().GetWithOptions(0, 1000, &opts)

Просмотреть файл

@@ -129,7 +129,7 @@ func channelGroupEnableCmdF(command *cobra.Command, args []string) error {
return errors.New("Unable to find channel '" + args[0] + "'")
}
if channel.Type != model.CHANNEL_PRIVATE {
if channel.Type != model.ChannelTypePrivate {
return errors.New("Channel '" + args[0] + "' is not private. It cannot be group-constrained")
}

Просмотреть файл

@@ -52,7 +52,7 @@ func ldapSyncCmdF(command *cobra.Command, args []string) error {
if ldapI := a.Ldap(); ldapI != nil {
job, err := ldapI.StartSynchronizeJob(true, includeRemovedMembers)
if err != nil || job.Status == model.JOB_STATUS_ERROR || job.Status == model.JOB_STATUS_CANCELED {
if err != nil || job.Status == model.JobStatusError || job.Status == model.JobStatusCanceled {
CommandPrintErrorln("ERROR: AD/LDAP Synchronization please check the server logs")
} else {
CommandPrettyPrintln("SUCCESS: AD/LDAP Synchronization Complete")

Просмотреть файл

@@ -65,18 +65,18 @@ func makeSystemAdminCmdF(command *cobra.Command, args []string) error {
roles := strings.Fields(user.Roles)
for _, role := range roles {
switch role {
case model.SYSTEM_ADMIN_ROLE_ID:
case model.SystemAdminRoleId:
systemAdmin = true
case model.SYSTEM_USER_ROLE_ID:
case model.SystemUserRoleId:
systemUser = true
}
}
if !systemUser {
roles = append(roles, model.SYSTEM_USER_ROLE_ID)
roles = append(roles, model.SystemUserRoleId)
}
if !systemAdmin {
roles = append(roles, model.SYSTEM_ADMIN_ROLE_ID)
roles = append(roles, model.SystemAdminRoleId)
}
updatedUser, errUpdate := a.UpdateUserRoles(user.Id, strings.Join(roles, " "), true)
@@ -115,9 +115,9 @@ func makeMemberCmdF(command *cobra.Command, args []string) error {
roles := strings.Fields(user.Roles)
for _, role := range roles {
switch role {
case model.SYSTEM_ADMIN_ROLE_ID:
case model.SystemAdminRoleId:
default:
if role == model.SYSTEM_USER_ROLE_ID {
if role == model.SystemUserRoleId {
systemUser = true
}
newRoles = append(newRoles, role)
@@ -125,7 +125,7 @@ func makeMemberCmdF(command *cobra.Command, args []string) error {
}
if !systemUser {
newRoles = append(roles, model.SYSTEM_USER_ROLE_ID)
newRoles = append(roles, model.SystemUserRoleId)
}
updatedUser, errUpdate := a.UpdateUserRoles(user.Id, strings.Join(newRoles, " "), true)

Просмотреть файл

@@ -160,9 +160,9 @@ func createTeamCmdF(command *cobra.Command, args []string) error {
email = strings.ToLower(email)
useprivate, _ := command.Flags().GetBool("private")
teamType := model.TEAM_OPEN
teamType := model.TeamOpen
if useprivate {
teamType = model.TEAM_INVITE
teamType = model.TeamInvite
}
team := &model.Team{
@@ -480,10 +480,10 @@ func modifyTeamCmdF(command *cobra.Command, args []string) error {
}
if public {
team.Type = model.TEAM_OPEN
team.Type = model.TeamOpen
team.AllowOpenInvite = true
} else if private {
team.Type = model.TEAM_INVITE
team.Type = model.TeamInvite
team.AllowOpenInvite = false
}

Просмотреть файл

@@ -245,9 +245,9 @@ func TestModifyTeam(t *testing.T) {
updatedTeam, _ := th.App.GetTeam(team.Id)
require.False(t, !updatedTeam.AllowOpenInvite && team.Type == model.TEAM_INVITE, "Failed modifying team's privacy to private")
require.False(t, !updatedTeam.AllowOpenInvite && team.Type == model.TeamInvite, "Failed modifying team's privacy to private")
th.CheckCommand(t, "team", "modify", team.Name, "--public")
require.False(t, updatedTeam.AllowOpenInvite && team.Type == model.TEAM_OPEN, "Failed modifying team's privacy to private")
require.False(t, updatedTeam.AllowOpenInvite && team.Type == model.TeamOpen, "Failed modifying team's privacy to private")
}

Просмотреть файл

@@ -524,10 +524,10 @@ func botToUser(command *cobra.Command, args []string, a *app.App) error {
}
systemAdmin, _ := command.Flags().GetBool("system_admin")
if systemAdmin && !user.IsInRole(model.SYSTEM_ADMIN_ROLE_ID) {
if systemAdmin && !user.IsInRole(model.SystemAdminRoleId) {
if _, appErr = a.UpdateUserRoles(
user.Id,
fmt.Sprintf("%s %s", user.Roles, model.SYSTEM_ADMIN_ROLE_ID),
fmt.Sprintf("%s %s", user.Roles, model.SystemAdminRoleId),
false); appErr != nil {
return fmt.Errorf("Unable to make user system admin. Error: %s" + appErr.Error())
}

Просмотреть файл

@@ -37,10 +37,10 @@ func TestListWebhooks(t *testing.T) {
defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions)
}()
th.AddPermissionToRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PermissionManageIncomingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageIncomingWebhooks.Id, model.TeamUserRoleId)
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
dispName := "myhookinc"
hook := &model.IncomingWebhook{DisplayName: dispName, ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId}
@@ -80,10 +80,10 @@ func TestShowWebhook(t *testing.T) {
defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions)
}()
th.AddPermissionToRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PermissionManageIncomingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageIncomingWebhooks.Id, model.TeamUserRoleId)
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
dispName := "incominghook"
hook := &model.IncomingWebhook{
@@ -145,8 +145,8 @@ func TestCreateIncomingWebhook(t *testing.T) {
defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions)
}()
th.AddPermissionToRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PermissionManageIncomingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageIncomingWebhooks.Id, model.TeamUserRoleId)
// should fail because you need to specify valid channel
require.Error(t, th.RunCommand(t, "webhook", "create-incoming"))
@@ -193,8 +193,8 @@ func TestModifyIncomingWebhook(t *testing.T) {
defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions)
}()
th.AddPermissionToRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PermissionManageIncomingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageIncomingWebhooks.Id, model.TeamUserRoleId)
description := "myhookincdesc"
displayName := "myhookincname"
@@ -257,8 +257,8 @@ func TestCreateOutgoingWebhook(t *testing.T) {
defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions)
}()
th.AddPermissionToRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
// team, user, display name, trigger words, callback urls are required
team := th.BasicTeam.Id
@@ -313,8 +313,8 @@ func TestModifyOutgoingWebhook(t *testing.T) {
defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions)
}()
th.AddPermissionToRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
description := "myhookoutdesc"
displayName := "myhookoutname"
@@ -417,10 +417,10 @@ func TestDeleteWebhooks(t *testing.T) {
defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions)
}()
th.AddPermissionToRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PermissionManageIncomingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageIncomingWebhooks.Id, model.TeamUserRoleId)
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
dispName := "myhookinc"
inHookStruct := &model.IncomingWebhook{DisplayName: dispName, ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId}
@@ -457,8 +457,8 @@ func TestMoveOutgoingWebhook(t *testing.T) {
defaultRolePermissions := th.SaveDefaultRolePermissions()
defer th.RestoreDefaultRolePermissions(defaultRolePermissions)
th.AddPermissionToRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID)
th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId)
th.RemovePermissionFromRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId)
description := "myhookoutdesc"
displayName := "myhookoutname"
@@ -501,7 +501,7 @@ func TestMoveOutgoingWebhook(t *testing.T) {
require.Error(t, th.RunCommand(t, "webhook", "move-outgoing", newTeam.Id, th.BasicTeam.Id+":"+oldHook.Id, "--channel", "invalid"))
channel := th.CreateChannelWithClientAndTeam(th.SystemAdminClient, model.CHANNEL_OPEN, newTeam.Id)
channel := th.CreateChannelWithClientAndTeam(th.SystemAdminClient, model.ChannelTypeOpen, newTeam.Id)
th.CheckCommand(t, "webhook", "move-outgoing", newTeam.Id, th.BasicTeam.Id+":"+oldHook.Id, "--channel", channel.Name)
_, webhookErr := th.App.GetOutgoingWebhook(oldHook.Id)