Disambiguates some units. (#19875)
* Disambiguates some units. * Updates DB attribute. * Updates some more error-prone units. * Updates some tests with legible constants. * Updates query for MySQL case sensitivity. * Fixes more casing issues. Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -57,7 +57,7 @@ func (s *SqlRetentionPolicyStore) Save(policy *model.RetentionPolicyWithTeamAndC
|
||||
policyInsertQuery, policyInsertArgs, err := s.getQueryBuilder().
|
||||
Insert("RetentionPolicies").
|
||||
Columns("Id", "DisplayName", "PostDuration").
|
||||
Values(policy.ID, policy.DisplayName, policy.PostDuration).
|
||||
Values(policy.ID, policy.DisplayName, policy.PostDurationDays).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -214,13 +214,13 @@ func (s *SqlRetentionPolicyStore) Patch(patch *model.RetentionPolicyWithTeamAndC
|
||||
|
||||
policyUpdateQuery := ""
|
||||
policyUpdateArgs := []interface{}{}
|
||||
if patch.DisplayName != "" || patch.PostDuration != nil {
|
||||
if patch.DisplayName != "" || patch.PostDurationDays != nil {
|
||||
builder := s.getQueryBuilder().Update("RetentionPolicies")
|
||||
if patch.DisplayName != "" {
|
||||
builder = builder.Set("DisplayName", patch.DisplayName)
|
||||
}
|
||||
if patch.PostDuration != nil {
|
||||
builder = builder.Set("PostDuration", *patch.PostDuration)
|
||||
if patch.PostDurationDays != nil {
|
||||
builder = builder.Set("PostDuration", *patch.PostDurationDays)
|
||||
}
|
||||
policyUpdateQuery, policyUpdateArgs, err = builder.
|
||||
Where(sq.Eq{"Id": patch.ID}).
|
||||
@@ -357,7 +357,7 @@ func (s *SqlRetentionPolicyStore) buildGetPoliciesQuery(id string, offset, limit
|
||||
Select(`
|
||||
RetentionPolicies.Id as "Id",
|
||||
RetentionPolicies.DisplayName,
|
||||
RetentionPolicies.PostDuration,
|
||||
RetentionPolicies.PostDuration as "PostDuration",
|
||||
A.Count AS ChannelCount,
|
||||
B.Count AS TeamCount
|
||||
`).
|
||||
@@ -697,7 +697,7 @@ func (s *SqlRetentionPolicyStore) DeleteOrphanedRows(limit int) (deleted int64,
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetTeamPoliciesForUser(userID string, offset, limit int) ([]*model.RetentionPolicyForTeam, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select(`Teams.Id AS "Id", RetentionPolicies.PostDuration`).
|
||||
Select(`Teams.Id AS "Id", RetentionPolicies.PostDuration AS "PostDuration"`).
|
||||
From("Users").
|
||||
InnerJoin("TeamMembers ON Users.Id = TeamMembers.UserId").
|
||||
InnerJoin("Teams ON TeamMembers.TeamId = Teams.Id").
|
||||
@@ -758,7 +758,7 @@ func (s *SqlRetentionPolicyStore) GetTeamPoliciesCountForUser(userID string) (in
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetChannelPoliciesForUser(userID string, offset, limit int) ([]*model.RetentionPolicyForChannel, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select(`Channels.Id as "Id", RetentionPolicies.PostDuration`).
|
||||
Select(`Channels.Id as "Id", RetentionPolicies.PostDuration as "PostDuration"`).
|
||||
From("Users").
|
||||
InnerJoin("ChannelMembers ON Users.Id = ChannelMembers.UserId").
|
||||
InnerJoin("Channels ON ChannelMembers.ChannelId = Channels.Id").
|
||||
|
||||
@@ -375,14 +375,14 @@ func testPermanentDeleteBatchForRetentionPolicies(t *testing.T, ss store.Store)
|
||||
|
||||
channelPolicy, err := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{channel.Id},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
nowMillis := leaveTime + *channelPolicy.PostDuration*24*60*60*1000 + 1
|
||||
nowMillis := leaveTime + *channelPolicy.PostDurationDays*model.DayInMilliseconds + 1
|
||||
_, _, err = ss.ChannelMemberHistory().PermanentDeleteBatchForRetentionPolicies(
|
||||
nowMillis, 0, limit, model.RetentionPolicyCursor{})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -3805,8 +3805,8 @@ func testChannelStoreGetAllChannels(t *testing.T, ss store.Store, s SqlStore) {
|
||||
// Exclude policy constrained
|
||||
policy, nErr := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "Policy 1",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{c1.Id},
|
||||
})
|
||||
@@ -6269,8 +6269,8 @@ func testChannelStoreSearchAllChannels(t *testing.T, ss store.Store) {
|
||||
|
||||
_, nErr = ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "Policy 1",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{o14.Id},
|
||||
})
|
||||
|
||||
@@ -3063,8 +3063,8 @@ func testPostStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
t.Run("with data retention policies", func(t *testing.T) {
|
||||
channelPolicy, err2 := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{channel.Id},
|
||||
})
|
||||
@@ -3083,7 +3083,7 @@ func testPostStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
_, err2 = ss.Post().Get(context.Background(), post.Id, model.GetPostsOptions{}, "")
|
||||
require.NoError(t, err2, "global policy should have been ignored due to granular policy")
|
||||
|
||||
nowMillis := post.CreateAt + *channelPolicy.PostDuration*24*60*60*1000 + 1
|
||||
nowMillis := post.CreateAt + *channelPolicy.PostDurationDays*model.DayInMilliseconds + 1
|
||||
_, _, err2 = ss.Post().PermanentDeleteBatchForRetentionPolicies(nowMillis, 0, 1000, model.RetentionPolicyCursor{})
|
||||
require.NoError(t, err2)
|
||||
_, err2 = ss.Post().Get(context.Background(), post.Id, model.GetPostsOptions{}, "")
|
||||
@@ -3092,8 +3092,8 @@ func testPostStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
// Create a team policy which is stricter than the channel policy
|
||||
teamPolicy, err2 := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(20),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(20),
|
||||
},
|
||||
TeamIDs: []string{team.Id},
|
||||
})
|
||||
@@ -3102,7 +3102,7 @@ func testPostStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
post, err2 = ss.Post().Save(post)
|
||||
require.NoError(t, err2)
|
||||
|
||||
nowMillis = post.CreateAt + *teamPolicy.PostDuration*24*60*60*1000 + 1
|
||||
nowMillis = post.CreateAt + *teamPolicy.PostDurationDays*model.DayInMilliseconds + 1
|
||||
_, _, err2 = ss.Post().PermanentDeleteBatchForRetentionPolicies(nowMillis, 0, 1000, model.RetentionPolicyCursor{})
|
||||
require.NoError(t, err2)
|
||||
_, err2 = ss.Post().Get(context.Background(), post.Id, model.GetPostsOptions{}, "")
|
||||
@@ -3144,8 +3144,8 @@ func testPostStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
|
||||
channelPolicy, err2 := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{c1.Id},
|
||||
})
|
||||
@@ -3153,8 +3153,8 @@ func testPostStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
defer ss.RetentionPolicy().Delete(channelPolicy.ID)
|
||||
teamPolicy, err2 := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
TeamIDs: []string{team.Id},
|
||||
})
|
||||
@@ -3186,7 +3186,7 @@ func testPostStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
})
|
||||
require.NoError(t, err2)
|
||||
|
||||
nowMillis := int64(1 + 30*24*60*60*1000 + 1)
|
||||
nowMillis := int64(1 + 30*model.DayInMilliseconds + 1)
|
||||
deleted, _, err2 := ss.Post().PermanentDeleteBatchForRetentionPolicies(nowMillis, 2, 1000, model.RetentionPolicyCursor{})
|
||||
require.NoError(t, err2)
|
||||
require.Equal(t, int64(3), deleted)
|
||||
|
||||
@@ -34,9 +34,9 @@ func getRetentionPolicyWithTeamAndChannelIds(t *testing.T, ss store.Store, polic
|
||||
require.NoError(t, err)
|
||||
policyWithIds := model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policyID,
|
||||
DisplayName: policyWithCounts.DisplayName,
|
||||
PostDuration: policyWithCounts.PostDuration,
|
||||
ID: policyID,
|
||||
DisplayName: policyWithCounts.DisplayName,
|
||||
PostDurationDays: policyWithCounts.PostDurationDays,
|
||||
},
|
||||
ChannelIDs: make([]string, int(policyWithCounts.ChannelCount)),
|
||||
TeamIDs: make([]string, int(policyWithCounts.TeamCount)),
|
||||
@@ -57,7 +57,7 @@ func getRetentionPolicyWithTeamAndChannelIds(t *testing.T, ss store.Store, polic
|
||||
func CheckRetentionPolicyWithTeamAndChannelIdsAreEqual(t *testing.T, p1, p2 *model.RetentionPolicyWithTeamAndChannelIDs) {
|
||||
require.Equal(t, p1.ID, p2.ID)
|
||||
require.Equal(t, p1.DisplayName, p2.DisplayName)
|
||||
require.Equal(t, p1.PostDuration, p2.PostDuration)
|
||||
require.Equal(t, p1.PostDurationDays, p2.PostDurationDays)
|
||||
require.Equal(t, len(p1.ChannelIDs), len(p2.ChannelIDs))
|
||||
if p1.ChannelIDs == nil || p2.ChannelIDs == nil {
|
||||
require.Equal(t, p1.ChannelIDs, p2.ChannelIDs)
|
||||
@@ -83,7 +83,7 @@ func CheckRetentionPolicyWithTeamAndChannelIdsAreEqual(t *testing.T, p1, p2 *mod
|
||||
func CheckRetentionPolicyWithTeamAndChannelCountsAreEqual(t *testing.T, p1, p2 *model.RetentionPolicyWithTeamAndChannelCounts) {
|
||||
require.Equal(t, p1.ID, p2.ID)
|
||||
require.Equal(t, p1.DisplayName, p2.DisplayName)
|
||||
require.Equal(t, p1.PostDuration, p2.PostDuration)
|
||||
require.Equal(t, p1.PostDurationDays, p2.PostDurationDays)
|
||||
require.Equal(t, p1.ChannelCount, p2.ChannelCount)
|
||||
require.Equal(t, p1.TeamCount, p2.TeamCount)
|
||||
}
|
||||
@@ -175,8 +175,8 @@ func deleteTeamsAndChannels(ss store.Store, teamIDs, channelIDs []string) {
|
||||
func createRetentionPolicyWithTeamAndChannelIds(displayName string, teamIDs, channelIDs []string) *model.RetentionPolicyWithTeamAndChannelIDs {
|
||||
return &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: displayName,
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: displayName,
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
TeamIDs: teamIDs,
|
||||
ChannelIDs: channelIDs,
|
||||
@@ -255,22 +255,22 @@ func testRetentionPolicyStorePatch(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("modify PostDuration", func(t *testing.T) {
|
||||
patch := &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policy.ID,
|
||||
PostDuration: model.NewInt64(10000),
|
||||
ID: policy.ID,
|
||||
PostDurationDays: model.NewInt64(10000),
|
||||
},
|
||||
}
|
||||
_, err := ss.RetentionPolicy().Patch(patch)
|
||||
require.NoError(t, err)
|
||||
expected := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
expected.PostDuration = patch.PostDuration
|
||||
expected.PostDurationDays = patch.PostDurationDays
|
||||
checkRetentionPolicyLikeThisExists(t, ss, expected)
|
||||
|
||||
// Store a negative value (= infinity)
|
||||
patch.PostDuration = model.NewInt64(-1)
|
||||
patch.PostDurationDays = model.NewInt64(-1)
|
||||
_, err = ss.RetentionPolicy().Patch(patch)
|
||||
require.NoError(t, err)
|
||||
expected = copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
expected.PostDuration = patch.PostDuration
|
||||
expected.PostDurationDays = patch.PostDurationDays
|
||||
checkRetentionPolicyLikeThisExists(t, ss, expected)
|
||||
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
|
||||
@@ -259,8 +259,8 @@ func testTeamStoreSearchAll(t *testing.T, ss store.Store) {
|
||||
|
||||
_, err = ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDuration: model.NewInt64(20),
|
||||
DisplayName: "Policy 1",
|
||||
PostDurationDays: model.NewInt64(20),
|
||||
},
|
||||
TeamIDs: []string{q.Id},
|
||||
})
|
||||
@@ -665,8 +665,8 @@ func testTeamStoreGetAllPage(t *testing.T, ss store.Store) {
|
||||
|
||||
policy, err := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "Policy 1",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
TeamIDs: []string{o.Id},
|
||||
})
|
||||
|
||||
@@ -442,14 +442,14 @@ func testThreadStorePermanentDeleteBatchForRetentionPolicies(t *testing.T, ss st
|
||||
|
||||
channelPolicy, err := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{channel.Id},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
nowMillis := thread.LastReplyAt + *channelPolicy.PostDuration*24*60*60*1000 + 1
|
||||
nowMillis := thread.LastReplyAt + *channelPolicy.PostDurationDays*model.DayInMilliseconds + 1
|
||||
_, _, err = ss.Thread().PermanentDeleteBatchForRetentionPolicies(nowMillis, 0, limit, model.RetentionPolicyCursor{})
|
||||
require.NoError(t, err)
|
||||
thread, err = ss.Thread().Get(post.Id)
|
||||
@@ -464,14 +464,14 @@ func testThreadStorePermanentDeleteBatchForRetentionPolicies(t *testing.T, ss st
|
||||
// Create a team policy which is stricter than the channel policy
|
||||
teamPolicy, err := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(20),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(20),
|
||||
},
|
||||
TeamIDs: []string{team.Id},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
nowMillis = thread.LastReplyAt + *teamPolicy.PostDuration*24*60*60*1000 + 1
|
||||
nowMillis = thread.LastReplyAt + *teamPolicy.PostDurationDays*model.DayInMilliseconds + 1
|
||||
_, _, err = ss.Thread().PermanentDeleteBatchForRetentionPolicies(nowMillis, 0, limit, model.RetentionPolicyCursor{})
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Thread().Get(post.Id)
|
||||
@@ -529,14 +529,14 @@ func testThreadStorePermanentDeleteBatchThreadMembershipsForRetentionPolicies(t
|
||||
|
||||
channelPolicy, err := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(30),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{channel.Id},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
nowMillis := threadMembership.LastUpdated + *channelPolicy.PostDuration*24*60*60*1000 + 1
|
||||
nowMillis := threadMembership.LastUpdated + *channelPolicy.PostDurationDays*model.DayInMilliseconds + 1
|
||||
_, _, err = ss.Thread().PermanentDeleteBatchThreadMembershipsForRetentionPolicies(nowMillis, 0, limit, model.RetentionPolicyCursor{})
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Thread().GetMembershipForUser(userID, post.Id)
|
||||
@@ -548,14 +548,14 @@ func testThreadStorePermanentDeleteBatchThreadMembershipsForRetentionPolicies(t
|
||||
// Create a team policy which is stricter than the channel policy
|
||||
teamPolicy, err := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "DisplayName",
|
||||
PostDuration: model.NewInt64(20),
|
||||
DisplayName: "DisplayName",
|
||||
PostDurationDays: model.NewInt64(20),
|
||||
},
|
||||
TeamIDs: []string{team.Id},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
nowMillis = threadMembership.LastUpdated + *teamPolicy.PostDuration*24*60*60*1000 + 1
|
||||
nowMillis = threadMembership.LastUpdated + *teamPolicy.PostDurationDays*model.DayInMilliseconds + 1
|
||||
_, _, err = ss.Thread().PermanentDeleteBatchThreadMembershipsForRetentionPolicies(nowMillis, 0, limit, model.RetentionPolicyCursor{})
|
||||
require.NoError(t, err)
|
||||
_, err = ss.Thread().GetMembershipForUser(userID, post.Id)
|
||||
|
||||
Ссылка в новой задаче
Block a user