From 06ec648cf30e3968c0fdb2514c8d59dff97c757c Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 31 Oct 2017 12:00:21 -0400 Subject: PLT-7978 Add websocket event for user role update (#7745) * Add websocket event for user role update * Fix tests * More test fixes --- api4/apitestlib.go | 6 +++--- api4/post_test.go | 8 ++++---- api4/user.go | 2 +- api4/user_test.go | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'api4') diff --git a/api4/apitestlib.go b/api4/apitestlib.go index b7d07e89e..d777f8c19 100644 --- a/api4/apitestlib.go +++ b/api4/apitestlib.go @@ -194,7 +194,7 @@ func (me *TestHelper) InitBasic() *TestHelper { me.waitForConnectivity() me.TeamAdminUser = me.CreateUser() - me.App.UpdateUserRoles(me.TeamAdminUser.Id, model.ROLE_SYSTEM_USER.Id) + me.App.UpdateUserRoles(me.TeamAdminUser.Id, model.ROLE_SYSTEM_USER.Id, false) me.LoginTeamAdmin() me.BasicTeam = me.CreateTeam() me.BasicChannel = me.CreatePublicChannel() @@ -211,7 +211,7 @@ func (me *TestHelper) InitBasic() *TestHelper { me.App.AddUserToChannel(me.BasicUser2, me.BasicChannel2) me.App.AddUserToChannel(me.BasicUser, me.BasicPrivateChannel) me.App.AddUserToChannel(me.BasicUser2, me.BasicPrivateChannel) - me.App.UpdateUserRoles(me.BasicUser.Id, model.ROLE_SYSTEM_USER.Id) + me.App.UpdateUserRoles(me.BasicUser.Id, model.ROLE_SYSTEM_USER.Id, false) me.LoginBasic() return me @@ -221,7 +221,7 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper { me.waitForConnectivity() me.SystemAdminUser = me.CreateUser() - me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_ADMIN.Id) + me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_ADMIN.Id, false) me.LoginSystemAdmin() return me diff --git a/api4/post_test.go b/api4/post_test.go index 6f195296a..15553137a 100644 --- a/api4/post_test.go +++ b/api4/post_test.go @@ -292,7 +292,7 @@ func TestCreatePostPublic(t *testing.T) { _, resp = Client.CreatePost(post) CheckForbiddenStatus(t, resp) - th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL_PUBLIC.Id) + th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL_PUBLIC.Id, false) th.App.InvalidateAllCaches() Client.Login(user.Email, user.Password) @@ -304,7 +304,7 @@ func TestCreatePostPublic(t *testing.T) { _, resp = Client.CreatePost(post) CheckForbiddenStatus(t, resp) - th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id) + th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id, false) th.App.JoinUserToTeam(th.BasicTeam, ruser, "") th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.ROLE_TEAM_USER.Id+" "+model.ROLE_TEAM_POST_ALL_PUBLIC.Id) th.App.InvalidateAllCaches() @@ -339,7 +339,7 @@ func TestCreatePostAll(t *testing.T) { _, resp = Client.CreatePost(post) CheckForbiddenStatus(t, resp) - th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL.Id) + th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL.Id, false) th.App.InvalidateAllCaches() Client.Login(user.Email, user.Password) @@ -355,7 +355,7 @@ func TestCreatePostAll(t *testing.T) { _, resp = Client.CreatePost(post) CheckNoError(t, resp) - th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id) + th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id, false) th.App.JoinUserToTeam(th.BasicTeam, ruser, "") th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.ROLE_TEAM_USER.Id+" "+model.ROLE_TEAM_POST_ALL.Id) th.App.InvalidateAllCaches() diff --git a/api4/user.go b/api4/user.go index 2f8e72ad9..7343ce326 100644 --- a/api4/user.go +++ b/api4/user.go @@ -651,7 +651,7 @@ func updateUserRoles(c *Context, w http.ResponseWriter, r *http.Request) { return } - if _, err := c.App.UpdateUserRoles(c.Params.UserId, newRoles); err != nil { + if _, err := c.App.UpdateUserRoles(c.Params.UserId, newRoles, true); err != nil { c.Err = err return } else { diff --git a/api4/user_test.go b/api4/user_test.go index 0121c71af..98f88ab64 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -2200,7 +2200,7 @@ func TestCreateUserAccessToken(t *testing.T) { _, resp = Client.CreateUserAccessToken(th.BasicUser.Id, "") CheckBadRequestStatus(t, resp) - th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id) + th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = false }) _, resp = Client.CreateUserAccessToken(th.BasicUser.Id, testDescription) @@ -2278,7 +2278,7 @@ func TestGetUserAccessToken(t *testing.T) { _, resp = Client.GetUserAccessToken(model.NewId()) CheckForbiddenStatus(t, resp) - th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id) + th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false) token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription) CheckNoError(t, resp) @@ -2339,7 +2339,7 @@ func TestRevokeUserAccessToken(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id) + th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false) token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription) CheckNoError(t, resp) @@ -2387,7 +2387,7 @@ func TestDisableUserAccessToken(t *testing.T) { }() *utils.Cfg.ServiceSettings.EnableUserAccessTokens = true - th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id) + th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false) token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription) CheckNoError(t, resp) @@ -2434,7 +2434,7 @@ func TestEnableUserAccessToken(t *testing.T) { }() *utils.Cfg.ServiceSettings.EnableUserAccessTokens = true - th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id) + th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false) token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription) CheckNoError(t, resp) @@ -2476,7 +2476,7 @@ func TestUserAccessTokenInactiveUser(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id) + th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false) token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription) CheckNoError(t, resp) @@ -2499,7 +2499,7 @@ func TestUserAccessTokenDisableConfig(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id) + th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false) token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription) CheckNoError(t, resp) -- cgit v1.2.3-1-g7c22