Gh 9610 add plugin api for update user active method (#9854)

* wip

* wip

* After running make plugin-mocks

* Add
TestUpdateUserActive and run make pluginapi

* Adding plugin_api_test.go

* Better formatting of code using gofmt

* Fix tests and run make pluginapi

* Specify the minimum server version on the comments

* Include more tests as per the CR

* Fix tests

* Checking err.Id intsead of err & Removed comments and trailing spaces

* wip

* Fix tests as per CR and spaces

* Make changes to tests as per CR
Этот коммит содержится в:
akhilanandbv003
2018-12-12 09:18:41 -06:00
коммит произвёл Jesse Hallam
родитель febc5115fd
Коммит 11059b0251
7 изменённых файлов: 112 добавлений и 0 удалений

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

@@ -195,6 +195,10 @@ func (api *PluginAPI) UpdateUser(user *model.User) (*model.User, *model.AppError
return api.app.UpdateUser(user, true)
}
func (api *PluginAPI) UpdateUserActive(userId string, active bool) *model.AppError {
return api.app.UpdateUserActive(userId, active)
}
func (api *PluginAPI) GetUserStatus(userId string) (*model.Status, *model.AppError) {
return api.app.GetStatus(userId)
}

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

@@ -620,6 +620,33 @@ func TestPluginAPIRemoveTeamIcon(t *testing.T) {
require.Nil(t, err)
}
func TestPluginAPIUpdateUserActive(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
err := api.UpdateUserActive(th.BasicUser.Id, true)
require.Nil(t, err)
user, err := api.GetUser(th.BasicUser.Id)
require.Nil(t, err)
require.Equal(t, int64(0), user.DeleteAt)
err = api.UpdateUserActive(th.BasicUser.Id, false)
require.Nil(t, err)
user, err = api.GetUser(th.BasicUser.Id)
require.Nil(t, err)
require.NotNil(t, user)
require.NotEqual(t, int64(0), user.DeleteAt)
err = api.UpdateUserActive(th.BasicUser.Id, true)
require.Nil(t, err)
err = api.UpdateUserActive(th.BasicUser.Id, true)
require.Nil(t, err)
user, err = api.GetUser(th.BasicUser.Id)
require.Nil(t, err)
require.Equal(t, int64(0), user.DeleteAt)
}
func TestPluginAPIGetDirectChannel(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()

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

@@ -1056,6 +1056,19 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
return rusers[0], nil
}
func (a *App) UpdateUserActive(userId string, active bool) *model.AppError {
user, err := a.GetUser(userId)
if err != nil {
return err
}
if _, err = a.UpdateActive(user, active); err != nil {
return err
}
return nil
}
func (a *App) UpdateUserNotifyProps(userId string, props map[string]string) (*model.User, *model.AppError) {
user, err := a.GetUser(userId)
if err != nil {

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

@@ -154,6 +154,24 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) {
assert.False(t, err == nil)
}
func TestUpdateUserActive(t *testing.T) {
th := Setup()
defer th.TearDown()
user := th.CreateUser()
EnableUserDeactivation := th.App.Config().TeamSettings.EnableUserDeactivation
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserDeactivation = EnableUserDeactivation })
}()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.EnableUserDeactivation = true
})
err := th.App.UpdateUserActive(user.Id, false)
assert.Nil(t, err)
}
func TestUpdateOAuthUserAttrs(t *testing.T) {
th := Setup()
defer th.TearDown()