2021-06-04 15:23:15 +02:00
|
|
|
package app
|
|
|
|
|
2022-07-07 16:46:53 +02:00
|
|
|
import (
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
|
|
|
)
|
2021-06-04 15:23:15 +02:00
|
|
|
|
2022-08-25 00:08:58 +02:00
|
|
|
func (a *App) GetTeamUsers(teamID string, asGuestID string) ([]*model.User, error) {
|
2022-11-02 22:07:10 +02:00
|
|
|
return a.store.GetUsersByTeam(teamID, asGuestID, a.config.ShowEmailAddress, a.config.ShowFullName)
|
2022-03-22 16:24:34 +02:00
|
|
|
}
|
|
|
|
|
2022-09-10 03:56:44 +02:00
|
|
|
func (a *App) SearchTeamUsers(teamID string, searchQuery string, asGuestID string, excludeBots bool) ([]*model.User, error) {
|
2023-02-14 18:17:33 +02:00
|
|
|
users, err := a.store.SearchUsersByTeam(teamID, searchQuery, asGuestID, excludeBots, a.config.ShowEmailAddress, a.config.ShowFullName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, u := range users {
|
|
|
|
if a.permissions.HasPermissionToTeam(u.ID, teamID, model.PermissionManageTeam) {
|
|
|
|
users[i].Permissions = append(users[i].Permissions, model.PermissionManageTeam.Id)
|
|
|
|
}
|
|
|
|
if a.permissions.HasPermissionTo(u.ID, model.PermissionManageSystem) {
|
|
|
|
users[i].Permissions = append(users[i].Permissions, model.PermissionManageSystem.Id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return users, nil
|
2021-06-04 15:23:15 +02:00
|
|
|
}
|
2022-02-28 13:28:16 +02:00
|
|
|
|
2022-09-15 13:58:20 +02:00
|
|
|
func (a *App) UpdateUserConfig(userID string, patch model.UserPreferencesPatch) ([]mmModel.Preference, error) {
|
|
|
|
updatedPreferences, err := a.store.PatchUserPreferences(userID, patch)
|
2022-02-28 13:28:16 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-08-29 09:25:12 +02:00
|
|
|
return updatedPreferences, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) GetUserPreferences(userID string) ([]mmModel.Preference, error) {
|
|
|
|
return a.store.GetUserPreferences(userID)
|
2022-02-28 13:28:16 +02:00
|
|
|
}
|
2022-07-07 16:46:53 +02:00
|
|
|
|
2022-08-25 00:08:58 +02:00
|
|
|
func (a *App) UserIsGuest(userID string) (bool, error) {
|
|
|
|
user, err := a.store.GetUserByID(userID)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return user.IsGuest, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) CanSeeUser(seerUser string, seenUser string) (bool, error) {
|
|
|
|
isGuest, err := a.UserIsGuest(seerUser)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
if isGuest {
|
|
|
|
hasSharedChannels, err := a.store.CanSeeUser(seerUser, seenUser)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return hasSharedChannels, nil
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2022-07-07 16:46:53 +02:00
|
|
|
func (a *App) SearchUserChannels(teamID string, userID string, query string) ([]*mmModel.Channel, error) {
|
2023-02-22 23:55:13 +02:00
|
|
|
channels, err := a.store.SearchUserChannels(teamID, userID, query)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var writeableChannels []*mmModel.Channel
|
|
|
|
for _, channel := range channels {
|
|
|
|
if a.permissions.HasPermissionToChannel(userID, channel.Id, model.PermissionCreatePost) {
|
|
|
|
writeableChannels = append(writeableChannels, channel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return writeableChannels, nil
|
2022-07-07 16:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) GetChannel(teamID string, channelID string) (*mmModel.Channel, error) {
|
|
|
|
return a.store.GetChannel(teamID, channelID)
|
|
|
|
}
|