* parent 48256721c4 (#14358)

author Eli Yukelzon <reflog@gmail.com> 1585814774 +0300
committer Eli Yukelzon <reflog@gmail.com> 1589111022 +0300

Sidebar caregories implemented

Apply suggestions from code review

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>

Update store/sqlstore/channel_store.go

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>

Update store/sqlstore/channel_store.go

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>

code review suggestions

status messages

edge case

bugs...

timeout reverse

* MM-25126 Add a separate default sorting method for categories (#14575)

* MM-25158 Add user to initial sidebar categories when joining team (#14570)

* MM-25281  Place new categories in the correct position (#14609)

* MM-25277  Return channels that aren't in a category as part of the Channels/Direct Messages categories (#14601)

* MM-25276  Remove categories when leaving a team (#14600)

* Remove categories when leaving a team

* layers

* corrected cleanup function

* lint

* .

* corrected errors in postgres

* .

* MM-25280  Ensure that the "update category order" API call only contains real category IDs and isn't missing any IDs (#14626)

* Ensure that the "update category order" API call only contains real category IDs and isn't missing any IDs

* tests

* correct status code

* MM-25278  Change "update category" API to return 400 when changing unsupported fields (#14599)

* MM-25279  Change category migration to only populate channels in Favorites (#14627)

* MM-25157 Add API to delete custom categories  (#14574)

* MM-25157 Add API to delete custom categories

* get categories fix

* maxorder fix

* Use correct websocket event when deleting category

* Fix tests and remove debug code

* Actually use the right websocket event this time

* test cleanup

* Update test for new category order

Co-authored-by: Eli Yukelzon <reflog@gmail.com>

* MM-24914 Various fixes for sidebar channel handling (#14756)

* Fix checking for channel membership when reordering channels

* Remove unique constraint on SidebarCategories

* Set column sizes for SidebarCategories and SidebarChannels tables

* Allow changing the sorting method for non-DM categories

* Fix nil pointers in error handling

* Fix orphaned channels from other team being returned in Channels category

* Fix non-orphaned channels being duplicated in the Channels category

* Remove unique constraint on SidebarChannels

* Fix category/name of favorites preferences

* Fix testSidebarChannelsMigration

* Rename err to nErr and appErr to err

* Fix channel order returned by GetSidebarCategories on MySQL

* Fix adding/removing favorites preferences

* Remove leftover TODO

* Change SidebarCategoryType enums to use full names (#14786)

* Change SidebarCategoryType enums to use full names

* Fix Channels constant

* Remove leftover debug code

* MM-24914 Fix updateCategory endpoint returning the wrong type (#14795)

* MM-24914 Make some changes to UpdateSidebarCategories (#14806)

* Fix orphaned DMs not always being returned

* MM-24914 Make some changes to UpdateSidebarCategories

* Run updateSidebarCategoryOrderT in a transaction

* Fix deleting SidebarChannels based on order of arguments to UpdateSidebarCategories

* bump for api testing

* bump for api testing

* Change CreateInitialSidebarCategories to return a plain error

* Change MigrateSidebarCategories to return a plain error

* Remove usage of UpdateColumns when updating sidebar categories (#14843)

* Remove usage of UpdateColumns when changing category order

* Add a random test case

* Remove usage of UpdateColumns when updating sidebar categories (#14843)

* Remove usage of UpdateColumns when changing category order

* Add a random test case

* Remove usage of UpdateColumns when updating sidebar categories (#14843)

* Remove usage of UpdateColumns when changing category order

* Add a random test case

* MM-26343 Make CreateInitialSidebarCategories idempotent (#14870)

* Fix bad merge

* Fix another bad merge

* Fix unintentionally removed i18n string

Co-authored-by: Eli Yukelzon <reflog@gmail.com>
Этот коммит содержится в:
Harrison Healey
2020-07-06 18:20:35 -04:00
коммит произвёл GitHub
родитель 83a80a2422
Коммит de6a57cdc3
31 изменённых файлов: 3855 добавлений и 4 удалений

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

@@ -415,6 +415,7 @@ type AppIface interface {
CreateRole(role *model.Role) (*model.Role, *model.AppError)
CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
CreateSession(session *model.Session) (*model.Session, *model.AppError)
CreateSidebarCategory(userId, teamId string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError)
CreateTeam(team *model.Team) (*model.Team, *model.AppError)
CreateTeamWithUser(team *model.Team, userId string) (*model.Team, *model.AppError)
CreateTermsOfService(text, userId string) (*model.TermsOfService, *model.AppError)
@@ -449,6 +450,7 @@ type AppIface interface {
DeletePreferences(userId string, preferences model.Preferences) *model.AppError
DeleteReactionForPost(reaction *model.Reaction) *model.AppError
DeleteScheme(schemeId string) (*model.Scheme, *model.AppError)
DeleteSidebarCategory(userId, teamId, categoryId string) *model.AppError
DeleteToken(token *model.Token) *model.AppError
DiagnosticId() string
DisableAutoResponder(userId string, asAdmin bool) *model.AppError
@@ -633,6 +635,9 @@ type AppIface interface {
GetSession(token string) (*model.Session, *model.AppError)
GetSessionById(sessionId string) (*model.Session, *model.AppError)
GetSessions(userId string) ([]*model.Session, *model.AppError)
GetSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError)
GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError)
GetSidebarCategoryOrder(userId, teamId string) ([]string, *model.AppError)
GetSinglePost(postId string) (*model.Post, *model.AppError)
GetSiteURL() string
GetStatus(userId string) (*model.Status, *model.AppError)
@@ -861,6 +866,7 @@ type AppIface interface {
Session() *model.Session
SessionCacheLength() int
SessionHasPermissionTo(session model.Session, permission *model.Permission) bool
SessionHasPermissionToCategory(session model.Session, userId, teamId, categoryId string) bool
SessionHasPermissionToChannel(session model.Session, channelId string, permission *model.Permission) bool
SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool
SessionHasPermissionToTeam(session model.Session, teamId string, permission *model.Permission) bool
@@ -953,6 +959,8 @@ type AppIface interface {
UpdateRole(role *model.Role) (*model.Role, *model.AppError)
UpdateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
UpdateSessionsIsGuest(userId string, isGuest bool)
UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError)
UpdateSidebarCategoryOrder(userId, teamId string, categoryOrder []string) *model.AppError
UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
UpdateTeamMemberRoles(teamId string, userId string, newRoles string) (*model.TeamMember, *model.AppError)
UpdateTeamMemberSchemeRoles(teamId string, userId string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError)

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

@@ -89,6 +89,14 @@ func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postId
return a.SessionHasPermissionTo(session, permission)
}
func (a *App) SessionHasPermissionToCategory(session model.Session, userId, teamId, categoryId string) bool {
if a.SessionHasPermissionTo(session, model.PERMISSION_EDIT_OTHER_USERS) {
return true
}
category, err := a.GetSidebarCategory(categoryId)
return err == nil && category != nil && category.UserId == session.UserId && category.UserId == userId && category.TeamId == teamId
}
func (a *App) SessionHasPermissionToUser(session model.Session, userId string) bool {
if userId == "" {
return false

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

@@ -2383,6 +2383,10 @@ func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.
return err
}
if appErr := a.Srv().Store.Channel().UpdateSidebarChannelCategoryOnMove(channel, team.Id); appErr != nil {
return appErr
}
channel.TeamId = team.Id
if _, err := a.Srv().Store.Channel().Update(channel); err != nil {
var appErr *model.AppError
@@ -2598,3 +2602,70 @@ func (a *App) ClearChannelMembersCache(channelID string) {
page++
}
}
func (a *App) createInitialSidebarCategories(user *model.User, team *model.Team) *model.AppError {
nErr := a.Srv().Store.Channel().CreateInitialSidebarCategories(user, team.Id)
if nErr != nil {
return model.NewAppError("createInitialSidebarCategories", "app.channel.create_initial_sidebar_categories.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
}
return nil
}
func (a *App) GetSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
return a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
}
func (a *App) GetSidebarCategoryOrder(userId, teamId string) ([]string, *model.AppError) {
return a.Srv().Store.Channel().GetSidebarCategoryOrder(userId, teamId)
}
func (a *App) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
return a.Srv().Store.Channel().GetSidebarCategory(categoryId)
}
func (a *App) CreateSidebarCategory(userId, teamId string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
category, err := a.Srv().Store.Channel().CreateSidebarCategory(userId, teamId, newCategory)
if err != nil {
return nil, err
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_CREATED, teamId, "", userId, nil)
message.Add("category_id", category.Id)
a.Publish(message)
return category, nil
}
func (a *App) UpdateSidebarCategoryOrder(userId, teamId string, categoryOrder []string) *model.AppError {
err := a.Srv().Store.Channel().UpdateSidebarCategoryOrder(userId, teamId, categoryOrder)
if err != nil {
return err
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_ORDER_UPDATED, teamId, "", userId, nil)
message.Add("order", categoryOrder)
a.Publish(message)
return nil
}
func (a *App) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
result, err := a.Srv().Store.Channel().UpdateSidebarCategories(userId, teamId, categories)
if err != nil {
return nil, err
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_UPDATED, teamId, "", userId, nil)
a.Publish(message)
return result, nil
}
func (a *App) DeleteSidebarCategory(userId, teamId, categoryId string) *model.AppError {
err := a.Srv().Store.Channel().DeleteSidebarCategory(categoryId)
if err != nil {
return err
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_DELETED, teamId, "", userId, nil)
message.Add("category_id", categoryId)
a.Publish(message)
return nil
}

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

@@ -1795,3 +1795,66 @@ func TestMarkChannelsAsViewedPanic(t *testing.T) {
_, err := th.App.MarkChannelsAsViewed([]string{"channelID"}, "userID", th.App.Session().Id)
require.Nil(t, err)
}
func TestSidebarCategory(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
basicChannel2 := th.CreateChannel(th.BasicTeam)
defer th.App.PermanentDeleteChannel(basicChannel2)
user := th.CreateUser()
defer th.App.Srv().Store.User().PermanentDelete(user.Id)
th.LinkUserToTeam(user, th.BasicTeam)
th.AddUserToChannel(user, basicChannel2)
var createdCategory *model.SidebarCategoryWithChannels
t.Run("CreateSidebarCategory", func(t *testing.T) {
catData := model.SidebarCategoryWithChannels{
SidebarCategory: model.SidebarCategory{
DisplayName: "TEST",
},
Channels: []string{th.BasicChannel.Id, basicChannel2.Id, basicChannel2.Id},
}
_, err := th.App.CreateSidebarCategory(user.Id, th.BasicTeam.Id, &catData)
require.NotNil(t, err, "Should return error due to duplicate IDs")
catData.Channels = []string{th.BasicChannel.Id, basicChannel2.Id}
cat, err := th.App.CreateSidebarCategory(user.Id, th.BasicTeam.Id, &catData)
require.Nil(t, err, "Expected no error")
require.NotNil(t, cat, "Expected category object, got nil")
createdCategory = cat
})
t.Run("UpdateSidebarCategories", func(t *testing.T) {
require.NotNil(t, createdCategory)
createdCategory.Channels = []string{th.BasicChannel.Id}
updatedCat, err := th.App.UpdateSidebarCategories(user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{createdCategory})
require.Nil(t, err, "Expected no error")
require.NotNil(t, updatedCat, "Expected category object, got nil")
require.Len(t, updatedCat, 1)
require.Len(t, updatedCat[0].Channels, 1)
require.Equal(t, updatedCat[0].Channels[0], th.BasicChannel.Id)
})
t.Run("UpdateSidebarCategoryOrder", func(t *testing.T) {
err := th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, []string{th.BasicChannel.Id, basicChannel2.Id})
require.NotNil(t, err, "Should return error due to invalid order")
actualOrder, err := th.App.GetSidebarCategoryOrder(user.Id, th.BasicTeam.Id)
require.Nil(t, err, "Should fetch order successfully")
actualOrder[2], actualOrder[3] = actualOrder[3], actualOrder[2]
err = th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, actualOrder)
require.Nil(t, err, "Should update order successfully")
actualOrder[2] = "asd"
err = th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, actualOrder)
require.NotNil(t, err, "Should return error due to invalid id")
})
t.Run("GetSidebarCategoryOrder", func(t *testing.T) {
catOrder, err := th.App.GetSidebarCategoryOrder(user.Id, th.BasicTeam.Id)
require.Nil(t, err, "Expected no error")
require.Len(t, catOrder, 4)
require.Equal(t, catOrder[1], createdCategory.Id, "the newly created category should be after favorites")
})
}

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

@@ -2025,6 +2025,28 @@ func (a *OpenTracingAppLayer) CreateSession(session *model.Session) (*model.Sess
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) CreateSidebarCategory(userId string, teamId string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateSidebarCategory")
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.CreateSidebarCategory(userId, teamId, newCategory)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) CreateTeam(team *model.Team) (*model.Team, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateTeam")
@@ -2857,6 +2879,28 @@ func (a *OpenTracingAppLayer) DeleteScheme(schemeId string) (*model.Scheme, *mod
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) DeleteSidebarCategory(userId string, teamId string, categoryId string) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DeleteSidebarCategory")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0 := a.app.DeleteSidebarCategory(userId, teamId, categoryId)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
func (a *OpenTracingAppLayer) DeleteToken(token *model.Token) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DeleteToken")
@@ -7539,6 +7583,72 @@ func (a *OpenTracingAppLayer) GetSessions(userId string) ([]*model.Session, *mod
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetSidebarCategories(userId string, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSidebarCategories")
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.GetSidebarCategories(userId, teamId)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSidebarCategory")
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.GetSidebarCategory(categoryId)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetSidebarCategoryOrder(userId string, teamId string) ([]string, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSidebarCategoryOrder")
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.GetSidebarCategoryOrder(userId, teamId)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetSinglePost(postId string) (*model.Post, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSinglePost")
@@ -12642,6 +12752,23 @@ func (a *OpenTracingAppLayer) SessionHasPermissionTo(session model.Session, perm
return resultVar0
}
func (a *OpenTracingAppLayer) SessionHasPermissionToCategory(session model.Session, userId string, teamId string, categoryId string) bool {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SessionHasPermissionToCategory")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0 := a.app.SessionHasPermissionToCategory(session, userId, teamId, categoryId)
return resultVar0
}
func (a *OpenTracingAppLayer) SessionHasPermissionToChannel(session model.Session, channelId string, permission *model.Permission) bool {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SessionHasPermissionToChannel")
@@ -14484,6 +14611,50 @@ func (a *OpenTracingAppLayer) UpdateSessionsIsGuest(userId string, isGuest bool)
a.app.UpdateSessionsIsGuest(userId, isGuest)
}
func (a *OpenTracingAppLayer) UpdateSidebarCategories(userId string, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateSidebarCategories")
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.UpdateSidebarCategories(userId, teamId, categories)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) UpdateSidebarCategoryOrder(userId string, teamId string, categoryOrder []string) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateSidebarCategoryOrder")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0 := a.app.UpdateSidebarCategoryOrder(userId, teamId, categoryOrder)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
func (a *OpenTracingAppLayer) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateTeam")

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

@@ -53,7 +53,13 @@ func (a *App) UpdatePreferences(userId string, preferences model.Preferences) *m
return err
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PREFERENCES_CHANGED, "", "", userId, nil)
if err := a.Srv().Store.Channel().UpdateSidebarChannelsByPreferences(&preferences); err != nil {
return err
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_UPDATED, "", "", userId, nil)
a.Publish(message)
message = model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PREFERENCES_CHANGED, "", "", userId, nil)
message.Add("preferences", preferences.ToJson())
a.Publish(message)

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

@@ -653,6 +653,15 @@ func (a *App) JoinUserToTeam(team *model.Team, user *model.User, userRequestorId
return err
}
if err := a.createInitialSidebarCategories(user, team); err != nil {
mlog.Error(
"Encountered an issue creating default sidebar categories.",
mlog.String("user_id", user.Id),
mlog.String("team_id", team.Id),
mlog.Err(err),
)
}
shouldBeAdmin := team.Email == user.Email
if !user.IsGuest() {
@@ -969,6 +978,10 @@ func (a *App) RemoveTeamMemberFromTeam(teamMember *model.TeamMember, requestorId
return err
}
if err := a.Srv().Store.Channel().ClearSidebarOnTeamLeave(user.Id, teamMember.TeamId); err != nil {
return err
}
// delete the preferences that set the last channel used in the team and other team specific preferences
if err := a.Srv().Store.Preference().DeleteCategory(user.Id, teamMember.TeamId); err != nil {
return err
@@ -1031,8 +1044,7 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User, requestorId string)
}
}
err = a.RemoveTeamMemberFromTeam(teamMember, requestorId)
if err != nil {
if err := a.RemoveTeamMemberFromTeam(teamMember, requestorId); err != nil {
return err
}

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

@@ -165,7 +165,21 @@ func TestAddUserToTeam(t *testing.T) {
_, err = th.App.AddUserToTeam(th.BasicTeam.Id, ruser3.Id, "")
require.NotNil(t, err, "Should not have allowed restricted user3")
require.Equal(t, "JoinUserToTeam", err.Where, "Error should be JoinUserToTeam")
})
t.Run("should set up initial sidebar categories when joining a team", func(t *testing.T) {
user := th.CreateUser()
team := th.CreateTeam()
_, err := th.App.AddUserToTeam(team.Id, user.Id, "")
require.Nil(t, err)
res, err := th.App.GetSidebarCategories(user.Id, team.Id)
require.Nil(t, err)
assert.Len(t, res.Categories, 3)
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
assert.Equal(t, model.SidebarCategoryChannels, res.Categories[1].Type)
assert.Equal(t, model.SidebarCategoryDirectMessages, res.Categories[2].Type)
})
}
@@ -390,6 +404,27 @@ func TestAddUserToTeamByToken(t *testing.T) {
require.NotNil(t, err, "Should not add restricted user")
require.Equal(t, "JoinUserToTeam", err.Where, "Error should be JoinUserToTeam")
})
t.Run("should set up initial sidebar categories when joining a team by token", func(t *testing.T) {
user := th.CreateUser()
team := th.CreateTeam()
token := model.NewToken(
TOKEN_TYPE_TEAM_INVITATION,
model.MapToJson(map[string]string{"teamId": team.Id}),
)
require.Nil(t, th.App.Srv().Store.Token().Save(token))
_, err := th.App.AddUserToTeamByToken(user.Id, token.Token)
require.Nil(t, err)
res, err := th.App.GetSidebarCategories(user.Id, team.Id)
require.Nil(t, err)
assert.Len(t, res.Categories, 3)
assert.Equal(t, model.SidebarCategoryFavorites, res.Categories[0].Type)
assert.Equal(t, model.SidebarCategoryChannels, res.Categories[1].Type)
assert.Equal(t, model.SidebarCategoryDirectMessages, res.Categories[2].Type)
})
}
func TestAddUserToTeamByTeamId(t *testing.T) {