Merge branch 'master' into mark-as-unread

Этот коммит содержится в:
Harrison Healey
2019-10-29 10:11:41 -04:00
родитель 9b1ba32dc6 38c0bde7f8
Коммит eb36329e8d
112 изменённых файлов: 1569 добавлений и 1479 удалений

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

@@ -1790,7 +1790,7 @@ func (s SqlChannelStore) RemoveAllDeactivatedMembers(channelId string) *model.Ap
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError {
if _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil {
return model.NewAppError("SqlChannelStore.RemoveMember", "store.sql_channel.permanent_delete_members_by_user.app_error", nil, "user_id="+userId+", "+err.Error(), http.StatusInternalServerError)
return model.NewAppError("SqlChannelStore.ChannelPermanentDeleteMembersByUser", "store.sql_channel.permanent_delete_members_by_user.app_error", nil, "user_id="+userId+", "+err.Error(), http.StatusInternalServerError)
}
return nil
}

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

@@ -123,6 +123,18 @@ func (s *SqlGroupStore) Get(groupId string) (*model.Group, *model.AppError) {
return group, nil
}
func (s *SqlGroupStore) GetByName(name string) (*model.Group, *model.AppError) {
var group *model.Group
if err := s.GetReplica().SelectOne(&group, "SELECT * from UserGroups WHERE Name = :Name", map[string]interface{}{"Name": name}); err != nil {
if err == sql.ErrNoRows {
return nil, model.NewAppError("SqlGroupStore.GroupGetByName", "store.sql_group.no_rows", nil, err.Error(), http.StatusNotFound)
}
return nil, model.NewAppError("SqlGroupStore.GroupGetByName", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
}
return group, nil
}
func (s *SqlGroupStore) GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError) {
var groups []*model.Group
query := s.getQueryBuilder().Select("*").From("UserGroups").Where(sq.Eq{"Id": groupIDs})
@@ -158,6 +170,26 @@ func (s *SqlGroupStore) GetAllBySource(groupSource model.GroupSource) ([]*model.
return groups, nil
}
func (s *SqlGroupStore) GetByUser(userId string) ([]*model.Group, *model.AppError) {
var groups []*model.Group
query := `
SELECT
UserGroups.*
FROM
GroupMembers
JOIN UserGroups ON UserGroups.Id = GroupMembers.GroupId
WHERE
GroupMembers.DeleteAt = 0
AND UserId = :UserId`
if _, err := s.GetReplica().Select(&groups, query, map[string]interface{}{"UserId": userId}); err != nil {
return nil, model.NewAppError("SqlGroupStore.GetByUser", "store.select_error", nil, err.Error(), http.StatusInternalServerError)
}
return groups, nil
}
func (s *SqlGroupStore) Update(group *model.Group) (*model.Group, *model.AppError) {
var retrievedGroup *model.Group
if err := s.GetMaster().SelectOne(&retrievedGroup, "SELECT * FROM UserGroups WHERE Id = :Id", map[string]interface{}{"Id": group.Id}); err != nil {
@@ -341,6 +373,13 @@ func (s *SqlGroupStore) DeleteMember(groupID string, userID string) (*model.Grou
return retrievedMember, nil
}
func (s *SqlGroupStore) PermanentDeleteMembersByUser(userId string) *model.AppError {
if _, err := s.GetMaster().Exec("DELETE FROM GroupMembers WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil {
return model.NewAppError("SqlGroupStore.GroupPermanentDeleteMembersByUser", "store.sql_group.permanent_delete_members_by_user.app_error", map[string]interface{}{"UserId": userId}, "", http.StatusInternalServerError)
}
return nil
}
func (s *SqlGroupStore) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
if err := groupSyncable.IsValid(); err != nil {
return nil, err

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

@@ -14,10 +14,10 @@ import (
func createAudit(ss store.Store, userId, sessionId string) *model.Audit {
audit := model.Audit{
UserId: userId,
UserId: userId,
SessionId: sessionId,
IpAddress: "ipaddress",
Action: "Action",
Action: "Action",
}
ss.Audit().Save(&audit)
return &audit
@@ -46,7 +46,7 @@ func createChannelWithSchemeId(ss store.Store, schemeId *string) *model.Channel
return c
}
func createCommand(ss store.Store, userId, teamId string) * model.Command {
func createCommand(ss store.Store, userId, teamId string) *model.Command {
m := model.Command{}
m.CreatorId = userId
m.Method = model.COMMAND_METHOD_POST
@@ -75,19 +75,15 @@ func createChannelMemberHistory(ss store.Store, channelId, userId string) *model
}
func createChannelWithTeamId(ss store.Store, id string) *model.Channel {
return createChannel(ss, id, model.NewId());
return createChannel(ss, id, model.NewId())
}
func createChannelWithCreatorId(ss store.Store, id string) *model.Channel {
return createChannel(ss, model.NewId(), id);
return createChannel(ss, model.NewId(), id)
}
func createChannelMemberWithChannelId(ss store.Store, id string) *model.ChannelMember {
return createChannelMember(ss, id, model.NewId());
}
func createChannelMemberWithUserId(ss store.Store, id string) *model.ChannelMember {
return createChannelMember(ss, model.NewId(), id);
return createChannelMember(ss, id, model.NewId())
}
func createCommandWebhook(ss store.Store, commandId, userId, channelId string) *model.CommandWebhook {
@@ -192,20 +188,20 @@ func createPost(ss store.Store, channelId, userId, rootId, parentId string) *mod
}
func createPostWithChannelId(ss store.Store, id string) *model.Post {
return createPost(ss, id, model.NewId(), "", "");
return createPost(ss, id, model.NewId(), "", "")
}
func createPostWithUserId(ss store.Store, id string) *model.Post {
return createPost(ss, model.NewId(), id, "", "");
return createPost(ss, model.NewId(), id, "", "")
}
func createPreferences(ss store.Store, userId string) *model.Preferences {
preferences := model.Preferences{
{
UserId: userId,
Name: model.NewId(),
UserId: userId,
Name: model.NewId(),
Category: model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW,
Value: "somevalue",
Value: "somevalue",
},
}
ss.Preference().Save(&preferences)
@@ -369,10 +365,10 @@ func TestCheckParentChildIntegrity(t *testing.T) {
supplier := ss.(*store.LayeredStore).DatabaseLayer.(*SqlSupplier)
t.Run("should receive an error", func(t *testing.T) {
config := relationalCheckConfig{
parentName: "NotValid",
parentName: "NotValid",
parentIdAttr: "NotValid",
childName: "NotValid",
childIdAttr: "NotValid",
childName: "NotValid",
childIdAttr: "NotValid",
}
result := checkParentChildIntegrity(supplier, config)
require.NotNil(t, result.Err)
@@ -402,7 +398,7 @@ func TestCheckChannelsCommandWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: channelId,
ChildId: cwh.Id,
ChildId: cwh.Id,
}, data.Records[0])
dbmap.Delete(cwh)
})
@@ -488,7 +484,7 @@ func TestCheckChannelsIncomingWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: channelId,
ChildId: wh.Id,
ChildId: wh.Id,
}, data.Records[0])
dbmap.Delete(wh)
})
@@ -518,7 +514,7 @@ func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: channelId,
ChildId: wh.Id,
ChildId: wh.Id,
}, data.Records[0])
dbmap.Delete(wh)
})
@@ -545,7 +541,7 @@ func TestCheckChannelsPostsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: post.ChannelId,
ChildId: post.Id,
ChildId: post.Id,
}, data.Records[0])
dbmap.Delete(post)
})
@@ -573,7 +569,7 @@ func TestCheckCommandsCommandWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: commandId,
ChildId: cwh.Id,
ChildId: cwh.Id,
}, data.Records[0])
dbmap.Delete(cwh)
})
@@ -631,7 +627,7 @@ func TestCheckPostsPostsParentIdIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: parentId,
ChildId: post.Id,
ChildId: post.Id,
}, data.Records[0])
dbmap.Delete(root)
dbmap.Delete(post)
@@ -662,7 +658,7 @@ func TestCheckPostsPostsRootIdIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: rootId,
ChildId: post.Id,
ChildId: post.Id,
}, data.Records[0])
dbmap.Delete(post)
})
@@ -720,7 +716,7 @@ func TestCheckSchemesChannelsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: schemeId,
ChildId: channel.Id,
ChildId: channel.Id,
}, data.Records[0])
dbmap.Delete(channel)
})
@@ -751,7 +747,7 @@ func TestCheckSchemesTeamsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: schemeId,
ChildId: team.Id,
ChildId: team.Id,
}, data.Records[0])
dbmap.Delete(team)
})
@@ -782,7 +778,7 @@ func TestCheckSessionsAuditsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: sessionId,
ChildId: audit.Id,
ChildId: audit.Id,
}, data.Records[0])
ss.Audit().PermanentDeleteByUser(userId)
})
@@ -809,7 +805,7 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: channel.TeamId,
ChildId: channel.Id,
ChildId: channel.Id,
}, data.Records[0])
dbmap.Delete(channel)
})
@@ -837,7 +833,7 @@ func TestCheckTeamsCommandsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: teamId,
ChildId: cmd.Id,
ChildId: cmd.Id,
}, data.Records[0])
dbmap.Delete(cmd)
})
@@ -865,7 +861,7 @@ func TestCheckTeamsIncomingWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: teamId,
ChildId: wh.Id,
ChildId: wh.Id,
}, data.Records[0])
dbmap.Delete(wh)
})
@@ -893,7 +889,7 @@ func TestCheckTeamsOutgoingWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: teamId,
ChildId: wh.Id,
ChildId: wh.Id,
}, data.Records[0])
dbmap.Delete(wh)
})
@@ -951,7 +947,7 @@ func TestCheckUsersAuditsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: audit.Id,
ChildId: audit.Id,
}, data.Records[0])
ss.Audit().PermanentDeleteByUser(userId)
})
@@ -979,7 +975,7 @@ func TestCheckUsersCommandWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: cwh.Id,
ChildId: cwh.Id,
}, data.Records[0])
dbmap.Delete(cwh)
})
@@ -1006,7 +1002,7 @@ func TestCheckUsersChannelsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: channel.CreatorId,
ChildId: channel.Id,
ChildId: channel.Id,
}, data.Records[0])
dbmap.Delete(channel)
})
@@ -1094,7 +1090,7 @@ func TestCheckUsersCommandsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: cmd.Id,
ChildId: cmd.Id,
}, data.Records[0])
dbmap.Delete(cmd)
})
@@ -1124,7 +1120,7 @@ func TestCheckUsersCompliancesIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: compliance.Id,
ChildId: compliance.Id,
}, data.Records[0])
dbmap.Delete(compliance)
})
@@ -1154,7 +1150,7 @@ func TestCheckUsersEmojiIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: emoji.Id,
ChildId: emoji.Id,
}, data.Records[0])
dbmap.Delete(emoji)
})
@@ -1211,7 +1207,7 @@ func TestCheckUsersIncomingWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: wh.Id,
ChildId: wh.Id,
}, data.Records[0])
dbmap.Delete(wh)
})
@@ -1241,7 +1237,7 @@ func TestCheckUsersOAuthAccessDataIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: ad.Token,
ChildId: ad.Token,
}, data.Records[0])
ss.OAuth().RemoveAccessData(ad.Token)
})
@@ -1271,7 +1267,7 @@ func TestCheckUsersOAuthAppsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: app.Id,
ChildId: app.Id,
}, data.Records[0])
ss.OAuth().DeleteApp(app.Id)
})
@@ -1301,7 +1297,7 @@ func TestCheckUsersOAuthAuthDataIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: ad.Code,
ChildId: ad.Code,
}, data.Records[0])
ss.OAuth().RemoveAuthData(ad.Code)
})
@@ -1329,7 +1325,7 @@ func TestCheckUsersOutgoingWebhooksIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: wh.Id,
ChildId: wh.Id,
}, data.Records[0])
dbmap.Delete(wh)
})
@@ -1356,7 +1352,7 @@ func TestCheckUsersPostsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: post.UserId,
ChildId: post.Id,
ChildId: post.Id,
}, data.Records[0])
dbmap.Delete(post)
})
@@ -1442,7 +1438,7 @@ func TestCheckUsersSessionsIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: session.Id,
ChildId: session.Id,
}, data.Records[0])
dbmap.Delete(session)
})
@@ -1531,7 +1527,7 @@ func TestCheckUsersUserAccessTokensIntegrity(t *testing.T) {
require.Len(t, data.Records, 1)
require.Equal(t, store.OrphanedRecord{
ParentId: userId,
ChildId: uat.Id,
ChildId: uat.Id,
}, data.Records[0])
ss.UserAccessToken().Delete(uat.Id)
})

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

@@ -1346,7 +1346,6 @@ func (s *SqlPostStore) GetOldest() (*model.Post, *model.AppError) {
}
func (s *SqlPostStore) determineMaxPostSize() int {
var maxPostSize int = model.POST_MESSAGE_MAX_RUNES_V1
var maxPostSizeBytes int32
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
@@ -1384,7 +1383,7 @@ func (s *SqlPostStore) determineMaxPostSize() int {
}
// Assume a worst-case representation of four bytes per rune.
maxPostSize = int(maxPostSizeBytes) / 4
maxPostSize := int(maxPostSizeBytes) / 4
// To maintain backwards compatibility, don't yield a maximum post
// size smaller than the previous limit, even though it wasn't

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

@@ -699,7 +699,7 @@ func (ss *SqlSupplier) AlterColumnDefaultIfExists(tableName string, columnName s
return false
}
var defaultValue = ""
var defaultValue string
if ss.DriverName() == model.DATABASE_DRIVER_MYSQL {
// Some column types in MySQL cannot have defaults, so don't try to configure anything.
if mySqlColDefault == nil {

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

@@ -4,7 +4,6 @@
package sqlstore
import (
"database/sql"
"encoding/json"
"os"
"strings"
@@ -602,33 +601,6 @@ func UpgradeDatabaseToVersion57(sqlStore SqlStore) {
}
}
func getRole(sqlStore SqlStore, name string) (*model.Role, error) {
var dbRole Role
if err := sqlStore.GetReplica().SelectOne(&dbRole, "SELECT * from Roles WHERE Name = :Name", map[string]interface{}{"Name": name}); err != nil {
if err == sql.ErrNoRows {
return nil, errors.Wrapf(err, "failed to find role %s", name)
} else {
return nil, errors.Wrapf(err, "failed to query role %s", name)
}
}
return dbRole.ToModel(), nil
}
func saveRole(sqlStore SqlStore, role *model.Role) error {
dbRole := NewRoleFromModel(role)
dbRole.UpdateAt = model.GetMillis()
if rowsChanged, err := sqlStore.GetMaster().Update(dbRole); err != nil {
return errors.Wrap(err, "failed to update role")
} else if rowsChanged != 1 {
return errors.New("found no role to update")
}
return nil
}
func UpgradeDatabaseToVersion58(sqlStore SqlStore) {
if shouldPerformUpgrade(sqlStore, VERSION_5_7_0, VERSION_5_8_0) {
// idx_channels_txt was removed in `UpgradeDatabaseToVersion50`, but merged as part of

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

@@ -1267,7 +1267,7 @@ func generateSearchQuery(query sq.SelectBuilder, terms []string, fields []string
func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
term = sanitizeSearchTerm(term, "*")
searchType := USER_SEARCH_TYPE_NAMES_NO_FULL_NAME
var searchType []string
if options.AllowEmails {
if options.AllowFullNames {
searchType = USER_SEARCH_TYPE_ALL
@@ -1359,8 +1359,7 @@ func (us SqlUserStore) GetProfilesNotInTeam(teamId string, groupConstrained bool
}
func (us SqlUserStore) GetEtagForProfilesNotInTeam(teamId string) string {
var querystr string
querystr = `
querystr := `
SELECT
CONCAT(MAX(UpdateAt), '.', COUNT(Id)) as etag
FROM