Create direct message respect the user role (Guest/Normal user) (#11697)
* Create direct message respect the user role (Guest/Normal user) * Fixing build * Updating Timer store layer
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
619f0ebf5c
Коммит
2df3951f6f
@@ -340,15 +340,19 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
||||
close(uc2)
|
||||
}()
|
||||
|
||||
if result := <-uc1; result.Err != nil {
|
||||
result := <-uc1
|
||||
if result.Err != nil {
|
||||
return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, userId, http.StatusBadRequest)
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
if result := <-uc2; result.Err != nil {
|
||||
result = <-uc2
|
||||
if result.Err != nil {
|
||||
return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, otherUserId, http.StatusBadRequest)
|
||||
}
|
||||
otherUser := result.Data.(*model.User)
|
||||
|
||||
channel, err := a.Srv.Store.Channel().CreateDirectChannel(userId, otherUserId)
|
||||
channel, err := a.Srv.Store.Channel().CreateDirectChannel(user, otherUser)
|
||||
if err != nil {
|
||||
if err.Id == store.CHANNEL_EXISTS_ERROR {
|
||||
return channel, err
|
||||
|
||||
@@ -489,24 +489,26 @@ func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64)
|
||||
return newChannel, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||
func (s SqlChannelStore) CreateDirectChannel(user *model.User, otherUser *model.User) (*model.Channel, *model.AppError) {
|
||||
channel := new(model.Channel)
|
||||
|
||||
channel.DisplayName = ""
|
||||
channel.Name = model.GetDMNameFromIds(otherUserId, userId)
|
||||
channel.Name = model.GetDMNameFromIds(otherUser.Id, user.Id)
|
||||
|
||||
channel.Header = ""
|
||||
channel.Type = model.CHANNEL_DIRECT
|
||||
|
||||
cm1 := &model.ChannelMember{
|
||||
UserId: userId,
|
||||
UserId: user.Id,
|
||||
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
||||
SchemeUser: true,
|
||||
SchemeGuest: user.IsGuest(),
|
||||
SchemeUser: !user.IsGuest(),
|
||||
}
|
||||
cm2 := &model.ChannelMember{
|
||||
UserId: otherUserId,
|
||||
UserId: otherUser.Id,
|
||||
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
||||
SchemeUser: true,
|
||||
SchemeGuest: otherUser.IsGuest(),
|
||||
SchemeUser: !otherUser.IsGuest(),
|
||||
}
|
||||
|
||||
return s.SaveDirectChannel(channel, cm1, cm2)
|
||||
|
||||
@@ -105,7 +105,7 @@ type TeamStore interface {
|
||||
|
||||
type ChannelStore interface {
|
||||
Save(channel *model.Channel, maxChannelsPerTeam int64) (*model.Channel, *model.AppError)
|
||||
CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError)
|
||||
CreateDirectChannel(userId *model.User, otherUserId *model.User) (*model.Channel, *model.AppError)
|
||||
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, *model.AppError)
|
||||
Update(channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
Get(id string, allowFromCache bool) (*model.Channel, *model.AppError)
|
||||
|
||||
@@ -230,7 +230,7 @@ func testChannelStoreCreateDirectChannel(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u2.Id}, -1)
|
||||
require.Nil(t, err)
|
||||
|
||||
c1, err := ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
||||
c1, err := ss.Channel().CreateDirectChannel(u1, u2)
|
||||
if err != nil {
|
||||
t.Fatal("couldn't create direct channel", err)
|
||||
}
|
||||
@@ -1173,7 +1173,9 @@ func testChannelStoreGetAllChannels(t *testing.T, ss store.Store, s SqlSupplier)
|
||||
_, err = ss.Channel().Save(&c3, -1)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Channel().CreateDirectChannel(model.NewId(), model.NewId())
|
||||
u1 := model.User{Id: model.NewId()}
|
||||
u2 := model.User{Id: model.NewId()}
|
||||
_, err = ss.Channel().CreateDirectChannel(&u1, &u2)
|
||||
require.Nil(t, err)
|
||||
|
||||
userIds := []string{model.NewId(), model.NewId(), model.NewId()}
|
||||
@@ -1649,12 +1651,17 @@ func testChannelStoreGetMembersForUser(t *testing.T, ss store.Store) {
|
||||
})
|
||||
|
||||
t.Run("with channels and direct messages", func(t *testing.T) {
|
||||
_, err = ss.Channel().CreateDirectChannel(model.NewId(), m1.UserId)
|
||||
user := model.User{Id: m1.UserId}
|
||||
u1 := model.User{Id: model.NewId()}
|
||||
u2 := model.User{Id: model.NewId()}
|
||||
u3 := model.User{Id: model.NewId()}
|
||||
u4 := model.User{Id: model.NewId()}
|
||||
_, err = ss.Channel().CreateDirectChannel(&u1, &user)
|
||||
require.Nil(t, err)
|
||||
_, err = ss.Channel().CreateDirectChannel(model.NewId(), m1.UserId)
|
||||
_, err = ss.Channel().CreateDirectChannel(&u2, &user)
|
||||
require.Nil(t, err)
|
||||
// other user direct message
|
||||
_, err = ss.Channel().CreateDirectChannel(model.NewId(), model.NewId())
|
||||
_, err = ss.Channel().CreateDirectChannel(&u3, &u4)
|
||||
require.Nil(t, err)
|
||||
|
||||
var members *model.ChannelMembers
|
||||
@@ -3004,9 +3011,9 @@ func testChannelStoreAutocompleteInTeamForSearch(t *testing.T, ss store.Store, s
|
||||
_, err = ss.Channel().Save(&o5, -1)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
||||
_, err = ss.Channel().CreateDirectChannel(u1, u2)
|
||||
require.Nil(t, err)
|
||||
_, err = ss.Channel().CreateDirectChannel(u2.Id, u3.Id)
|
||||
_, err = ss.Channel().CreateDirectChannel(u2, u3)
|
||||
require.Nil(t, err)
|
||||
|
||||
tt := []struct {
|
||||
@@ -3273,7 +3280,7 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) {
|
||||
_, err = ss.User().Save(u2)
|
||||
require.Nil(t, err)
|
||||
|
||||
d4, err := ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
||||
d4, err := ss.Channel().CreateDirectChannel(u1, u2)
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ func testComplianceExportDirectMessages(t *testing.T, ss store.Store) {
|
||||
c1, err = ss.Channel().Save(c1, -1)
|
||||
require.Nil(t, err)
|
||||
|
||||
cDM, err := ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
||||
cDM, err := ss.Channel().CreateDirectChannel(u1, u2)
|
||||
require.Nil(t, err)
|
||||
o1 := &model.Post{}
|
||||
o1.ChannelId = c1.Id
|
||||
@@ -507,7 +507,7 @@ func testMessageExportDirectMessageChannel(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err)
|
||||
|
||||
// as well as a DM channel between those users
|
||||
directMessageChannel, err := ss.Channel().CreateDirectChannel(user1.Id, user2.Id)
|
||||
directMessageChannel, err := ss.Channel().CreateDirectChannel(user1, user2)
|
||||
require.Nil(t, err)
|
||||
|
||||
// user1 also sends a DM to user2
|
||||
|
||||
@@ -131,11 +131,11 @@ func (_m *ChannelStore) ClearCaches() {
|
||||
}
|
||||
|
||||
// CreateDirectChannel provides a mock function with given fields: userId, otherUserId
|
||||
func (_m *ChannelStore) CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||
func (_m *ChannelStore) CreateDirectChannel(userId *model.User, otherUserId *model.User) (*model.Channel, *model.AppError) {
|
||||
ret := _m.Called(userId, otherUserId)
|
||||
|
||||
var r0 *model.Channel
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.Channel); ok {
|
||||
if rf, ok := ret.Get(0).(func(*model.User, *model.User) *model.Channel); ok {
|
||||
r0 = rf(userId, otherUserId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -144,7 +144,7 @@ func (_m *ChannelStore) CreateDirectChannel(userId string, otherUserId string) (
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||
if rf, ok := ret.Get(1).(func(*model.User, *model.User) *model.AppError); ok {
|
||||
r1 = rf(userId, otherUserId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
|
||||
@@ -583,7 +583,7 @@ func (s *TimerLayerChannelStore) ClearCaches() {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||
func (s *TimerLayerChannelStore) CreateDirectChannel(userId *model.User, otherUserId *model.User) (*model.Channel, *model.AppError) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.ChannelStore.CreateDirectChannel(userId, otherUserId)
|
||||
|
||||
Ссылка в новой задаче
Block a user