Fix empty string comparison issues in the codebase (#16686)

Automatic Merge
Этот коммит содержится в:
Madhav Hugar
2021-01-25 11:15:17 +01:00
коммит произвёл GitHub
родитель 200a56fa5a
Коммит 94c24eea20
107 изменённых файлов: 368 добавлений и 368 удалений

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

@@ -173,13 +173,13 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(channel.Type) > 0 && channel.Type != oldChannel.Type {
if channel.Type != "" && channel.Type != oldChannel.Type {
c.Err = model.NewAppError("updateChannel", "api.channel.update_channel.typechange.app_error", nil, "", http.StatusBadRequest)
return
}
if oldChannel.Name == model.DEFAULT_CHANNEL {
if len(channel.Name) > 0 && channel.Name != oldChannel.Name {
if channel.Name != "" && channel.Name != oldChannel.Name {
c.Err = model.NewAppError("updateChannel", "api.channel.update_channel.tried.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "", http.StatusBadRequest)
return
}
@@ -190,11 +190,11 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelDisplayName := oldChannel.DisplayName
if len(channel.DisplayName) > 0 {
if channel.DisplayName != "" {
oldChannel.DisplayName = channel.DisplayName
}
if len(channel.Name) > 0 {
if channel.Name != "" {
oldChannel.Name = channel.Name
auditRec.AddMeta("new_channel_name", oldChannel.Name)
}

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

@@ -216,7 +216,7 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
customOnly, _ := strconv.ParseBool(r.URL.Query().Get("custom_only"))
teamId := r.URL.Query().Get("team_id")
if len(teamId) == 0 {
if teamId == "" {
c.SetInvalidParam("team_id")
return
}

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

@@ -181,7 +181,7 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
var config map[string]string
if len(c.App.Session().UserId) == 0 {
if c.App.Session().UserId == "" {
config = c.App.LimitedClientConfigWithComputed()
} else {
config = c.App.ClientConfigWithComputed()

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

@@ -565,7 +565,7 @@ func getFileLink(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(info.PostId) == 0 {
if info.PostId == "" {
c.Err = model.NewAppError("getPublicLink", "api.file.get_public_link.no_post.app_error", nil, "file_id="+info.Id, http.StatusBadRequest)
return
}
@@ -658,7 +658,7 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
hash := r.URL.Query().Get("h")
if len(hash) == 0 {
if hash == "" {
c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_invalid.app_error", nil, "", http.StatusBadRequest)
utils.RenderWebAppError(c.App.Config(), w, r, c.Err, c.App.AsymmetricSigningKey())
return

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

@@ -67,7 +67,7 @@ func testDoUploadFileRequest(t testing.TB, c *model.Client4, url string, blob []
req.ContentLength = contentLength
}
req.Header.Set("Content-Type", contentType)
if len(c.AuthToken) > 0 {
if c.AuthToken != "" {
req.Header.Set(model.HEADER_AUTH, c.AuthType+" "+c.AuthToken)
}

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

@@ -792,7 +792,7 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
}
sinceString := r.URL.Query().Get("since")
if len(sinceString) > 0 {
if sinceString != "" {
since, parseError := strconv.ParseInt(sinceString, 10, 64)
if parseError != nil {
c.SetInvalidParam("since")

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

@@ -271,7 +271,7 @@ func unlinkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
func migrateIdLdap(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.StringInterfaceFromJson(r.Body)
toAttribute, ok := props["toAttribute"].(string)
if !ok || len(toAttribute) == 0 {
if !ok || toAttribute == "" {
c.SetInvalidParam("toAttribute")
return
}

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

@@ -41,7 +41,7 @@ func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
url := ""
ok := false
if url, ok = props["url"].(string); len(url) == 0 || !ok {
if url, ok = props["url"].(string); url == "" || !ok {
c.SetInvalidParam("url")
return
}

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

@@ -136,13 +136,13 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
afterPost := r.URL.Query().Get("after")
if len(afterPost) > 0 && !model.IsValidId(afterPost) {
if afterPost != "" && !model.IsValidId(afterPost) {
c.SetInvalidParam("after")
return
}
beforePost := r.URL.Query().Get("before")
if len(beforePost) > 0 && !model.IsValidId(beforePost) {
if beforePost != "" && !model.IsValidId(beforePost) {
c.SetInvalidParam("before")
return
}
@@ -150,7 +150,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
sinceString := r.URL.Query().Get("since")
var since int64
var parseError error
if len(sinceString) > 0 {
if sinceString != "" {
since, parseError = strconv.ParseInt(sinceString, 10, 64)
if parseError != nil {
c.SetInvalidParam("since")
@@ -175,7 +175,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
if since > 0 {
list, err = c.App.GetPostsSince(model.GetPostsSinceOptions{ChannelId: channelId, Time: since, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads, CollapsedThreadsExtended: collapsedThreadsExtended})
} else if len(afterPost) > 0 {
} else if afterPost != "" {
etag = c.App.GetPostsEtag(channelId, collapsedThreads)
if c.HandleEtag(etag, "Get Posts After", w, r) {
@@ -183,7 +183,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
list, err = c.App.GetPostsAfterPost(model.GetPostsOptions{ChannelId: channelId, PostId: afterPost, Page: page, PerPage: perPage, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads})
} else if len(beforePost) > 0 {
} else if beforePost != "" {
etag = c.App.GetPostsEtag(channelId, collapsedThreads)
if c.HandleEtag(etag, "Get Posts Before", w, r) {
@@ -206,7 +206,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(etag) > 0 {
if etag != "" {
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
}
@@ -269,7 +269,7 @@ func getPostsForChannelAroundLastUnread(c *Context, w http.ResponseWriter, r *ht
clientPostList := c.App.PreparePostListForClient(postList)
if len(etag) > 0 {
if etag != "" {
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
}
w.Write([]byte(clientPostList.ToJson()))
@@ -292,9 +292,9 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
var posts *model.PostList
var err *model.AppError
if len(channelId) > 0 {
if channelId != "" {
posts, err = c.App.GetFlaggedPostsForChannel(c.Params.UserId, channelId, c.Params.Page, c.Params.PerPage)
} else if len(teamId) > 0 {
} else if teamId != "" {
posts, err = c.App.GetFlaggedPostsForTeam(c.Params.UserId, teamId, c.Params.Page, c.Params.PerPage)
} else {
posts, err = c.App.GetFlaggedPosts(c.Params.UserId, c.Params.Page, c.Params.PerPage)
@@ -476,7 +476,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if params.Terms == nil || len(*params.Terms) == 0 {
if params.Terms == nil || *params.Terms == "" {
c.SetInvalidParam("terms")
return
}

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

@@ -23,7 +23,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !model.IsValidId(reaction.UserId) || !model.IsValidId(reaction.PostId) || len(reaction.EmojiName) == 0 || len(reaction.EmojiName) > model.EMOJI_NAME_MAX_LENGTH {
if !model.IsValidId(reaction.UserId) || !model.IsValidId(reaction.PostId) || reaction.EmojiName == "" || len(reaction.EmojiName) > model.EMOJI_NAME_MAX_LENGTH {
c.Err = model.NewAppError("saveReaction", "api.reaction.save_reaction.invalid.app_error", nil, "", http.StatusBadRequest)
return
}

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

@@ -413,7 +413,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
}
url := r.URL.Query().Get("url")
if len(url) == 0 {
if url == "" {
c.SetInvalidParam("url")
return
}

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

@@ -657,9 +657,9 @@ func addUserToTeamFromInvite(c *Context, w http.ResponseWriter, r *http.Request)
defer c.LogAuditRec(auditRec)
auditRec.AddMeta("invite_id", inviteId)
if len(tokenId) > 0 {
if tokenId != "" {
member, err = c.App.AddTeamMemberByToken(c.App.Session().UserId, tokenId)
} else if len(inviteId) > 0 {
} else if inviteId != "" {
if c.App.Session().Props[model.SESSION_PROP_IS_GUEST] == "true" {
c.Err = model.NewAppError("addUserToTeamFromInvite", "api.team.add_user_to_team_from_invite.guest.app_error", nil, "", http.StatusForbidden)
return

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

@@ -122,7 +122,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
var ruser *model.User
var err *model.AppError
if len(tokenId) > 0 {
if tokenId != "" {
token, nErr := c.App.Srv().Store.Token().GetByToken(tokenId)
if nErr != nil {
var status int
@@ -148,7 +148,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
ruser, err = c.App.CreateUserWithToken(user, token)
} else if len(inviteId) > 0 {
} else if inviteId != "" {
ruser, err = c.App.CreateUserWithInviteId(user, inviteId, redirect)
} else if c.IsSystemAdmin() {
ruser, err = c.App.CreateUserAsAdmin(user, redirect)
@@ -431,7 +431,7 @@ func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(*c.App.Config().FileSettings.DriverName) == 0 {
if *c.App.Config().FileSettings.DriverName == "" {
c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.storage.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -491,7 +491,7 @@ func setDefaultProfileImage(c *Context, w http.ResponseWriter, r *http.Request)
return
}
if len(*c.App.Config().FileSettings.DriverName) == 0 {
if *c.App.Config().FileSettings.DriverName == "" {
c.Err = model.NewAppError("setDefaultProfileImage", "api.user.upload_profile_user.storage.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -633,7 +633,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
channelRolesString := r.URL.Query().Get("channel_roles")
teamRolesString := r.URL.Query().Get("team_roles")
if len(notInChannelId) > 0 && len(inTeamId) == 0 {
if notInChannelId != "" && inTeamId == "" {
c.SetInvalidUrlParam("team_id")
return
}
@@ -726,14 +726,14 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
}
profiles, err = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
} else if len(notInChannelId) > 0 {
} else if notInChannelId != "" {
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), notInChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
profiles, err = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
} else if len(notInTeamId) > 0 {
} else if notInTeamId != "" {
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), notInTeamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
@@ -745,7 +745,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
}
profiles, err = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
} else if len(inTeamId) > 0 {
} else if inTeamId != "" {
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), inTeamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
@@ -762,7 +762,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
}
profiles, err = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
}
} else if len(inChannelId) > 0 {
} else if inChannelId != "" {
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), inChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
@@ -772,7 +772,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
profiles, err = c.App.GetUsersInChannelPage(userGetOptions, c.IsSystemAdmin())
}
} else if len(inGroupId) > 0 {
} else if inGroupId != "" {
if c.App.Srv().License() == nil || !*c.App.Srv().License().Features.LDAPGroups {
c.Err = model.NewAppError("Api4.getUsersInGroup", "api.ldap_groups.license_error", nil, "", http.StatusNotImplemented)
return
@@ -802,7 +802,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(etag) > 0 {
if etag != "" {
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
}
c.App.UpdateLastActivityAtIfNeeded(*c.App.Session())
@@ -823,7 +823,7 @@ func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
IsAdmin: c.IsSystemAdmin(),
}
if len(sinceString) > 0 {
if sinceString != "" {
since, parseError := strconv.ParseInt(sinceString, 10, 64)
if parseError != nil {
c.SetInvalidParam("since")
@@ -890,7 +890,7 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(props.Term) == 0 {
if props.Term == "" {
c.SetInvalidParam("term")
return
}
@@ -996,14 +996,14 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
options.AllowFullNames = *c.App.Config().PrivacySettings.ShowFullName
}
if len(channelId) > 0 {
if channelId != "" {
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
}
if len(teamId) > 0 {
if teamId != "" {
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
@@ -1019,11 +1019,11 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(channelId) > 0 {
if channelId != "" {
// We're using the channelId to search for users inside that channel and the team
// to get the not in channel list. Also we want to include the DM and GM users for
// that team which could only be obtained having the team id.
if len(teamId) == 0 {
if teamId == "" {
c.Err = model.NewAppError("autocompleteUser",
"api.user.autocomplete_users.missing_team_id.app_error",
nil,
@@ -1040,7 +1040,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
autocomplete.Users = result.InChannel
autocomplete.OutOfChannel = result.OutOfChannel
} else if len(teamId) > 0 {
} else if teamId != "" {
result, err := c.App.AutocompleteUsersInTeam(teamId, name, options)
if err != nil {
c.Err = err
@@ -1432,7 +1432,7 @@ func checkUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.MapFromJson(r.Body)
loginId := props["login_id"]
if len(loginId) == 0 {
if loginId == "" {
c.SetInvalidParam("login_id")
return
}
@@ -1488,7 +1488,7 @@ func updateUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
code := ""
if activate {
code, ok = props["code"].(string)
if !ok || len(code) == 0 {
if !ok || code == "" {
c.SetInvalidParam("code")
return
}
@@ -1576,7 +1576,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
if c.Params.UserId == c.App.Session().UserId {
currentPassword := props["current_password"]
if len(currentPassword) <= 0 {
if currentPassword == "" {
c.SetInvalidParam("current_password")
return
}
@@ -1634,7 +1634,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
email := props["email"]
email = strings.ToLower(email)
if len(email) == 0 {
if email == "" {
c.SetInvalidParam("email")
return
}
@@ -1735,7 +1735,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
certPem, certSubject, certEmail := c.App.CheckForClientSideCert(r)
mlog.Debug("Client Cert", mlog.String("cert_subject", certSubject), mlog.String("cert_email", certEmail))
if len(certPem) == 0 || len(certEmail) == 0 {
if certPem == "" || certEmail == "" {
c.Err = model.NewAppError("ClientSideCertMissing", "api.user.login.client_side_cert.certificate.app_error", nil, "", http.StatusBadRequest)
return
}
@@ -1984,7 +1984,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.MapFromJson(r.Body)
deviceId := props["device_id"]
if len(deviceId) == 0 {
if deviceId == "" {
c.SetInvalidParam("device_id")
return
}
@@ -2095,7 +2095,7 @@ func sendVerificationEmail(c *Context, w http.ResponseWriter, r *http.Request) {
email := props["email"]
email = strings.ToLower(email)
if len(email) == 0 {
if email == "" {
c.SetInvalidParam("email")
return
}
@@ -2238,7 +2238,7 @@ func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request)
return
}
if len(props.Term) == 0 {
if props.Term == "" {
c.SetInvalidParam("term")
return
}
@@ -2709,7 +2709,7 @@ func migrateAuthToLDAP(c *Context, w http.ResponseWriter, r *http.Request) {
c.SetInvalidParam("from")
return
}
if len(from) == 0 || (from != "email" && from != "gitlab" && from != "saml" && from != "google" && from != "office365") {
if from == "" || (from != "email" && from != "gitlab" && from != "saml" && from != "google" && from != "office365") {
c.SetInvalidParam("from")
return
}
@@ -2768,7 +2768,7 @@ func migrateAuthToSaml(c *Context, w http.ResponseWriter, r *http.Request) {
c.SetInvalidParam("from")
return
}
if len(from) == 0 || (from != "email" && from != "gitlab" && from != "ldap" && from != "google" && from != "office365") {
if from == "" || (from != "email" && from != "gitlab" && from != "ldap" && from != "google" && from != "office365") {
c.SetInvalidParam("from")
return
}
@@ -2840,7 +2840,7 @@ func getThreadsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
sinceString := r.URL.Query().Get("since")
if len(sinceString) > 0 {
if sinceString != "" {
since, parseError := strconv.ParseUint(sinceString, 10, 64)
if parseError != nil {
c.SetInvalidParam("since")
@@ -2850,7 +2850,7 @@ func getThreadsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
pageString := r.URL.Query().Get("page")
if len(pageString) > 0 {
if pageString != "" {
page, parseError := strconv.ParseUint(pageString, 10, 64)
if parseError != nil {
c.SetInvalidParam("page")
@@ -2860,7 +2860,7 @@ func getThreadsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
pageSizeString := r.URL.Query().Get("pageSize")
if len(pageString) > 0 {
if pageString != "" {
pageSize, parseError := strconv.ParseUint(pageSizeString, 10, 64)
if parseError != nil {
c.SetInvalidParam("pageSize")

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

@@ -54,7 +54,7 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
role := r.URL.Query().Get("role")
sort := r.URL.Query().Get("sort")
if len(notInChannelId) > 0 && len(inTeamId) == 0 {
if notInChannelId != "" && inTeamId == "" {
c.SetInvalidUrlParam("team_id")
return
}
@@ -102,16 +102,16 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
if withoutTeamBool, _ := strconv.ParseBool(withoutTeam); withoutTeamBool {
profiles, err = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
} else if len(notInChannelId) > 0 {
} else if notInChannelId != "" {
profiles, err = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
} else if len(notInTeamId) > 0 {
} else if notInTeamId != "" {
etag = c.App.GetUsersNotInTeamEtag(inTeamId, "")
if c.HandleEtag(etag, "Get Users Not in Team", w, r) {
return
}
profiles, err = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
} else if len(inTeamId) > 0 {
} else if inTeamId != "" {
if sort == "last_activity_at" {
profiles, err = c.App.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
} else if sort == "create_at" {
@@ -123,7 +123,7 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
}
profiles, err = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
}
} else if len(inChannelId) > 0 {
} else if inChannelId != "" {
if sort == "status" {
profiles, err = c.App.GetUsersInChannelPageByStatus(userGetOptions, c.IsSystemAdmin())
} else {
@@ -138,7 +138,7 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if len(etag) > 0 {
if etag != "" {
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
}
w.Write([]byte(model.UserListToJson(profiles)))
@@ -158,7 +158,7 @@ func localGetUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
IsAdmin: c.IsSystemAdmin(),
}
if len(sinceString) > 0 {
if sinceString != "" {
since, parseError := strconv.ParseInt(sinceString, 10, 64)
if parseError != nil {
c.SetInvalidParam("since")

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

@@ -173,7 +173,7 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
var hooks []*model.IncomingWebhook
var err *model.AppError
if len(teamId) > 0 {
if teamId != "" {
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
c.SetPermissionError(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS)
return
@@ -436,7 +436,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
var hooks []*model.OutgoingWebhook
var err *model.AppError
if len(channelId) > 0 {
if channelId != "" {
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
return
@@ -448,7 +448,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
}
hooks, err = c.App.GetOutgoingWebhooksForChannelPageByUser(channelId, userId, c.Params.Page, c.Params.PerPage)
} else if len(teamId) > 0 {
} else if teamId != "" {
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
return

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

@@ -31,7 +31,7 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {
wc := c.App.NewWebConn(ws, *c.App.Session(), c.App.T, "")
if len(c.App.Session().UserId) > 0 {
if c.App.Session().UserId != "" {
c.App.HubRegister(wc)
}