From ce2646de3e6385e66fb01d533f0917838ed8b30e Mon Sep 17 00:00:00 2001 From: mkraft Date: Thu, 7 Apr 2022 13:58:40 -0400 Subject: [PATCH] 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 --- api4/channel_test.go | 8 ++-- api4/team.go | 2 +- api4/team_test.go | 8 ++-- api4/user.go | 4 +- app/session.go | 2 +- model/config.go | 42 ++++++++++--------- model/data_retention_policy.go | 14 +++---- model/license.go | 7 +++- store/sqlstore/retention_policy_store.go | 14 +++---- .../storetest/channel_member_history_store.go | 6 +-- store/storetest/channel_store.go | 8 ++-- store/storetest/post_store.go | 22 +++++----- store/storetest/retention_policy_store.go | 24 +++++------ store/storetest/team_store.go | 8 ++-- store/storetest/thread_store.go | 24 +++++------ 15 files changed, 99 insertions(+), 94 deletions(-) diff --git a/api4/channel_test.go b/api4/channel_test.go index 9acadeb1f3..a79554cb8f 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -1169,8 +1169,8 @@ func TestGetAllChannels(t *testing.T) { policyChannel := (sysManagerChannels)[0] policy, err := th.App.Srv().Store.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{ RetentionPolicy: model.RetentionPolicy{ - DisplayName: "Policy 1", - PostDuration: model.NewInt64(30), + DisplayName: "Policy 1", + PostDurationDays: model.NewInt64(30), }, ChannelIDs: []string{policyChannel.Id}, }) @@ -1621,8 +1621,8 @@ func TestSearchAllChannels(t *testing.T) { policyChannel := sysManagerChannels[0] policy, savePolicyErr := th.App.Srv().Store.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{ RetentionPolicy: model.RetentionPolicy{ - DisplayName: "Policy 1", - PostDuration: model.NewInt64(30), + DisplayName: "Policy 1", + PostDurationDays: model.NewInt64(30), }, ChannelIDs: []string{policyChannel.Id}, }) diff --git a/api4/team.go b/api4/team.go index 3d2604ba2e..5ef022b541 100644 --- a/api4/team.go +++ b/api4/team.go @@ -1501,7 +1501,7 @@ func getTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "image/png") - w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, private", 24*60*60)) // 24 hrs + w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, private", model.DayInSeconds)) // 24 hrs w.Header().Set(model.HeaderEtagServer, etag) w.Write(img) } diff --git a/api4/team_test.go b/api4/team_test.go index 8a3e0341ec..e4518b5802 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -1066,8 +1066,8 @@ func TestGetAllTeams(t *testing.T) { // Now actually create the policy and assign the team to it policy, savePolicyErr := th.App.Srv().Store.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{ RetentionPolicy: model.RetentionPolicy{ - DisplayName: "Policy 1", - PostDuration: model.NewInt64(30), + DisplayName: "Policy 1", + PostDurationDays: model.NewInt64(30), }, TeamIDs: []string{policyTeam.Id}, }) @@ -1379,8 +1379,8 @@ func TestSearchAllTeams(t *testing.T) { // Now actually create the policy and assign the team to it policy, savePolicyErr := th.App.Srv().Store.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{ RetentionPolicy: model.RetentionPolicy{ - DisplayName: "Policy 1", - PostDuration: model.NewInt64(30), + DisplayName: "Policy 1", + PostDurationDays: model.NewInt64(30), }, TeamIDs: []string{policyTeam.Id}, }) diff --git a/api4/user.go b/api4/user.go index a2bb38d9d1..fb2c25b747 100644 --- a/api4/user.go +++ b/api4/user.go @@ -364,7 +364,7 @@ func getDefaultProfileImage(c *Context, w http.ResponseWriter, r *http.Request) return } - w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, private", 24*60*60)) // 24 hrs + w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, private", model.DayInSeconds)) // 24 hrs w.Header().Set("Content-Type", "image/png") w.Write(img) } @@ -406,7 +406,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { if readFailed { w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, private", 5*60)) // 5 mins } else { - w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, private", 24*60*60)) // 24 hrs + w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%v, private", model.DayInSeconds)) // 24 hrs w.Header().Set(model.HeaderEtagServer, etag) } diff --git a/app/session.go b/app/session.go index 1d3a1833bb..cfa188360e 100644 --- a/app/session.go +++ b/app/session.go @@ -267,7 +267,7 @@ func (a *App) ExtendSessionExpiryIfNeeded(session *model.Session) bool { // Only extend the expiry if the lessor of 1% or 1 day has elapsed within the // current session duration. - threshold := int64(math.Min(float64(sessionLength)*0.01, float64(24*60*60*1000))) + threshold := int64(math.Min(float64(sessionLength)*0.01, float64(model.DayInMilliseconds))) // Minimum session length is 1 day as of this writing, therefore a minimum ~14 minutes threshold. // However we'll add a sanity check here in case that changes. Minimum 5 minute threshold, // meaning we won't write a new expiry more than every 5 minutes. diff --git a/model/config.go b/model/config.go index cd90888c7a..cb7ba9dd8d 100644 --- a/model/config.go +++ b/model/config.go @@ -275,15 +275,16 @@ var ServerTLSSupportedCiphers = map[string]uint16{ } type ServiceSettings struct { - SiteURL *string `access:"environment_web_server,authentication_saml,write_restrictable"` - WebsocketURL *string `access:"write_restrictable,cloud_restrictable"` - LicenseFileLocation *string `access:"write_restrictable,cloud_restrictable"` // telemetry: none - ListenAddress *string `access:"environment_web_server,write_restrictable,cloud_restrictable"` // telemetry: none - ConnectionSecurity *string `access:"environment_web_server,write_restrictable,cloud_restrictable"` - TLSCertFile *string `access:"environment_web_server,write_restrictable,cloud_restrictable"` - TLSKeyFile *string `access:"environment_web_server,write_restrictable,cloud_restrictable"` - TLSMinVer *string `access:"write_restrictable,cloud_restrictable"` // telemetry: none - TLSStrictTransport *bool `access:"write_restrictable,cloud_restrictable"` + SiteURL *string `access:"environment_web_server,authentication_saml,write_restrictable"` + WebsocketURL *string `access:"write_restrictable,cloud_restrictable"` + LicenseFileLocation *string `access:"write_restrictable,cloud_restrictable"` // telemetry: none + ListenAddress *string `access:"environment_web_server,write_restrictable,cloud_restrictable"` // telemetry: none + ConnectionSecurity *string `access:"environment_web_server,write_restrictable,cloud_restrictable"` + TLSCertFile *string `access:"environment_web_server,write_restrictable,cloud_restrictable"` + TLSKeyFile *string `access:"environment_web_server,write_restrictable,cloud_restrictable"` + TLSMinVer *string `access:"write_restrictable,cloud_restrictable"` // telemetry: none + TLSStrictTransport *bool `access:"write_restrictable,cloud_restrictable"` + // In seconds. TLSStrictTransportMaxAge *int64 `access:"write_restrictable,cloud_restrictable"` // telemetry: none TLSOverwriteCiphers []string `access:"write_restrictable,cloud_restrictable"` // telemetry: none UseLetsEncrypt *bool `access:"environment_web_server,write_restrictable,cloud_restrictable"` @@ -1884,17 +1885,18 @@ func (s *ThemeSettings) SetDefaults() { } type TeamSettings struct { - SiteName *string `access:"site_customization"` - MaxUsersPerTeam *int `access:"site_users_and_teams"` - EnableUserCreation *bool `access:"authentication_signup"` - EnableOpenServer *bool `access:"authentication_signup"` - EnableUserDeactivation *bool `access:"experimental_features"` - RestrictCreationToDomains *string `access:"authentication_signup"` // telemetry: none - EnableCustomUserStatuses *bool `access:"site_users_and_teams"` - EnableCustomBrand *bool `access:"site_customization"` - CustomBrandText *string `access:"site_customization"` - CustomDescriptionText *string `access:"site_customization"` - RestrictDirectMessage *string `access:"site_users_and_teams"` + SiteName *string `access:"site_customization"` + MaxUsersPerTeam *int `access:"site_users_and_teams"` + EnableUserCreation *bool `access:"authentication_signup"` + EnableOpenServer *bool `access:"authentication_signup"` + EnableUserDeactivation *bool `access:"experimental_features"` + RestrictCreationToDomains *string `access:"authentication_signup"` // telemetry: none + EnableCustomUserStatuses *bool `access:"site_users_and_teams"` + EnableCustomBrand *bool `access:"site_customization"` + CustomBrandText *string `access:"site_customization"` + CustomDescriptionText *string `access:"site_customization"` + RestrictDirectMessage *string `access:"site_users_and_teams"` + // In seconds. UserStatusAwayTimeout *int64 `access:"experimental_features"` MaxChannelsPerTeam *int64 `access:"site_users_and_teams"` MaxNotificationsPerChannel *int64 `access:"environment_push_notification_server"` diff --git a/model/data_retention_policy.go b/model/data_retention_policy.go index 3210251700..549b98012d 100644 --- a/model/data_retention_policy.go +++ b/model/data_retention_policy.go @@ -13,9 +13,9 @@ type GlobalRetentionPolicy struct { } type RetentionPolicy struct { - ID string `db:"Id" json:"id"` - DisplayName string `json:"display_name"` - PostDuration *int64 `json:"post_duration"` + ID string `db:"Id" json:"id"` + DisplayName string `json:"display_name"` + PostDurationDays *int64 `db:"PostDuration" json:"post_duration"` } type RetentionPolicyWithTeamAndChannelIDs struct { @@ -46,8 +46,8 @@ type RetentionPolicyWithTeamAndChannelCountsList struct { } type RetentionPolicyForTeam struct { - TeamID string `db:"Id" json:"team_id"` - PostDuration int64 `json:"post_duration"` + TeamID string `db:"Id" json:"team_id"` + PostDurationDays int64 `db:"PostDuration" json:"post_duration"` } type RetentionPolicyForTeamList struct { @@ -56,8 +56,8 @@ type RetentionPolicyForTeamList struct { } type RetentionPolicyForChannel struct { - ChannelID string `db:"Id" json:"channel_id"` - PostDuration int64 `json:"post_duration"` + ChannelID string `db:"Id" json:"channel_id"` + PostDurationDays int64 `db:"PostDuration" json:"post_duration"` } type RetentionPolicyForChannelList struct { diff --git a/model/license.go b/model/license.go index c8a953053f..c647faca87 100644 --- a/model/license.go +++ b/model/license.go @@ -11,9 +11,12 @@ import ( ) const ( + DayInSeconds = 24 * 60 * 60 + DayInMilliseconds = DayInSeconds * 1000 + ExpiredLicenseError = "api.license.add_license.expired.app_error" InvalidLicenseError = "api.license.add_license.invalid.app_error" - LicenseGracePeriod = 1000 * 60 * 60 * 24 * 10 //10 days + LicenseGracePeriod = DayInMilliseconds * 10 //10 days LicenseRenewalLink = "https://mattermost.com/renew/" LicenseShortSkuE10 = "E10" @@ -307,7 +310,7 @@ func (l *License) HasEnterpriseMarketplacePlugins() bool { // NewTestLicense returns a license that expires in the future and has the given features. func NewTestLicense(features ...string) *License { ret := &License{ - ExpiresAt: GetMillis() + 90*24*60*60*1000, + ExpiresAt: GetMillis() + 90*DayInMilliseconds, Customer: &Customer{}, Features: &Features{}, } diff --git a/store/sqlstore/retention_policy_store.go b/store/sqlstore/retention_policy_store.go index 6b1891897a..eae017ce5c 100644 --- a/store/sqlstore/retention_policy_store.go +++ b/store/sqlstore/retention_policy_store.go @@ -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"). diff --git a/store/storetest/channel_member_history_store.go b/store/storetest/channel_member_history_store.go index 1e88a66fe3..ef344aab3e 100644 --- a/store/storetest/channel_member_history_store.go +++ b/store/storetest/channel_member_history_store.go @@ -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) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index ed999b3b2b..338069a13a 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -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}, }) diff --git a/store/storetest/post_store.go b/store/storetest/post_store.go index 1c476d2e45..0ea40fc5c0 100644 --- a/store/storetest/post_store.go +++ b/store/storetest/post_store.go @@ -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) diff --git a/store/storetest/retention_policy_store.go b/store/storetest/retention_policy_store.go index fbdd1e21ee..5bf18edfda 100644 --- a/store/storetest/retention_policy_store.go +++ b/store/storetest/retention_policy_store.go @@ -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) diff --git a/store/storetest/team_store.go b/store/storetest/team_store.go index 7f7960941e..cbad0cb7fd 100644 --- a/store/storetest/team_store.go +++ b/store/storetest/team_store.go @@ -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}, }) diff --git a/store/storetest/thread_store.go b/store/storetest/thread_store.go index e57c37becf..d2c32fe3cb 100644 --- a/store/storetest/thread_store.go +++ b/store/storetest/thread_store.go @@ -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)