Revert "[MM-8497] Ability to set Do Not Disturb for a specified period of time (#16067)" (#17657)

This reverts commit 77d42568f9.
Этот коммит содержится в:
Jesse Hallam
2021-05-21 09:38:27 -03:00
коммит произвёл GitHub
родитель e1b13c10fc
Коммит ff383990f8
26 изменённых файлов: 21 добавлений и 584 удалений

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

@@ -578,7 +578,3 @@ func (a *App) dbHealthCheckKey() string {
func (a *App) SetServer(srv *Server) {
a.srv = srv
}
func (a *App) UpdateExpiredDNDStatuses() ([]*model.Status, error) {
return a.Srv().Store.Status().UpdateExpiredDNDStatuses()
}

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

@@ -311,9 +311,6 @@ type AppIface interface {
// relative to either the session creation date or the current time, depending
// on the `ExtendSessionOnActivity` config setting.
SetSessionExpireInDays(session *model.Session, days int)
// SetStatusDoNotDisturbTimed takes endtime in unix epoch format in UTC
// and sets status of given userId to dnd which will be restored back after endtime
SetStatusDoNotDisturbTimed(userId string, endtime int64)
// SetStatusLastActivityAt sets the last activity at for a user on the local app server and updates
// status to away if needed. Used by the WS to set status to away if an 'online' device disconnects
// while an 'away' device is still connected
@@ -360,9 +357,6 @@ type AppIface interface {
UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
// UpdateChannelScheme saves the new SchemeId of the channel passed.
UpdateChannelScheme(channel *model.Channel) (*model.Channel, *model.AppError)
// UpdateDNDStatusOfUsers is a recurring task which is started when server starts
// which unsets dnd status of users if needed and saves and broadcasts it
UpdateDNDStatusOfUsers()
// UpdateProductNotices is called periodically from a scheduled worker to fetch new notices and update the cache
UpdateProductNotices() *model.AppError
// UpdateViewedProductNotices is called from the frontend to mark a set of notices as 'viewed' by user
@@ -1047,7 +1041,6 @@ type AppIface interface {
UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError)
UpdateConfig(f func(*model.Config))
UpdateEphemeralPost(userID string, post *model.Post) *model.Post
UpdateExpiredDNDStatuses() ([]*model.Status, error)
UpdateGroup(group *model.Group) (*model.Group, *model.AppError)
UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
UpdateHashedPassword(user *model.User, newHashedPassword string) *model.AppError

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

@@ -14,7 +14,6 @@ import (
"testing"
"time"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/app/request"
@@ -162,14 +161,8 @@ func SetupWithoutPreloadMigrations(tb testing.TB) *TestHelper {
func SetupWithStoreMock(tb testing.TB) *TestHelper {
mockStore := testlib.GetMockStoreForSetupFunctions()
th := setupTestHelper(mockStore, false, false, tb)
statusMock := mocks.StatusStore{}
statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil)
statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.STATUS_ONLINE}, nil)
statusMock.On("UpdateLastActivityAt", "user1", mock.Anything).Return(nil)
statusMock.On("SaveOrUpdate", mock.AnythingOfType("*model.Status")).Return(nil)
emptyMockStore := mocks.Store{}
emptyMockStore.On("Close").Return(nil)
emptyMockStore.On("Status").Return(&statusMock)
th.App.Srv().Store = &emptyMockStore
return th
}
@@ -177,14 +170,8 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
mockStore := testlib.GetMockStoreForSetupFunctions()
th := setupTestHelper(mockStore, true, false, tb)
statusMock := mocks.StatusStore{}
statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil)
statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.STATUS_ONLINE}, nil)
statusMock.On("UpdateLastActivityAt", "user1", mock.Anything).Return(nil)
statusMock.On("SaveOrUpdate", mock.AnythingOfType("*model.Status")).Return(nil)
emptyMockStore := mocks.Store{}
emptyMockStore.On("Close").Return(nil)
emptyMockStore.On("Status").Return(&statusMock)
th.App.Srv().Store = &emptyMockStore
return th
}

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

@@ -14926,21 +14926,6 @@ func (a *OpenTracingAppLayer) SetStatusDoNotDisturb(userID string) {
a.app.SetStatusDoNotDisturb(userID)
}
func (a *OpenTracingAppLayer) SetStatusDoNotDisturbTimed(userId string, endtime int64) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetStatusDoNotDisturbTimed")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
a.app.SetStatusDoNotDisturbTimed(userId, endtime)
}
func (a *OpenTracingAppLayer) SetStatusLastActivityAt(userID string, activityAt int64) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetStatusLastActivityAt")
@@ -15866,21 +15851,6 @@ func (a *OpenTracingAppLayer) UpdateConfig(f func(*model.Config)) {
a.app.UpdateConfig(f)
}
func (a *OpenTracingAppLayer) UpdateDNDStatusOfUsers() {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateDNDStatusOfUsers")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
a.app.UpdateDNDStatusOfUsers()
}
func (a *OpenTracingAppLayer) UpdateEphemeralPost(userID string, post *model.Post) *model.Post {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateEphemeralPost")
@@ -15898,28 +15868,6 @@ func (a *OpenTracingAppLayer) UpdateEphemeralPost(userID string, post *model.Pos
return resultVar0
}
func (a *OpenTracingAppLayer) UpdateExpiredDNDStatuses() ([]*model.Status, error) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateExpiredDNDStatuses")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.UpdateExpiredDNDStatuses()
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateGroup")

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

@@ -317,14 +317,6 @@ func (api *PluginAPI) UpdateUserStatus(userID, status string) (*model.Status, *m
return api.app.GetStatus(userID)
}
func (api *PluginAPI) SetUserStatusTimedDND(userID string, endTime int64) (*model.Status, *model.AppError) {
// read-after-write bug which will fail if there are replicas.
// it works for now because we have a cache in between.
// FIXME: make SetStatusDoNotDisturbTimed return updated status
api.app.SetStatusDoNotDisturbTimed(userID, endTime)
return api.app.GetStatus(userID)
}
func (api *PluginAPI) GetUsersInChannel(channelID, sortBy string, page, perPage int) ([]*model.User, *model.AppError) {
switch sortBy {
case model.CHANNEL_SORT_BY_USERNAME:

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

@@ -205,9 +205,6 @@ type Server struct {
featureFlagStop chan struct{}
featureFlagStopped chan struct{}
featureFlagSynchronizerMutex sync.Mutex
dndnTaskMut sync.Mutex
dndTask *model.ScheduledTask
}
func NewServer(options ...Option) (*Server, error) {
@@ -668,7 +665,6 @@ func NewServer(options ...Option) (*Server, error) {
s.runLicenseExpirationCheckJob()
runCheckAdminSupportStatusJob(fakeApp, c)
runCheckWarnMetricStatusJob(fakeApp, c)
runDNDStatusExpireJob(fakeApp)
})
s.runJobs()
}
@@ -1047,12 +1043,6 @@ func (s *Server) Shutdown() {
mlog.Warn("Error flushing logs", mlog.Err(err))
}
s.dndnTaskMut.Lock()
if s.dndTask != nil {
s.dndTask.Cancel()
}
s.dndnTaskMut.Unlock()
mlog.Info("Server stopped")
// this should just write the "server stopped" record, the rest are already flushed.
@@ -2286,26 +2276,3 @@ func (s *Server) ReadFile(path string) ([]byte, *model.AppError) {
// }
// return result, nil
// }
func runDNDStatusExpireJob(a *App) {
if a.IsLeader() {
a.srv.dndnTaskMut.Lock()
a.srv.dndTask = model.CreateRecurringTaskFromNextIntervalTime("Unset DND Statuses", a.UpdateDNDStatusOfUsers, 5*time.Minute)
a.srv.dndnTaskMut.Unlock()
}
a.srv.AddClusterLeaderChangedListener(func() {
mlog.Info("Cluster leader changed. Determining if unset DNS status task should be running", mlog.Bool("isLeader", a.IsLeader()))
if a.IsLeader() {
a.srv.dndnTaskMut.Lock()
a.srv.dndTask = model.CreateRecurringTaskFromNextIntervalTime("Unset DND Statuses", a.UpdateDNDStatusOfUsers, 5*time.Minute)
a.srv.dndnTaskMut.Unlock()
} else {
a.srv.dndnTaskMut.Lock()
if a.srv.dndTask != nil {
a.srv.dndTask.Cancel()
a.srv.dndTask = nil
}
a.srv.dndnTaskMut.Unlock()
}
})
}

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

@@ -282,28 +282,6 @@ func (a *App) SetStatusAwayIfNeeded(userID string, manual bool) {
a.SaveAndBroadcastStatus(status)
}
// SetStatusDoNotDisturbTimed takes endtime in unix epoch format in UTC
// and sets status of given userId to dnd which will be restored back after endtime
func (a *App) SetStatusDoNotDisturbTimed(userId string, endtime int64) {
if !*a.Config().ServiceSettings.EnableUserStatuses {
return
}
status, err := a.GetStatus(userId)
if err != nil {
status = &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
}
status.PrevStatus = status.Status
status.Status = model.STATUS_DND
status.Manual = true
status.DNDEndTime = endtime
a.SaveAndBroadcastStatus(status)
}
func (a *App) SetStatusDoNotDisturb(userID string) {
if !*a.Config().ServiceSettings.EnableUserStatuses {
return
@@ -387,20 +365,6 @@ func (a *App) IsUserAway(lastActivityAt int64) bool {
return model.GetMillis()-lastActivityAt >= *a.Config().TeamSettings.UserStatusAwayTimeout*1000
}
// UpdateDNDStatusOfUsers is a recurring task which is started when server starts
// which unsets dnd status of users if needed and saves and broadcasts it
func (a *App) UpdateDNDStatusOfUsers() {
statuses, err := a.UpdateExpiredDNDStatuses()
if err != nil {
mlog.Warn("Failed to fetch dnd statues from store", mlog.String("err", err.Error()))
return
}
for i := range statuses {
a.AddStatusCache(statuses[i])
a.BroadcastStatus(statuses[i])
}
}
func (a *App) SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError {
user, err := a.GetUser(userID)
if err != nil {