Fix to respect System Console settings (#4110)

* fix for plugin viewing names and emails

* fix some tests

* fix some tests

* fix more tests

* fix more tests

* clean-up

* cleanup, fix issue on initial load

* revert manifest changes

* implement on personal server side

* revert user.go changes

* lint fix

* fix test

* check config for null before setting boolean value

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
Scott Bishel 2022-11-02 14:07:10 -06:00 committed by GitHub
parent bb7b04c78b
commit 08f09f0c99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 117 additions and 59 deletions

View file

@ -46,6 +46,12 @@ func TestSetConfiguration(t *testing.T) {
TeammateNameDisplay: &usernameRef, TeammateNameDisplay: &usernameRef,
} }
falseRef := false
basePrivacySettings := &model.PrivacySettings{
ShowEmailAddress: &falseRef,
ShowFullName: &falseRef,
}
baseConfig := &model.Config{ baseConfig := &model.Config{
FeatureFlags: baseFeatureFlags, FeatureFlags: baseFeatureFlags,
PluginSettings: *basePluginSettings, PluginSettings: *basePluginSettings,
@ -53,6 +59,7 @@ func TestSetConfiguration(t *testing.T) {
FileSettings: *baseFileSettings, FileSettings: *baseFileSettings,
DataRetentionSettings: *baseDataRetentionSettings, DataRetentionSettings: *baseDataRetentionSettings,
TeamSettings: *baseTeamSettings, TeamSettings: *baseTeamSettings,
PrivacySettings: *basePrivacySettings,
} }
t.Run("test enable telemetry", func(t *testing.T) { t.Run("test enable telemetry", func(t *testing.T) {

View file

@ -70,6 +70,16 @@ func createBoardsConfig(mmconfig mm_model.Config, baseURL string, serverID strin
featureFlags := parseFeatureFlags(mmconfig.FeatureFlags.ToMap()) featureFlags := parseFeatureFlags(mmconfig.FeatureFlags.ToMap())
showEmailAddress := false
if mmconfig.PrivacySettings.ShowEmailAddress != nil {
showEmailAddress = *mmconfig.PrivacySettings.ShowEmailAddress
}
showFullName := false
if mmconfig.PrivacySettings.ShowFullName != nil {
showFullName = *mmconfig.PrivacySettings.ShowFullName
}
return &config.Configuration{ return &config.Configuration{
ServerRoot: baseURL + "/plugins/focalboard", ServerRoot: baseURL + "/plugins/focalboard",
Port: -1, Port: -1,
@ -99,6 +109,8 @@ func createBoardsConfig(mmconfig mm_model.Config, baseURL string, serverID strin
EnableDataRetention: enableBoardsDeletion, EnableDataRetention: enableBoardsDeletion,
DataRetentionDays: *mmconfig.DataRetentionSettings.BoardsRetentionDays, DataRetentionDays: *mmconfig.DataRetentionSettings.BoardsRetentionDays,
TeammateNameDisplay: *mmconfig.TeamSettings.TeammateNameDisplay, TeammateNameDisplay: *mmconfig.TeamSettings.TeammateNameDisplay,
ShowEmailAddress: showEmailAddress,
ShowFullName: showFullName,
} }
} }

View file

@ -97,6 +97,16 @@ func (b *BoardsApp) OnConfigurationChange() error {
b.server.Config().EnableDataRetention = enableBoardsDeletion b.server.Config().EnableDataRetention = enableBoardsDeletion
b.server.Config().DataRetentionDays = *mmconfig.DataRetentionSettings.BoardsRetentionDays b.server.Config().DataRetentionDays = *mmconfig.DataRetentionSettings.BoardsRetentionDays
b.server.Config().TeammateNameDisplay = *mmconfig.TeamSettings.TeammateNameDisplay b.server.Config().TeammateNameDisplay = *mmconfig.TeamSettings.TeammateNameDisplay
showEmailAddress := false
if mmconfig.PrivacySettings.ShowEmailAddress != nil {
showEmailAddress = *mmconfig.PrivacySettings.ShowEmailAddress
}
b.server.Config().ShowEmailAddress = showEmailAddress
showFullName := false
if mmconfig.PrivacySettings.ShowFullName != nil {
showFullName = *mmconfig.PrivacySettings.ShowFullName
}
b.server.Config().ShowFullName = showFullName
b.server.UpdateAppConfig() b.server.UpdateAppConfig()
b.wsPluginAdapter.BroadcastConfigChange(*b.server.App().GetClientConfig()) b.wsPluginAdapter.BroadcastConfigChange(*b.server.App().GetClientConfig())

View file

@ -70,11 +70,18 @@ func TestOnConfigurationChange(t *testing.T) {
TeammateNameDisplay: &usernameRef, TeammateNameDisplay: &usernameRef,
} }
falseRef := false
basePrivacySettings := &serverModel.PrivacySettings{
ShowEmailAddress: &falseRef,
ShowFullName: &falseRef,
}
baseConfig := &serverModel.Config{ baseConfig := &serverModel.Config{
FeatureFlags: baseFeatureFlags, FeatureFlags: baseFeatureFlags,
PluginSettings: *basePluginSettings, PluginSettings: *basePluginSettings,
DataRetentionSettings: *baseDataRetentionSettings, DataRetentionSettings: *baseDataRetentionSettings,
TeamSettings: *baseTeamSettings, TeamSettings: *baseTeamSettings,
PrivacySettings: *basePrivacySettings,
} }
t.Run("Test Load Plugin Success", func(t *testing.T) { t.Run("Test Load Plugin Success", func(t *testing.T) {

View file

@ -69,7 +69,7 @@ func (a *App) GetUsersList(userIDs []string) ([]*model.User, error) {
return nil, errors.New("No User IDs") return nil, errors.New("No User IDs")
} }
users, err := a.store.GetUsersList(userIDs) users, err := a.store.GetUsersList(userIDs, a.config.ShowEmailAddress, a.config.ShowFullName)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "unable to find users") return nil, errors.Wrap(err, "unable to find users")
} }

View file

@ -159,7 +159,7 @@ func TestPatchBoard(t *testing.T) {
}, nil) }, nil)
// Type not null will retrieve team members // Type not null will retrieve team members
th.Store.EXPECT().GetUsersByTeam(teamID, "").Return([]*model.User{}, nil) th.Store.EXPECT().GetUsersByTeam(teamID, "", false, false).Return([]*model.User{}, nil)
th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return( th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return(
&model.Board{ &model.Board{
@ -197,7 +197,7 @@ func TestPatchBoard(t *testing.T) {
}, nil) }, nil)
// Type not null will retrieve team members // Type not null will retrieve team members
th.Store.EXPECT().GetUsersByTeam(teamID, "").Return([]*model.User{}, nil) th.Store.EXPECT().GetUsersByTeam(teamID, "", false, false).Return([]*model.User{}, nil)
th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return( th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return(
&model.Board{ &model.Board{
@ -234,7 +234,7 @@ func TestPatchBoard(t *testing.T) {
IsTemplate: true, IsTemplate: true,
}, nil) }, nil)
// Type not null will retrieve team members // Type not null will retrieve team members
th.Store.EXPECT().GetUsersByTeam(teamID, "").Return([]*model.User{{ID: userID}}, nil) th.Store.EXPECT().GetUsersByTeam(teamID, "", false, false).Return([]*model.User{{ID: userID}}, nil)
th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return( th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return(
&model.Board{ &model.Board{
@ -272,7 +272,7 @@ func TestPatchBoard(t *testing.T) {
IsTemplate: true, IsTemplate: true,
}, nil) }, nil)
// Type not null will retrieve team members // Type not null will retrieve team members
th.Store.EXPECT().GetUsersByTeam(teamID, "").Return([]*model.User{{ID: userID}}, nil) th.Store.EXPECT().GetUsersByTeam(teamID, "", false, false).Return([]*model.User{{ID: userID}}, nil)
th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return( th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return(
&model.Board{ &model.Board{
@ -310,7 +310,7 @@ func TestPatchBoard(t *testing.T) {
IsTemplate: true, IsTemplate: true,
}, nil) }, nil)
// Type not null will retrieve team members // Type not null will retrieve team members
th.Store.EXPECT().GetUsersByTeam(teamID, "").Return([]*model.User{{ID: userID}}, nil) th.Store.EXPECT().GetUsersByTeam(teamID, "", false, false).Return([]*model.User{{ID: userID}}, nil)
th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return( th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return(
&model.Board{ &model.Board{
@ -348,7 +348,7 @@ func TestPatchBoard(t *testing.T) {
IsTemplate: true, IsTemplate: true,
}, nil) }, nil)
// Type not null will retrieve team members // Type not null will retrieve team members
th.Store.EXPECT().GetUsersByTeam(teamID, "").Return([]*model.User{{ID: userID}}, nil) th.Store.EXPECT().GetUsersByTeam(teamID, "", false, false).Return([]*model.User{{ID: userID}}, nil)
th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return( th.Store.EXPECT().PatchBoard(boardID, patch, userID).Return(
&model.Board{ &model.Board{

View file

@ -41,7 +41,7 @@ func TestPrepareOnboardingTour(t *testing.T) {
th.Store.EXPECT().GetMembersForBoard("board_id_2").Return([]*model.BoardMember{}, nil).Times(1) th.Store.EXPECT().GetMembersForBoard("board_id_2").Return([]*model.BoardMember{}, nil).Times(1)
th.Store.EXPECT().GetBoard(welcomeBoard.ID).Return(&welcomeBoard, nil).Times(1) th.Store.EXPECT().GetBoard(welcomeBoard.ID).Return(&welcomeBoard, nil).Times(1)
th.Store.EXPECT().GetBoard("board_id_2").Return(&welcomeBoard, nil).Times(1) th.Store.EXPECT().GetBoard("board_id_2").Return(&welcomeBoard, nil).Times(1)
th.Store.EXPECT().GetUsersByTeam("0", "").Return([]*model.User{}, nil) th.Store.EXPECT().GetUsersByTeam("0", "", false, false).Return([]*model.User{}, nil)
privateWelcomeBoard := model.Board{ privateWelcomeBoard := model.Board{
ID: "board_id_1", ID: "board_id_1",
@ -104,7 +104,7 @@ func TestCreateWelcomeBoard(t *testing.T) {
Return(&model.BoardsAndBlocks{Boards: []*model.Board{&welcomeBoard}}, nil, nil) Return(&model.BoardsAndBlocks{Boards: []*model.Board{&welcomeBoard}}, nil, nil)
th.Store.EXPECT().GetMembersForBoard(welcomeBoard.ID).Return([]*model.BoardMember{}, nil).Times(3) th.Store.EXPECT().GetMembersForBoard(welcomeBoard.ID).Return([]*model.BoardMember{}, nil).Times(3)
th.Store.EXPECT().GetBoard(welcomeBoard.ID).Return(&welcomeBoard, nil).AnyTimes() th.Store.EXPECT().GetBoard(welcomeBoard.ID).Return(&welcomeBoard, nil).AnyTimes()
th.Store.EXPECT().GetUsersByTeam("0", "").Return([]*model.User{}, nil) th.Store.EXPECT().GetUsersByTeam("0", "", false, false).Return([]*model.User{}, nil)
privateWelcomeBoard := model.Board{ privateWelcomeBoard := model.Board{
ID: "board_id_1", ID: "board_id_1",

View file

@ -6,11 +6,11 @@ import (
) )
func (a *App) GetTeamUsers(teamID string, asGuestID string) ([]*model.User, error) { func (a *App) GetTeamUsers(teamID string, asGuestID string) ([]*model.User, error) {
return a.store.GetUsersByTeam(teamID, asGuestID) return a.store.GetUsersByTeam(teamID, asGuestID, a.config.ShowEmailAddress, a.config.ShowFullName)
} }
func (a *App) SearchTeamUsers(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error) { func (a *App) SearchTeamUsers(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error) {
return a.store.SearchUsersByTeam(teamID, searchQuery, asGuestID, excludeBots) return a.store.SearchUsersByTeam(teamID, searchQuery, asGuestID, excludeBots, a.config.ShowEmailAddress, a.config.ShowFullName)
} }
func (a *App) UpdateUserConfig(userID string, patch model.UserPreferencesPatch) ([]mmModel.Preference, error) { func (a *App) UpdateUserConfig(userID string, patch model.UserPreferencesPatch) ([]mmModel.Preference, error) {

View file

@ -156,7 +156,7 @@ func (s *PluginTestStore) GetUserPreferences(userID string) (mmModel.Preferences
return nil, errTestStore return nil, errTestStore
} }
func (s *PluginTestStore) GetUsersByTeam(teamID string, asGuestID string) ([]*model.User, error) { func (s *PluginTestStore) GetUsersByTeam(teamID string, asGuestID string, showEmail, showName bool) ([]*model.User, error) {
if asGuestID == "guest" { if asGuestID == "guest" {
return []*model.User{ return []*model.User{
s.users["viewer"], s.users["viewer"],
@ -191,9 +191,9 @@ func (s *PluginTestStore) GetUsersByTeam(teamID string, asGuestID string) ([]*mo
return nil, errTestStore return nil, errTestStore
} }
func (s *PluginTestStore) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error) { func (s *PluginTestStore) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool, showEmail, showName bool) ([]*model.User, error) {
users := []*model.User{} users := []*model.User{}
teamUsers, err := s.GetUsersByTeam(teamID, asGuestID) teamUsers, err := s.GetUsersByTeam(teamID, asGuestID, showEmail, showName)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -54,6 +54,8 @@ type Configuration struct {
EnableDataRetention bool `json:"enable_data_retention" mapstructure:"enable_data_retention"` EnableDataRetention bool `json:"enable_data_retention" mapstructure:"enable_data_retention"`
DataRetentionDays int `json:"data_retention_days" mapstructure:"data_retention_days"` DataRetentionDays int `json:"data_retention_days" mapstructure:"data_retention_days"`
TeammateNameDisplay string `json:"teammate_name_display" mapstructure:"teammateNameDisplay"` TeammateNameDisplay string `json:"teammate_name_display" mapstructure:"teammateNameDisplay"`
ShowEmailAddress bool `json:"show_email_address" mapstructure:"showEmailAddress"`
ShowFullName bool `json:"show_full_name" mapstructure:"showFullName"`
AuthMode string `json:"authMode" mapstructure:"authMode"` AuthMode string `json:"authMode" mapstructure:"authMode"`
@ -103,6 +105,8 @@ func ReadConfigFile(configFilePath string) (*Configuration, error) {
viper.SetDefault("DataRetentionDays", 365) // 1 year is default viper.SetDefault("DataRetentionDays", 365) // 1 year is default
viper.SetDefault("PrometheusAddress", "") viper.SetDefault("PrometheusAddress", "")
viper.SetDefault("TeammateNameDisplay", "username") viper.SetDefault("TeammateNameDisplay", "username")
viper.SetDefault("ShowEmailAddress", false)
viper.SetDefault("ShowFullName", false)
err := viper.ReadInConfig() // Find and read the config file err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file if err != nil { // Handle errors reading the config file

View file

@ -331,12 +331,8 @@ func (s *MattermostAuthLayer) getQueryBuilder() sq.StatementBuilderType {
return builder.RunWith(s.mmDB) return builder.RunWith(s.mmDB)
} }
func (s *MattermostAuthLayer) GetUsersByTeam(teamID string, asGuestID string) ([]*model.User, error) { func (s *MattermostAuthLayer) GetUsersByTeam(teamID string, asGuestID string, showEmail, showName bool) ([]*model.User, error) {
query := s.getQueryBuilder(). query := s.baseUserQuery(showEmail, showName).
Select("u.id", "u.username", "u.email", "u.nickname", "u.firstname", "u.lastname", "u.CreateAt as create_at", "u.UpdateAt as update_at",
"u.DeleteAt as delete_at", "b.UserId IS NOT NULL AS is_bot, u.roles = 'system_guest' as is_guest").
From("Users as u").
LeftJoin("Bots b ON ( b.UserID = u.id )").
Where(sq.Eq{"u.deleteAt": 0}) Where(sq.Eq{"u.deleteAt": 0})
if asGuestID == "" { if asGuestID == "" {
@ -372,12 +368,8 @@ func (s *MattermostAuthLayer) GetUsersByTeam(teamID string, asGuestID string) ([
return users, nil return users, nil
} }
func (s *MattermostAuthLayer) GetUsersList(userIDs []string) ([]*model.User, error) { func (s *MattermostAuthLayer) GetUsersList(userIDs []string, showEmail, showName bool) ([]*model.User, error) {
query := s.getQueryBuilder(). query := s.baseUserQuery(showEmail, showName).
Select("u.id", "u.username", "u.email", "u.nickname", "u.firstname", "u.lastname", "u.CreateAt as create_at", "u.UpdateAt as update_at",
"u.DeleteAt as delete_at", "b.UserId IS NOT NULL AS is_bot, u.roles = 'system_guest' as is_guest").
From("Users as u").
LeftJoin("Bots b ON ( b.UserId = u.id )").
Where(sq.Eq{"u.id": userIDs}) Where(sq.Eq{"u.id": userIDs})
rows, err := query.Query() rows, err := query.Query()
@ -398,12 +390,8 @@ func (s *MattermostAuthLayer) GetUsersList(userIDs []string) ([]*model.User, err
return users, nil return users, nil
} }
func (s *MattermostAuthLayer) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error) { func (s *MattermostAuthLayer) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots, showEmail, showName bool) ([]*model.User, error) {
query := s.getQueryBuilder(). query := s.baseUserQuery(showEmail, showName).
Select("u.id", "u.username", "u.email", "u.nickname", "u.firstname", "u.lastname", "u.CreateAt as create_at", "u.UpdateAt as update_at",
"u.DeleteAt as delete_at", "b.UserId IS NOT NULL AS is_bot, u.roles = 'system_guest' as is_guest").
From("Users as u").
LeftJoin("Bots b ON ( b.UserId = u.id )").
Where(sq.Eq{"u.deleteAt": 0}). Where(sq.Eq{"u.deleteAt": 0}).
Where(sq.Or{ Where(sq.Or{
sq.Like{"u.username": "%" + searchQuery + "%"}, sq.Like{"u.username": "%" + searchQuery + "%"},
@ -647,6 +635,36 @@ func boardFields(prefix string) []string {
return prefixedFields return prefixedFields
} }
func (s *MattermostAuthLayer) baseUserQuery(showEmail, showName bool) sq.SelectBuilder {
emailField := "''"
if showEmail {
emailField = "u.email"
}
firstNameField := "''"
lastNameField := "''"
if showName {
firstNameField = "u.firstname"
lastNameField = "u.lastname"
}
return s.getQueryBuilder().
Select(
"u.id",
"u.username",
emailField,
"u.nickname",
firstNameField,
lastNameField,
"u.CreateAt as create_at",
"u.UpdateAt as update_at",
"u.DeleteAt as delete_at",
"b.UserId IS NOT NULL AS is_bot",
"u.roles = 'system_guest' as is_guest",
).
From("Users as u").
LeftJoin("Bots b ON ( b.UserID = u.id )")
}
// SearchBoardsForUser returns all boards that match with the // SearchBoardsForUser returns all boards that match with the
// term that are either private and which the user is a member of, or // term that are either private and which the user is a member of, or
// they're open, regardless of the user membership. // they're open, regardless of the user membership.

View file

@ -1137,33 +1137,33 @@ func (mr *MockStoreMockRecorder) GetUserTimezone(arg0 interface{}) *gomock.Call
} }
// GetUsersByTeam mocks base method. // GetUsersByTeam mocks base method.
func (m *MockStore) GetUsersByTeam(arg0, arg1 string) ([]*model.User, error) { func (m *MockStore) GetUsersByTeam(arg0, arg1 string, arg2, arg3 bool) ([]*model.User, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetUsersByTeam", arg0, arg1) ret := m.ctrl.Call(m, "GetUsersByTeam", arg0, arg1, arg2, arg3)
ret0, _ := ret[0].([]*model.User) ret0, _ := ret[0].([]*model.User)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
// GetUsersByTeam indicates an expected call of GetUsersByTeam. // GetUsersByTeam indicates an expected call of GetUsersByTeam.
func (mr *MockStoreMockRecorder) GetUsersByTeam(arg0, arg1 interface{}) *gomock.Call { func (mr *MockStoreMockRecorder) GetUsersByTeam(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsersByTeam", reflect.TypeOf((*MockStore)(nil).GetUsersByTeam), arg0, arg1) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsersByTeam", reflect.TypeOf((*MockStore)(nil).GetUsersByTeam), arg0, arg1, arg2, arg3)
} }
// GetUsersList mocks base method. // GetUsersList mocks base method.
func (m *MockStore) GetUsersList(arg0 []string) ([]*model.User, error) { func (m *MockStore) GetUsersList(arg0 []string, arg1, arg2 bool) ([]*model.User, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetUsersList", arg0) ret := m.ctrl.Call(m, "GetUsersList", arg0, arg1, arg2)
ret0, _ := ret[0].([]*model.User) ret0, _ := ret[0].([]*model.User)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
// GetUsersList indicates an expected call of GetUsersList. // GetUsersList indicates an expected call of GetUsersList.
func (mr *MockStoreMockRecorder) GetUsersList(arg0 interface{}) *gomock.Call { func (mr *MockStoreMockRecorder) GetUsersList(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsersList", reflect.TypeOf((*MockStore)(nil).GetUsersList), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsersList", reflect.TypeOf((*MockStore)(nil).GetUsersList), arg0, arg1, arg2)
} }
// InsertBlock mocks base method. // InsertBlock mocks base method.
@ -1430,18 +1430,18 @@ func (mr *MockStoreMockRecorder) SearchUserChannels(arg0, arg1, arg2 interface{}
} }
// SearchUsersByTeam mocks base method. // SearchUsersByTeam mocks base method.
func (m *MockStore) SearchUsersByTeam(arg0, arg1, arg2 string, arg3 bool) ([]*model.User, error) { func (m *MockStore) SearchUsersByTeam(arg0, arg1, arg2 string, arg3, arg4, arg5 bool) ([]*model.User, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SearchUsersByTeam", arg0, arg1, arg2, arg3) ret := m.ctrl.Call(m, "SearchUsersByTeam", arg0, arg1, arg2, arg3, arg4, arg5)
ret0, _ := ret[0].([]*model.User) ret0, _ := ret[0].([]*model.User)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
// SearchUsersByTeam indicates an expected call of SearchUsersByTeam. // SearchUsersByTeam indicates an expected call of SearchUsersByTeam.
func (mr *MockStoreMockRecorder) SearchUsersByTeam(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { func (mr *MockStoreMockRecorder) SearchUsersByTeam(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchUsersByTeam", reflect.TypeOf((*MockStore)(nil).SearchUsersByTeam), arg0, arg1, arg2, arg3) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchUsersByTeam", reflect.TypeOf((*MockStore)(nil).SearchUsersByTeam), arg0, arg1, arg2, arg3, arg4, arg5)
} }
// SendMessage mocks base method. // SendMessage mocks base method.

View file

@ -539,13 +539,13 @@ func (s *SQLStore) GetUserTimezone(userID string) (string, error) {
} }
func (s *SQLStore) GetUsersByTeam(teamID string, asGuestID string) ([]*model.User, error) { func (s *SQLStore) GetUsersByTeam(teamID string, asGuestID string, showEmail bool, showName bool) ([]*model.User, error) {
return s.getUsersByTeam(s.db, teamID, asGuestID) return s.getUsersByTeam(s.db, teamID, asGuestID, showEmail, showName)
} }
func (s *SQLStore) GetUsersList(userIDs []string) ([]*model.User, error) { func (s *SQLStore) GetUsersList(userIDs []string, showEmail bool, showName bool) ([]*model.User, error) {
return s.getUsersList(s.db, userIDs) return s.getUsersList(s.db, userIDs, showEmail, showName)
} }
@ -791,8 +791,8 @@ func (s *SQLStore) SearchUserChannels(teamID string, userID string, query string
} }
func (s *SQLStore) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error) { func (s *SQLStore) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool, showEmail bool, showName bool) ([]*model.User, error) {
return s.searchUsersByTeam(s.db, teamID, searchQuery, asGuestID, excludeBots) return s.searchUsersByTeam(s.db, teamID, searchQuery, asGuestID, excludeBots, showEmail, showName)
} }

View file

@ -102,7 +102,7 @@ func (s *SQLStore) getUserByID(db sq.BaseRunner, userID string) (*model.User, er
return s.getUserByCondition(db, sq.Eq{"id": userID}) return s.getUserByCondition(db, sq.Eq{"id": userID})
} }
func (s *SQLStore) getUsersList(db sq.BaseRunner, userIDs []string) ([]*model.User, error) { func (s *SQLStore) getUsersList(db sq.BaseRunner, userIDs []string, _, _ bool) ([]*model.User, error) {
users, err := s.getUsersByCondition(db, sq.Eq{"id": userIDs}, 0) users, err := s.getUsersByCondition(db, sq.Eq{"id": userIDs}, 0)
if err != nil { if err != nil {
return nil, err return nil, err
@ -214,7 +214,7 @@ func (s *SQLStore) updateUserPasswordByID(db sq.BaseRunner, userID, password str
return nil return nil
} }
func (s *SQLStore) getUsersByTeam(db sq.BaseRunner, _ string, _ string) ([]*model.User, error) { func (s *SQLStore) getUsersByTeam(db sq.BaseRunner, _ string, _ string, _, _ bool) ([]*model.User, error) {
users, err := s.getUsersByCondition(db, nil, 0) users, err := s.getUsersByCondition(db, nil, 0)
if model.IsErrNotFound(err) { if model.IsErrNotFound(err) {
return []*model.User{}, nil return []*model.User{}, nil
@ -223,7 +223,7 @@ func (s *SQLStore) getUsersByTeam(db sq.BaseRunner, _ string, _ string) ([]*mode
return users, err return users, err
} }
func (s *SQLStore) searchUsersByTeam(db sq.BaseRunner, _ string, searchQuery string, _ string, _ bool) ([]*model.User, error) { func (s *SQLStore) searchUsersByTeam(db sq.BaseRunner, _ string, searchQuery string, _ string, _, _, _ bool) ([]*model.User, error) {
users, err := s.getUsersByCondition(db, &sq.Like{"username": "%" + searchQuery + "%"}, 10) users, err := s.getUsersByCondition(db, &sq.Like{"username": "%" + searchQuery + "%"}, 10)
if model.IsErrNotFound(err) { if model.IsErrNotFound(err) {
return []*model.User{}, nil return []*model.User{}, nil

View file

@ -56,15 +56,15 @@ type Store interface {
GetRegisteredUserCount() (int, error) GetRegisteredUserCount() (int, error)
GetUserByID(userID string) (*model.User, error) GetUserByID(userID string) (*model.User, error)
GetUsersList(userIDs []string) ([]*model.User, error) GetUsersList(userIDs []string, showEmail, showName bool) ([]*model.User, error)
GetUserByEmail(email string) (*model.User, error) GetUserByEmail(email string) (*model.User, error)
GetUserByUsername(username string) (*model.User, error) GetUserByUsername(username string) (*model.User, error)
CreateUser(user *model.User) (*model.User, error) CreateUser(user *model.User) (*model.User, error)
UpdateUser(user *model.User) (*model.User, error) UpdateUser(user *model.User) (*model.User, error)
UpdateUserPassword(username, password string) error UpdateUserPassword(username, password string) error
UpdateUserPasswordByID(userID, password string) error UpdateUserPasswordByID(userID, password string) error
GetUsersByTeam(teamID string, asGuestID string) ([]*model.User, error) GetUsersByTeam(teamID string, asGuestID string, showEmail, showName bool) ([]*model.User, error)
SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool, showEmail, showName bool) ([]*model.User, error)
PatchUserPreferences(userID string, patch model.UserPreferencesPatch) (mmModel.Preferences, error) PatchUserPreferences(userID string, patch model.UserPreferencesPatch) (mmModel.Preferences, error)
GetUserPreferences(userID string) (mmModel.Preferences, error) GetUserPreferences(userID string) (mmModel.Preferences, error)

View file

@ -56,7 +56,7 @@ func StoreTestUserStore(t *testing.T, setup func(t *testing.T) (store.Store, fun
func testGetUsersByTeam(t *testing.T, store store.Store) { func testGetUsersByTeam(t *testing.T, store store.Store) {
t.Run("GetTeamUsers", func(t *testing.T) { t.Run("GetTeamUsers", func(t *testing.T) {
users, err := store.GetUsersByTeam("team_1", "") users, err := store.GetUsersByTeam("team_1", "", false, false)
require.Equal(t, 0, len(users)) require.Equal(t, 0, len(users))
require.NoError(t, err) require.NoError(t, err)
@ -78,7 +78,7 @@ func testGetUsersByTeam(t *testing.T, store store.Store) {
}) })
}() }()
users, err = store.GetUsersByTeam("team_1", "") users, err = store.GetUsersByTeam("team_1", "", false, false)
require.Equal(t, 1, len(users)) require.Equal(t, 1, len(users))
require.Equal(t, "darth.vader", users[0].Username) require.Equal(t, "darth.vader", users[0].Username)
require.NoError(t, err) require.NoError(t, err)
@ -184,7 +184,7 @@ func testGetUsersList(t *testing.T, store store.Store) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) { t.Run(tc.Name, func(t *testing.T) {
users, err := store.GetUsersList(tc.UserIDs) users, err := store.GetUsersList(tc.UserIDs, false, false)
if tc.ExpectedError { if tc.ExpectedError {
require.Error(t, err) require.Error(t, err)
require.True(t, model.IsErrNotFound(err)) require.True(t, model.IsErrNotFound(err))