Mm 30807 granular data retention scaffold (#17464)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
368b642105
Коммит
f36f5c74b1
@@ -39,6 +39,7 @@ type OpenTracingLayer struct {
|
||||
ProductNoticesStore store.ProductNoticesStore
|
||||
ReactionStore store.ReactionStore
|
||||
RemoteClusterStore store.RemoteClusterStore
|
||||
RetentionPolicyStore store.RetentionPolicyStore
|
||||
RoleStore store.RoleStore
|
||||
SchemeStore store.SchemeStore
|
||||
SessionStore store.SessionStore
|
||||
@@ -140,6 +141,10 @@ func (s *OpenTracingLayer) RemoteCluster() store.RemoteClusterStore {
|
||||
return s.RemoteClusterStore
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayer) RetentionPolicy() store.RetentionPolicyStore {
|
||||
return s.RetentionPolicyStore
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayer) Role() store.RoleStore {
|
||||
return s.RoleStore
|
||||
}
|
||||
@@ -305,6 +310,11 @@ type OpenTracingLayerRemoteClusterStore struct {
|
||||
Root *OpenTracingLayer
|
||||
}
|
||||
|
||||
type OpenTracingLayerRetentionPolicyStore struct {
|
||||
store.RetentionPolicyStore
|
||||
Root *OpenTracingLayer
|
||||
}
|
||||
|
||||
type OpenTracingLayerRoleStore struct {
|
||||
store.RoleStore
|
||||
Root *OpenTracingLayer
|
||||
@@ -6117,6 +6127,330 @@ func (s *OpenTracingLayerRemoteClusterStore) UpdateTopics(remoteClusterId string
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) AddChannels(policyId string, channelIds []string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.AddChannels")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
err := s.RetentionPolicyStore.AddChannels(policyId, channelIds)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) AddTeams(policyId string, teamIds []string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.AddTeams")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
err := s.RetentionPolicyStore.AddTeams(policyId, teamIds)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) Delete(id string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.Delete")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
err := s.RetentionPolicyStore.Delete(id)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) Get(id string) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.Get")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.Get(id)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetAll(offset int, limit int) ([]*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetAll")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetAll(offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetChannelPoliciesCountForUser(userID string) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetChannelPoliciesCountForUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetChannelPoliciesCountForUser(userID)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetChannelPoliciesForUser(userID string, offset int, limit int) ([]*model.RetentionPolicyForChannel, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetChannelPoliciesForUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetChannelPoliciesForUser(userID, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetChannels(policyId string, offset int, limit int) (model.ChannelListWithTeamData, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetChannels")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetChannels(policyId, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetChannelsCount(policyId string) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetChannelsCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetChannelsCount(policyId)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetCount() (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetCount()
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetTeamPoliciesCountForUser(userID string) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetTeamPoliciesCountForUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetTeamPoliciesCountForUser(userID)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetTeamPoliciesForUser(userID string, offset int, limit int) ([]*model.RetentionPolicyForTeam, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetTeamPoliciesForUser")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetTeamPoliciesForUser(userID, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetTeams(policyId string, offset int, limit int) ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetTeams")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetTeams(policyId, offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) GetTeamsCount(policyId string) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.GetTeamsCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.GetTeamsCount(policyId)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) Patch(patch *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.Patch")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.Patch(patch)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) RemoveChannels(policyId string, channelIds []string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.RemoveChannels")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
err := s.RetentionPolicyStore.RemoveChannels(policyId, channelIds)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) RemoveTeams(policyId string, teamIds []string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.RemoveTeams")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
err := s.RetentionPolicyStore.RemoveTeams(policyId, teamIds)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRetentionPolicyStore) Save(policy *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RetentionPolicyStore.Save")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.RetentionPolicyStore.Save(policy)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerRoleStore) AllChannelSchemeRoles() ([]*model.Role, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "RoleStore.AllChannelSchemeRoles")
|
||||
@@ -7426,43 +7760,7 @@ func (s *OpenTracingLayerTeamStore) AnalyticsGetTeamCountForScheme(schemeID stri
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) AnalyticsPrivateTeamCount() (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.AnalyticsPrivateTeamCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.AnalyticsPrivateTeamCount()
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) AnalyticsPublicTeamCount() (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.AnalyticsPublicTeamCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.AnalyticsPublicTeamCount()
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, error) {
|
||||
func (s *OpenTracingLayerTeamStore) AnalyticsTeamCount(opts *model.TeamSearch) (int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.AnalyticsTeamCount")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -7471,7 +7769,7 @@ func (s *OpenTracingLayerTeamStore) AnalyticsTeamCount(includeDeleted bool) (int
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.AnalyticsTeamCount(includeDeleted)
|
||||
result, err := s.TeamStore.AnalyticsTeamCount(opts)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -7583,7 +7881,7 @@ func (s *OpenTracingLayerTeamStore) GetAllForExportAfter(limit int, afterID stri
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) GetAllPage(offset int, limit int) ([]*model.Team, error) {
|
||||
func (s *OpenTracingLayerTeamStore) GetAllPage(offset int, limit int, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.GetAllPage")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -7592,7 +7890,7 @@ func (s *OpenTracingLayerTeamStore) GetAllPage(offset int, limit int) ([]*model.
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.GetAllPage(offset, limit)
|
||||
result, err := s.TeamStore.GetAllPage(offset, limit, opts)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -7619,42 +7917,6 @@ func (s *OpenTracingLayerTeamStore) GetAllPrivateTeamListing() ([]*model.Team, e
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.GetAllPrivateTeamPageListing")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.GetAllPrivateTeamPageListing(offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.GetAllPublicTeamPageListing")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.GetAllPublicTeamPageListing(offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.GetAllTeamListing")
|
||||
@@ -7673,24 +7935,6 @@ func (s *OpenTracingLayerTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.GetAllTeamPageListing")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.GetAllTeamPageListing(offset, limit)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) GetByInviteId(inviteID string) (*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.GetByInviteId")
|
||||
@@ -8172,7 +8416,7 @@ func (s *OpenTracingLayerTeamStore) SaveMultipleMembers(members []*model.TeamMem
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) SearchAll(term string, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
func (s *OpenTracingLayerTeamStore) SearchAll(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.SearchAll")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -8181,7 +8425,7 @@ func (s *OpenTracingLayerTeamStore) SearchAll(term string, opts *model.TeamSearc
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.SearchAll(term, opts)
|
||||
result, err := s.TeamStore.SearchAll(opts)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -8190,7 +8434,7 @@ func (s *OpenTracingLayerTeamStore) SearchAll(term string, opts *model.TeamSearc
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
func (s *OpenTracingLayerTeamStore) SearchAllPaged(opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.SearchAllPaged")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -8199,7 +8443,7 @@ func (s *OpenTracingLayerTeamStore) SearchAllPaged(term string, opts *model.Team
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, resultVar1, err := s.TeamStore.SearchAllPaged(term, opts)
|
||||
result, resultVar1, err := s.TeamStore.SearchAllPaged(opts)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -8208,7 +8452,7 @@ func (s *OpenTracingLayerTeamStore) SearchAllPaged(term string, opts *model.Team
|
||||
return result, resultVar1, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
func (s *OpenTracingLayerTeamStore) SearchOpen(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.SearchOpen")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -8217,7 +8461,7 @@ func (s *OpenTracingLayerTeamStore) SearchOpen(term string) ([]*model.Team, erro
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.SearchOpen(term)
|
||||
result, err := s.TeamStore.SearchOpen(opts)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -8226,7 +8470,7 @@ func (s *OpenTracingLayerTeamStore) SearchOpen(term string) ([]*model.Team, erro
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerTeamStore) SearchPrivate(term string) ([]*model.Team, error) {
|
||||
func (s *OpenTracingLayerTeamStore) SearchPrivate(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "TeamStore.SearchPrivate")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -8235,7 +8479,7 @@ func (s *OpenTracingLayerTeamStore) SearchPrivate(term string) ([]*model.Team, e
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.TeamStore.SearchPrivate(term)
|
||||
result, err := s.TeamStore.SearchPrivate(opts)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -10906,6 +11150,7 @@ func New(childStore store.Store, ctx context.Context) *OpenTracingLayer {
|
||||
newStore.ProductNoticesStore = &OpenTracingLayerProductNoticesStore{ProductNoticesStore: childStore.ProductNotices(), Root: &newStore}
|
||||
newStore.ReactionStore = &OpenTracingLayerReactionStore{ReactionStore: childStore.Reaction(), Root: &newStore}
|
||||
newStore.RemoteClusterStore = &OpenTracingLayerRemoteClusterStore{RemoteClusterStore: childStore.RemoteCluster(), Root: &newStore}
|
||||
newStore.RetentionPolicyStore = &OpenTracingLayerRetentionPolicyStore{RetentionPolicyStore: childStore.RetentionPolicy(), Root: &newStore}
|
||||
newStore.RoleStore = &OpenTracingLayerRoleStore{RoleStore: childStore.Role(), Root: &newStore}
|
||||
newStore.SchemeStore = &OpenTracingLayerSchemeStore{SchemeStore: childStore.Scheme(), Root: &newStore}
|
||||
newStore.SessionStore = &OpenTracingLayerSessionStore{SessionStore: childStore.Session(), Root: &newStore}
|
||||
|
||||
@@ -41,6 +41,7 @@ type RetryLayer struct {
|
||||
ProductNoticesStore store.ProductNoticesStore
|
||||
ReactionStore store.ReactionStore
|
||||
RemoteClusterStore store.RemoteClusterStore
|
||||
RetentionPolicyStore store.RetentionPolicyStore
|
||||
RoleStore store.RoleStore
|
||||
SchemeStore store.SchemeStore
|
||||
SessionStore store.SessionStore
|
||||
@@ -142,6 +143,10 @@ func (s *RetryLayer) RemoteCluster() store.RemoteClusterStore {
|
||||
return s.RemoteClusterStore
|
||||
}
|
||||
|
||||
func (s *RetryLayer) RetentionPolicy() store.RetentionPolicyStore {
|
||||
return s.RetentionPolicyStore
|
||||
}
|
||||
|
||||
func (s *RetryLayer) Role() store.RoleStore {
|
||||
return s.RoleStore
|
||||
}
|
||||
@@ -307,6 +312,11 @@ type RetryLayerRemoteClusterStore struct {
|
||||
Root *RetryLayer
|
||||
}
|
||||
|
||||
type RetryLayerRetentionPolicyStore struct {
|
||||
store.RetentionPolicyStore
|
||||
Root *RetryLayer
|
||||
}
|
||||
|
||||
type RetryLayerRoleStore struct {
|
||||
store.RoleStore
|
||||
Root *RetryLayer
|
||||
@@ -6620,6 +6630,366 @@ func (s *RetryLayerRemoteClusterStore) UpdateTopics(remoteClusterId string, topi
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) AddChannels(policyId string, channelIds []string) error {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
err := s.RetentionPolicyStore.AddChannels(policyId, channelIds)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) AddTeams(policyId string, teamIds []string) error {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
err := s.RetentionPolicyStore.AddTeams(policyId, teamIds)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) Delete(id string) error {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
err := s.RetentionPolicyStore.Delete(id)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) Get(id string) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.Get(id)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetAll(offset int, limit int) ([]*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetAll(offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetChannelPoliciesCountForUser(userID string) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetChannelPoliciesCountForUser(userID)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetChannelPoliciesForUser(userID string, offset int, limit int) ([]*model.RetentionPolicyForChannel, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetChannelPoliciesForUser(userID, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetChannels(policyId string, offset int, limit int) (model.ChannelListWithTeamData, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetChannels(policyId, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetChannelsCount(policyId string) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetChannelsCount(policyId)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetCount() (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetCount()
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetTeamPoliciesCountForUser(userID string) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetTeamPoliciesCountForUser(userID)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetTeamPoliciesForUser(userID string, offset int, limit int) ([]*model.RetentionPolicyForTeam, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetTeamPoliciesForUser(userID, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetTeams(policyId string, offset int, limit int) ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetTeams(policyId, offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) GetTeamsCount(policyId string) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.GetTeamsCount(policyId)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) Patch(patch *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.Patch(patch)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) RemoveChannels(policyId string, channelIds []string) error {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
err := s.RetentionPolicyStore.RemoveChannels(policyId, channelIds)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) RemoveTeams(policyId string, teamIds []string) error {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
err := s.RetentionPolicyStore.RemoveTeams(policyId, teamIds)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRetentionPolicyStore) Save(policy *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.RetentionPolicyStore.Save(policy)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerRoleStore) AllChannelSchemeRoles() ([]*model.Role, error) {
|
||||
|
||||
tries := 0
|
||||
@@ -8066,51 +8436,11 @@ func (s *RetryLayerTeamStore) AnalyticsGetTeamCountForScheme(schemeID string) (i
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) AnalyticsPrivateTeamCount() (int64, error) {
|
||||
func (s *RetryLayerTeamStore) AnalyticsTeamCount(opts *model.TeamSearch) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.AnalyticsPrivateTeamCount()
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) AnalyticsPublicTeamCount() (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.AnalyticsPublicTeamCount()
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.AnalyticsTeamCount(includeDeleted)
|
||||
result, err := s.TeamStore.AnalyticsTeamCount(opts)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -8232,11 +8562,11 @@ func (s *RetryLayerTeamStore) GetAllForExportAfter(limit int, afterID string) ([
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) GetAllPage(offset int, limit int) ([]*model.Team, error) {
|
||||
func (s *RetryLayerTeamStore) GetAllPage(offset int, limit int, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.GetAllPage(offset, limit)
|
||||
result, err := s.TeamStore.GetAllPage(offset, limit, opts)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -8272,46 +8602,6 @@ func (s *RetryLayerTeamStore) GetAllPrivateTeamListing() ([]*model.Team, error)
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.GetAllPrivateTeamPageListing(offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.GetAllPublicTeamPageListing(offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
@@ -8332,26 +8622,6 @@ func (s *RetryLayerTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.GetAllTeamPageListing(offset, limit)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
if !isRepeatableError(err) {
|
||||
return result, err
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) GetByInviteId(inviteID string) (*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
@@ -8878,11 +9148,11 @@ func (s *RetryLayerTeamStore) SaveMultipleMembers(members []*model.TeamMember, m
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) SearchAll(term string, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
func (s *RetryLayerTeamStore) SearchAll(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.SearchAll(term, opts)
|
||||
result, err := s.TeamStore.SearchAll(opts)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -8898,11 +9168,11 @@ func (s *RetryLayerTeamStore) SearchAll(term string, opts *model.TeamSearch) ([]
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
func (s *RetryLayerTeamStore) SearchAllPaged(opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, resultVar1, err := s.TeamStore.SearchAllPaged(term, opts)
|
||||
result, resultVar1, err := s.TeamStore.SearchAllPaged(opts)
|
||||
if err == nil {
|
||||
return result, resultVar1, nil
|
||||
}
|
||||
@@ -8918,11 +9188,11 @@ func (s *RetryLayerTeamStore) SearchAllPaged(term string, opts *model.TeamSearch
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
func (s *RetryLayerTeamStore) SearchOpen(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.SearchOpen(term)
|
||||
result, err := s.TeamStore.SearchOpen(opts)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -8938,11 +9208,11 @@ func (s *RetryLayerTeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerTeamStore) SearchPrivate(term string) ([]*model.Team, error) {
|
||||
func (s *RetryLayerTeamStore) SearchPrivate(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.TeamStore.SearchPrivate(term)
|
||||
result, err := s.TeamStore.SearchPrivate(opts)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -11824,6 +12094,7 @@ func New(childStore store.Store) *RetryLayer {
|
||||
newStore.ProductNoticesStore = &RetryLayerProductNoticesStore{ProductNoticesStore: childStore.ProductNotices(), Root: &newStore}
|
||||
newStore.ReactionStore = &RetryLayerReactionStore{ReactionStore: childStore.Reaction(), Root: &newStore}
|
||||
newStore.RemoteClusterStore = &RetryLayerRemoteClusterStore{RemoteClusterStore: childStore.RemoteCluster(), Root: &newStore}
|
||||
newStore.RetentionPolicyStore = &RetryLayerRetentionPolicyStore{RetentionPolicyStore: childStore.RetentionPolicy(), Root: &newStore}
|
||||
newStore.RoleStore = &RetryLayerRoleStore{RoleStore: childStore.Role(), Root: &newStore}
|
||||
newStore.SchemeStore = &RetryLayerSchemeStore{SchemeStore: childStore.Scheme(), Root: &newStore}
|
||||
newStore.SessionStore = &RetryLayerSessionStore{SessionStore: childStore.Session(), Root: &newStore}
|
||||
|
||||
@@ -40,6 +40,7 @@ func genStore() *mocks.Store {
|
||||
mock.On("Preference").Return(&mocks.PreferenceStore{})
|
||||
mock.On("ProductNotices").Return(&mocks.ProductNoticesStore{})
|
||||
mock.On("Reaction").Return(&mocks.ReactionStore{})
|
||||
mock.On("RetentionPolicy").Return(&mocks.RetentionPolicyStore{})
|
||||
mock.On("Role").Return(&mocks.RoleStore{})
|
||||
mock.On("Scheme").Return(&mocks.SchemeStore{})
|
||||
mock.On("Session").Return(&mocks.SessionStore{})
|
||||
|
||||
@@ -1036,6 +1036,9 @@ func (s SqlChannelStore) getAllChannelsQuery(opts store.ChannelSearchOpts, forCo
|
||||
selectStr = "count(c.Id)"
|
||||
} else {
|
||||
selectStr = "c.*, Teams.DisplayName AS TeamDisplayName, Teams.Name AS TeamName, Teams.UpdateAt AS TeamUpdateAt"
|
||||
if opts.IncludePolicyID {
|
||||
selectStr += ", RetentionPoliciesChannels.PolicyId"
|
||||
}
|
||||
}
|
||||
|
||||
query := s.getQueryBuilder().
|
||||
@@ -1059,6 +1062,13 @@ func (s SqlChannelStore) getAllChannelsQuery(opts store.ChannelSearchOpts, forCo
|
||||
query = query.Where(sq.NotEq{"c.Name": opts.ExcludeChannelNames})
|
||||
}
|
||||
|
||||
if opts.ExcludePolicyConstrained || opts.IncludePolicyID {
|
||||
query = query.LeftJoin("RetentionPoliciesChannels ON c.Id = RetentionPoliciesChannels.ChannelId")
|
||||
}
|
||||
if opts.ExcludePolicyConstrained {
|
||||
query = query.Where("RetentionPoliciesChannels.ChannelId IS NULL")
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -2660,7 +2670,7 @@ func (s SqlChannelStore) SearchForUserInTeam(userId string, teamId string, term
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) channelSearchQuery(term string, opts store.ChannelSearchOpts, countQuery bool) sq.SelectBuilder {
|
||||
func (s SqlChannelStore) channelSearchQuery(opts *store.ChannelSearchOpts) sq.SelectBuilder {
|
||||
var limit int
|
||||
if opts.PerPage != nil {
|
||||
limit = *opts.PerPage
|
||||
@@ -2669,10 +2679,16 @@ func (s SqlChannelStore) channelSearchQuery(term string, opts store.ChannelSearc
|
||||
}
|
||||
|
||||
var selectStr string
|
||||
if countQuery {
|
||||
if opts.CountOnly {
|
||||
selectStr = "count(*)"
|
||||
} else {
|
||||
selectStr = "c.*, t.DisplayName AS TeamDisplayName, t.Name AS TeamName, t.UpdateAt as TeamUpdateAt"
|
||||
selectStr = "c.*"
|
||||
if opts.IncludeTeamInfo {
|
||||
selectStr += ", t.DisplayName AS TeamDisplayName, t.Name AS TeamName, t.UpdateAt as TeamUpdateAt"
|
||||
}
|
||||
if opts.IncludePolicyID {
|
||||
selectStr += ", RetentionPoliciesChannels.PolicyId"
|
||||
}
|
||||
}
|
||||
|
||||
query := s.getQueryBuilder().
|
||||
@@ -2681,7 +2697,7 @@ func (s SqlChannelStore) channelSearchQuery(term string, opts store.ChannelSearc
|
||||
Join("Teams AS t ON t.Id = c.TeamId")
|
||||
|
||||
// don't bother ordering or limiting if we're just getting the count
|
||||
if !countQuery {
|
||||
if !opts.CountOnly {
|
||||
query = query.
|
||||
OrderBy("c.DisplayName, t.DisplayName").
|
||||
Limit(uint64(limit))
|
||||
@@ -2692,14 +2708,27 @@ func (s SqlChannelStore) channelSearchQuery(term string, opts store.ChannelSearc
|
||||
query = query.Where(sq.Eq{"c.DeleteAt": int(0)})
|
||||
}
|
||||
|
||||
if opts.IsPaginated() && !countQuery {
|
||||
if opts.IsPaginated() && !opts.CountOnly {
|
||||
query = query.Offset(uint64(*opts.Page * *opts.PerPage))
|
||||
}
|
||||
|
||||
likeClause, likeTerm := s.buildLIKEClause(term, "c.Name, c.DisplayName, c.Purpose")
|
||||
if opts.PolicyID != "" {
|
||||
query = query.
|
||||
InnerJoin("RetentionPoliciesChannels ON c.Id = RetentionPoliciesChannels.ChannelId").
|
||||
Where(sq.Eq{"RetentionPoliciesChannels.PolicyId": opts.PolicyID})
|
||||
} else if opts.ExcludePolicyConstrained {
|
||||
query = query.
|
||||
LeftJoin("RetentionPoliciesChannels ON c.Id = RetentionPoliciesChannels.ChannelId").
|
||||
Where("RetentionPoliciesChannels.ChannelId IS NULL")
|
||||
} else if opts.IncludePolicyID {
|
||||
query = query.
|
||||
LeftJoin("RetentionPoliciesChannels ON c.Id = RetentionPoliciesChannels.ChannelId")
|
||||
}
|
||||
|
||||
likeClause, likeTerm := s.buildLIKEClause(opts.Term, "c.Name, c.DisplayName, c.Purpose")
|
||||
if likeTerm != "" {
|
||||
likeClause = strings.ReplaceAll(likeClause, ":LikeTerm", "?")
|
||||
fulltextClause, fulltextTerm := s.buildFulltextClause(term, "c.Name, c.DisplayName, c.Purpose")
|
||||
fulltextClause, fulltextTerm := s.buildFulltextClause(opts.Term, "c.Name, c.DisplayName, c.Purpose")
|
||||
fulltextClause = strings.ReplaceAll(fulltextClause, ":FulltextTerm", "?")
|
||||
query = query.Where(sq.Or{
|
||||
sq.Expr(likeClause, likeTerm, likeTerm, likeTerm), // Keep the number of likeTerms same as the number
|
||||
@@ -2730,7 +2759,7 @@ func (s SqlChannelStore) channelSearchQuery(term string, opts store.ChannelSearc
|
||||
}
|
||||
|
||||
if opts.Public && !opts.Private {
|
||||
query = query.Where(sq.Eq{"c.Type": model.CHANNEL_OPEN})
|
||||
query = query.InnerJoin("PublicChannels ON c.Id = PublicChannels.Id")
|
||||
} else if opts.Private && !opts.Public {
|
||||
query = query.Where(sq.Eq{"c.Type": model.CHANNEL_PRIVATE})
|
||||
} else {
|
||||
@@ -2744,7 +2773,9 @@ func (s SqlChannelStore) channelSearchQuery(term string, opts store.ChannelSearc
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) SearchAllChannels(term string, opts store.ChannelSearchOpts) (*model.ChannelListWithTeamData, int64, error) {
|
||||
queryString, args, err := s.channelSearchQuery(term, opts, false).ToSql()
|
||||
opts.Term = term
|
||||
opts.IncludeTeamInfo = true
|
||||
queryString, args, err := s.channelSearchQuery(&opts).ToSql()
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "channel_tosql")
|
||||
}
|
||||
@@ -2757,7 +2788,8 @@ func (s SqlChannelStore) SearchAllChannels(term string, opts store.ChannelSearch
|
||||
|
||||
// only query a 2nd time for the count if the results are being requested paginated.
|
||||
if opts.IsPaginated() {
|
||||
queryString, args, err = s.channelSearchQuery(term, opts, true).ToSql()
|
||||
opts.CountOnly = true
|
||||
queryString, args, err = s.channelSearchQuery(&opts).ToSql()
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "channel_tosql")
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ func TestChannelSearchQuerySQLInjection(t *testing.T) {
|
||||
SqlStore: st.SqlStore,
|
||||
}
|
||||
|
||||
opts := store.ChannelSearchOpts{}
|
||||
builder := s.channelSearchQuery("'or'1'=sleep(3))); -- -", opts, false)
|
||||
opts := store.ChannelSearchOpts{Term: "'or'1'=sleep(3))); -- -"}
|
||||
builder := s.channelSearchQuery(&opts)
|
||||
query, _, err := builder.ToSql()
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, query, "sleep")
|
||||
|
||||
609
store/sqlstore/retention_policy_store.go
Обычный файл
609
store/sqlstore/retention_policy_store.go
Обычный файл
@@ -0,0 +1,609 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/lib/pq"
|
||||
"github.com/mattermost/gorp"
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SqlRetentionPolicyStore struct {
|
||||
*SqlStore
|
||||
metrics einterfaces.MetricsInterface
|
||||
}
|
||||
|
||||
func newSqlRetentionPolicyStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) store.RetentionPolicyStore {
|
||||
s := &SqlRetentionPolicyStore{
|
||||
SqlStore: sqlStore,
|
||||
metrics: metrics,
|
||||
}
|
||||
|
||||
for _, db := range sqlStore.GetAllConns() {
|
||||
table := db.AddTableWithName(model.RetentionPolicy{}, "RetentionPolicies")
|
||||
table.SetKeys(false, "Id")
|
||||
table.ColMap("Id").SetMaxSize(26)
|
||||
table.ColMap("DisplayName").SetMaxSize(64)
|
||||
|
||||
tableC := db.AddTableWithName(model.RetentionPolicyChannel{}, "RetentionPoliciesChannels")
|
||||
tableC.SetKeys(false, "ChannelId")
|
||||
tableC.ColMap("PolicyId").SetMaxSize(26)
|
||||
tableC.ColMap("ChannelId").SetMaxSize(26)
|
||||
|
||||
tableT := db.AddTableWithName(model.RetentionPolicyTeam{}, "RetentionPoliciesTeams")
|
||||
tableT.SetKeys(false, "TeamId")
|
||||
tableT.ColMap("PolicyId").SetMaxSize(26)
|
||||
tableT.ColMap("TeamId").SetMaxSize(26)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) createIndexesIfNotExists() {
|
||||
s.CreateCompositeIndexIfNotExists("IDX_RetentionPolicies_DisplayName_Id", "RetentionPolicies",
|
||||
[]string{"DisplayName", "Id"})
|
||||
s.CreateIndexIfNotExists("IDX_RetentionPoliciesChannels_PolicyId", "RetentionPoliciesChannels", "PolicyId")
|
||||
s.CreateIndexIfNotExists("IDX_RetentionPoliciesTeams_PolicyId", "RetentionPoliciesTeams", "PolicyId")
|
||||
s.CreateForeignKeyIfNotExists("RetentionPoliciesChannels", "PolicyId", "RetentionPolicies", "Id", true)
|
||||
s.CreateForeignKeyIfNotExists("RetentionPoliciesTeams", "PolicyId", "RetentionPolicies", "Id", true)
|
||||
}
|
||||
|
||||
// executePossiblyEmptyQuery only executes the query if it is non-empty. This helps avoid
|
||||
// having to check for MySQL, which, unlike Postgres, does not allow empty queries.
|
||||
func executePossiblyEmptyQuery(txn *gorp.Transaction, query string, args ...interface{}) (sql.Result, error) {
|
||||
if query == "" {
|
||||
return nil, nil
|
||||
}
|
||||
return txn.Exec(query, args...)
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) Save(policy *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
// Strategy:
|
||||
// 1. Insert new policy
|
||||
// 2. Insert new channels into policy
|
||||
// 3. Insert new teams into policy
|
||||
|
||||
if err := s.checkTeamsExist(policy.TeamIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.checkChannelsExist(policy.ChannelIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policy.ID = model.NewId()
|
||||
|
||||
policyInsertQuery, policyInsertArgs, err := s.getQueryBuilder().
|
||||
Insert("RetentionPolicies").
|
||||
Columns("Id", "DisplayName", "PostDuration").
|
||||
Values(policy.ID, policy.DisplayName, policy.PostDuration).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelsInsertQuery, channelsInsertArgs, err := s.buildInsertRetentionPoliciesChannelsQuery(policy.ID, policy.ChannelIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
teamsInsertQuery, teamsInsertArgs, err := s.buildInsertRetentionPoliciesTeamsQuery(policy.ID, policy.TeamIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policySelectQuery, policySelectProps := s.buildGetPolicyQuery(policy.ID)
|
||||
|
||||
txn, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer finalizeTransaction(txn)
|
||||
// Create a new policy in RetentionPolicies
|
||||
if _, err = txn.Exec(policyInsertQuery, policyInsertArgs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Insert the channel IDs into RetentionPoliciesChannels
|
||||
if _, err = executePossiblyEmptyQuery(txn, channelsInsertQuery, channelsInsertArgs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Insert the team IDs into RetentionPoliciesTeams
|
||||
if _, err = executePossiblyEmptyQuery(txn, teamsInsertQuery, teamsInsertArgs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Select the new policy (with team/channel counts) which we just created
|
||||
var newPolicy model.RetentionPolicyWithTeamAndChannelCounts
|
||||
if err = txn.SelectOne(&newPolicy, policySelectQuery, policySelectProps); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = txn.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &newPolicy, nil
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) checkTeamsExist(teamIDs []string) error {
|
||||
if len(teamIDs) > 0 {
|
||||
teamsSelectQuery, teamsSelectArgs, err := s.getQueryBuilder().
|
||||
Select("Id").
|
||||
From("Teams").
|
||||
Where(sq.Eq{"Id": teamIDs}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var rows []*string
|
||||
_, err = s.GetReplica().Select(&rows, teamsSelectQuery, teamsSelectArgs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(rows) == len(teamIDs) {
|
||||
return nil
|
||||
}
|
||||
retrievedIDs := make(map[string]bool)
|
||||
for _, teamID := range rows {
|
||||
retrievedIDs[*teamID] = true
|
||||
}
|
||||
for _, teamID := range teamIDs {
|
||||
if _, ok := retrievedIDs[teamID]; !ok {
|
||||
return store.NewErrNotFound("Team", teamID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) checkChannelsExist(channelIDs []string) error {
|
||||
if len(channelIDs) > 0 {
|
||||
channelsSelectQuery, channelsSelectArgs, err := s.getQueryBuilder().
|
||||
Select("Id").
|
||||
From("Channels").
|
||||
Where(sq.Eq{"Id": channelIDs}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var rows []*string
|
||||
_, err = s.GetReplica().Select(&rows, channelsSelectQuery, channelsSelectArgs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(rows) == len(channelIDs) {
|
||||
return nil
|
||||
}
|
||||
retrievedIDs := make(map[string]bool)
|
||||
for _, channelID := range rows {
|
||||
retrievedIDs[*channelID] = true
|
||||
}
|
||||
for _, channelID := range channelIDs {
|
||||
if _, ok := retrievedIDs[channelID]; !ok {
|
||||
return store.NewErrNotFound("Channel", channelID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) buildInsertRetentionPoliciesChannelsQuery(policyID string, channelIDs []string) (query string, args []interface{}, err error) {
|
||||
if len(channelIDs) > 0 {
|
||||
builder := s.getQueryBuilder().
|
||||
Insert("RetentionPoliciesChannels").
|
||||
Columns("PolicyId", "ChannelId")
|
||||
for _, channelID := range channelIDs {
|
||||
builder = builder.Values(policyID, channelID)
|
||||
}
|
||||
query, args, err = builder.ToSql()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) buildInsertRetentionPoliciesTeamsQuery(policyID string, teamIDs []string) (query string, args []interface{}, err error) {
|
||||
if len(teamIDs) > 0 {
|
||||
builder := s.getQueryBuilder().
|
||||
Insert("RetentionPoliciesTeams").
|
||||
Columns("PolicyId", "TeamId")
|
||||
for _, teamID := range teamIDs {
|
||||
builder = builder.Values(policyID, teamID)
|
||||
}
|
||||
query, args, err = builder.ToSql()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) Patch(patch *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
// Strategy:
|
||||
// 1. Update policy attributes
|
||||
// 2. Delete existing channels from policy
|
||||
// 3. Insert new channels into policy
|
||||
// 4. Delete existing teams from policy
|
||||
// 5. Insert new teams into policy
|
||||
// 6. Read new policy
|
||||
|
||||
var err error
|
||||
if err = s.checkTeamsExist(patch.TeamIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = s.checkChannelsExist(patch.ChannelIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policyUpdateQuery := ""
|
||||
policyUpdateArgs := []interface{}{}
|
||||
if patch.DisplayName != "" || patch.PostDuration != 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)
|
||||
}
|
||||
policyUpdateQuery, policyUpdateArgs, err = builder.
|
||||
Where(sq.Eq{"Id": patch.ID}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
channelsDeleteQuery := ""
|
||||
channelsDeleteArgs := []interface{}{}
|
||||
channelsInsertQuery := ""
|
||||
channelsInsertArgs := []interface{}{}
|
||||
if patch.ChannelIDs != nil {
|
||||
channelsDeleteQuery, channelsDeleteArgs, err = s.getQueryBuilder().
|
||||
Delete("RetentionPoliciesChannels").
|
||||
Where(sq.Eq{"PolicyId": patch.ID}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelsInsertQuery, channelsInsertArgs, err = s.buildInsertRetentionPoliciesChannelsQuery(patch.ID, patch.ChannelIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
teamsDeleteQuery := ""
|
||||
teamsDeleteArgs := []interface{}{}
|
||||
teamsInsertQuery := ""
|
||||
teamsInsertArgs := []interface{}{}
|
||||
if patch.TeamIDs != nil {
|
||||
teamsDeleteQuery, teamsDeleteArgs, err = s.getQueryBuilder().
|
||||
Delete("RetentionPoliciesTeams").
|
||||
Where(sq.Eq{"PolicyId": patch.ID}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
teamsInsertQuery, teamsInsertArgs, err = s.buildInsertRetentionPoliciesTeamsQuery(patch.ID, patch.TeamIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
policySelectQuery, policySelectProps := s.buildGetPolicyQuery(patch.ID)
|
||||
|
||||
txn, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer finalizeTransaction(txn)
|
||||
// Update the fields of the policy in RetentionPolicies
|
||||
if _, err = executePossiblyEmptyQuery(txn, policyUpdateQuery, policyUpdateArgs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Remove all channels from the policy in RetentionPoliciesChannels
|
||||
if _, err = executePossiblyEmptyQuery(txn, channelsDeleteQuery, channelsDeleteArgs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Insert the new channels for the policy in RetentionPoliciesChannels
|
||||
if _, err = executePossiblyEmptyQuery(txn, channelsInsertQuery, channelsInsertArgs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Remove all teams from the policy in RetentionPoliciesTeams
|
||||
if _, err = executePossiblyEmptyQuery(txn, teamsDeleteQuery, teamsDeleteArgs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Insert the new teams for the policy in RetentionPoliciesTeams
|
||||
if _, err = executePossiblyEmptyQuery(txn, teamsInsertQuery, teamsInsertArgs...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Select the policy which we just updated
|
||||
var newPolicy model.RetentionPolicyWithTeamAndChannelCounts
|
||||
if err = txn.SelectOne(&newPolicy, policySelectQuery, policySelectProps); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = txn.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &newPolicy, nil
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) buildGetPolicyQuery(id string) (query string, props map[string]interface{}) {
|
||||
return s.buildGetPoliciesQuery(id, 0, 1)
|
||||
}
|
||||
|
||||
// buildGetPoliciesQuery builds a query to select information for the policy with the specified
|
||||
// ID, or, if `id` is the empty string, from all policies. The results returned will be sorted by
|
||||
// policy display name and ID.
|
||||
func (s *SqlRetentionPolicyStore) buildGetPoliciesQuery(id string, offset, limit int) (query string, props map[string]interface{}) {
|
||||
props = map[string]interface{}{"Offset": offset, "Limit": limit}
|
||||
whereIdEqualsPolicyId := ""
|
||||
if id != "" {
|
||||
whereIdEqualsPolicyId = "WHERE RetentionPolicies.Id = :PolicyId"
|
||||
props["PolicyId"] = id
|
||||
}
|
||||
query = `
|
||||
SELECT RetentionPolicies.Id,
|
||||
RetentionPolicies.DisplayName,
|
||||
RetentionPolicies.PostDuration,
|
||||
A.Count AS ChannelCount,
|
||||
B.Count AS TeamCount
|
||||
FROM RetentionPolicies
|
||||
INNER JOIN (
|
||||
SELECT RetentionPolicies.Id,
|
||||
COUNT(RetentionPoliciesChannels.ChannelId) AS Count
|
||||
FROM RetentionPolicies
|
||||
LEFT JOIN RetentionPoliciesChannels ON RetentionPolicies.Id = RetentionPoliciesChannels.PolicyId
|
||||
` + whereIdEqualsPolicyId + `
|
||||
GROUP BY RetentionPolicies.Id
|
||||
ORDER BY RetentionPolicies.DisplayName, RetentionPolicies.Id
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset
|
||||
) AS A ON RetentionPolicies.Id = A.Id
|
||||
INNER JOIN (
|
||||
SELECT RetentionPolicies.Id,
|
||||
COUNT(RetentionPoliciesTeams.TeamId) AS Count
|
||||
FROM RetentionPolicies
|
||||
LEFT JOIN RetentionPoliciesTeams ON RetentionPolicies.Id = RetentionPoliciesTeams.PolicyId
|
||||
` + whereIdEqualsPolicyId + `
|
||||
GROUP BY RetentionPolicies.Id
|
||||
ORDER BY RetentionPolicies.DisplayName, RetentionPolicies.Id
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset
|
||||
) AS B ON RetentionPolicies.Id = B.Id
|
||||
ORDER BY RetentionPolicies.DisplayName, RetentionPolicies.Id`
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) Get(id string) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
query, props := s.buildGetPolicyQuery(id)
|
||||
var policy model.RetentionPolicyWithTeamAndChannelCounts
|
||||
if err := s.GetReplica().SelectOne(&policy, query, props); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &policy, nil
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetAll(offset, limit int) (policies []*model.RetentionPolicyWithTeamAndChannelCounts, err error) {
|
||||
query, props := s.buildGetPoliciesQuery("", offset, limit)
|
||||
_, err = s.GetReplica().Select(&policies, query, props)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetCount() (int64, error) {
|
||||
return s.GetReplica().SelectInt("SELECT COUNT(*) FROM RetentionPolicies")
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) Delete(id string) error {
|
||||
builder := s.getQueryBuilder().
|
||||
Delete("RetentionPolicies").
|
||||
Where(sq.Eq{"Id": id})
|
||||
result, err := builder.RunWith(s.GetMaster()).Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
numRowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
} else if numRowsAffected == 0 {
|
||||
return errors.New("policy not found")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetChannels(policyId string, offset, limit int) (channels model.ChannelListWithTeamData, err error) {
|
||||
const query = `
|
||||
SELECT Channels.*,
|
||||
Teams.DisplayName AS TeamDisplayName,
|
||||
Teams.Name AS TeamName,
|
||||
Teams.UpdateAt AS TeamUpdateAt
|
||||
FROM RetentionPoliciesChannels
|
||||
INNER JOIN Channels ON RetentionPoliciesChannels.ChannelId = Channels.Id
|
||||
INNER JOIN Teams ON Channels.TeamId = Teams.Id
|
||||
WHERE RetentionPoliciesChannels.PolicyId = :PolicyId
|
||||
ORDER BY Channels.DisplayName, Channels.Id
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset`
|
||||
props := map[string]interface{}{"PolicyId": policyId, "Limit": limit, "Offset": offset}
|
||||
_, err = s.GetReplica().Select(&channels, query, props)
|
||||
for _, channel := range channels {
|
||||
channel.PolicyID = model.NewString(policyId)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetChannelsCount(policyId string) (int64, error) {
|
||||
const query = `
|
||||
SELECT COUNT(*)
|
||||
FROM RetentionPolicies
|
||||
INNER JOIN RetentionPoliciesChannels ON RetentionPolicies.Id = RetentionPoliciesChannels.PolicyId
|
||||
WHERE RetentionPolicies.Id = :PolicyId`
|
||||
props := map[string]interface{}{"PolicyId": policyId}
|
||||
return s.GetReplica().SelectInt(query, props)
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) AddChannels(policyId string, channelIds []string) error {
|
||||
if len(channelIds) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := s.checkChannelsExist(channelIds); err != nil {
|
||||
return err
|
||||
}
|
||||
builder := s.getQueryBuilder().
|
||||
Insert("RetentionPoliciesChannels").
|
||||
Columns("policyId", "channelId")
|
||||
for _, channelId := range channelIds {
|
||||
builder = builder.Values(policyId, channelId)
|
||||
}
|
||||
_, err := builder.RunWith(s.GetMaster()).Exec()
|
||||
if err != nil {
|
||||
switch dbErr := err.(type) {
|
||||
case *pq.Error:
|
||||
if dbErr.Code == PGForeignKeyViolationErrorCode {
|
||||
return store.NewErrNotFound("RetentionPolicy", policyId)
|
||||
}
|
||||
case *mysql.MySQLError:
|
||||
if dbErr.Number == MySQLForeignKeyViolationErrorCode {
|
||||
return store.NewErrNotFound("RetentionPolicy", policyId)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) RemoveChannels(policyId string, channelIds []string) error {
|
||||
if len(channelIds) == 0 {
|
||||
return nil
|
||||
}
|
||||
builder := s.getQueryBuilder().
|
||||
Delete("RetentionPoliciesChannels").
|
||||
Where(sq.And{
|
||||
sq.Eq{"PolicyId": policyId},
|
||||
sq.Eq{"ChannelId": channelIds},
|
||||
})
|
||||
_, err := builder.RunWith(s.GetMaster()).Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetTeams(policyId string, offset, limit int) (teams []*model.Team, err error) {
|
||||
const query = `
|
||||
SELECT Teams.* FROM RetentionPoliciesTeams
|
||||
INNER JOIN Teams ON RetentionPoliciesTeams.TeamId = Teams.Id
|
||||
WHERE RetentionPoliciesTeams.PolicyId = :PolicyId
|
||||
ORDER BY Teams.DisplayName, Teams.Id
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset`
|
||||
props := map[string]interface{}{"PolicyId": policyId, "Limit": limit, "Offset": offset}
|
||||
_, err = s.GetReplica().Select(&teams, query, props)
|
||||
for _, team := range teams {
|
||||
team.PolicyID = &policyId
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetTeamsCount(policyId string) (int64, error) {
|
||||
const query = `
|
||||
SELECT COUNT(*)
|
||||
FROM RetentionPolicies
|
||||
INNER JOIN RetentionPoliciesTeams ON RetentionPolicies.Id = RetentionPoliciesTeams.PolicyId
|
||||
WHERE RetentionPolicies.Id = :PolicyId`
|
||||
props := map[string]interface{}{"PolicyId": policyId}
|
||||
return s.GetReplica().SelectInt(query, props)
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) AddTeams(policyId string, teamIds []string) error {
|
||||
if len(teamIds) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := s.checkTeamsExist(teamIds); err != nil {
|
||||
return err
|
||||
}
|
||||
builder := s.getQueryBuilder().
|
||||
Insert("RetentionPoliciesTeams").
|
||||
Columns("PolicyId", "TeamId")
|
||||
for _, teamId := range teamIds {
|
||||
builder = builder.Values(policyId, teamId)
|
||||
}
|
||||
_, err := builder.RunWith(s.GetMaster()).Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) RemoveTeams(policyId string, teamIds []string) error {
|
||||
if len(teamIds) == 0 {
|
||||
return nil
|
||||
}
|
||||
builder := s.getQueryBuilder().
|
||||
Delete("RetentionPoliciesTeams").
|
||||
Where(sq.And{
|
||||
sq.Eq{"PolicyId": policyId},
|
||||
sq.Eq{"TeamId": teamIds},
|
||||
})
|
||||
_, err := builder.RunWith(s.GetMaster()).Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetTeamPoliciesForUser(userID string, offset, limit int) (policies []*model.RetentionPolicyForTeam, err error) {
|
||||
const query = `
|
||||
SELECT Teams.Id, RetentionPolicies.PostDuration
|
||||
FROM Users
|
||||
INNER JOIN TeamMembers ON Users.Id = TeamMembers.UserId
|
||||
INNER JOIN Teams ON TeamMembers.TeamId = Teams.Id
|
||||
INNER JOIN RetentionPoliciesTeams ON Teams.Id = RetentionPoliciesTeams.TeamId
|
||||
INNER JOIN RetentionPolicies ON RetentionPoliciesTeams.PolicyId = RetentionPolicies.Id
|
||||
WHERE Users.Id = :UserId
|
||||
AND TeamMembers.DeleteAt = 0
|
||||
AND Teams.DeleteAt = 0
|
||||
ORDER BY Teams.Id
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset`
|
||||
props := map[string]interface{}{"UserId": userID, "Limit": limit, "Offset": offset}
|
||||
_, err = s.GetReplica().Select(&policies, query, props)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetTeamPoliciesCountForUser(userID string) (int64, error) {
|
||||
const query = `
|
||||
SELECT COUNT(*)
|
||||
FROM Users
|
||||
INNER JOIN TeamMembers ON Users.Id = TeamMembers.UserId
|
||||
INNER JOIN Teams ON TeamMembers.TeamId = Teams.Id
|
||||
INNER JOIN RetentionPoliciesTeams ON Teams.Id = RetentionPoliciesTeams.TeamId
|
||||
INNER JOIN RetentionPolicies ON RetentionPoliciesTeams.PolicyId = RetentionPolicies.Id
|
||||
WHERE Users.Id = :UserId
|
||||
AND TeamMembers.DeleteAt = 0
|
||||
AND Teams.DeleteAt = 0`
|
||||
props := map[string]interface{}{"UserId": userID}
|
||||
return s.GetReplica().SelectInt(query, props)
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetChannelPoliciesForUser(userID string, offset, limit int) (policies []*model.RetentionPolicyForChannel, err error) {
|
||||
const query = `
|
||||
SELECT Channels.Id, RetentionPolicies.PostDuration
|
||||
FROM Users
|
||||
INNER JOIN ChannelMembers ON Users.Id = ChannelMembers.UserId
|
||||
INNER JOIN Channels ON ChannelMembers.ChannelId = Channels.Id
|
||||
INNER JOIN RetentionPoliciesChannels ON Channels.Id = RetentionPoliciesChannels.ChannelId
|
||||
INNER JOIN RetentionPolicies ON RetentionPoliciesChannels.PolicyId = RetentionPolicies.Id
|
||||
WHERE Users.Id = :UserId
|
||||
AND Channels.DeleteAt = 0
|
||||
ORDER BY Channels.Id
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset`
|
||||
props := map[string]interface{}{"UserId": userID, "Limit": limit, "Offset": offset}
|
||||
_, err = s.GetReplica().Select(&policies, query, props)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SqlRetentionPolicyStore) GetChannelPoliciesCountForUser(userID string) (int64, error) {
|
||||
const query = `
|
||||
SELECT COUNT(*)
|
||||
FROM Users
|
||||
INNER JOIN ChannelMembers ON Users.Id = ChannelMembers.UserId
|
||||
INNER JOIN Channels ON ChannelMembers.ChannelId = Channels.Id
|
||||
INNER JOIN RetentionPoliciesChannels ON Channels.Id = RetentionPoliciesChannels.ChannelId
|
||||
INNER JOIN RetentionPolicies ON RetentionPoliciesChannels.PolicyId = RetentionPolicies.Id
|
||||
WHERE Users.Id = :UserId
|
||||
AND Channels.DeleteAt = 0`
|
||||
props := map[string]interface{}{"UserId": userID}
|
||||
return s.GetReplica().SelectInt(query, props)
|
||||
}
|
||||
14
store/sqlstore/retention_policy_store_test.go
Обычный файл
14
store/sqlstore/retention_policy_store_test.go
Обычный файл
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/store/storetest"
|
||||
)
|
||||
|
||||
func TestRetentionPolicyStore(t *testing.T) {
|
||||
StoreTestWithSqlStore(t, storetest.TestRetentionPolicyStore)
|
||||
}
|
||||
@@ -41,13 +41,17 @@ import (
|
||||
type migrationDirection string
|
||||
|
||||
const (
|
||||
IndexTypeFullText = "full_text"
|
||||
IndexTypeFullTextFunc = "full_text_func"
|
||||
IndexTypeDefault = "default"
|
||||
PGDupTableErrorCode = "42P07" // see https://github.com/lib/pq/blob/master/error.go#L268
|
||||
MySQLDupTableErrorCode = uint16(1050) // see https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html#error_er_table_exists_error
|
||||
DBPingAttempts = 18
|
||||
DBPingTimeoutSecs = 10
|
||||
IndexTypeFullText = "full_text"
|
||||
IndexTypeFullTextFunc = "full_text_func"
|
||||
IndexTypeDefault = "default"
|
||||
PGDupTableErrorCode = "42P07" // see https://github.com/lib/pq/blob/master/error.go#L268
|
||||
MySQLDupTableErrorCode = uint16(1050) // see https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html#error_er_table_exists_error
|
||||
PGForeignKeyViolationErrorCode = "23503"
|
||||
MySQLForeignKeyViolationErrorCode = 1452
|
||||
PGDuplicateObjectErrorCode = "42710"
|
||||
MySQLDuplicateObjectErrorCode = 1022
|
||||
DBPingAttempts = 18
|
||||
DBPingTimeoutSecs = 10
|
||||
// This is a numerical version string by postgres. The format is
|
||||
// 2 characters for major, minor, and patch version prior to 10.
|
||||
// After 10, it's major and minor only.
|
||||
@@ -95,6 +99,7 @@ type SqlStoreStores struct {
|
||||
team store.TeamStore
|
||||
channel store.ChannelStore
|
||||
post store.PostStore
|
||||
retentionPolicy store.RetentionPolicyStore
|
||||
thread store.ThreadStore
|
||||
user store.UserStore
|
||||
bot store.BotStore
|
||||
@@ -183,6 +188,7 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlS
|
||||
store.stores.team = newSqlTeamStore(store)
|
||||
store.stores.channel = newSqlChannelStore(store, metrics)
|
||||
store.stores.post = newSqlPostStore(store, metrics)
|
||||
store.stores.retentionPolicy = newSqlRetentionPolicyStore(store, metrics)
|
||||
store.stores.user = newSqlUserStore(store, metrics)
|
||||
store.stores.bot = newSqlBotStore(store, metrics)
|
||||
store.stores.audit = newSqlAuditStore(store)
|
||||
@@ -236,6 +242,7 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlS
|
||||
|
||||
store.stores.channel.(*SqlChannelStore).createIndexesIfNotExists()
|
||||
store.stores.post.(*SqlPostStore).createIndexesIfNotExists()
|
||||
store.stores.retentionPolicy.(*SqlRetentionPolicyStore).createIndexesIfNotExists()
|
||||
store.stores.thread.(*SqlThreadStore).createIndexesIfNotExists()
|
||||
store.stores.user.(*SqlUserStore).createIndexesIfNotExists()
|
||||
store.stores.bot.(*SqlBotStore).createIndexesIfNotExists()
|
||||
@@ -1076,6 +1083,30 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
return true
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateForeignKeyIfNotExists(
|
||||
tableName, columnName, refTableName, refColumnName string,
|
||||
onDeleteCascade bool,
|
||||
) (err error) {
|
||||
deleteClause := ""
|
||||
if onDeleteCascade {
|
||||
deleteClause = "ON DELETE CASCADE"
|
||||
}
|
||||
constraintName := "FK_" + tableName + "_" + refTableName
|
||||
sQuery := `
|
||||
ALTER TABLE ` + tableName + `
|
||||
ADD CONSTRAINT ` + constraintName + `
|
||||
FOREIGN KEY (` + columnName + `) REFERENCES ` + refTableName + ` (` + refColumnName + `)
|
||||
` + deleteClause + `;`
|
||||
_, err = ss.GetMaster().ExecNoTimeout(sQuery)
|
||||
if IsConstraintAlreadyExistsError(err) {
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
mlog.Warn("Could not create foreign key: " + err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool {
|
||||
|
||||
if ss.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
@@ -1121,6 +1152,20 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool
|
||||
return true
|
||||
}
|
||||
|
||||
func IsConstraintAlreadyExistsError(err error) bool {
|
||||
switch dbErr := err.(type) {
|
||||
case *pq.Error:
|
||||
if dbErr.Code == PGDuplicateObjectErrorCode {
|
||||
return true
|
||||
}
|
||||
case *mysql.MySQLError:
|
||||
if dbErr.Number == MySQLDuplicateObjectErrorCode {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsUniqueConstraintError(err error, indexName []string) bool {
|
||||
unique := false
|
||||
if pqErr, ok := err.(*pq.Error); ok && pqErr.Code == "23505" {
|
||||
@@ -1197,6 +1242,10 @@ func (ss *SqlStore) Post() store.PostStore {
|
||||
return ss.stores.post
|
||||
}
|
||||
|
||||
func (ss *SqlStore) RetentionPolicy() store.RetentionPolicyStore {
|
||||
return ss.stores.retentionPolicy
|
||||
}
|
||||
|
||||
func (ss *SqlStore) User() store.UserStore {
|
||||
return ss.stores.user
|
||||
}
|
||||
|
||||
@@ -370,12 +370,15 @@ func (s SqlTeamStore) GetByNames(names []string) ([]*model.Team, error) {
|
||||
return teams, nil
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) teamSearchQuery(term string, opts *model.TeamSearch, countQuery bool) sq.SelectBuilder {
|
||||
func (s SqlTeamStore) teamSearchQuery(opts *model.TeamSearch, countQuery bool) sq.SelectBuilder {
|
||||
var selectStr string
|
||||
if countQuery {
|
||||
selectStr = "count(*)"
|
||||
} else {
|
||||
selectStr = "*"
|
||||
selectStr = "t.*"
|
||||
if opts.IncludePolicyID != nil && *opts.IncludePolicyID {
|
||||
selectStr += ", RetentionPoliciesTeams.PolicyId"
|
||||
}
|
||||
}
|
||||
|
||||
query := s.getQueryBuilder().
|
||||
@@ -391,6 +394,7 @@ func (s SqlTeamStore) teamSearchQuery(term string, opts *model.TeamSearch, count
|
||||
}
|
||||
}
|
||||
|
||||
term := opts.Term
|
||||
if term != "" {
|
||||
term = sanitizeSearchTerm(term, "\\")
|
||||
term = wildcardSearchTerm(term)
|
||||
@@ -403,6 +407,19 @@ func (s SqlTeamStore) teamSearchQuery(term string, opts *model.TeamSearch, count
|
||||
query = query.Where(fmt.Sprintf("(Name %[1]s ? OR DisplayName %[1]s ?)", operatorKeyword), term, term)
|
||||
}
|
||||
|
||||
if opts.PolicyID != nil && *opts.PolicyID != "" {
|
||||
query = query.
|
||||
InnerJoin("RetentionPoliciesTeams ON t.Id = RetentionPoliciesTeams.TeamId").
|
||||
Where(sq.Eq{"RetentionPoliciesTeams.PolicyId": *opts.PolicyID})
|
||||
} else if opts.ExcludePolicyConstrained != nil && *opts.ExcludePolicyConstrained {
|
||||
query = query.
|
||||
LeftJoin("RetentionPoliciesTeams ON t.Id = RetentionPoliciesTeams.TeamId").
|
||||
Where("RetentionPoliciesTeams.TeamId IS NULL")
|
||||
} else if opts.IncludePolicyID != nil && *opts.IncludePolicyID {
|
||||
query = query.
|
||||
LeftJoin("RetentionPoliciesTeams ON t.Id = RetentionPoliciesTeams.TeamId")
|
||||
}
|
||||
|
||||
var teamFilters sq.Sqlizer
|
||||
var openInviteFilter sq.Sqlizer
|
||||
if opts.AllowOpenInvite != nil {
|
||||
@@ -442,6 +459,11 @@ func (s SqlTeamStore) teamSearchQuery(term string, opts *model.TeamSearch, count
|
||||
}
|
||||
}
|
||||
|
||||
if opts.TeamType != nil {
|
||||
teamTypeFilter := sq.Eq{"Type": *opts.TeamType}
|
||||
teamFilters = sq.And{teamFilters, teamTypeFilter}
|
||||
}
|
||||
|
||||
query = query.Where(teamFilters)
|
||||
|
||||
return query
|
||||
@@ -449,41 +471,41 @@ func (s SqlTeamStore) teamSearchQuery(term string, opts *model.TeamSearch, count
|
||||
|
||||
// SearchAll returns from the database a list of teams that match the Name or DisplayName
|
||||
// passed as the term search parameter.
|
||||
func (s SqlTeamStore) SearchAll(term string, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
func (s SqlTeamStore) SearchAll(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
var teams []*model.Team
|
||||
|
||||
queryString, args, err := s.teamSearchQuery(term, opts, false).ToSql()
|
||||
queryString, args, err := s.teamSearchQuery(opts, false).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetReplica().Select(&teams, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find Teams with term=%s", term)
|
||||
return nil, errors.Wrapf(err, "failed to find Teams with term=%s", opts.Term)
|
||||
}
|
||||
|
||||
return teams, nil
|
||||
}
|
||||
|
||||
// SearchAllPaged returns a teams list and the total count of teams that matched the search.
|
||||
func (s SqlTeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
func (s SqlTeamStore) SearchAllPaged(opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
var teams []*model.Team
|
||||
var totalCount int64
|
||||
|
||||
queryString, args, err := s.teamSearchQuery(term, opts, false).ToSql()
|
||||
queryString, args, err := s.teamSearchQuery(opts, false).ToSql()
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
if _, err = s.GetReplica().Select(&teams, queryString, args...); err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "failed to find Teams with term=%s", term)
|
||||
return nil, 0, errors.Wrapf(err, "failed to find Teams with term=%s", opts.Term)
|
||||
}
|
||||
|
||||
queryString, args, err = s.teamSearchQuery(term, opts, true).ToSql()
|
||||
queryString, args, err = s.teamSearchQuery(opts, true).ToSql()
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
totalCount, err = s.GetReplica().SelectInt(queryString, args...)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "failed to count Teams with term=%s", term)
|
||||
return nil, 0, errors.Wrapf(err, "failed to count Teams with term=%s", opts.Term)
|
||||
}
|
||||
|
||||
return teams, totalCount, nil
|
||||
@@ -491,53 +513,18 @@ func (s SqlTeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*mo
|
||||
|
||||
// SearchOpen returns from the database a list of public teams that match the Name or DisplayName
|
||||
// passed as the term search parameter.
|
||||
func (s SqlTeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
var teams []*model.Team
|
||||
|
||||
term = sanitizeSearchTerm(term, "\\")
|
||||
term = wildcardSearchTerm(term)
|
||||
query := s.teamsQuery.Where(sq.Eq{"Type": "O", "AllowOpenInvite": true})
|
||||
if s.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
query = query.Where(sq.Or{sq.Like{"Name": term}, sq.Like{"DisplayName": term}})
|
||||
} else {
|
||||
query = query.Where(sq.Or{sq.ILike{"Name": term}, sq.ILike{"DisplayName": term}})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetReplica().Select(&teams, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to count Teams with term=%s", term)
|
||||
}
|
||||
|
||||
return teams, nil
|
||||
func (s SqlTeamStore) SearchOpen(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
opts.TeamType = model.NewString("O")
|
||||
opts.AllowOpenInvite = model.NewBool(true)
|
||||
return s.SearchAll(opts)
|
||||
}
|
||||
|
||||
// SearchPrivate returns from the database a list of private teams that match the Name or DisplayName
|
||||
// passed as the term search parameter.
|
||||
func (s SqlTeamStore) SearchPrivate(term string) ([]*model.Team, error) {
|
||||
var teams []*model.Team
|
||||
|
||||
term = sanitizeSearchTerm(term, "\\")
|
||||
term = wildcardSearchTerm(term)
|
||||
query := s.teamsQuery.Where(sq.Eq{"Type": "O", "AllowOpenInvite": false})
|
||||
if s.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
query = query.Where(sq.Or{sq.Like{"Name": term}, sq.Like{"DisplayName": term}})
|
||||
} else {
|
||||
query = query.Where(sq.Or{sq.ILike{"Name": term}, sq.ILike{"DisplayName": term}})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
if _, err = s.GetReplica().Select(&teams, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to count Teams with term=%s", term)
|
||||
}
|
||||
return teams, nil
|
||||
func (s SqlTeamStore) SearchPrivate(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
opts.TeamType = model.NewString("O")
|
||||
opts.AllowOpenInvite = model.NewBool(false)
|
||||
return s.SearchAll(opts)
|
||||
}
|
||||
|
||||
// GetAll returns all teams
|
||||
@@ -558,13 +545,35 @@ func (s SqlTeamStore) GetAll() ([]*model.Team, error) {
|
||||
}
|
||||
|
||||
// GetAllPage returns teams, up to a total limit passed as parameter and paginated by offset number passed as parameter.
|
||||
func (s SqlTeamStore) GetAllPage(offset int, limit int) ([]*model.Team, error) {
|
||||
func (s SqlTeamStore) GetAllPage(offset int, limit int, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
var teams []*model.Team
|
||||
|
||||
query, args, err := s.teamsQuery.
|
||||
selectString := "Teams.*"
|
||||
if opts != nil && opts.IncludePolicyID != nil && *opts.IncludePolicyID {
|
||||
selectString += ", RetentionPoliciesTeams.PolicyId"
|
||||
}
|
||||
|
||||
builder := s.getQueryBuilder().
|
||||
Select(selectString).
|
||||
From("Teams").
|
||||
OrderBy("DisplayName").
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset)).ToSql()
|
||||
Offset(uint64(offset))
|
||||
|
||||
if opts != nil {
|
||||
if (opts.ExcludePolicyConstrained != nil && *opts.ExcludePolicyConstrained) ||
|
||||
(opts.IncludePolicyID != nil && *opts.IncludePolicyID) {
|
||||
builder = builder.LeftJoin("RetentionPoliciesTeams ON Teams.Id = RetentionPoliciesTeams.TeamId")
|
||||
}
|
||||
if opts.ExcludePolicyConstrained != nil && *opts.ExcludePolicyConstrained {
|
||||
builder = builder.Where("RetentionPoliciesTeams.TeamId IS NULL")
|
||||
}
|
||||
if opts.AllowOpenInvite != nil {
|
||||
builder = builder.Where(sq.Eq{"AllowOpenInvite": *opts.AllowOpenInvite})
|
||||
}
|
||||
}
|
||||
|
||||
query, args, err := builder.ToSql()
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
@@ -608,43 +617,6 @@ func (s SqlTeamStore) GetAllPrivateTeamListing() ([]*model.Team, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// GetAllPublicTeamPageListing returns public teams, up to a total limit passed as parameter and paginated by offset number passed as parameter.
|
||||
func (s SqlTeamStore) GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
query, args, err := s.teamsQuery.Where(sq.Eq{"AllowOpenInvite": true}).
|
||||
OrderBy("DisplayName").
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset)).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
var data []*model.Team
|
||||
if _, err = s.GetReplica().Select(&data, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// GetAllPrivateTeamPageListing returns private teams, up to a total limit passed as paramater and paginated by offset number passed as parameter.
|
||||
func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
query, args, err := s.teamsQuery.Where(sq.Eq{"AllowOpenInvite": false}).
|
||||
OrderBy("DisplayName").
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset)).ToSql()
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
var data []*model.Team
|
||||
if _, err = s.GetReplica().Select(&data, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// GetAllTeamListing returns all public teams.
|
||||
func (s SqlTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
query, args, err := s.teamsQuery.Where(sq.Eq{"AllowOpenInvite": true}).
|
||||
@@ -662,25 +634,6 @@ func (s SqlTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// GetAllTeamPageListing returns public teams, up to a total limit passed as parameter and paginated by offset number passed as parameter.
|
||||
func (s SqlTeamStore) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
query, args, err := s.teamsQuery.Where(sq.Eq{"AllowOpenInvite": true}).
|
||||
OrderBy("DisplayName").
|
||||
Limit(uint64(limit)).
|
||||
Offset(uint64(offset)).ToSql()
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
var teams []*model.Team
|
||||
if _, err = s.GetReplica().Select(&teams, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find Teams")
|
||||
}
|
||||
|
||||
return teams, nil
|
||||
}
|
||||
|
||||
// PermanentDelete permanently deletes from the database the team entry that matches the teamId passed as parameter.
|
||||
// To soft-delete the team you can Update it with the DeleteAt field set to the current millisecond using model.GetMillis()
|
||||
func (s SqlTeamStore) PermanentDelete(teamId string) error {
|
||||
@@ -696,49 +649,15 @@ func (s SqlTeamStore) PermanentDelete(teamId string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AnalyticsPublicTeamCount returns the number of active public teams.
|
||||
func (s SqlTeamStore) AnalyticsPublicTeamCount() (int64, error) {
|
||||
query, args, err := s.getQueryBuilder().
|
||||
Select("COUNT(*) FROM Teams").
|
||||
Where(sq.Eq{"DeleteAt": 0, "AllowOpenInvite": true}).ToSql()
|
||||
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
|
||||
c, err := s.GetReplica().SelectInt(query, args...)
|
||||
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count Teams")
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// AnalyticsPrivateTeamCount returns the number of active private teams.
|
||||
func (s SqlTeamStore) AnalyticsPrivateTeamCount() (int64, error) {
|
||||
query, args, err := s.getQueryBuilder().
|
||||
Select("COUNT(*) FROM Teams").
|
||||
Where(sq.Eq{"DeleteAt": 0, "AllowOpenInvite": false}).ToSql()
|
||||
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "team_tosql")
|
||||
}
|
||||
c, err := s.GetReplica().SelectInt(query, args...)
|
||||
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count Teams")
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// AnalyticsTeamCount returns the total number of teams including deleted teams if parameter passed is set to 'true'.
|
||||
func (s SqlTeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, error) {
|
||||
// AnalyticsTeamCount returns the total number of teams.
|
||||
func (s SqlTeamStore) AnalyticsTeamCount(opts *model.TeamSearch) (int64, error) {
|
||||
query := s.getQueryBuilder().Select("COUNT(*) FROM Teams")
|
||||
if !includeDeleted {
|
||||
if opts == nil || (opts.IncludeDeleted != nil && !*opts.IncludeDeleted) {
|
||||
query = query.Where(sq.Eq{"DeleteAt": 0})
|
||||
}
|
||||
if opts != nil && opts.AllowOpenInvite != nil {
|
||||
query = query.Where(sq.Eq{"AllowOpenInvite": *opts.AllowOpenInvite})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
|
||||
@@ -23,6 +23,7 @@ type Store interface {
|
||||
Team() TeamStore
|
||||
Channel() ChannelStore
|
||||
Post() PostStore
|
||||
RetentionPolicy() RetentionPolicyStore
|
||||
Thread() ThreadStore
|
||||
User() UserStore
|
||||
Bot() BotStore
|
||||
@@ -74,29 +75,45 @@ type Store interface {
|
||||
Context() context.Context
|
||||
}
|
||||
|
||||
type RetentionPolicyStore interface {
|
||||
Save(policy *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error)
|
||||
Patch(patch *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error)
|
||||
Get(id string) (*model.RetentionPolicyWithTeamAndChannelCounts, error)
|
||||
GetAll(offset, limit int) ([]*model.RetentionPolicyWithTeamAndChannelCounts, error)
|
||||
GetCount() (int64, error)
|
||||
Delete(id string) error
|
||||
GetChannels(policyId string, offset, limit int) (model.ChannelListWithTeamData, error)
|
||||
GetChannelsCount(policyId string) (int64, error)
|
||||
AddChannels(policyId string, channelIds []string) error
|
||||
RemoveChannels(policyId string, channelIds []string) error
|
||||
GetTeams(policyId string, offset, limit int) ([]*model.Team, error)
|
||||
GetTeamsCount(policyId string) (int64, error)
|
||||
AddTeams(policyId string, teamIds []string) error
|
||||
RemoveTeams(policyId string, teamIds []string) error
|
||||
GetTeamPoliciesForUser(userID string, offset, limit int) ([]*model.RetentionPolicyForTeam, error)
|
||||
GetTeamPoliciesCountForUser(userID string) (int64, error)
|
||||
GetChannelPoliciesForUser(userID string, offset, limit int) ([]*model.RetentionPolicyForChannel, error)
|
||||
GetChannelPoliciesCountForUser(userID string) (int64, error)
|
||||
}
|
||||
|
||||
type TeamStore interface {
|
||||
Save(team *model.Team) (*model.Team, error)
|
||||
Update(team *model.Team) (*model.Team, error)
|
||||
Get(id string) (*model.Team, error)
|
||||
GetByName(name string) (*model.Team, error)
|
||||
GetByNames(name []string) ([]*model.Team, error)
|
||||
SearchAll(term string, opts *model.TeamSearch) ([]*model.Team, error)
|
||||
SearchAllPaged(term string, opts *model.TeamSearch) ([]*model.Team, int64, error)
|
||||
SearchOpen(term string) ([]*model.Team, error)
|
||||
SearchPrivate(term string) ([]*model.Team, error)
|
||||
SearchAll(opts *model.TeamSearch) ([]*model.Team, error)
|
||||
SearchAllPaged(opts *model.TeamSearch) ([]*model.Team, int64, error)
|
||||
SearchOpen(opts *model.TeamSearch) ([]*model.Team, error)
|
||||
SearchPrivate(opts *model.TeamSearch) ([]*model.Team, error)
|
||||
GetAll() ([]*model.Team, error)
|
||||
GetAllPage(offset int, limit int) ([]*model.Team, error)
|
||||
GetAllPage(offset int, limit int, opts *model.TeamSearch) ([]*model.Team, error)
|
||||
GetAllPrivateTeamListing() ([]*model.Team, error)
|
||||
GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, error)
|
||||
GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, error)
|
||||
GetAllTeamListing() ([]*model.Team, error)
|
||||
GetAllTeamPageListing(offset int, limit int) ([]*model.Team, error)
|
||||
GetTeamsByUserId(userID string) ([]*model.Team, error)
|
||||
GetByInviteId(inviteID string) (*model.Team, error)
|
||||
PermanentDelete(teamID string) error
|
||||
AnalyticsTeamCount(includeDeleted bool) (int64, error)
|
||||
AnalyticsPublicTeamCount() (int64, error)
|
||||
AnalyticsPrivateTeamCount() (int64, error)
|
||||
AnalyticsTeamCount(opts *model.TeamSearch) (int64, error)
|
||||
SaveMultipleMembers(members []*model.TeamMember, maxUsersPerTeam int) ([]*model.TeamMember, error)
|
||||
SaveMember(member *model.TeamMember, maxUsersPerTeam int) (*model.TeamMember, error)
|
||||
UpdateMember(member *model.TeamMember) (*model.TeamMember, error)
|
||||
@@ -848,17 +865,23 @@ type SharedChannelStore interface {
|
||||
// PerPage number of results per page, if paginated.
|
||||
//
|
||||
type ChannelSearchOpts struct {
|
||||
NotAssociatedToGroup string
|
||||
IncludeDeleted bool
|
||||
Deleted bool
|
||||
ExcludeChannelNames []string
|
||||
TeamIds []string
|
||||
GroupConstrained bool
|
||||
ExcludeGroupConstrained bool
|
||||
Public bool
|
||||
Private bool
|
||||
Page *int
|
||||
PerPage *int
|
||||
Term string
|
||||
NotAssociatedToGroup string
|
||||
IncludeDeleted bool
|
||||
Deleted bool
|
||||
ExcludeChannelNames []string
|
||||
TeamIds []string
|
||||
GroupConstrained bool
|
||||
ExcludeGroupConstrained bool
|
||||
PolicyID string
|
||||
ExcludePolicyConstrained bool
|
||||
IncludePolicyID bool
|
||||
IncludeTeamInfo bool
|
||||
CountOnly bool
|
||||
Public bool
|
||||
Private bool
|
||||
Page *int
|
||||
PerPage *int
|
||||
}
|
||||
|
||||
func (c *ChannelSearchOpts) IsPaginated() bool {
|
||||
|
||||
@@ -3375,6 +3375,33 @@ func testChannelStoreGetAllChannels(t *testing.T, ss store.Store, s SqlStore) {
|
||||
require.NoError(t, nErr)
|
||||
assert.Len(t, *list, 1)
|
||||
|
||||
// Exclude policy constrained
|
||||
policy, nErr := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDuration: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{c1.Id},
|
||||
})
|
||||
require.NoError(t, nErr)
|
||||
list, nErr = ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{ExcludePolicyConstrained: true})
|
||||
require.NoError(t, nErr)
|
||||
assert.Len(t, *list, 1)
|
||||
assert.Equal(t, c3.Id, (*list)[0].Id)
|
||||
|
||||
// Without the policy ID
|
||||
list, nErr = ss.Channel().GetAllChannels(0, 1, store.ChannelSearchOpts{})
|
||||
require.NoError(t, nErr)
|
||||
assert.Len(t, *list, 1)
|
||||
assert.Equal(t, c1.Id, (*list)[0].Id)
|
||||
assert.Nil(t, (*list)[0].PolicyID)
|
||||
// With the policy ID
|
||||
list, nErr = ss.Channel().GetAllChannels(0, 1, store.ChannelSearchOpts{IncludePolicyID: true})
|
||||
require.NoError(t, nErr)
|
||||
assert.Len(t, *list, 1)
|
||||
assert.Equal(t, c1.Id, (*list)[0].Id)
|
||||
assert.Equal(t, *(*list)[0].PolicyID, policy.ID)
|
||||
|
||||
// Manually truncate Channels table until testlib can handle cleanups
|
||||
s.GetMaster().Exec("TRUNCATE Channels")
|
||||
}
|
||||
@@ -5459,6 +5486,16 @@ func testChannelStoreSearchAllChannels(t *testing.T, ss store.Store) {
|
||||
}
|
||||
_, nErr = ss.Channel().Save(&o14, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
_, nErr = ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDuration: model.NewInt64(30),
|
||||
},
|
||||
ChannelIDs: []string{o14.Id},
|
||||
})
|
||||
require.NoError(t, nErr)
|
||||
|
||||
testCases := []struct {
|
||||
Description string
|
||||
Term string
|
||||
@@ -5494,6 +5531,7 @@ func testChannelStoreSearchAllChannels(t *testing.T, ss store.Store) {
|
||||
{"Filter group constrained", "", store.ChannelSearchOpts{IncludeDeleted: false, GroupConstrained: true, Page: model.NewInt(0), PerPage: model.NewInt(5)}, &model.ChannelList{&o5}, 1},
|
||||
{"Filter exclude group constrained and include deleted", "", store.ChannelSearchOpts{IncludeDeleted: true, ExcludeGroupConstrained: true, Page: model.NewInt(0), PerPage: model.NewInt(5)}, &model.ChannelList{&o1, &o2, &o3, &o4, &o6}, 13},
|
||||
{"Filter private and exclude group constrained", "", store.ChannelSearchOpts{IncludeDeleted: false, ExcludeGroupConstrained: true, Private: true, Page: model.NewInt(0), PerPage: model.NewInt(5)}, &model.ChannelList{&o4, &o8}, 2},
|
||||
{"Exclude policy constrained", "", store.ChannelSearchOpts{ExcludePolicyConstrained: true}, &model.ChannelList{&o1, &o2, &o3, &o4, &o5, &o6, &o7, &o8, &o9, &o10, &o11, &o12}, 0},
|
||||
{"Filter team 2", "", store.ChannelSearchOpts{IncludeDeleted: false, TeamIds: []string{t2.Id}, Page: model.NewInt(0), PerPage: model.NewInt(5)}, &model.ChannelList{&o2, &o14}, 2},
|
||||
{"Filter team 2, private", "", store.ChannelSearchOpts{IncludeDeleted: false, TeamIds: []string{t2.Id}, Private: true, Page: model.NewInt(0), PerPage: model.NewInt(5)}, &model.ChannelList{}, 0},
|
||||
{"Filter team 1 and team 2, private", "", store.ChannelSearchOpts{IncludeDeleted: false, TeamIds: []string{t1.Id, t2.Id}, Private: true, Page: model.NewInt(0), PerPage: model.NewInt(5)}, &model.ChannelList{&o4, &o5, &o8}, 3},
|
||||
|
||||
374
store/storetest/mocks/RetentionPolicyStore.go
Обычный файл
374
store/storetest/mocks/RetentionPolicyStore.go
Обычный файл
@@ -0,0 +1,374 @@
|
||||
// Code generated by mockery v1.0.0. DO NOT EDIT.
|
||||
|
||||
// Regenerate this file using `make store-mocks`.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
model "github.com/mattermost/mattermost-server/v5/model"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// RetentionPolicyStore is an autogenerated mock type for the RetentionPolicyStore type
|
||||
type RetentionPolicyStore struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// AddChannels provides a mock function with given fields: policyId, channelIds
|
||||
func (_m *RetentionPolicyStore) AddChannels(policyId string, channelIds []string) error {
|
||||
ret := _m.Called(policyId, channelIds)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, []string) error); ok {
|
||||
r0 = rf(policyId, channelIds)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// AddTeams provides a mock function with given fields: policyId, teamIds
|
||||
func (_m *RetentionPolicyStore) AddTeams(policyId string, teamIds []string) error {
|
||||
ret := _m.Called(policyId, teamIds)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, []string) error); ok {
|
||||
r0 = rf(policyId, teamIds)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: id
|
||||
func (_m *RetentionPolicyStore) Delete(id string) error {
|
||||
ret := _m.Called(id)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(id)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: id
|
||||
func (_m *RetentionPolicyStore) Get(id string) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
ret := _m.Called(id)
|
||||
|
||||
var r0 *model.RetentionPolicyWithTeamAndChannelCounts
|
||||
if rf, ok := ret.Get(0).(func(string) *model.RetentionPolicyWithTeamAndChannelCounts); ok {
|
||||
r0 = rf(id)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.RetentionPolicyWithTeamAndChannelCounts)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(id)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAll provides a mock function with given fields: offset, limit
|
||||
func (_m *RetentionPolicyStore) GetAll(offset int, limit int) ([]*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
ret := _m.Called(offset, limit)
|
||||
|
||||
var r0 []*model.RetentionPolicyWithTeamAndChannelCounts
|
||||
if rf, ok := ret.Get(0).(func(int, int) []*model.RetentionPolicyWithTeamAndChannelCounts); ok {
|
||||
r0 = rf(offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.RetentionPolicyWithTeamAndChannelCounts)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int, int) error); ok {
|
||||
r1 = rf(offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetChannelPoliciesCountForUser provides a mock function with given fields: userID
|
||||
func (_m *RetentionPolicyStore) GetChannelPoliciesCountForUser(userID string) (int64, error) {
|
||||
ret := _m.Called(userID)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(userID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(userID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetChannelPoliciesForUser provides a mock function with given fields: userID, offset, limit
|
||||
func (_m *RetentionPolicyStore) GetChannelPoliciesForUser(userID string, offset int, limit int) ([]*model.RetentionPolicyForChannel, error) {
|
||||
ret := _m.Called(userID, offset, limit)
|
||||
|
||||
var r0 []*model.RetentionPolicyForChannel
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) []*model.RetentionPolicyForChannel); ok {
|
||||
r0 = rf(userID, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.RetentionPolicyForChannel)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
|
||||
r1 = rf(userID, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetChannels provides a mock function with given fields: policyId, offset, limit
|
||||
func (_m *RetentionPolicyStore) GetChannels(policyId string, offset int, limit int) (model.ChannelListWithTeamData, error) {
|
||||
ret := _m.Called(policyId, offset, limit)
|
||||
|
||||
var r0 model.ChannelListWithTeamData
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) model.ChannelListWithTeamData); ok {
|
||||
r0 = rf(policyId, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(model.ChannelListWithTeamData)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
|
||||
r1 = rf(policyId, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetChannelsCount provides a mock function with given fields: policyId
|
||||
func (_m *RetentionPolicyStore) GetChannelsCount(policyId string) (int64, error) {
|
||||
ret := _m.Called(policyId)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(policyId)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(policyId)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetCount provides a mock function with given fields:
|
||||
func (_m *RetentionPolicyStore) GetCount() (int64, error) {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func() int64); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func() error); ok {
|
||||
r1 = rf()
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTeamPoliciesCountForUser provides a mock function with given fields: userID
|
||||
func (_m *RetentionPolicyStore) GetTeamPoliciesCountForUser(userID string) (int64, error) {
|
||||
ret := _m.Called(userID)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(userID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(userID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTeamPoliciesForUser provides a mock function with given fields: userID, offset, limit
|
||||
func (_m *RetentionPolicyStore) GetTeamPoliciesForUser(userID string, offset int, limit int) ([]*model.RetentionPolicyForTeam, error) {
|
||||
ret := _m.Called(userID, offset, limit)
|
||||
|
||||
var r0 []*model.RetentionPolicyForTeam
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) []*model.RetentionPolicyForTeam); ok {
|
||||
r0 = rf(userID, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.RetentionPolicyForTeam)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
|
||||
r1 = rf(userID, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTeams provides a mock function with given fields: policyId, offset, limit
|
||||
func (_m *RetentionPolicyStore) GetTeams(policyId string, offset int, limit int) ([]*model.Team, error) {
|
||||
ret := _m.Called(policyId, offset, limit)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) []*model.Team); ok {
|
||||
r0 = rf(policyId, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
|
||||
r1 = rf(policyId, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetTeamsCount provides a mock function with given fields: policyId
|
||||
func (_m *RetentionPolicyStore) GetTeamsCount(policyId string) (int64, error) {
|
||||
ret := _m.Called(policyId)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(policyId)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(policyId)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Patch provides a mock function with given fields: patch
|
||||
func (_m *RetentionPolicyStore) Patch(patch *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
ret := _m.Called(patch)
|
||||
|
||||
var r0 *model.RetentionPolicyWithTeamAndChannelCounts
|
||||
if rf, ok := ret.Get(0).(func(*model.RetentionPolicyWithTeamAndChannelIDs) *model.RetentionPolicyWithTeamAndChannelCounts); ok {
|
||||
r0 = rf(patch)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.RetentionPolicyWithTeamAndChannelCounts)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.RetentionPolicyWithTeamAndChannelIDs) error); ok {
|
||||
r1 = rf(patch)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// RemoveChannels provides a mock function with given fields: policyId, channelIds
|
||||
func (_m *RetentionPolicyStore) RemoveChannels(policyId string, channelIds []string) error {
|
||||
ret := _m.Called(policyId, channelIds)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, []string) error); ok {
|
||||
r0 = rf(policyId, channelIds)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// RemoveTeams provides a mock function with given fields: policyId, teamIds
|
||||
func (_m *RetentionPolicyStore) RemoveTeams(policyId string, teamIds []string) error {
|
||||
ret := _m.Called(policyId, teamIds)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, []string) error); ok {
|
||||
r0 = rf(policyId, teamIds)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Save provides a mock function with given fields: policy
|
||||
func (_m *RetentionPolicyStore) Save(policy *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
ret := _m.Called(policy)
|
||||
|
||||
var r0 *model.RetentionPolicyWithTeamAndChannelCounts
|
||||
if rf, ok := ret.Get(0).(func(*model.RetentionPolicyWithTeamAndChannelIDs) *model.RetentionPolicyWithTeamAndChannelCounts); ok {
|
||||
r0 = rf(policy)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.RetentionPolicyWithTeamAndChannelCounts)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.RetentionPolicyWithTeamAndChannelIDs) error); ok {
|
||||
r1 = rf(policy)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
@@ -476,6 +476,22 @@ func (_m *Store) ReplicaLagTime() error {
|
||||
return r0
|
||||
}
|
||||
|
||||
// RetentionPolicy provides a mock function with given fields:
|
||||
func (_m *Store) RetentionPolicy() store.RetentionPolicyStore {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 store.RetentionPolicyStore
|
||||
if rf, ok := ret.Get(0).(func() store.RetentionPolicyStore); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.RetentionPolicyStore)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Role provides a mock function with given fields:
|
||||
func (_m *Store) Role() store.RoleStore {
|
||||
ret := _m.Called()
|
||||
|
||||
@@ -37,62 +37,20 @@ func (_m *TeamStore) AnalyticsGetTeamCountForScheme(schemeID string) (int64, err
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// AnalyticsPrivateTeamCount provides a mock function with given fields:
|
||||
func (_m *TeamStore) AnalyticsPrivateTeamCount() (int64, error) {
|
||||
ret := _m.Called()
|
||||
// AnalyticsTeamCount provides a mock function with given fields: opts
|
||||
func (_m *TeamStore) AnalyticsTeamCount(opts *model.TeamSearch) (int64, error) {
|
||||
ret := _m.Called(opts)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func() int64); ok {
|
||||
r0 = rf()
|
||||
if rf, ok := ret.Get(0).(func(*model.TeamSearch) int64); ok {
|
||||
r0 = rf(opts)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func() error); ok {
|
||||
r1 = rf()
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// AnalyticsPublicTeamCount provides a mock function with given fields:
|
||||
func (_m *TeamStore) AnalyticsPublicTeamCount() (int64, error) {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func() int64); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func() error); ok {
|
||||
r1 = rf()
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// AnalyticsTeamCount provides a mock function with given fields: includeDeleted
|
||||
func (_m *TeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, error) {
|
||||
ret := _m.Called(includeDeleted)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(bool) int64); ok {
|
||||
r0 = rf(includeDeleted)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(bool) error); ok {
|
||||
r1 = rf(includeDeleted)
|
||||
if rf, ok := ret.Get(1).(func(*model.TeamSearch) error); ok {
|
||||
r1 = rf(opts)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -209,13 +167,13 @@ func (_m *TeamStore) GetAllForExportAfter(limit int, afterID string) ([]*model.T
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAllPage provides a mock function with given fields: offset, limit
|
||||
func (_m *TeamStore) GetAllPage(offset int, limit int) ([]*model.Team, error) {
|
||||
ret := _m.Called(offset, limit)
|
||||
// GetAllPage provides a mock function with given fields: offset, limit, opts
|
||||
func (_m *TeamStore) GetAllPage(offset int, limit int, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
ret := _m.Called(offset, limit, opts)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(int, int) []*model.Team); ok {
|
||||
r0 = rf(offset, limit)
|
||||
if rf, ok := ret.Get(0).(func(int, int, *model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(offset, limit, opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
@@ -223,8 +181,8 @@ func (_m *TeamStore) GetAllPage(offset int, limit int) ([]*model.Team, error) {
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int, int) error); ok {
|
||||
r1 = rf(offset, limit)
|
||||
if rf, ok := ret.Get(1).(func(int, int, *model.TeamSearch) error); ok {
|
||||
r1 = rf(offset, limit, opts)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -255,52 +213,6 @@ func (_m *TeamStore) GetAllPrivateTeamListing() ([]*model.Team, error) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAllPrivateTeamPageListing provides a mock function with given fields: offset, limit
|
||||
func (_m *TeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
ret := _m.Called(offset, limit)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(int, int) []*model.Team); ok {
|
||||
r0 = rf(offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int, int) error); ok {
|
||||
r1 = rf(offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAllPublicTeamPageListing provides a mock function with given fields: offset, limit
|
||||
func (_m *TeamStore) GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
ret := _m.Called(offset, limit)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(int, int) []*model.Team); ok {
|
||||
r0 = rf(offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int, int) error); ok {
|
||||
r1 = rf(offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAllTeamListing provides a mock function with given fields:
|
||||
func (_m *TeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
ret := _m.Called()
|
||||
@@ -324,29 +236,6 @@ func (_m *TeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAllTeamPageListing provides a mock function with given fields: offset, limit
|
||||
func (_m *TeamStore) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
ret := _m.Called(offset, limit)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(int, int) []*model.Team); ok {
|
||||
r0 = rf(offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int, int) error); ok {
|
||||
r1 = rf(offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetByInviteId provides a mock function with given fields: inviteID
|
||||
func (_m *TeamStore) GetByInviteId(inviteID string) (*model.Team, error) {
|
||||
ret := _m.Called(inviteID)
|
||||
@@ -892,13 +781,13 @@ func (_m *TeamStore) SaveMultipleMembers(members []*model.TeamMember, maxUsersPe
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchAll provides a mock function with given fields: term, opts
|
||||
func (_m *TeamStore) SearchAll(term string, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
ret := _m.Called(term, opts)
|
||||
// SearchAll provides a mock function with given fields: opts
|
||||
func (_m *TeamStore) SearchAll(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
ret := _m.Called(opts)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(string, *model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(term, opts)
|
||||
if rf, ok := ret.Get(0).(func(*model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
@@ -906,8 +795,8 @@ func (_m *TeamStore) SearchAll(term string, opts *model.TeamSearch) ([]*model.Te
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, *model.TeamSearch) error); ok {
|
||||
r1 = rf(term, opts)
|
||||
if rf, ok := ret.Get(1).(func(*model.TeamSearch) error); ok {
|
||||
r1 = rf(opts)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -915,13 +804,13 @@ func (_m *TeamStore) SearchAll(term string, opts *model.TeamSearch) ([]*model.Te
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchAllPaged provides a mock function with given fields: term, opts
|
||||
func (_m *TeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
ret := _m.Called(term, opts)
|
||||
// SearchAllPaged provides a mock function with given fields: opts
|
||||
func (_m *TeamStore) SearchAllPaged(opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
ret := _m.Called(opts)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(string, *model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(term, opts)
|
||||
if rf, ok := ret.Get(0).(func(*model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
@@ -929,15 +818,15 @@ func (_m *TeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*mod
|
||||
}
|
||||
|
||||
var r1 int64
|
||||
if rf, ok := ret.Get(1).(func(string, *model.TeamSearch) int64); ok {
|
||||
r1 = rf(term, opts)
|
||||
if rf, ok := ret.Get(1).(func(*model.TeamSearch) int64); ok {
|
||||
r1 = rf(opts)
|
||||
} else {
|
||||
r1 = ret.Get(1).(int64)
|
||||
}
|
||||
|
||||
var r2 error
|
||||
if rf, ok := ret.Get(2).(func(string, *model.TeamSearch) error); ok {
|
||||
r2 = rf(term, opts)
|
||||
if rf, ok := ret.Get(2).(func(*model.TeamSearch) error); ok {
|
||||
r2 = rf(opts)
|
||||
} else {
|
||||
r2 = ret.Error(2)
|
||||
}
|
||||
@@ -945,13 +834,13 @@ func (_m *TeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*mod
|
||||
return r0, r1, r2
|
||||
}
|
||||
|
||||
// SearchOpen provides a mock function with given fields: term
|
||||
func (_m *TeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
ret := _m.Called(term)
|
||||
// SearchOpen provides a mock function with given fields: opts
|
||||
func (_m *TeamStore) SearchOpen(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
ret := _m.Called(opts)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(string) []*model.Team); ok {
|
||||
r0 = rf(term)
|
||||
if rf, ok := ret.Get(0).(func(*model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
@@ -959,8 +848,8 @@ func (_m *TeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(term)
|
||||
if rf, ok := ret.Get(1).(func(*model.TeamSearch) error); ok {
|
||||
r1 = rf(opts)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -968,13 +857,13 @@ func (_m *TeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchPrivate provides a mock function with given fields: term
|
||||
func (_m *TeamStore) SearchPrivate(term string) ([]*model.Team, error) {
|
||||
ret := _m.Called(term)
|
||||
// SearchPrivate provides a mock function with given fields: opts
|
||||
func (_m *TeamStore) SearchPrivate(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
ret := _m.Called(opts)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(string) []*model.Team); ok {
|
||||
r0 = rf(term)
|
||||
if rf, ok := ret.Get(0).(func(*model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
@@ -982,8 +871,8 @@ func (_m *TeamStore) SearchPrivate(term string) ([]*model.Team, error) {
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||
r1 = rf(term)
|
||||
if rf, ok := ret.Get(1).(func(*model.TeamSearch) error); ok {
|
||||
r1 = rf(opts)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
658
store/storetest/retention_policy_store.go
Обычный файл
658
store/storetest/retention_policy_store.go
Обычный файл
@@ -0,0 +1,658 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package storetest
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRetentionPolicyStore(t *testing.T, ss store.Store, s SqlStore) {
|
||||
t.Run("Save", func(t *testing.T) { testRetentionPolicyStoreSave(t, ss, s) })
|
||||
t.Run("Patch", func(t *testing.T) { testRetentionPolicyStorePatch(t, ss, s) })
|
||||
t.Run("Get", func(t *testing.T) { testRetentionPolicyStoreGet(t, ss, s) })
|
||||
t.Run("GetCount", func(t *testing.T) { testRetentionPolicyStoreGetCount(t, ss, s) })
|
||||
t.Run("Delete", func(t *testing.T) { testRetentionPolicyStoreDelete(t, ss, s) })
|
||||
t.Run("GetChannels", func(t *testing.T) { testRetentionPolicyStoreGetChannels(t, ss, s) })
|
||||
t.Run("AddChannels", func(t *testing.T) { testRetentionPolicyStoreAddChannels(t, ss, s) })
|
||||
t.Run("RemoveChannels", func(t *testing.T) { testRetentionPolicyStoreRemoveChannels(t, ss, s) })
|
||||
t.Run("GetTeams", func(t *testing.T) { testRetentionPolicyStoreGetTeams(t, ss, s) })
|
||||
t.Run("AddTeams", func(t *testing.T) { testRetentionPolicyStoreAddTeams(t, ss, s) })
|
||||
t.Run("RemoveTeams", func(t *testing.T) { testRetentionPolicyStoreRemoveTeams(t, ss, s) })
|
||||
t.Run("GetPoliciesForUser", func(t *testing.T) { testRetentionPolicyStoreGetPoliciesForUser(t, ss, s) })
|
||||
}
|
||||
|
||||
func getRetentionPolicyWithTeamAndChannelIds(t *testing.T, ss store.Store, policyID string) *model.RetentionPolicyWithTeamAndChannelIDs {
|
||||
policyWithCounts, err := ss.RetentionPolicy().Get(policyID)
|
||||
require.NoError(t, err)
|
||||
policyWithIds := model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policyID,
|
||||
DisplayName: policyWithCounts.DisplayName,
|
||||
PostDuration: policyWithCounts.PostDuration,
|
||||
},
|
||||
ChannelIDs: make([]string, int(policyWithCounts.ChannelCount)),
|
||||
TeamIDs: make([]string, int(policyWithCounts.TeamCount)),
|
||||
}
|
||||
channels, err := ss.RetentionPolicy().GetChannels(policyID, 0, 1000)
|
||||
require.NoError(t, err)
|
||||
for i, channel := range channels {
|
||||
policyWithIds.ChannelIDs[i] = channel.Id
|
||||
}
|
||||
teams, err := ss.RetentionPolicy().GetTeams(policyID, 0, 1000)
|
||||
require.NoError(t, err)
|
||||
for i, team := range teams {
|
||||
policyWithIds.TeamIDs[i] = team.Id
|
||||
}
|
||||
return &policyWithIds
|
||||
}
|
||||
|
||||
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, len(p1.ChannelIDs), len(p2.ChannelIDs))
|
||||
if p1.ChannelIDs == nil || p2.ChannelIDs == nil {
|
||||
require.Equal(t, p1.ChannelIDs, p2.ChannelIDs)
|
||||
} else {
|
||||
sort.Strings(p1.ChannelIDs)
|
||||
sort.Strings(p2.ChannelIDs)
|
||||
}
|
||||
for i := range p1.ChannelIDs {
|
||||
require.Equal(t, p1.ChannelIDs[i], p2.ChannelIDs[i])
|
||||
}
|
||||
if p1.TeamIDs == nil || p2.TeamIDs == nil {
|
||||
require.Equal(t, p1.TeamIDs, p2.TeamIDs)
|
||||
} else {
|
||||
sort.Strings(p1.TeamIDs)
|
||||
sort.Strings(p2.TeamIDs)
|
||||
}
|
||||
require.Equal(t, len(p1.TeamIDs), len(p2.TeamIDs))
|
||||
for i := range p1.TeamIDs {
|
||||
require.Equal(t, p1.TeamIDs[i], p2.TeamIDs[i])
|
||||
}
|
||||
}
|
||||
|
||||
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.ChannelCount, p2.ChannelCount)
|
||||
require.Equal(t, p1.TeamCount, p2.TeamCount)
|
||||
}
|
||||
|
||||
func checkRetentionPolicyLikeThisExists(t *testing.T, ss store.Store, expected *model.RetentionPolicyWithTeamAndChannelIDs) {
|
||||
retrieved := getRetentionPolicyWithTeamAndChannelIds(t, ss, expected.ID)
|
||||
CheckRetentionPolicyWithTeamAndChannelIdsAreEqual(t, expected, retrieved)
|
||||
}
|
||||
|
||||
func copyRetentionPolicyWithTeamAndChannelIds(policy *model.RetentionPolicyWithTeamAndChannelIDs) *model.RetentionPolicyWithTeamAndChannelIDs {
|
||||
copy := &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: policy.RetentionPolicy,
|
||||
ChannelIDs: make([]string, len(policy.ChannelIDs)),
|
||||
TeamIDs: make([]string, len(policy.TeamIDs)),
|
||||
}
|
||||
for i, channelID := range policy.ChannelIDs {
|
||||
copy.ChannelIDs[i] = channelID
|
||||
}
|
||||
for i, teamID := range policy.TeamIDs {
|
||||
copy.TeamIDs[i] = teamID
|
||||
}
|
||||
return copy
|
||||
}
|
||||
|
||||
func createChannelsForRetentionPolicy(t *testing.T, ss store.Store, teamId string, numChannels int) (channelIDs []string) {
|
||||
channelIDs = make([]string, numChannels)
|
||||
for i := range channelIDs {
|
||||
name := "channel" + model.NewId()
|
||||
channel := &model.Channel{
|
||||
TeamId: teamId,
|
||||
DisplayName: "Channel " + name,
|
||||
Name: name,
|
||||
Type: model.CHANNEL_OPEN,
|
||||
}
|
||||
channel, err := ss.Channel().Save(channel, -1)
|
||||
require.NoError(t, err)
|
||||
channelIDs[i] = channel.Id
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func createTeamsForRetentionPolicy(t *testing.T, ss store.Store, numTeams int) (teamIDs []string) {
|
||||
teamIDs = make([]string, numTeams)
|
||||
for i := range teamIDs {
|
||||
name := "team" + model.NewId()
|
||||
team := &model.Team{
|
||||
DisplayName: "Team " + name,
|
||||
Name: name,
|
||||
Type: model.TEAM_OPEN,
|
||||
}
|
||||
team, err := ss.Team().Save(team)
|
||||
require.NoError(t, err)
|
||||
teamIDs[i] = team.Id
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func createTeamsAndChannelsForRetentionPolicy(t *testing.T, ss store.Store) (teamIDs, channelIDs []string) {
|
||||
teamIDs = createTeamsForRetentionPolicy(t, ss, 2)
|
||||
channels1 := createChannelsForRetentionPolicy(t, ss, teamIDs[0], 1)
|
||||
channels2 := createChannelsForRetentionPolicy(t, ss, teamIDs[1], 2)
|
||||
channelIDs = append(channels1, channels2...)
|
||||
return
|
||||
}
|
||||
|
||||
func cleanupRetentionPolicyTest(s SqlStore) {
|
||||
// Manually clear tables until testlib can handle cleanups
|
||||
tables := []string{"RetentionPolicies", "RetentionPoliciesChannels", "RetentionPoliciesTeams"}
|
||||
for _, table := range tables {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM " + table); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func deleteTeamsAndChannels(ss store.Store, teamIDs, channelIDs []string) {
|
||||
for _, teamID := range teamIDs {
|
||||
if err := ss.Team().PermanentDelete(teamID); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
for _, channelID := range channelIDs {
|
||||
if err := ss.Channel().PermanentDelete(channelID); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func createRetentionPolicyWithTeamAndChannelIds(displayName string, teamIDs, channelIDs []string) *model.RetentionPolicyWithTeamAndChannelIDs {
|
||||
return &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: displayName,
|
||||
PostDuration: model.NewInt64(30),
|
||||
},
|
||||
TeamIDs: teamIDs,
|
||||
ChannelIDs: channelIDs,
|
||||
}
|
||||
}
|
||||
|
||||
// saveRetentionPolicyWithTeamAndChannelIds creates a model.RetentionPolicyWithTeamAndChannelIds struct using
|
||||
// the display name, team IDs, and channel IDs. The new policy ID will be assigned to the struct and returned.
|
||||
// The team IDs and channel IDs are kept the same.
|
||||
func saveRetentionPolicyWithTeamAndChannelIds(t *testing.T, ss store.Store, displayName string, teamIDs, channelIDs []string) *model.RetentionPolicyWithTeamAndChannelIDs {
|
||||
proposal := createRetentionPolicyWithTeamAndChannelIds(displayName, teamIDs, channelIDs)
|
||||
policyWithCounts, err := ss.RetentionPolicy().Save(proposal)
|
||||
require.NoError(t, err)
|
||||
proposal.ID = policyWithCounts.ID
|
||||
return proposal
|
||||
}
|
||||
|
||||
func restoreRetentionPolicy(t *testing.T, ss store.Store, policy *model.RetentionPolicyWithTeamAndChannelIDs) {
|
||||
_, err := ss.RetentionPolicy().Patch(policy)
|
||||
require.NoError(t, err)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreSave(t *testing.T, ss store.Store, s SqlStore) {
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("teams and channels are nil", func(t *testing.T) {
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", nil, nil)
|
||||
policy.ChannelIDs = []string{}
|
||||
policy.TeamIDs = []string{}
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
t.Run("teams and channels are empty", func(t *testing.T) {
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 2", []string{}, []string{})
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
t.Run("some teams and channels are specified", func(t *testing.T) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 3", teamIDs, channelIDs)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
t.Run("team specified does not exist", func(t *testing.T) {
|
||||
policy := createRetentionPolicyWithTeamAndChannelIds("Policy 4", []string{"no_such_team"}, []string{})
|
||||
_, err := ss.RetentionPolicy().Save(policy)
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("channel specified does not exist", func(t *testing.T) {
|
||||
policy := createRetentionPolicyWithTeamAndChannelIds("Policy 5", []string{}, []string{"no_such_channel"})
|
||||
_, err := ss.RetentionPolicy().Save(policy)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStorePatch(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", teamIDs, channelIDs)
|
||||
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("modify DisplayName", func(t *testing.T) {
|
||||
patch := &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policy.ID,
|
||||
DisplayName: "something new",
|
||||
},
|
||||
}
|
||||
_, err := ss.RetentionPolicy().Patch(patch)
|
||||
require.NoError(t, err)
|
||||
expected := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
expected.DisplayName = patch.DisplayName
|
||||
checkRetentionPolicyLikeThisExists(t, ss, expected)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
})
|
||||
t.Run("modify PostDuration", func(t *testing.T) {
|
||||
patch := &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policy.ID,
|
||||
PostDuration: model.NewInt64(10000),
|
||||
},
|
||||
}
|
||||
_, err := ss.RetentionPolicy().Patch(patch)
|
||||
require.NoError(t, err)
|
||||
expected := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
expected.PostDuration = patch.PostDuration
|
||||
checkRetentionPolicyLikeThisExists(t, ss, expected)
|
||||
|
||||
// Store a negative value (= infinity)
|
||||
patch.PostDuration = model.NewInt64(-1)
|
||||
_, err = ss.RetentionPolicy().Patch(patch)
|
||||
require.NoError(t, err)
|
||||
expected = copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
expected.PostDuration = patch.PostDuration
|
||||
checkRetentionPolicyLikeThisExists(t, ss, expected)
|
||||
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
})
|
||||
t.Run("clear TeamIds", func(t *testing.T) {
|
||||
patch := &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policy.ID,
|
||||
},
|
||||
TeamIDs: make([]string, 0),
|
||||
}
|
||||
_, err := ss.RetentionPolicy().Patch(patch)
|
||||
require.NoError(t, err)
|
||||
expected := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
expected.TeamIDs = make([]string, 0)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, expected)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
})
|
||||
t.Run("add team which does not exist", func(t *testing.T) {
|
||||
patch := &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policy.ID,
|
||||
},
|
||||
TeamIDs: []string{"no_such_team"},
|
||||
}
|
||||
_, err := ss.RetentionPolicy().Patch(patch)
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("clear ChannelIds", func(t *testing.T) {
|
||||
patch := &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policy.ID,
|
||||
},
|
||||
ChannelIDs: make([]string, 0),
|
||||
}
|
||||
_, err := ss.RetentionPolicy().Patch(patch)
|
||||
require.NoError(t, err)
|
||||
expected := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
expected.ChannelIDs = make([]string, 0)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, expected)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
})
|
||||
t.Run("add channel which does not exist", func(t *testing.T) {
|
||||
patch := &model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
ID: policy.ID,
|
||||
},
|
||||
ChannelIDs: []string{"no_such_channel"},
|
||||
}
|
||||
_, err := ss.RetentionPolicy().Patch(patch)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreGet(t *testing.T, ss store.Store, s SqlStore) {
|
||||
// create multiple policies
|
||||
policiesWithCounts := make([]*model.RetentionPolicyWithTeamAndChannelCounts, 0)
|
||||
for i := 0; i < 3; i++ {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
policyWithIds := createRetentionPolicyWithTeamAndChannelIds(
|
||||
"Policy "+strconv.Itoa(i+1), teamIDs, channelIDs)
|
||||
policyWithCounts, err := ss.RetentionPolicy().Save(policyWithIds)
|
||||
require.NoError(t, err)
|
||||
policiesWithCounts = append(policiesWithCounts, policyWithCounts)
|
||||
}
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("get all", func(t *testing.T) {
|
||||
retrievedPolicies, err := ss.RetentionPolicy().GetAll(0, 60)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(policiesWithCounts), len(retrievedPolicies))
|
||||
for i := range policiesWithCounts {
|
||||
CheckRetentionPolicyWithTeamAndChannelCountsAreEqual(t, policiesWithCounts[i], retrievedPolicies[i])
|
||||
}
|
||||
})
|
||||
t.Run("get all with limit", func(t *testing.T) {
|
||||
for i := range policiesWithCounts {
|
||||
retrievedPolicies, err := ss.RetentionPolicy().GetAll(i, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(retrievedPolicies))
|
||||
CheckRetentionPolicyWithTeamAndChannelCountsAreEqual(t, policiesWithCounts[i], retrievedPolicies[0])
|
||||
}
|
||||
})
|
||||
t.Run("get all with same display name", func(t *testing.T) {
|
||||
for i := 0; i < 5; i++ {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
proposal := createRetentionPolicyWithTeamAndChannelIds(
|
||||
"Policy Name", teamIDs, channelIDs)
|
||||
_, err := ss.RetentionPolicy().Save(proposal)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
policies, err := ss.RetentionPolicy().GetAll(0, 60)
|
||||
require.NoError(t, err)
|
||||
for i := 1; i < len(policies); i++ {
|
||||
require.True(t,
|
||||
policies[i-1].DisplayName < policies[i].DisplayName ||
|
||||
(policies[i-1].DisplayName == policies[i].DisplayName &&
|
||||
policies[i-1].ID < policies[i].ID),
|
||||
"policies with the same display name should be sorted by ID")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreGetCount(t *testing.T, ss store.Store, s SqlStore) {
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("no policies", func(t *testing.T) {
|
||||
count, err := ss.RetentionPolicy().GetCount()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), count)
|
||||
})
|
||||
t.Run("some policies", func(t *testing.T) {
|
||||
for i := 0; i < 2; i++ {
|
||||
saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy "+strconv.Itoa(i), nil, nil)
|
||||
}
|
||||
count, err := ss.RetentionPolicy().GetCount()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(2), count)
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreDelete(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", teamIDs, channelIDs)
|
||||
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("delete policy", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().Delete(policy.ID)
|
||||
require.NoError(t, err)
|
||||
policies, err := ss.RetentionPolicy().GetAll(0, 1)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, policies)
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreGetChannels(t *testing.T, ss store.Store, s SqlStore) {
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("no channels", func(t *testing.T) {
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", nil, nil)
|
||||
channels, err := ss.RetentionPolicy().GetChannels(policy.ID, 0, 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, channels, 0)
|
||||
})
|
||||
t.Run("some channels", func(t *testing.T) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 2", teamIDs, channelIDs)
|
||||
channels, err := ss.RetentionPolicy().GetChannels(policy.ID, 0, len(channelIDs))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, channels, len(channelIDs))
|
||||
sort.Strings(channelIDs)
|
||||
sort.Slice(channels, func(i, j int) bool {
|
||||
return channels[i].Id < channels[j].Id
|
||||
})
|
||||
for i := range channelIDs {
|
||||
require.Equal(t, channelIDs[i], channels[i].Id)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreAddChannels(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", teamIDs, channelIDs)
|
||||
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("add empty array", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().AddChannels(policy.ID, []string{})
|
||||
require.NoError(t, err)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
t.Run("add new channels", func(t *testing.T) {
|
||||
channelIDs := createChannelsForRetentionPolicy(t, ss, teamIDs[0], 2)
|
||||
defer deleteTeamsAndChannels(ss, nil, channelIDs)
|
||||
err := ss.RetentionPolicy().AddChannels(policy.ID, channelIDs)
|
||||
require.NoError(t, err)
|
||||
// verify that the channels were actually added
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
copy.ChannelIDs = append(copy.ChannelIDs, channelIDs...)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, copy)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
})
|
||||
t.Run("add channel which does not exist", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().AddChannels(policy.ID, []string{"no_such_channel"})
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("add channel to policy which does not exist", func(t *testing.T) {
|
||||
channelIDs := createChannelsForRetentionPolicy(t, ss, teamIDs[0], 1)
|
||||
defer deleteTeamsAndChannels(ss, nil, channelIDs)
|
||||
err := ss.RetentionPolicy().AddChannels("no_such_policy", channelIDs)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreRemoveChannels(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", teamIDs, channelIDs)
|
||||
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("remove empty array", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().RemoveChannels(policy.ID, []string{})
|
||||
require.NoError(t, err)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
t.Run("remove existing channel", func(t *testing.T) {
|
||||
channelID := channelIDs[0]
|
||||
err := ss.RetentionPolicy().RemoveChannels(policy.ID, []string{channelID})
|
||||
require.NoError(t, err)
|
||||
// verify that the channel was actually removed
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
copy.ChannelIDs = make([]string, 0)
|
||||
for _, oldChannelID := range policy.ChannelIDs {
|
||||
if oldChannelID != channelID {
|
||||
copy.ChannelIDs = append(copy.ChannelIDs, oldChannelID)
|
||||
}
|
||||
}
|
||||
checkRetentionPolicyLikeThisExists(t, ss, copy)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
})
|
||||
t.Run("remove channel which does not exist", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().RemoveChannels(policy.ID, []string{"no_such_channel"})
|
||||
require.NoError(t, err)
|
||||
// verify that the policy did not change
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreGetTeams(t *testing.T, ss store.Store, s SqlStore) {
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("no teams", func(t *testing.T) {
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", nil, nil)
|
||||
teams, err := ss.RetentionPolicy().GetTeams(policy.ID, 0, 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, teams, 0)
|
||||
})
|
||||
t.Run("some teams", func(t *testing.T) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 2", teamIDs, channelIDs)
|
||||
teams, err := ss.RetentionPolicy().GetTeams(policy.ID, 0, len(teamIDs))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, teams, len(teamIDs))
|
||||
sort.Strings(teamIDs)
|
||||
sort.Slice(teams, func(i, j int) bool {
|
||||
return teams[i].Id < teams[j].Id
|
||||
})
|
||||
for i := range teamIDs {
|
||||
require.Equal(t, teamIDs[i], teams[i].Id)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreAddTeams(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", teamIDs, channelIDs)
|
||||
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("add empty array", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().AddTeams(policy.ID, []string{})
|
||||
require.NoError(t, err)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
t.Run("add new teams", func(t *testing.T) {
|
||||
teamIDs := createTeamsForRetentionPolicy(t, ss, 2)
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, nil)
|
||||
err := ss.RetentionPolicy().AddTeams(policy.ID, teamIDs)
|
||||
require.NoError(t, err)
|
||||
// verify that the teams were actually added
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
copy.TeamIDs = append(copy.TeamIDs, teamIDs...)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, copy)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
})
|
||||
t.Run("add team which does not exist", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().AddTeams(policy.ID, []string{"no_such_team"})
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("add team to policy which does not exist", func(t *testing.T) {
|
||||
teamIDs := createTeamsForRetentionPolicy(t, ss, 1)
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, nil)
|
||||
err := ss.RetentionPolicy().AddTeams("no_such_policy", teamIDs)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreRemoveTeams(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
policy := saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", teamIDs, channelIDs)
|
||||
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
t.Run("remove empty array", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().RemoveTeams(policy.ID, []string{})
|
||||
require.NoError(t, err)
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
t.Run("remove existing team", func(t *testing.T) {
|
||||
teamID := teamIDs[0]
|
||||
err := ss.RetentionPolicy().RemoveTeams(policy.ID, []string{teamID})
|
||||
require.NoError(t, err)
|
||||
// verify that the team was actually removed
|
||||
copy := copyRetentionPolicyWithTeamAndChannelIds(policy)
|
||||
copy.TeamIDs = make([]string, 0)
|
||||
for _, oldTeamID := range policy.TeamIDs {
|
||||
if oldTeamID != teamID {
|
||||
copy.TeamIDs = append(copy.TeamIDs, oldTeamID)
|
||||
}
|
||||
}
|
||||
checkRetentionPolicyLikeThisExists(t, ss, copy)
|
||||
restoreRetentionPolicy(t, ss, policy)
|
||||
})
|
||||
t.Run("remove team which does not exist", func(t *testing.T) {
|
||||
err := ss.RetentionPolicy().RemoveTeams(policy.ID, []string{"no_such_team"})
|
||||
require.NoError(t, err)
|
||||
// verify that the policy did not change
|
||||
checkRetentionPolicyLikeThisExists(t, ss, policy)
|
||||
})
|
||||
}
|
||||
|
||||
func testRetentionPolicyStoreGetPoliciesForUser(t *testing.T, ss store.Store, s SqlStore) {
|
||||
teamIDs, channelIDs := createTeamsAndChannelsForRetentionPolicy(t, ss)
|
||||
saveRetentionPolicyWithTeamAndChannelIds(t, ss, "Policy 1", teamIDs, channelIDs)
|
||||
|
||||
defer deleteTeamsAndChannels(ss, teamIDs, channelIDs)
|
||||
defer cleanupRetentionPolicyTest(s)
|
||||
|
||||
user, userSaveErr := ss.User().Save(&model.User{
|
||||
Email: MakeEmail(),
|
||||
Username: model.NewId(),
|
||||
})
|
||||
require.NoError(t, userSaveErr)
|
||||
|
||||
t.Run("user has no relevant policies", func(t *testing.T) {
|
||||
// Teams
|
||||
teamPolicies, err := ss.RetentionPolicy().GetTeamPoliciesForUser(user.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, teamPolicies)
|
||||
count, err := ss.RetentionPolicy().GetTeamPoliciesCountForUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), count)
|
||||
// Channels
|
||||
channelPolicies, err := ss.RetentionPolicy().GetChannelPoliciesForUser(user.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, channelPolicies)
|
||||
count, err = ss.RetentionPolicy().GetChannelPoliciesCountForUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), count)
|
||||
})
|
||||
|
||||
t.Run("user has relevant policies", func(t *testing.T) {
|
||||
for _, teamID := range teamIDs {
|
||||
_, err := ss.Team().SaveMember(&model.TeamMember{TeamId: teamID, UserId: user.Id}, -1)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
for _, channelID := range channelIDs {
|
||||
_, err := ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channelID, UserId: user.Id, NotifyProps: model.GetDefaultChannelNotifyProps()})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
// Teams
|
||||
teamPolicies, err := ss.RetentionPolicy().GetTeamPoliciesForUser(user.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, teamPolicies, len(teamIDs))
|
||||
count, err := ss.RetentionPolicy().GetTeamPoliciesCountForUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(len(teamIDs)), count)
|
||||
// Channels
|
||||
channelPolicies, err := ss.RetentionPolicy().GetChannelPoliciesForUser(user.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, channelPolicies, len(channelIDs))
|
||||
count, err = ss.RetentionPolicy().GetChannelPoliciesCountForUser(user.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(len(channelIDs)), count)
|
||||
})
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func testHasSharedChannel(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
func testGetSharedChannels(t *testing.T, ss store.Store) {
|
||||
clearSharedChannels(ss)
|
||||
require.NoError(t, clearSharedChannels(ss))
|
||||
|
||||
creator := model.NewId()
|
||||
team1 := model.NewId()
|
||||
|
||||
@@ -20,6 +20,7 @@ type Store struct {
|
||||
ChannelStore mocks.ChannelStore
|
||||
PostStore mocks.PostStore
|
||||
UserStore mocks.UserStore
|
||||
RetentionPolicyStore mocks.RetentionPolicyStore
|
||||
BotStore mocks.BotStore
|
||||
AuditStore mocks.AuditStore
|
||||
ClusterDiscoveryStore mocks.ClusterDiscoveryStore
|
||||
@@ -61,6 +62,7 @@ func (s *Store) Team() store.TeamStore { return &s.T
|
||||
func (s *Store) Channel() store.ChannelStore { return &s.ChannelStore }
|
||||
func (s *Store) Post() store.PostStore { return &s.PostStore }
|
||||
func (s *Store) User() store.UserStore { return &s.UserStore }
|
||||
func (s *Store) RetentionPolicy() store.RetentionPolicyStore { return &s.RetentionPolicyStore }
|
||||
func (s *Store) Bot() store.BotStore { return &s.BotStore }
|
||||
func (s *Store) ProductNotices() store.ProductNoticesStore { return &s.ProductNoticesStore }
|
||||
func (s *Store) Audit() store.AuditStore { return &s.AuditStore }
|
||||
|
||||
@@ -39,6 +39,7 @@ func TestTeamStore(t *testing.T, ss store.Store) {
|
||||
t.Run("GetByInviteId", func(t *testing.T) { testTeamStoreGetByInviteId(t, ss) })
|
||||
t.Run("ByUserId", func(t *testing.T) { testTeamStoreByUserId(t, ss) })
|
||||
t.Run("GetAllTeamListing", func(t *testing.T) { testGetAllTeamListing(t, ss) })
|
||||
t.Run("GetAllTeamPage", func(t *testing.T) { testTeamStoreGetAllPage(t, ss) })
|
||||
t.Run("GetAllTeamPageListing", func(t *testing.T) { testGetAllTeamPageListing(t, ss) })
|
||||
t.Run("GetAllPrivateTeamListing", func(t *testing.T) { testGetAllPrivateTeamListing(t, ss) })
|
||||
t.Run("GetAllPrivateTeamPageListing", func(t *testing.T) { testGetAllPrivateTeamPageListing(t, ss) })
|
||||
@@ -213,6 +214,8 @@ func testTeamStoreGetByName(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
func testTeamStoreSearchAll(t *testing.T, ss store.Store) {
|
||||
cleanupTeamStore(t, ss)
|
||||
|
||||
o := model.Team{}
|
||||
o.DisplayName = "ADisplayName" + NewTestId()
|
||||
o.Name = "searchterm-" + NewTestId()
|
||||
@@ -244,14 +247,23 @@ func testTeamStoreSearchAll(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&g)
|
||||
require.NoError(t, err)
|
||||
|
||||
q := model.Team{}
|
||||
q := &model.Team{}
|
||||
q.DisplayName = "CHOCOLATE"
|
||||
q.Name = "ilovecake"
|
||||
q.Email = MakeEmail()
|
||||
q.Type = model.TEAM_OPEN
|
||||
q.AllowOpenInvite = false
|
||||
|
||||
_, err = ss.Team().Save(&q)
|
||||
q, err = ss.Team().Save(q)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDuration: model.NewInt64(20),
|
||||
},
|
||||
TeamIDs: []string{q.Id},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
@@ -368,11 +380,17 @@ func testTeamStoreSearchAll(t *testing.T, ss store.Store) {
|
||||
2,
|
||||
[]string{p.Id, o.Id},
|
||||
},
|
||||
{
|
||||
"Search for teams which are not part of a data retention policy",
|
||||
&model.TeamSearch{Term: "", ExcludePolicyConstrained: model.NewBool(true)},
|
||||
3,
|
||||
[]string{o.Id, p.Id, g.Id},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
response, err := ss.Team().SearchAll(tc.Opts.Term, tc.Opts)
|
||||
response, err := ss.Team().SearchAll(tc.Opts)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.ExpectedLenth, len(response))
|
||||
responseTeamIds := []string{}
|
||||
@@ -479,7 +497,7 @@ func testTeamStoreSearchOpen(t *testing.T, ss store.Store) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
r1, err := ss.Team().SearchOpen(tc.Term)
|
||||
r1, err := ss.Team().SearchOpen(&model.TeamSearch{Term: tc.Term})
|
||||
require.NoError(t, err)
|
||||
results := r1
|
||||
require.Equal(t, tc.ExpectedLength, len(results))
|
||||
@@ -585,7 +603,7 @@ func testTeamStoreSearchPrivate(t *testing.T, ss store.Store) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
r1, err := ss.Team().SearchPrivate(tc.Term)
|
||||
r1, err := ss.Team().SearchPrivate(&model.TeamSearch{Term: tc.Term})
|
||||
require.NoError(t, err)
|
||||
results := r1
|
||||
require.Equal(t, tc.ExpectedLength, len(results))
|
||||
@@ -641,6 +659,64 @@ func testTeamStoreByUserId(t *testing.T, ss store.Store) {
|
||||
require.Equal(t, teams[0].Id, o1.Id, "should be a member")
|
||||
}
|
||||
|
||||
func testTeamStoreGetAllPage(t *testing.T, ss store.Store) {
|
||||
o := model.Team{}
|
||||
o.DisplayName = "ADisplayName" + model.NewId()
|
||||
o.Name = "zz" + model.NewId() + "a"
|
||||
o.Email = MakeEmail()
|
||||
o.Type = model.TEAM_OPEN
|
||||
o.AllowOpenInvite = true
|
||||
_, err := ss.Team().Save(&o)
|
||||
require.NoError(t, err)
|
||||
|
||||
policy, err := ss.RetentionPolicy().Save(&model.RetentionPolicyWithTeamAndChannelIDs{
|
||||
RetentionPolicy: model.RetentionPolicy{
|
||||
DisplayName: "Policy 1",
|
||||
PostDuration: model.NewInt64(30),
|
||||
},
|
||||
TeamIDs: []string{o.Id},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Without ExcludePolicyConstrained
|
||||
teams, err := ss.Team().GetAllPage(0, 100, nil)
|
||||
require.NoError(t, err)
|
||||
found := false
|
||||
for _, team := range teams {
|
||||
if team.Id == o.Id {
|
||||
found = true
|
||||
require.Nil(t, team.PolicyID)
|
||||
break
|
||||
}
|
||||
}
|
||||
require.True(t, found)
|
||||
|
||||
// With ExcludePolicyConstrained
|
||||
teams, err = ss.Team().GetAllPage(0, 100, &model.TeamSearch{ExcludePolicyConstrained: model.NewBool(true)})
|
||||
require.NoError(t, err)
|
||||
found = false
|
||||
for _, team := range teams {
|
||||
if team.Id == o.Id {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
require.False(t, found)
|
||||
|
||||
// With policy ID
|
||||
teams, err = ss.Team().GetAllPage(0, 100, &model.TeamSearch{IncludePolicyID: model.NewBool(true)})
|
||||
require.NoError(t, err)
|
||||
found = false
|
||||
for _, team := range teams {
|
||||
if team.Id == o.Id {
|
||||
found = true
|
||||
require.Equal(t, *team.PolicyID, policy.ID)
|
||||
break
|
||||
}
|
||||
}
|
||||
require.True(t, found)
|
||||
}
|
||||
|
||||
func testGetAllTeamListing(t *testing.T, ss store.Store) {
|
||||
o1 := model.Team{}
|
||||
o1.DisplayName = "DisplayName"
|
||||
@@ -722,7 +798,9 @@ func testGetAllTeamPageListing(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&o4)
|
||||
require.NoError(t, err)
|
||||
|
||||
teams, err := ss.Team().GetAllTeamPageListing(0, 10)
|
||||
opts := &model.TeamSearch{AllowOpenInvite: model.NewBool(true)}
|
||||
|
||||
teams, err := ss.Team().GetAllPage(0, 10, opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, team := range teams {
|
||||
@@ -740,7 +818,7 @@ func testGetAllTeamPageListing(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&o5)
|
||||
require.NoError(t, err)
|
||||
|
||||
teams, err = ss.Team().GetAllTeamPageListing(0, 4)
|
||||
teams, err = ss.Team().GetAllPage(0, 4, opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, team := range teams {
|
||||
@@ -749,7 +827,7 @@ func testGetAllTeamPageListing(t *testing.T, ss store.Store) {
|
||||
|
||||
require.LessOrEqual(t, len(teams), 4, "should have returned max of 4 teams")
|
||||
|
||||
teams, err = ss.Team().GetAllTeamPageListing(1, 1)
|
||||
teams, err = ss.Team().GetAllPage(1, 1, opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, team := range teams {
|
||||
@@ -840,7 +918,9 @@ func testGetAllPrivateTeamPageListing(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&o4)
|
||||
require.NoError(t, err)
|
||||
|
||||
teams, listErr := ss.Team().GetAllPrivateTeamPageListing(0, 10)
|
||||
opts := &model.TeamSearch{AllowOpenInvite: model.NewBool(false)}
|
||||
|
||||
teams, listErr := ss.Team().GetAllPage(0, 10, opts)
|
||||
require.NoError(t, listErr)
|
||||
for _, team := range teams {
|
||||
require.False(t, team.AllowOpenInvite, "should have returned team with AllowOpenInvite as false")
|
||||
@@ -857,7 +937,7 @@ func testGetAllPrivateTeamPageListing(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&o5)
|
||||
require.NoError(t, err)
|
||||
|
||||
teams, listErr = ss.Team().GetAllPrivateTeamPageListing(0, 4)
|
||||
teams, listErr = ss.Team().GetAllPage(0, 4, opts)
|
||||
require.NoError(t, listErr)
|
||||
for _, team := range teams {
|
||||
require.False(t, team.AllowOpenInvite, "should have returned team with AllowOpenInvite as false")
|
||||
@@ -865,7 +945,7 @@ func testGetAllPrivateTeamPageListing(t *testing.T, ss store.Store) {
|
||||
|
||||
require.LessOrEqual(t, len(teams), 4, "should have returned max of 4 teams")
|
||||
|
||||
teams, listErr = ss.Team().GetAllPrivateTeamPageListing(1, 1)
|
||||
teams, listErr = ss.Team().GetAllPage(1, 1, opts)
|
||||
require.NoError(t, listErr)
|
||||
for _, team := range teams {
|
||||
require.False(t, team.AllowOpenInvite, "should have returned team with AllowOpenInvite as false")
|
||||
@@ -913,7 +993,9 @@ func testGetAllPublicTeamPageListing(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&o4)
|
||||
require.NoError(t, err)
|
||||
|
||||
teams, err := ss.Team().GetAllPublicTeamPageListing(0, 10)
|
||||
opts := &model.TeamSearch{AllowOpenInvite: model.NewBool(true)}
|
||||
|
||||
teams, err := ss.Team().GetAllPage(0, 10, opts)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []*model.Team{t1, t3}, teams)
|
||||
|
||||
@@ -926,11 +1008,11 @@ func testGetAllPublicTeamPageListing(t *testing.T, ss store.Store) {
|
||||
t5, err := ss.Team().Save(&o5)
|
||||
require.NoError(t, err)
|
||||
|
||||
teams, err = ss.Team().GetAllPublicTeamPageListing(0, 4)
|
||||
teams, err = ss.Team().GetAllPage(0, 4, opts)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []*model.Team{t1, t3, t5}, teams)
|
||||
|
||||
_, err = ss.Team().GetAllPublicTeamPageListing(1, 1)
|
||||
_, err = ss.Team().GetAllPage(1, 1, opts)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -986,7 +1068,7 @@ func testPublicTeamCount(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&o3)
|
||||
require.NoError(t, err)
|
||||
|
||||
teamCount, err := ss.Team().AnalyticsPublicTeamCount()
|
||||
teamCount, err := ss.Team().AnalyticsTeamCount(&model.TeamSearch{AllowOpenInvite: model.NewBool(true)})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(2), teamCount, "should only be 1 team")
|
||||
}
|
||||
@@ -1021,7 +1103,7 @@ func testPrivateTeamCount(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&o3)
|
||||
require.NoError(t, err)
|
||||
|
||||
teamCount, err := ss.Team().AnalyticsPrivateTeamCount()
|
||||
teamCount, err := ss.Team().AnalyticsTeamCount(&model.TeamSearch{AllowOpenInvite: model.NewBool(false)})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(2), teamCount, "should only be 1 team")
|
||||
}
|
||||
@@ -1037,7 +1119,7 @@ func testTeamCount(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// not including deleted teams
|
||||
teamCount, err := ss.Team().AnalyticsTeamCount(false)
|
||||
teamCount, err := ss.Team().AnalyticsTeamCount(nil)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 0, int(teamCount), "should be at least 1 team")
|
||||
|
||||
@@ -1047,11 +1129,11 @@ func testTeamCount(t *testing.T, ss store.Store) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// get the count of teams not including deleted
|
||||
countNotIncludingDeleted, err := ss.Team().AnalyticsTeamCount(false)
|
||||
countNotIncludingDeleted, err := ss.Team().AnalyticsTeamCount(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
// get the count of teams including deleted
|
||||
countIncludingDeleted, err := ss.Team().AnalyticsTeamCount(true)
|
||||
countIncludingDeleted, err := ss.Team().AnalyticsTeamCount(&model.TeamSearch{IncludeDeleted: model.NewBool(true)})
|
||||
require.NoError(t, err)
|
||||
|
||||
// count including deleted should be one greater than not including deleted
|
||||
|
||||
@@ -39,6 +39,7 @@ type TimerLayer struct {
|
||||
ProductNoticesStore store.ProductNoticesStore
|
||||
ReactionStore store.ReactionStore
|
||||
RemoteClusterStore store.RemoteClusterStore
|
||||
RetentionPolicyStore store.RetentionPolicyStore
|
||||
RoleStore store.RoleStore
|
||||
SchemeStore store.SchemeStore
|
||||
SessionStore store.SessionStore
|
||||
@@ -140,6 +141,10 @@ func (s *TimerLayer) RemoteCluster() store.RemoteClusterStore {
|
||||
return s.RemoteClusterStore
|
||||
}
|
||||
|
||||
func (s *TimerLayer) RetentionPolicy() store.RetentionPolicyStore {
|
||||
return s.RetentionPolicyStore
|
||||
}
|
||||
|
||||
func (s *TimerLayer) Role() store.RoleStore {
|
||||
return s.RoleStore
|
||||
}
|
||||
@@ -305,6 +310,11 @@ type TimerLayerRemoteClusterStore struct {
|
||||
Root *TimerLayer
|
||||
}
|
||||
|
||||
type TimerLayerRetentionPolicyStore struct {
|
||||
store.RetentionPolicyStore
|
||||
Root *TimerLayer
|
||||
}
|
||||
|
||||
type TimerLayerRoleStore struct {
|
||||
store.RoleStore
|
||||
Root *TimerLayer
|
||||
@@ -5535,6 +5545,294 @@ func (s *TimerLayerRemoteClusterStore) UpdateTopics(remoteClusterId string, topi
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) AddChannels(policyId string, channelIds []string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
err := s.RetentionPolicyStore.AddChannels(policyId, channelIds)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.AddChannels", success, elapsed)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) AddTeams(policyId string, teamIds []string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
err := s.RetentionPolicyStore.AddTeams(policyId, teamIds)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.AddTeams", success, elapsed)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) Delete(id string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
err := s.RetentionPolicyStore.Delete(id)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.Delete", success, elapsed)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) Get(id string) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.Get(id)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.Get", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetAll(offset int, limit int) ([]*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetAll(offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetAll", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetChannelPoliciesCountForUser(userID string) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetChannelPoliciesCountForUser(userID)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetChannelPoliciesCountForUser", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetChannelPoliciesForUser(userID string, offset int, limit int) ([]*model.RetentionPolicyForChannel, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetChannelPoliciesForUser(userID, offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetChannelPoliciesForUser", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetChannels(policyId string, offset int, limit int) (model.ChannelListWithTeamData, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetChannels(policyId, offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetChannels", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetChannelsCount(policyId string) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetChannelsCount(policyId)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetChannelsCount", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetCount() (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetCount()
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetCount", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetTeamPoliciesCountForUser(userID string) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetTeamPoliciesCountForUser(userID)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetTeamPoliciesCountForUser", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetTeamPoliciesForUser(userID string, offset int, limit int) ([]*model.RetentionPolicyForTeam, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetTeamPoliciesForUser(userID, offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetTeamPoliciesForUser", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetTeams(policyId string, offset int, limit int) ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetTeams(policyId, offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetTeams", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) GetTeamsCount(policyId string) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.GetTeamsCount(policyId)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.GetTeamsCount", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) Patch(patch *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.Patch(patch)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.Patch", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) RemoveChannels(policyId string, channelIds []string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
err := s.RetentionPolicyStore.RemoveChannels(policyId, channelIds)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.RemoveChannels", success, elapsed)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) RemoveTeams(policyId string, teamIds []string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
err := s.RetentionPolicyStore.RemoveTeams(policyId, teamIds)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.RemoveTeams", success, elapsed)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRetentionPolicyStore) Save(policy *model.RetentionPolicyWithTeamAndChannelIDs) (*model.RetentionPolicyWithTeamAndChannelCounts, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.RetentionPolicyStore.Save(policy)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("RetentionPolicyStore.Save", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerRoleStore) AllChannelSchemeRoles() ([]*model.Role, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
@@ -6702,42 +7000,10 @@ func (s *TimerLayerTeamStore) AnalyticsGetTeamCountForScheme(schemeID string) (i
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) AnalyticsPrivateTeamCount() (int64, error) {
|
||||
func (s *TimerLayerTeamStore) AnalyticsTeamCount(opts *model.TeamSearch) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.AnalyticsPrivateTeamCount()
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.AnalyticsPrivateTeamCount", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) AnalyticsPublicTeamCount() (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.AnalyticsPublicTeamCount()
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.AnalyticsPublicTeamCount", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) AnalyticsTeamCount(includeDeleted bool) (int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.AnalyticsTeamCount(includeDeleted)
|
||||
result, err := s.TeamStore.AnalyticsTeamCount(opts)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -6845,10 +7111,10 @@ func (s *TimerLayerTeamStore) GetAllForExportAfter(limit int, afterID string) ([
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) GetAllPage(offset int, limit int) ([]*model.Team, error) {
|
||||
func (s *TimerLayerTeamStore) GetAllPage(offset int, limit int, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.GetAllPage(offset, limit)
|
||||
result, err := s.TeamStore.GetAllPage(offset, limit, opts)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -6877,38 +7143,6 @@ func (s *TimerLayerTeamStore) GetAllPrivateTeamListing() ([]*model.Team, error)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.GetAllPrivateTeamPageListing(offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.GetAllPrivateTeamPageListing", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) GetAllPublicTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.GetAllPublicTeamPageListing(offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.GetAllPublicTeamPageListing", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
@@ -6925,22 +7159,6 @@ func (s *TimerLayerTeamStore) GetAllTeamListing() ([]*model.Team, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) GetAllTeamPageListing(offset int, limit int) ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.GetAllTeamPageListing(offset, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.GetAllTeamPageListing", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) GetByInviteId(inviteID string) (*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
@@ -7372,10 +7590,10 @@ func (s *TimerLayerTeamStore) SaveMultipleMembers(members []*model.TeamMember, m
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) SearchAll(term string, opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
func (s *TimerLayerTeamStore) SearchAll(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.SearchAll(term, opts)
|
||||
result, err := s.TeamStore.SearchAll(opts)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -7388,10 +7606,10 @@ func (s *TimerLayerTeamStore) SearchAll(term string, opts *model.TeamSearch) ([]
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
func (s *TimerLayerTeamStore) SearchAllPaged(opts *model.TeamSearch) ([]*model.Team, int64, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, resultVar1, err := s.TeamStore.SearchAllPaged(term, opts)
|
||||
result, resultVar1, err := s.TeamStore.SearchAllPaged(opts)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -7404,10 +7622,10 @@ func (s *TimerLayerTeamStore) SearchAllPaged(term string, opts *model.TeamSearch
|
||||
return result, resultVar1, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
func (s *TimerLayerTeamStore) SearchOpen(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.SearchOpen(term)
|
||||
result, err := s.TeamStore.SearchOpen(opts)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -7420,10 +7638,10 @@ func (s *TimerLayerTeamStore) SearchOpen(term string) ([]*model.Team, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerTeamStore) SearchPrivate(term string) ([]*model.Team, error) {
|
||||
func (s *TimerLayerTeamStore) SearchPrivate(opts *model.TeamSearch) ([]*model.Team, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.TeamStore.SearchPrivate(term)
|
||||
result, err := s.TeamStore.SearchPrivate(opts)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -9848,6 +10066,7 @@ func New(childStore store.Store, metrics einterfaces.MetricsInterface) *TimerLay
|
||||
newStore.ProductNoticesStore = &TimerLayerProductNoticesStore{ProductNoticesStore: childStore.ProductNotices(), Root: &newStore}
|
||||
newStore.ReactionStore = &TimerLayerReactionStore{ReactionStore: childStore.Reaction(), Root: &newStore}
|
||||
newStore.RemoteClusterStore = &TimerLayerRemoteClusterStore{RemoteClusterStore: childStore.RemoteCluster(), Root: &newStore}
|
||||
newStore.RetentionPolicyStore = &TimerLayerRetentionPolicyStore{RetentionPolicyStore: childStore.RetentionPolicy(), Root: &newStore}
|
||||
newStore.RoleStore = &TimerLayerRoleStore{RoleStore: childStore.Role(), Root: &newStore}
|
||||
newStore.SchemeStore = &TimerLayerSchemeStore{SchemeStore: childStore.Scheme(), Root: &newStore}
|
||||
newStore.SessionStore = &TimerLayerSessionStore{SessionStore: childStore.Session(), Root: &newStore}
|
||||
|
||||
Ссылка в новой задаче
Block a user