summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/access.go8
-rw-r--r--model/authorize.go16
-rw-r--r--model/channel.go20
-rw-r--r--model/channel_member.go12
-rw-r--r--model/client.go25
-rw-r--r--model/config.go44
-rw-r--r--model/file_info.go9
-rw-r--r--model/file_info_test.go22
-rw-r--r--model/incoming_webhook.go12
-rw-r--r--model/oauth.go18
-rw-r--r--model/outgoing_webhook.go20
-rw-r--r--model/post.go28
-rw-r--r--model/preference.go8
-rw-r--r--model/team.go24
-rw-r--r--model/user.go29
-rw-r--r--model/utils.go6
16 files changed, 163 insertions, 138 deletions
diff --git a/model/access.go b/model/access.go
index 6c9254004..877b3c4f0 100644
--- a/model/access.go
+++ b/model/access.go
@@ -34,19 +34,19 @@ type AccessResponse struct {
func (ad *AccessData) IsValid() *AppError {
if len(ad.AuthCode) == 0 || len(ad.AuthCode) > 128 {
- return NewAppError("AccessData.IsValid", "Invalid auth code", "")
+ return NewLocAppError("AccessData.IsValid", "model.access.is_valid.auth_code.app_error", nil, "")
}
if len(ad.Token) != 26 {
- return NewAppError("AccessData.IsValid", "Invalid access token", "")
+ return NewLocAppError("AccessData.IsValid", "model.access.is_valid.access_token.app_error", nil, "")
}
if len(ad.RefreshToken) > 26 {
- return NewAppError("AccessData.IsValid", "Invalid refresh token", "")
+ return NewLocAppError("AccessData.IsValid", "model.access.is_valid.refresh_token.app_error", nil, "")
}
if len(ad.RedirectUri) > 256 {
- return NewAppError("AccessData.IsValid", "Invalid redirect uri", "")
+ return NewLocAppError("AccessData.IsValid", "model.access.is_valid.redirect_uri.app_error", nil, "")
}
return nil
diff --git a/model/authorize.go b/model/authorize.go
index 4176a9b89..e0d665bae 100644
--- a/model/authorize.go
+++ b/model/authorize.go
@@ -29,35 +29,35 @@ type AuthData struct {
func (ad *AuthData) IsValid() *AppError {
if len(ad.ClientId) != 26 {
- return NewAppError("AuthData.IsValid", "Invalid client id", "")
+ return NewLocAppError("AuthData.IsValid", "model.authorize.is_valid.client_id.app_error", nil, "")
}
if len(ad.UserId) != 26 {
- return NewAppError("AuthData.IsValid", "Invalid user id", "")
+ return NewLocAppError("AuthData.IsValid", "model.authorize.is_valid.user_id.app_error", nil, "")
}
if len(ad.Code) == 0 || len(ad.Code) > 128 {
- return NewAppError("AuthData.IsValid", "Invalid authorization code", "client_id="+ad.ClientId)
+ return NewLocAppError("AuthData.IsValid", "model.authorize.is_valid.auth_code.app_error", nil, "client_id="+ad.ClientId)
}
if ad.ExpiresIn == 0 {
- return NewAppError("AuthData.IsValid", "Expires in must be set", "")
+ return NewLocAppError("AuthData.IsValid", "model.authorize.is_valid.expires.app_error", nil, "")
}
if ad.CreateAt <= 0 {
- return NewAppError("AuthData.IsValid", "Create at must be a valid time", "client_id="+ad.ClientId)
+ return NewLocAppError("AuthData.IsValid", "model.authorize.is_valid.create_at.app_error", nil, "client_id="+ad.ClientId)
}
if len(ad.RedirectUri) > 256 {
- return NewAppError("AuthData.IsValid", "Invalid redirect uri", "client_id="+ad.ClientId)
+ return NewLocAppError("AuthData.IsValid", "model.authorize.is_valid.redirect_uri.app_error", nil, "client_id="+ad.ClientId)
}
if len(ad.State) > 128 {
- return NewAppError("AuthData.IsValid", "Invalid state", "client_id="+ad.ClientId)
+ return NewLocAppError("AuthData.IsValid", "model.authorize.is_valid.state.app_error", nil, "client_id="+ad.ClientId)
}
if len(ad.Scope) > 128 {
- return NewAppError("AuthData.IsValid", "Invalid scope", "client_id="+ad.ClientId)
+ return NewLocAppError("AuthData.IsValid", "model.authorize.is_valid.scope.app_error", nil, "client_id="+ad.ClientId)
}
return nil
diff --git a/model/channel.go b/model/channel.go
index 7109500d4..e7002e3cb 100644
--- a/model/channel.go
+++ b/model/channel.go
@@ -64,43 +64,43 @@ func (o *Channel) ExtraEtag(memberLimit int) string {
func (o *Channel) IsValid() *AppError {
if len(o.Id) != 26 {
- return NewAppError("Channel.IsValid", "Invalid Id", "")
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.id.app_error", nil, "")
}
if o.CreateAt == 0 {
- return NewAppError("Channel.IsValid", "Create at must be a valid time", "id="+o.Id)
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.create_at.app_error", nil, "id="+o.Id)
}
if o.UpdateAt == 0 {
- return NewAppError("Channel.IsValid", "Update at must be a valid time", "id="+o.Id)
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.update_at.app_error", nil, "id="+o.Id)
}
if utf8.RuneCountInString(o.DisplayName) > 64 {
- return NewAppError("Channel.IsValid", "Invalid display name", "id="+o.Id)
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.display_name.app_error", nil, "id="+o.Id)
}
if len(o.Name) > 64 {
- return NewAppError("Channel.IsValid", "Invalid name", "id="+o.Id)
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.name.app_error", nil, "id="+o.Id)
}
if !IsValidChannelIdentifier(o.Name) {
- return NewAppError("Channel.IsValid", "Name must be 2 or more lowercase alphanumeric characters", "id="+o.Id)
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.2_or_more.app_error", nil, "id="+o.Id)
}
if !(o.Type == CHANNEL_OPEN || o.Type == CHANNEL_PRIVATE || o.Type == CHANNEL_DIRECT) {
- return NewAppError("Channel.IsValid", "Invalid type", "id="+o.Id)
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.type.app_error", nil, "id="+o.Id)
}
if utf8.RuneCountInString(o.Header) > 1024 {
- return NewAppError("Channel.IsValid", "Invalid header", "id="+o.Id)
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.header.app_error", nil, "id="+o.Id)
}
if utf8.RuneCountInString(o.Purpose) > 128 {
- return NewAppError("Channel.IsValid", "Invalid purpose", "id="+o.Id)
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.purpose.app_error", nil, "id="+o.Id)
}
if len(o.CreatorId) > 26 {
- return NewAppError("Channel.IsValid", "Invalid creator id", "")
+ return NewLocAppError("Channel.IsValid", "model.channel.is_valid.creator_id.app_error", nil, "")
}
return nil
diff --git a/model/channel_member.go b/model/channel_member.go
index e822ba443..66e20da64 100644
--- a/model/channel_member.go
+++ b/model/channel_member.go
@@ -53,27 +53,29 @@ func ChannelMemberFromJson(data io.Reader) *ChannelMember {
func (o *ChannelMember) IsValid() *AppError {
if len(o.ChannelId) != 26 {
- return NewAppError("ChannelMember.IsValid", "Invalid channel id", "")
+ return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.channel_id.app_error", nil, "")
}
if len(o.UserId) != 26 {
- return NewAppError("ChannelMember.IsValid", "Invalid user id", "")
+ return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.user_id.app_error", nil, "")
}
for _, role := range strings.Split(o.Roles, " ") {
if !(role == "" || role == CHANNEL_ROLE_ADMIN) {
- return NewAppError("ChannelMember.IsValid", "Invalid role", "role="+role)
+ return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.role.app_error", nil, "role="+role)
}
}
notifyLevel := o.NotifyProps["desktop"]
if len(notifyLevel) > 20 || !IsChannelNotifyLevelValid(notifyLevel) {
- return NewAppError("ChannelMember.IsValid", "Invalid notify level", "notify_level="+notifyLevel)
+ return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.notify_level.app_error",
+ nil, "notify_level="+notifyLevel)
}
markUnreadLevel := o.NotifyProps["mark_unread"]
if len(markUnreadLevel) > 20 || !IsChannelMarkUnreadLevelValid(markUnreadLevel) {
- return NewAppError("ChannelMember.IsValid", "Invalid mark unread level", "mark_unread_level="+markUnreadLevel)
+ return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.unread_level.app_error",
+ nil, "mark_unread_level="+markUnreadLevel)
}
return nil
diff --git a/model/client.go b/model/client.go
index a4da6d513..21b8d8f7a 100644
--- a/model/client.go
+++ b/model/client.go
@@ -56,7 +56,7 @@ func (c *Client) DoPost(url, data, contentType string) (*http.Response, *AppErro
rq.Header.Set("Content-Type", contentType)
if rp, err := c.HttpClient.Do(rq); err != nil {
- return nil, NewAppError(url, "We encountered an error while connecting to the server", err.Error())
+ return nil, NewLocAppError(url, "model.client.connecting.app_error", nil, err.Error())
} else if rp.StatusCode >= 300 {
return nil, AppErrorFromJson(rp.Body)
} else {
@@ -72,7 +72,7 @@ func (c *Client) DoApiPost(url string, data string) (*http.Response, *AppError)
}
if rp, err := c.HttpClient.Do(rq); err != nil {
- return nil, NewAppError(url, "We encountered an error while connecting to the server", err.Error())
+ return nil, NewLocAppError(url, "model.client.connecting.app_error", nil, err.Error())
} else if rp.StatusCode >= 300 {
return nil, AppErrorFromJson(rp.Body)
} else {
@@ -92,7 +92,7 @@ func (c *Client) DoApiGet(url string, data string, etag string) (*http.Response,
}
if rp, err := c.HttpClient.Do(rq); err != nil {
- return nil, NewAppError(url, "We encountered an error while connecting to the server", err.Error())
+ return nil, NewLocAppError(url, "model.client.connecting.app_error", nil, err.Error())
} else if rp.StatusCode == 304 {
return rp, nil
} else if rp.StatusCode >= 300 {
@@ -298,7 +298,7 @@ func (c *Client) login(m map[string]string) (*Result, *AppError) {
sessionToken := getCookie(SESSION_COOKIE_TOKEN, r)
if c.AuthToken != sessionToken.Value {
- NewAppError("/users/login", "Authentication tokens didn't match", "")
+ NewLocAppError("/users/login", "model.client.login.app_error", nil, "")
}
return &Result{r.Header.Get(HEADER_REQUEST_ID),
@@ -479,7 +479,7 @@ func (c *Client) TestEmail(config *Config) (*Result, *AppError) {
}
}
-func (c *Client) GetAnalytics(teamId, name string) (*Result, *AppError) {
+func (c *Client) GetTeamAnalytics(teamId, name string) (*Result, *AppError) {
if r, err := c.DoApiGet("/admin/analytics/"+teamId+"/"+name, "", ""); err != nil {
return nil, err
} else {
@@ -488,6 +488,15 @@ func (c *Client) GetAnalytics(teamId, name string) (*Result, *AppError) {
}
}
+func (c *Client) GetSystemAnalytics(name string) (*Result, *AppError) {
+ if r, err := c.DoApiGet("/admin/analytics/"+name, "", ""); err != nil {
+ return nil, err
+ } else {
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), AnalyticsRowsFromJson(r.Body)}, nil
+ }
+}
+
func (c *Client) CreateChannel(channel *Channel) (*Result, *AppError) {
if r, err := c.DoApiPost("/channels/create", channel.ToJson()); err != nil {
return nil, err
@@ -735,7 +744,7 @@ func (c *Client) UploadFile(url string, data []byte, contentType string) (*Resul
}
if rp, err := c.HttpClient.Do(rq); err != nil {
- return nil, NewAppError(url, "We encountered an error while connecting to the server", err.Error())
+ return nil, NewLocAppError(url, "model.client.connecting.app_error", nil, err.Error())
} else if rp.StatusCode >= 300 {
return nil, AppErrorFromJson(rp.Body)
} else {
@@ -757,7 +766,7 @@ func (c *Client) GetFile(url string, isFullUrl bool) (*Result, *AppError) {
}
if rp, err := c.HttpClient.Do(rq); err != nil {
- return nil, NewAppError(url, "We encountered an error while connecting to the server", err.Error())
+ return nil, NewLocAppError(url, "model.client.connecting.app_error", nil, err.Error())
} else if rp.StatusCode >= 300 {
return nil, AppErrorFromJson(rp.Body)
} else {
@@ -775,7 +784,7 @@ func (c *Client) GetFileInfo(url string) (*Result, *AppError) {
}
if rp, err := c.HttpClient.Do(rq); err != nil {
- return nil, NewAppError(url, "We encountered an error while connecting to the server", err.Error())
+ return nil, NewLocAppError(url, "model.client.connecting.app_error", nil, err.Error())
} else if rp.StatusCode >= 300 {
return nil, AppErrorFromJson(rp.Body)
} else {
diff --git a/model/config.go b/model/config.go
index c0e66d50c..f518e8f8d 100644
--- a/model/config.go
+++ b/model/config.go
@@ -359,87 +359,87 @@ func (o *Config) SetDefaults() {
func (o *Config) IsValid() *AppError {
if o.ServiceSettings.MaximumLoginAttempts <= 0 {
- return NewAppError("Config.IsValid", "Invalid maximum login attempts for service settings. Must be a positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "")
}
if len(o.ServiceSettings.ListenAddress) == 0 {
- return NewAppError("Config.IsValid", "Invalid listen address for service settings Must be set.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "")
}
if o.TeamSettings.MaxUsersPerTeam <= 0 {
- return NewAppError("Config.IsValid", "Invalid maximum users per team for team settings. Must be a positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "")
}
if len(o.SqlSettings.AtRestEncryptKey) < 32 {
- return NewAppError("Config.IsValid", "Invalid at rest encrypt key for SQL settings. Must be 32 chars or more.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "")
}
if !(o.SqlSettings.DriverName == DATABASE_DRIVER_MYSQL || o.SqlSettings.DriverName == DATABASE_DRIVER_POSTGRES) {
- return NewAppError("Config.IsValid", "Invalid driver name for SQL settings. Must be 'mysql' or 'postgres'", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_driver.app_error", nil, "")
}
if o.SqlSettings.MaxIdleConns <= 0 {
- return NewAppError("Config.IsValid", "Invalid maximum idle connection for SQL settings. Must be a positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_idle.app_error", nil, "")
}
if len(o.SqlSettings.DataSource) == 0 {
- return NewAppError("Config.IsValid", "Invalid data source for SQL settings. Must be set.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_data_src.app_error", nil, "")
}
if o.SqlSettings.MaxOpenConns <= 0 {
- return NewAppError("Config.IsValid", "Invalid maximum open connection for SQL settings. Must be a positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "")
}
if !(o.FileSettings.DriverName == IMAGE_DRIVER_LOCAL || o.FileSettings.DriverName == IMAGE_DRIVER_S3) {
- return NewAppError("Config.IsValid", "Invalid driver name for file settings. Must be 'local' or 'amazons3'", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.file_driver.app_error", nil, "")
}
if o.FileSettings.PreviewHeight < 0 {
- return NewAppError("Config.IsValid", "Invalid preview height for file settings. Must be a zero or positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.file_preview_height.app_error", nil, "")
}
if o.FileSettings.PreviewWidth <= 0 {
- return NewAppError("Config.IsValid", "Invalid preview width for file settings. Must be a positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.file_preview_width.app_error", nil, "")
}
if o.FileSettings.ProfileHeight <= 0 {
- return NewAppError("Config.IsValid", "Invalid profile height for file settings. Must be a positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.file_profile_height.app_error", nil, "")
}
if o.FileSettings.ProfileWidth <= 0 {
- return NewAppError("Config.IsValid", "Invalid profile width for file settings. Must be a positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.file_profile_width.app_error", nil, "")
}
if o.FileSettings.ThumbnailHeight <= 0 {
- return NewAppError("Config.IsValid", "Invalid thumbnail height for file settings. Must be a positive number.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.file_thumb_height.app_error", nil, "")
}
- if o.FileSettings.ThumbnailHeight <= 0 {
- return NewAppError("Config.IsValid", "Invalid thumbnail width for file settings. Must be a positive number.", "")
+ if o.FileSettings.ThumbnailWidth <= 0 {
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.file_thumb_width.app_error", nil, "")
}
if len(o.FileSettings.PublicLinkSalt) < 32 {
- return NewAppError("Config.IsValid", "Invalid public link salt for file settings. Must be 32 chars or more.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.file_salt.app_error", nil, "")
}
if !(o.EmailSettings.ConnectionSecurity == CONN_SECURITY_NONE || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_TLS || o.EmailSettings.ConnectionSecurity == CONN_SECURITY_STARTTLS) {
- return NewAppError("Config.IsValid", "Invalid connection security for email settings. Must be '', 'TLS', or 'STARTTLS'", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "")
}
if len(o.EmailSettings.InviteSalt) < 32 {
- return NewAppError("Config.IsValid", "Invalid invite salt for email settings. Must be 32 chars or more.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.email_salt.app_error", nil, "")
}
if len(o.EmailSettings.PasswordResetSalt) < 32 {
- return NewAppError("Config.IsValid", "Invalid password reset salt for email settings. Must be 32 chars or more.", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.email_reset_salt.app_error", nil, "")
}
if o.RateLimitSettings.MemoryStoreSize <= 0 {
- return NewAppError("Config.IsValid", "Invalid memory store size for rate limit settings. Must be a positive number", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.rate_mem.app_error", nil, "")
}
if o.RateLimitSettings.PerSec <= 0 {
- return NewAppError("Config.IsValid", "Invalid per sec for rate limit settings. Must be a positive number", "")
+ return NewLocAppError("Config.IsValid", "model.config.is_valid.rate_sec.app_error", nil, "")
}
return nil
diff --git a/model/file_info.go b/model/file_info.go
index 741b4e55d..f785042b3 100644
--- a/model/file_info.go
+++ b/model/file_info.go
@@ -32,11 +32,16 @@ func GetInfoForBytes(filename string, data []byte) (*FileInfo, *AppError) {
mimeType = mime.TypeByExtension(extension)
}
+ if extension != "" && extension[0] == '.' {
+ // the client expects a file extension without the leading period
+ extension = extension[1:]
+ }
+
hasPreviewImage := isImage
if mimeType == "image/gif" {
// just show the gif itself instead of a preview image for animated gifs
if gifImage, err := gif.DecodeAll(bytes.NewReader(data)); err != nil {
- return nil, NewAppError("GetInfoForBytes", "Could not decode gif.", "filename="+filename)
+ return nil, NewLocAppError("GetInfoForBytes", "model.file_info.get.gif.app_error", nil, "filename="+filename)
} else {
hasPreviewImage = len(gifImage.Image) == 1
}
@@ -45,7 +50,7 @@ func GetInfoForBytes(filename string, data []byte) (*FileInfo, *AppError) {
return &FileInfo{
Filename: filename,
Size: size,
- Extension: extension[1:],
+ Extension: extension,
MimeType: mimeType,
HasPreviewImage: hasPreviewImage,
}, nil
diff --git a/model/file_info_test.go b/model/file_info_test.go
index ecf0d509c..e89681626 100644
--- a/model/file_info_test.go
+++ b/model/file_info_test.go
@@ -19,7 +19,7 @@ func TestGetInfoForBytes(t *testing.T) {
} else if info.Size != 1000 {
t.Fatalf("Got incorrect size: %v", info.Size)
} else if info.Extension != "txt" {
- t.Fatalf("Git incorrect file extension: %v", info.Extension)
+ t.Fatalf("Got incorrect file extension: %v", info.Extension)
} else if info.MimeType != "text/plain; charset=utf-8" {
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
} else if info.HasPreviewImage {
@@ -33,7 +33,7 @@ func TestGetInfoForBytes(t *testing.T) {
} else if info.Size != 1000 {
t.Fatalf("Got incorrect size: %v", info.Size)
} else if info.Extension != "png" {
- t.Fatalf("Git incorrect file extension: %v", info.Extension)
+ t.Fatalf("Got incorrect file extension: %v", info.Extension)
} else if info.MimeType != "image/png" {
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
} else if !info.HasPreviewImage {
@@ -49,7 +49,7 @@ func TestGetInfoForBytes(t *testing.T) {
} else if info.Size != 35 {
t.Fatalf("Got incorrect size: %v", info.Size)
} else if info.Extension != "gif" {
- t.Fatalf("Git incorrect file extension: %v", info.Extension)
+ t.Fatalf("Got incorrect file extension: %v", info.Extension)
} else if info.MimeType != "image/gif" {
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
} else if !info.HasPreviewImage {
@@ -67,10 +67,24 @@ func TestGetInfoForBytes(t *testing.T) {
} else if info.Size != 38689 {
t.Fatalf("Got incorrect size: %v", info.Size)
} else if info.Extension != "gif" {
- t.Fatalf("Git incorrect file extension: %v", info.Extension)
+ t.Fatalf("Got incorrect file extension: %v", info.Extension)
} else if info.MimeType != "image/gif" {
t.Fatalf("Got incorrect mime type: %v", info.MimeType)
} else if info.HasPreviewImage {
t.Fatalf("Got HasPreviewImage = true for animated gif")
}
+
+ if info, err := GetInfoForBytes("filewithoutextension", fakeFile); err != nil {
+ t.Fatal(err)
+ } else if info.Filename != "filewithoutextension" {
+ t.Fatalf("Got incorrect filename: %v", info.Filename)
+ } else if info.Size != 1000 {
+ t.Fatalf("Got incorrect size: %v", info.Size)
+ } else if info.Extension != "" {
+ t.Fatalf("Got incorrect file extension: %v", info.Extension)
+ } else if info.MimeType != "" {
+ t.Fatalf("Got incorrect mime type: %v", info.MimeType)
+ } else if info.HasPreviewImage {
+ t.Fatalf("Got HasPreviewImage = true for non-image file")
+ }
}
diff --git a/model/incoming_webhook.go b/model/incoming_webhook.go
index 8ead0da9f..8432f5fea 100644
--- a/model/incoming_webhook.go
+++ b/model/incoming_webhook.go
@@ -76,27 +76,27 @@ func IncomingWebhookListFromJson(data io.Reader) []*IncomingWebhook {
func (o *IncomingWebhook) IsValid() *AppError {
if len(o.Id) != 26 {
- return NewAppError("IncomingWebhook.IsValid", "Invalid Id", "")
+ return NewLocAppError("IncomingWebhook.IsValid", "model.incoming_hook.id.app_error", nil, "")
}
if o.CreateAt == 0 {
- return NewAppError("IncomingWebhook.IsValid", "Create at must be a valid time", "id="+o.Id)
+ return NewLocAppError("IncomingWebhook.IsValid", "model.incoming_hook.create_at.app_error", nil, "id="+o.Id)
}
if o.UpdateAt == 0 {
- return NewAppError("IncomingWebhook.IsValid", "Update at must be a valid time", "id="+o.Id)
+ return NewLocAppError("IncomingWebhook.IsValid", "model.incoming_hook.update_at.app_error", nil, "id="+o.Id)
}
if len(o.UserId) != 26 {
- return NewAppError("IncomingWebhook.IsValid", "Invalid user id", "")
+ return NewLocAppError("IncomingWebhook.IsValid", "model.incoming_hook.user_id.app_error", nil, "")
}
if len(o.ChannelId) != 26 {
- return NewAppError("IncomingWebhook.IsValid", "Invalid channel id", "")
+ return NewLocAppError("IncomingWebhook.IsValid", "model.incoming_hook.channel_id.app_error", nil, "")
}
if len(o.TeamId) != 26 {
- return NewAppError("IncomingWebhook.IsValid", "Invalid channel id", "")
+ return NewLocAppError("IncomingWebhook.IsValid", "model.incoming_hook.team_id.app_error", nil, "")
}
return nil
diff --git a/model/oauth.go b/model/oauth.go
index 8336e26ba..c54df107c 100644
--- a/model/oauth.go
+++ b/model/oauth.go
@@ -34,39 +34,39 @@ type OAuthApp struct {
func (a *OAuthApp) IsValid() *AppError {
if len(a.Id) != 26 {
- return NewAppError("OAuthApp.IsValid", "Invalid app id", "")
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.app_id.app_error", nil, "")
}
if a.CreateAt == 0 {
- return NewAppError("OAuthApp.IsValid", "Create at must be a valid time", "app_id="+a.Id)
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.create_at.app_error", nil, "app_id="+a.Id)
}
if a.UpdateAt == 0 {
- return NewAppError("OAuthApp.IsValid", "Update at must be a valid time", "app_id="+a.Id)
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.update_at.app_error", nil, "app_id="+a.Id)
}
if len(a.CreatorId) != 26 {
- return NewAppError("OAuthApp.IsValid", "Invalid creator id", "app_id="+a.Id)
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.creator_id.app_error", nil, "app_id="+a.Id)
}
if len(a.ClientSecret) == 0 || len(a.ClientSecret) > 128 {
- return NewAppError("OAuthApp.IsValid", "Invalid client secret", "app_id="+a.Id)
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.client_secret.app_error", nil, "app_id="+a.Id)
}
if len(a.Name) == 0 || len(a.Name) > 64 {
- return NewAppError("OAuthApp.IsValid", "Invalid name", "app_id="+a.Id)
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.name.app_error", nil, "app_id="+a.Id)
}
if len(a.CallbackUrls) == 0 || len(fmt.Sprintf("%s", a.CallbackUrls)) > 1024 {
- return NewAppError("OAuthApp.IsValid", "Invalid callback urls", "app_id="+a.Id)
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.callback.app_error", nil, "app_id="+a.Id)
}
if len(a.Homepage) == 0 || len(a.Homepage) > 256 {
- return NewAppError("OAuthApp.IsValid", "Invalid homepage", "app_id="+a.Id)
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.homepage.app_error", nil, "app_id="+a.Id)
}
if utf8.RuneCountInString(a.Description) > 512 {
- return NewAppError("OAuthApp.IsValid", "Invalid description", "app_id="+a.Id)
+ return NewLocAppError("OAuthApp.IsValid", "model.oauth.is_valid.description.app_error", nil, "app_id="+a.Id)
}
return nil
diff --git a/model/outgoing_webhook.go b/model/outgoing_webhook.go
index 0b4fd6bbe..70de4d26e 100644
--- a/model/outgoing_webhook.go
+++ b/model/outgoing_webhook.go
@@ -65,44 +65,44 @@ func OutgoingWebhookListFromJson(data io.Reader) []*OutgoingWebhook {
func (o *OutgoingWebhook) IsValid() *AppError {
if len(o.Id) != 26 {
- return NewAppError("OutgoingWebhook.IsValid", "Invalid Id", "")
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.id.app_error", nil, "")
}
if len(o.Token) != 26 {
- return NewAppError("OutgoingWebhook.IsValid", "Invalid token", "")
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.token.app_error", nil, "")
}
if o.CreateAt == 0 {
- return NewAppError("OutgoingWebhook.IsValid", "Create at must be a valid time", "id="+o.Id)
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.create_at.app_error", nil, "id="+o.Id)
}
if o.UpdateAt == 0 {
- return NewAppError("OutgoingWebhook.IsValid", "Update at must be a valid time", "id="+o.Id)
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.update_at.app_error", nil, "id="+o.Id)
}
if len(o.CreatorId) != 26 {
- return NewAppError("OutgoingWebhook.IsValid", "Invalid user id", "")
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.user_id.app_error", nil, "")
}
if len(o.ChannelId) != 0 && len(o.ChannelId) != 26 {
- return NewAppError("OutgoingWebhook.IsValid", "Invalid channel id", "")
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.channel_id.app_error", nil, "")
}
if len(o.TeamId) != 26 {
- return NewAppError("OutgoingWebhook.IsValid", "Invalid team id", "")
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.team_id.app_error", nil, "")
}
if len(fmt.Sprintf("%s", o.TriggerWords)) > 1024 {
- return NewAppError("OutgoingWebhook.IsValid", "Invalid trigger words", "")
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.words.app_error", nil, "")
}
if len(o.CallbackURLs) == 0 || len(fmt.Sprintf("%s", o.CallbackURLs)) > 1024 {
- return NewAppError("OutgoingWebhook.IsValid", "Invalid callback urls", "")
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.callback.app_error", nil, "")
}
for _, callback := range o.CallbackURLs {
if !IsValidHttpUrl(callback) {
- return NewAppError("OutgoingWebhook.IsValid", "Invalid callback URLs. Each must be a valid URL and start with http:// or https://", "")
+ return NewLocAppError("OutgoingWebhook.IsValid", "model.outgoing_hook.is_valid.url.app_error", nil, "")
}
}
diff --git a/model/post.go b/model/post.go
index 5c86ce70d..f9f5a4d1c 100644
--- a/model/post.go
+++ b/model/post.go
@@ -62,60 +62,60 @@ func (o *Post) Etag() string {
func (o *Post) IsValid() *AppError {
if len(o.Id) != 26 {
- return NewAppError("Post.IsValid", "Invalid Id", "")
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.id.app_error", nil, "")
}
if o.CreateAt == 0 {
- return NewAppError("Post.IsValid", "Create at must be a valid time", "id="+o.Id)
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.create_at.app_error", nil, "id="+o.Id)
}
if o.UpdateAt == 0 {
- return NewAppError("Post.IsValid", "Update at must be a valid time", "id="+o.Id)
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.update_at.app_error", nil, "id="+o.Id)
}
if len(o.UserId) != 26 {
- return NewAppError("Post.IsValid", "Invalid user id", "")
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.user_id.app_error", nil, "")
}
if len(o.ChannelId) != 26 {
- return NewAppError("Post.IsValid", "Invalid channel id", "")
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.channel_id.app_error", nil, "")
}
if !(len(o.RootId) == 26 || len(o.RootId) == 0) {
- return NewAppError("Post.IsValid", "Invalid root id", "")
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.root_id.app_error", nil, "")
}
if !(len(o.ParentId) == 26 || len(o.ParentId) == 0) {
- return NewAppError("Post.IsValid", "Invalid parent id", "")
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.parent_id.app_error", nil, "")
}
if len(o.ParentId) == 26 && len(o.RootId) == 0 {
- return NewAppError("Post.IsValid", "Invalid root id must be set if parent id set", "")
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.root_parent.app_error", nil, "")
}
if !(len(o.OriginalId) == 26 || len(o.OriginalId) == 0) {
- return NewAppError("Post.IsValid", "Invalid original id", "")
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.original_id.app_error", nil, "")
}
if utf8.RuneCountInString(o.Message) > 4000 {
- return NewAppError("Post.IsValid", "Invalid message", "id="+o.Id)
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.msg.app_error", nil, "id="+o.Id)
}
if utf8.RuneCountInString(o.Hashtags) > 1000 {
- return NewAppError("Post.IsValid", "Invalid hashtags", "id="+o.Id)
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.hashtags.app_error", nil, "id="+o.Id)
}
// should be removed once more message types are supported
if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_SLACK_ATTACHMENT || o.Type == POST_HEADER_CHANGE) {
- return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type)
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.type.app_error", nil, "id="+o.Type)
}
if utf8.RuneCountInString(ArrayToJson(o.Filenames)) > 4000 {
- return NewAppError("Post.IsValid", "Invalid filenames", "id="+o.Id)
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.filenames.app_error", nil, "id="+o.Id)
}
if utf8.RuneCountInString(StringInterfaceToJson(o.Props)) > 8000 {
- return NewAppError("Post.IsValid", "Invalid props", "id="+o.Id)
+ return NewLocAppError("Post.IsValid", "model.post.is_valid.props.app_error", nil, "id="+o.Id)
}
return nil
diff --git a/model/preference.go b/model/preference.go
index e3ad23ed4..b2ec93105 100644
--- a/model/preference.go
+++ b/model/preference.go
@@ -47,19 +47,19 @@ func PreferenceFromJson(data io.Reader) *Preference {
func (o *Preference) IsValid() *AppError {
if len(o.UserId) != 26 {
- return NewAppError("Preference.IsValid", "Invalid user id", "user_id="+o.UserId)
+ return NewLocAppError("Preference.IsValid", "model.preference.is_valid.id.app_error", nil, "user_id="+o.UserId)
}
if len(o.Category) == 0 || len(o.Category) > 32 {
- return NewAppError("Preference.IsValid", "Invalid category", "category="+o.Category)
+ return NewLocAppError("Preference.IsValid", "model.preference.is_valid.category.app_error", nil, "category="+o.Category)
}
if len(o.Name) == 0 || len(o.Name) > 32 {
- return NewAppError("Preference.IsValid", "Invalid name", "name="+o.Name)
+ return NewLocAppError("Preference.IsValid", "model.preference.is_valid.name.app_error", nil, "name="+o.Name)
}
if utf8.RuneCountInString(o.Value) > 128 {
- return NewAppError("Preference.IsValid", "Value is too long", "value="+o.Value)
+ return NewLocAppError("Preference.IsValid", "model.preference.is_valid.value.app_error", nil, "value="+o.Value)
}
return nil
diff --git a/model/team.go b/model/team.go
index e7dde4766..9e9eaa25f 100644
--- a/model/team.go
+++ b/model/team.go
@@ -104,51 +104,51 @@ func (o *Team) Etag() string {
func (o *Team) IsValid(restrictTeamNames bool) *AppError {
if len(o.Id) != 26 {
- return NewAppError("Team.IsValid", "Invalid Id", "")
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.id.app_error", nil, "")
}
if o.CreateAt == 0 {
- return NewAppError("Team.IsValid", "Create at must be a valid time", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.create_at.app_error", nil, "id="+o.Id)
}
if o.UpdateAt == 0 {
- return NewAppError("Team.IsValid", "Update at must be a valid time", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.update_at.app_error", nil, "id="+o.Id)
}
if len(o.Email) > 128 {
- return NewAppError("Team.IsValid", "Invalid email", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.email.app_error", nil, "id="+o.Id)
}
if len(o.Email) > 0 && !IsValidEmail(o.Email) {
- return NewAppError("Team.IsValid", "Invalid email", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.email.app_error", nil, "id="+o.Id)
}
if utf8.RuneCountInString(o.DisplayName) == 0 || utf8.RuneCountInString(o.DisplayName) > 64 {
- return NewAppError("Team.IsValid", "Invalid name", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.name.app_error", nil, "id="+o.Id)
}
if len(o.Name) > 64 {
- return NewAppError("Team.IsValid", "Invalid URL Identifier", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.url.app_error", nil, "id="+o.Id)
}
if restrictTeamNames && IsReservedTeamName(o.Name) {
- return NewAppError("Team.IsValid", "This URL is unavailable. Please try another.", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.reserved.app_error", nil, "id="+o.Id)
}
if !IsValidTeamName(o.Name) {
- return NewAppError("Team.IsValid", "Name must be 4 or more lowercase alphanumeric characters", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.characters.app_error", nil, "id="+o.Id)
}
if !(o.Type == TEAM_OPEN || o.Type == TEAM_INVITE) {
- return NewAppError("Team.IsValid", "Invalid type", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.type.app_error", nil, "id="+o.Id)
}
if len(o.CompanyName) > 64 {
- return NewAppError("Team.IsValid", "Invalid company name", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.company.app_error", nil, "id="+o.Id)
}
if len(o.AllowedDomains) > 500 {
- return NewAppError("Team.IsValid", "Invalid allowed domains", "id="+o.Id)
+ return NewLocAppError("Team.IsValid", "model.team.is_valid.domains.app_error", nil, "id="+o.Id)
}
return nil
diff --git a/model/user.go b/model/user.go
index 7744b0073..675a1ded6 100644
--- a/model/user.go
+++ b/model/user.go
@@ -61,59 +61,59 @@ type User struct {
func (u *User) IsValid() *AppError {
if len(u.Id) != 26 {
- return NewAppError("User.IsValid", "Invalid user id", "")
+ return NewLocAppError("User.IsValid", "model.user.is_valid.id.app_error", nil, "")
}
if u.CreateAt == 0 {
- return NewAppError("User.IsValid", "Create at must be a valid time", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.create_at.app_error", nil, "user_id="+u.Id)
}
if u.UpdateAt == 0 {
- return NewAppError("User.IsValid", "Update at must be a valid time", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.update_at.app_error", nil, "user_id="+u.Id)
}
if len(u.TeamId) != 26 {
- return NewAppError("User.IsValid", "Invalid team id", "")
+ return NewLocAppError("User.IsValid", "model.user.is_valid.team_id.app_error", nil, "")
}
if !IsValidUsername(u.Username) {
- return NewAppError("User.IsValid", "Invalid username", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.username.app_error", nil, "user_id="+u.Id)
}
if len(u.Email) > 128 || len(u.Email) == 0 {
- return NewAppError("User.IsValid", "Invalid email", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.email.app_error", nil, "user_id="+u.Id)
}
if utf8.RuneCountInString(u.Nickname) > 64 {
- return NewAppError("User.IsValid", "Invalid nickname", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.nickname.app_error", nil, "user_id="+u.Id)
}
if utf8.RuneCountInString(u.FirstName) > 64 {
- return NewAppError("User.IsValid", "Invalid first name", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.first_name.app_error", nil, "user_id="+u.Id)
}
if utf8.RuneCountInString(u.LastName) > 64 {
- return NewAppError("User.IsValid", "Invalid last name", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.last_name.app_error", nil, "user_id="+u.Id)
}
if len(u.Password) > 128 {
- return NewAppError("User.IsValid", "Invalid password", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.pwd.app_error", nil, "user_id="+u.Id)
}
if len(u.AuthData) > 128 {
- return NewAppError("User.IsValid", "Invalid auth data", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.auth_data.app_error", nil, "user_id="+u.Id)
}
if len(u.AuthData) > 0 && len(u.AuthService) == 0 {
- return NewAppError("User.IsValid", "Invalid user, auth data must be set with auth type", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.auth_data_type.app_error", nil, "user_id="+u.Id)
}
if len(u.Password) > 0 && len(u.AuthData) > 0 {
- return NewAppError("User.IsValid", "Invalid user, password and auth data cannot both be set", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.auth_data_pwd.app_error", nil, "user_id="+u.Id)
}
if len(u.ThemeProps) > 2000 {
- return NewAppError("User.IsValid", "Invalid theme", "user_id="+u.Id)
+ return NewLocAppError("User.IsValid", "model.user.is_valid.theme.app_error", nil, "user_id="+u.Id)
}
return nil
@@ -236,7 +236,6 @@ func (u *User) Sanitize(options map[string]bool) {
}
func (u *User) ClearNonProfileFields() {
- u.CreateAt = 0
u.UpdateAt = 0
u.Password = ""
u.AuthData = ""
diff --git a/model/utils.go b/model/utils.go
index 042b5f195..70b7e3bbd 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -67,11 +67,7 @@ func AppErrorFromJson(data io.Reader) *AppError {
if err == nil {
return &er
} else {
- buf := new(bytes.Buffer)
- buf.ReadFrom(data)
- s := buf.String()
-
- return NewAppError("AppErrorFromJson", "could not decode", err.Error()+" "+s)
+ return NewLocAppError("AppErrorFromJson", "model.utils.decode_json.app_error", nil, err.Error())
}
}