Merge branch 'master' into mark-as-unread
Этот коммит содержится в:
@@ -1260,8 +1260,8 @@ func (a *App) GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.A
|
||||
return a.Srv.Store.Channel().GetAllChannelsCount(storeOpts)
|
||||
}
|
||||
|
||||
func (a *App) GetDeletedChannels(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetDeleted(teamId, offset, limit)
|
||||
func (a *App) GetDeletedChannels(teamId string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetDeleted(teamId, offset, limit, userId)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
@@ -1894,6 +1894,12 @@ func (a *App) SearchChannels(teamId string, term string) (*model.ChannelList, *m
|
||||
return a.Srv.Store.Channel().SearchInTeam(teamId, term, includeDeleted)
|
||||
}
|
||||
|
||||
func (a *App) SearchArchivedChannels(teamId string, term string, userId string) (*model.ChannelList, *model.AppError) {
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv.Store.Channel().SearchArchivedInTeam(teamId, term, userId)
|
||||
}
|
||||
|
||||
func (a *App) SearchChannelsForUser(userId, teamId, term string) (*model.ChannelList, *model.AppError) {
|
||||
includeDeleted := *a.Config().TeamSettings.ExperimentalViewArchivedChannels
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
@@ -42,6 +43,15 @@ func TestInviteProvider(t *testing.T) {
|
||||
userAndInvalidPrivate := "@" + basicUser3.Username + " ~" + privateChannel2.Name
|
||||
deactivatedUserPublicChannel := "@" + deactivatedUser.Username + " ~" + channel.Name
|
||||
|
||||
groupChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
|
||||
var err *model.AppError
|
||||
_, err = th.App.AddChannelMember(th.BasicUser.Id, groupChannel, "", "")
|
||||
require.Nil(t, err)
|
||||
groupChannel.GroupConstrained = model.NewBool(true)
|
||||
groupChannel, _ = th.App.UpdateChannel(groupChannel)
|
||||
|
||||
groupChannelNonUser := "@" + th.BasicUser2.Username + " ~" + groupChannel.Name
|
||||
|
||||
tests := []struct {
|
||||
desc string
|
||||
expected string
|
||||
@@ -97,6 +107,11 @@ func TestInviteProvider(t *testing.T) {
|
||||
expected: "api.command_invite.user_not_in_team.app_error",
|
||||
msg: basicUser4.Username,
|
||||
},
|
||||
{
|
||||
desc: "try to add a user not part of the group to a group channel",
|
||||
expected: "api.command_invite.group_constrained_user_denied",
|
||||
msg: groupChannelNonUser,
|
||||
},
|
||||
{
|
||||
desc: "try to add a user to a private channel with no permission",
|
||||
expected: "api.command_invite.private_channel.app_error",
|
||||
@@ -116,3 +131,59 @@ func TestInviteProvider(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInviteGroup(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.BasicTeam.GroupConstrained = model.NewBool(true)
|
||||
var err *model.AppError
|
||||
_, _ = th.App.AddTeamMember(th.BasicTeam.Id, th.BasicUser.Id)
|
||||
_, err = th.App.AddTeamMember(th.BasicTeam.Id, th.BasicUser2.Id)
|
||||
require.Nil(t, err)
|
||||
th.BasicTeam, _ = th.App.UpdateTeam(th.BasicTeam)
|
||||
|
||||
privateChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
|
||||
|
||||
groupChannelUser1 := "@" + th.BasicUser.Username + " ~" + privateChannel.Name
|
||||
groupChannelUser2 := "@" + th.BasicUser2.Username + " ~" + privateChannel.Name
|
||||
basicUser3 := th.CreateUser()
|
||||
groupChannelUser3 := "@" + basicUser3.Username + " ~" + privateChannel.Name
|
||||
|
||||
InviteP := InviteProvider{}
|
||||
args := &model.CommandArgs{
|
||||
T: func(s string, args ...interface{}) string { return s },
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.TEAM_USER_ROLE_ID}}},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
desc string
|
||||
expected string
|
||||
msg string
|
||||
}{
|
||||
{
|
||||
desc: "try to add an existing user part of the group to a group channel",
|
||||
expected: "api.command_invite.user_already_in_channel.app_error",
|
||||
msg: groupChannelUser1,
|
||||
},
|
||||
{
|
||||
desc: "try to add a user part of the group to a group channel",
|
||||
expected: "api.command_invite.success",
|
||||
msg: groupChannelUser2,
|
||||
},
|
||||
{
|
||||
desc: "try to add a user NOT part of the group to a group channel",
|
||||
expected: "api.command_invite.user_not_in_team.app_error",
|
||||
msg: groupChannelUser3,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
actual := InviteP.DoCommand(th.App, args, test.msg).Text
|
||||
assert.Equal(t, test.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func (a *App) LimitedClientConfig() map[string]string {
|
||||
return a.Srv.limitedClientConfig
|
||||
}
|
||||
|
||||
// Registers a function with a given to be called when the config is reloaded and may have changed. The function
|
||||
// Registers a function with a given listener to be called when the config is reloaded and may have changed. The function
|
||||
// will be called with two arguments: the old config and the new config. AddConfigListener returns a unique ID
|
||||
// for the listener that can later be used to remove it.
|
||||
func (s *Server) AddConfigListener(listener func(*model.Config, *model.Config)) string {
|
||||
@@ -104,7 +104,7 @@ func (a *App) RemoveConfigListener(id string) {
|
||||
}
|
||||
|
||||
// ensurePostActionCookieSecret ensures that the key for encrypting PostActionCookie exists
|
||||
// and future calls to PostAcrionCookieSecret will always return a valid key, same on all
|
||||
// and future calls to PostActionCookieSecret will always return a valid key, same on all
|
||||
// servers in the cluster
|
||||
func (a *App) ensurePostActionCookieSecret() error {
|
||||
if a.Srv.postActionCookieSecret != nil {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/mail"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
@@ -525,8 +524,6 @@ func (a *App) SendMail(to, subject, htmlBody string) *model.AppError {
|
||||
func (a *App) SendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader) *model.AppError {
|
||||
license := a.License()
|
||||
config := a.Config()
|
||||
fromMail := mail.Address{Name: *config.EmailSettings.FeedbackName, Address: *config.EmailSettings.FeedbackEmail}
|
||||
replyTo := mail.Address{Name: *config.EmailSettings.FeedbackName, Address: *config.EmailSettings.ReplyToAddress}
|
||||
|
||||
return mailservice.SendMailUsingConfigAdvanced(to, to, fromMail, replyTo, subject, htmlBody, nil, embeddedFiles, nil, config, license != nil && *license.Features.Compliance)
|
||||
return mailservice.SendMailWithEmbeddedFilesUsingConfig(to, subject, htmlBody, embeddedFiles, config, license != nil && *license.Features.Compliance)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
|
||||
|
||||
a.Srv.Go(func() {
|
||||
if err := a.SendNotificationMail(user.Email, html.UnescapeString(subjectText), bodyText); err != nil {
|
||||
mlog.Error("Error while sending the email", mlog.String("email", user.Email), mlog.Err(err))
|
||||
mlog.Error("Error while sending the email", mlog.String("user_email", user.Email), mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -285,7 +285,7 @@ func getFormattedPostTime(user *model.User, post *model.Post, useMilitaryTime bo
|
||||
func (a *App) generateHyperlinkForChannels(postMessage, teamName, teamURL string) string {
|
||||
team, err := a.GetTeamByName(teamName)
|
||||
if err != nil {
|
||||
mlog.Error("Encountered error while looking up team by name", mlog.String("Team Name", teamName), mlog.Err(err))
|
||||
mlog.Error("Encountered error while looking up team by name", mlog.String("team_name", teamName), mlog.Err(err))
|
||||
return postMessage
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
return nil, errors.Wrapf(err, "unable to load Mattermost translation files")
|
||||
}
|
||||
|
||||
err := s.RunOldAppInitalization()
|
||||
err := s.RunOldAppInitialization()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// This is a bridge between the old and new initalization for the context refactor.
|
||||
// It calls app layer initalization code that then turns around and acts on the server.
|
||||
// Don't add anything new here, new initilization should be done in the server and
|
||||
// This is a bridge between the old and new initialization for the context refactor.
|
||||
// It calls app layer initialization code that then turns around and acts on the server.
|
||||
// Don't add anything new here, new initialization should be done in the server and
|
||||
// performed in the NewServer function.
|
||||
func (s *Server) RunOldAppInitalization() error {
|
||||
func (s *Server) RunOldAppInitialization() error {
|
||||
s.FakeApp().CreatePushNotificationsHub()
|
||||
s.FakeApp().StartPushNotificationsHubWorkers()
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/color"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -74,8 +73,7 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
glUser := oauthgitlab.GitLabUser{Id: int64(r.Intn(1000)) + 1, Username: "o" + model.NewId(), Email: model.NewId() + "@simulator.amazonses.com", Name: "Joram Wilander"}
|
||||
glUser := oauthgitlab.GitLabUser{Id: 42, Username: "o" + model.NewId(), Email: model.NewId() + "@simulator.amazonses.com", Name: "Joram Wilander"}
|
||||
|
||||
json := glUser.ToJson()
|
||||
user, err := th.App.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
@@ -253,8 +251,8 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
|
||||
var user, user2 *model.User
|
||||
var gitlabUserObj oauthgitlab.GitLabUser
|
||||
user, gitlabUserObj = createGitlabUser(t, th.App, username, email)
|
||||
user2, _ = createGitlabUser(t, th.App, username2, email2)
|
||||
user, gitlabUserObj = createGitlabUser(t, th.App, 1, username, email)
|
||||
user2, _ = createGitlabUser(t, th.App, 2, username2, email2)
|
||||
|
||||
t.Run("UpdateUsername", func(t *testing.T) {
|
||||
t.Run("NoExistingUserWithSameUsername", func(t *testing.T) {
|
||||
@@ -443,9 +441,8 @@ func getGitlabUserPayload(gitlabUser oauthgitlab.GitLabUser, t *testing.T) []byt
|
||||
return payload
|
||||
}
|
||||
|
||||
func createGitlabUser(t *testing.T, a *App, username string, email string) (*model.User, oauthgitlab.GitLabUser) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
gitlabUserObj := oauthgitlab.GitLabUser{Id: int64(r.Intn(1000)) + 1, Username: username, Login: "user1", Email: email, Name: "Test User"}
|
||||
func createGitlabUser(t *testing.T, a *App, id int64, username string, email string) (*model.User, oauthgitlab.GitLabUser) {
|
||||
gitlabUserObj := oauthgitlab.GitLabUser{Id: id, Username: username, Login: "user1", Email: email, Name: "Test User"}
|
||||
gitlabUser := getGitlabUserPayload(gitlabUserObj, t)
|
||||
|
||||
var user *model.User
|
||||
|
||||
Ссылка в новой задаче
Block a user