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>
Этот коммит содержится в:
@@ -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},
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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},
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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{},
|
||||
}
|
||||
|
||||
@@ -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