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:
parent
bb7b04c78b
commit
08f09f0c99
16 changed files with 117 additions and 59 deletions
|
@ -46,6 +46,12 @@ func TestSetConfiguration(t *testing.T) {
|
|||
TeammateNameDisplay: &usernameRef,
|
||||
}
|
||||
|
||||
falseRef := false
|
||||
basePrivacySettings := &model.PrivacySettings{
|
||||
ShowEmailAddress: &falseRef,
|
||||
ShowFullName: &falseRef,
|
||||
}
|
||||
|
||||
baseConfig := &model.Config{
|
||||
FeatureFlags: baseFeatureFlags,
|
||||
PluginSettings: *basePluginSettings,
|
||||
|
@ -53,6 +59,7 @@ func TestSetConfiguration(t *testing.T) {
|
|||
FileSettings: *baseFileSettings,
|
||||
DataRetentionSettings: *baseDataRetentionSettings,
|
||||
TeamSettings: *baseTeamSettings,
|
||||
PrivacySettings: *basePrivacySettings,
|
||||
}
|
||||
|
||||
t.Run("test enable telemetry", func(t *testing.T) {
|
||||
|
|
|
@ -70,6 +70,16 @@ func createBoardsConfig(mmconfig mm_model.Config, baseURL string, serverID strin
|
|||
|
||||
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{
|
||||
ServerRoot: baseURL + "/plugins/focalboard",
|
||||
Port: -1,
|
||||
|
@ -99,6 +109,8 @@ func createBoardsConfig(mmconfig mm_model.Config, baseURL string, serverID strin
|
|||
EnableDataRetention: enableBoardsDeletion,
|
||||
DataRetentionDays: *mmconfig.DataRetentionSettings.BoardsRetentionDays,
|
||||
TeammateNameDisplay: *mmconfig.TeamSettings.TeammateNameDisplay,
|
||||
ShowEmailAddress: showEmailAddress,
|
||||
ShowFullName: showFullName,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,16 @@ func (b *BoardsApp) OnConfigurationChange() error {
|
|||
b.server.Config().EnableDataRetention = enableBoardsDeletion
|
||||
b.server.Config().DataRetentionDays = *mmconfig.DataRetentionSettings.BoardsRetentionDays
|
||||
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.wsPluginAdapter.BroadcastConfigChange(*b.server.App().GetClientConfig())
|
||||
|
|
|
@ -70,11 +70,18 @@ func TestOnConfigurationChange(t *testing.T) {
|
|||
TeammateNameDisplay: &usernameRef,
|
||||
}
|
||||
|
||||
falseRef := false
|
||||
basePrivacySettings := &serverModel.PrivacySettings{
|
||||
ShowEmailAddress: &falseRef,
|
||||
ShowFullName: &falseRef,
|
||||
}
|
||||
|
||||
baseConfig := &serverModel.Config{
|
||||
FeatureFlags: baseFeatureFlags,
|
||||
PluginSettings: *basePluginSettings,
|
||||
DataRetentionSettings: *baseDataRetentionSettings,
|
||||
TeamSettings: *baseTeamSettings,
|
||||
PrivacySettings: *basePrivacySettings,
|
||||
}
|
||||
|
||||
t.Run("Test Load Plugin Success", func(t *testing.T) {
|
||||
|
|
|
@ -69,7 +69,7 @@ func (a *App) GetUsersList(userIDs []string) ([]*model.User, error) {
|
|||
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 {
|
||||
return nil, errors.Wrap(err, "unable to find users")
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ func TestPatchBoard(t *testing.T) {
|
|||
}, nil)
|
||||
|
||||
// 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(
|
||||
&model.Board{
|
||||
|
@ -197,7 +197,7 @@ func TestPatchBoard(t *testing.T) {
|
|||
}, nil)
|
||||
|
||||
// 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(
|
||||
&model.Board{
|
||||
|
@ -234,7 +234,7 @@ func TestPatchBoard(t *testing.T) {
|
|||
IsTemplate: true,
|
||||
}, nil)
|
||||
// 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(
|
||||
&model.Board{
|
||||
|
@ -272,7 +272,7 @@ func TestPatchBoard(t *testing.T) {
|
|||
IsTemplate: true,
|
||||
}, nil)
|
||||
// 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(
|
||||
&model.Board{
|
||||
|
@ -310,7 +310,7 @@ func TestPatchBoard(t *testing.T) {
|
|||
IsTemplate: true,
|
||||
}, nil)
|
||||
// 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(
|
||||
&model.Board{
|
||||
|
@ -348,7 +348,7 @@ func TestPatchBoard(t *testing.T) {
|
|||
IsTemplate: true,
|
||||
}, nil)
|
||||
// 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(
|
||||
&model.Board{
|
||||
|
|
|
@ -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().GetBoard(welcomeBoard.ID).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{
|
||||
ID: "board_id_1",
|
||||
|
@ -104,7 +104,7 @@ func TestCreateWelcomeBoard(t *testing.T) {
|
|||
Return(&model.BoardsAndBlocks{Boards: []*model.Board{&welcomeBoard}}, nil, nil)
|
||||
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().GetUsersByTeam("0", "").Return([]*model.User{}, nil)
|
||||
th.Store.EXPECT().GetUsersByTeam("0", "", false, false).Return([]*model.User{}, nil)
|
||||
|
||||
privateWelcomeBoard := model.Board{
|
||||
ID: "board_id_1",
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
)
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
|
|
@ -156,7 +156,7 @@ func (s *PluginTestStore) GetUserPreferences(userID string) (mmModel.Preferences
|
|||
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" {
|
||||
return []*model.User{
|
||||
s.users["viewer"],
|
||||
|
@ -191,9 +191,9 @@ func (s *PluginTestStore) GetUsersByTeam(teamID string, asGuestID string) ([]*mo
|
|||
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{}
|
||||
teamUsers, err := s.GetUsersByTeam(teamID, asGuestID)
|
||||
teamUsers, err := s.GetUsersByTeam(teamID, asGuestID, showEmail, showName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ type Configuration struct {
|
|||
EnableDataRetention bool `json:"enable_data_retention" mapstructure:"enable_data_retention"`
|
||||
DataRetentionDays int `json:"data_retention_days" mapstructure:"data_retention_days"`
|
||||
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"`
|
||||
|
||||
|
@ -103,6 +105,8 @@ func ReadConfigFile(configFilePath string) (*Configuration, error) {
|
|||
viper.SetDefault("DataRetentionDays", 365) // 1 year is default
|
||||
viper.SetDefault("PrometheusAddress", "")
|
||||
viper.SetDefault("TeammateNameDisplay", "username")
|
||||
viper.SetDefault("ShowEmailAddress", false)
|
||||
viper.SetDefault("ShowFullName", false)
|
||||
|
||||
err := viper.ReadInConfig() // Find and read the config file
|
||||
if err != nil { // Handle errors reading the config file
|
||||
|
|
|
@ -331,12 +331,8 @@ func (s *MattermostAuthLayer) getQueryBuilder() sq.StatementBuilderType {
|
|||
return builder.RunWith(s.mmDB)
|
||||
}
|
||||
|
||||
func (s *MattermostAuthLayer) GetUsersByTeam(teamID string, asGuestID string) ([]*model.User, error) {
|
||||
query := s.getQueryBuilder().
|
||||
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 )").
|
||||
func (s *MattermostAuthLayer) GetUsersByTeam(teamID string, asGuestID string, showEmail, showName bool) ([]*model.User, error) {
|
||||
query := s.baseUserQuery(showEmail, showName).
|
||||
Where(sq.Eq{"u.deleteAt": 0})
|
||||
|
||||
if asGuestID == "" {
|
||||
|
@ -372,12 +368,8 @@ func (s *MattermostAuthLayer) GetUsersByTeam(teamID string, asGuestID string) ([
|
|||
return users, nil
|
||||
}
|
||||
|
||||
func (s *MattermostAuthLayer) GetUsersList(userIDs []string) ([]*model.User, error) {
|
||||
query := s.getQueryBuilder().
|
||||
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 )").
|
||||
func (s *MattermostAuthLayer) GetUsersList(userIDs []string, showEmail, showName bool) ([]*model.User, error) {
|
||||
query := s.baseUserQuery(showEmail, showName).
|
||||
Where(sq.Eq{"u.id": userIDs})
|
||||
|
||||
rows, err := query.Query()
|
||||
|
@ -398,12 +390,8 @@ func (s *MattermostAuthLayer) GetUsersList(userIDs []string) ([]*model.User, err
|
|||
return users, nil
|
||||
}
|
||||
|
||||
func (s *MattermostAuthLayer) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error) {
|
||||
query := s.getQueryBuilder().
|
||||
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 )").
|
||||
func (s *MattermostAuthLayer) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots, showEmail, showName bool) ([]*model.User, error) {
|
||||
query := s.baseUserQuery(showEmail, showName).
|
||||
Where(sq.Eq{"u.deleteAt": 0}).
|
||||
Where(sq.Or{
|
||||
sq.Like{"u.username": "%" + searchQuery + "%"},
|
||||
|
@ -647,6 +635,36 @@ func boardFields(prefix string) []string {
|
|||
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
|
||||
// term that are either private and which the user is a member of, or
|
||||
// they're open, regardless of the user membership.
|
||||
|
|
|
@ -1137,33 +1137,33 @@ func (mr *MockStoreMockRecorder) GetUserTimezone(arg0 interface{}) *gomock.Call
|
|||
}
|
||||
|
||||
// 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()
|
||||
ret := m.ctrl.Call(m, "GetUsersByTeam", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "GetUsersByTeam", arg0, arg1, arg2, arg3)
|
||||
ret0, _ := ret[0].([]*model.User)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// 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()
|
||||
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.
|
||||
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()
|
||||
ret := m.ctrl.Call(m, "GetUsersList", arg0)
|
||||
ret := m.ctrl.Call(m, "GetUsersList", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].([]*model.User)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// 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()
|
||||
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.
|
||||
|
@ -1430,18 +1430,18 @@ func (mr *MockStoreMockRecorder) SearchUserChannels(arg0, arg1, arg2 interface{}
|
|||
}
|
||||
|
||||
// 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()
|
||||
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)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// 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()
|
||||
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.
|
||||
|
|
|
@ -539,13 +539,13 @@ func (s *SQLStore) GetUserTimezone(userID string) (string, error) {
|
|||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetUsersByTeam(teamID string, asGuestID string) ([]*model.User, error) {
|
||||
return s.getUsersByTeam(s.db, teamID, asGuestID)
|
||||
func (s *SQLStore) GetUsersByTeam(teamID string, asGuestID string, showEmail bool, showName bool) ([]*model.User, error) {
|
||||
return s.getUsersByTeam(s.db, teamID, asGuestID, showEmail, showName)
|
||||
|
||||
}
|
||||
|
||||
func (s *SQLStore) GetUsersList(userIDs []string) ([]*model.User, error) {
|
||||
return s.getUsersList(s.db, userIDs)
|
||||
func (s *SQLStore) GetUsersList(userIDs []string, showEmail bool, showName bool) ([]*model.User, error) {
|
||||
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) {
|
||||
return s.searchUsersByTeam(s.db, teamID, searchQuery, asGuestID, excludeBots)
|
||||
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, showEmail, showName)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ func (s *SQLStore) getUserByID(db sq.BaseRunner, userID string) (*model.User, er
|
|||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -214,7 +214,7 @@ func (s *SQLStore) updateUserPasswordByID(db sq.BaseRunner, userID, password str
|
|||
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)
|
||||
if model.IsErrNotFound(err) {
|
||||
return []*model.User{}, nil
|
||||
|
@ -223,7 +223,7 @@ func (s *SQLStore) getUsersByTeam(db sq.BaseRunner, _ string, _ string) ([]*mode
|
|||
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)
|
||||
if model.IsErrNotFound(err) {
|
||||
return []*model.User{}, nil
|
||||
|
|
|
@ -56,15 +56,15 @@ type Store interface {
|
|||
|
||||
GetRegisteredUserCount() (int, 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)
|
||||
GetUserByUsername(username string) (*model.User, error)
|
||||
CreateUser(user *model.User) (*model.User, error)
|
||||
UpdateUser(user *model.User) (*model.User, error)
|
||||
UpdateUserPassword(username, password string) error
|
||||
UpdateUserPasswordByID(userID, password string) error
|
||||
GetUsersByTeam(teamID string, asGuestID string) ([]*model.User, error)
|
||||
SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error)
|
||||
GetUsersByTeam(teamID string, asGuestID string, showEmail, showName 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)
|
||||
GetUserPreferences(userID string) (mmModel.Preferences, error)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
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.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, "darth.vader", users[0].Username)
|
||||
require.NoError(t, err)
|
||||
|
@ -184,7 +184,7 @@ func testGetUsersList(t *testing.T, store store.Store) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
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 {
|
||||
require.Error(t, err)
|
||||
require.True(t, model.IsErrNotFound(err))
|
||||
|
|
Loading…
Reference in a new issue