Migrate Channel.GetMemberForPost to Sync by default (#11244)

* Migrate Channel.GetMemberForPost to Sync by default

* fix indentation
Этот коммит содержится в:
Sheshagiri Rao Mallipedhi
2019-06-20 13:07:26 +05:30
коммит произвёл Jesús Espino
родитель 327a1c92e8
Коммит be5c962913
5 изменённых файлов: 52 добавлений и 50 удалений

Просмотреть файл

@@ -66,9 +66,7 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
} }
func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool { func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool {
var channelMember *model.ChannelMember if channelMember, err := a.Srv.Store.Channel().GetMemberForPost(postId, session.UserId); err == nil {
if result := <-a.Srv.Store.Channel().GetMemberForPost(postId, session.UserId); result.Err == nil {
channelMember = result.Data.(*model.ChannelMember)
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) { if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
return true return true
@@ -165,10 +163,7 @@ func (a *App) HasPermissionToChannel(askingUserId string, channelId string, perm
} }
func (a *App) HasPermissionToChannelByPost(askingUserId string, postId string, permission *model.Permission) bool { func (a *App) HasPermissionToChannelByPost(askingUserId string, postId string, permission *model.Permission) bool {
var channelMember *model.ChannelMember if channelMember, err := a.Srv.Store.Channel().GetMemberForPost(postId, askingUserId); err == nil {
if result := <-a.Srv.Store.Channel().GetMemberForPost(postId, askingUserId); result.Err == nil {
channelMember = result.Data.(*model.ChannelMember)
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) { if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
return true return true
} }

Просмотреть файл

@@ -1464,11 +1464,9 @@ func (s SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string
return false return false
} }
func (s SqlChannelStore) GetMemberForPost(postId string, userId string) store.StoreChannel { func (s SqlChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) {
return store.Do(func(result *store.StoreResult) {
var dbMember channelMemberWithSchemeRoles var dbMember channelMemberWithSchemeRoles
if err := s.GetReplica().SelectOne(&dbMember, query := `
`
SELECT SELECT
ChannelMembers.*, ChannelMembers.*,
TeamScheme.DefaultChannelGuestRole TeamSchemeDefaultGuestRole, TeamScheme.DefaultChannelGuestRole TeamSchemeDefaultGuestRole,
@@ -1491,12 +1489,12 @@ func (s SqlChannelStore) GetMemberForPost(postId string, userId string) store.St
Schemes TeamScheme ON Teams.SchemeId = TeamScheme.Id Schemes TeamScheme ON Teams.SchemeId = TeamScheme.Id
WHERE WHERE
ChannelMembers.UserId = :UserId ChannelMembers.UserId = :UserId
AND Posts.Id = :PostId`, map[string]interface{}{"UserId": userId, "PostId": postId}); err != nil { AND
result.Err = model.NewAppError("SqlChannelStore.GetMemberForPost", "store.sql_channel.get_member_for_post.app_error", nil, "postId="+postId+", err="+err.Error(), http.StatusInternalServerError) Posts.Id = :PostId`
return if err := s.GetReplica().SelectOne(&dbMember, query, map[string]interface{}{"UserId": userId, "PostId": postId}); err != nil {
return nil, model.NewAppError("SqlChannelStore.GetMemberForPost", "store.sql_channel.get_member_for_post.app_error", nil, "postId="+postId+", err="+err.Error(), http.StatusInternalServerError)
} }
result.Data = dbMember.ToModel() return dbMember.ToModel(), nil
})
} }
func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) store.StoreChannel { func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) store.StoreChannel {

Просмотреть файл

@@ -167,7 +167,7 @@ type ChannelStore interface {
IsUserInChannelUseCache(userId string, channelId string) bool IsUserInChannelUseCache(userId string, channelId string) bool
GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError)
InvalidateCacheForChannelMembersNotifyProps(channelId string) InvalidateCacheForChannelMembersNotifyProps(channelId string)
GetMemberForPost(postId string, userId string) StoreChannel GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError)
InvalidateMemberCount(channelId string) InvalidateMemberCount(channelId string)
GetMemberCountFromCache(channelId string) int64 GetMemberCountFromCache(channelId string) int64
GetMemberCount(channelId string, allowFromCache bool) StoreChannel GetMemberCount(channelId string, allowFromCache bool) StoreChannel

Просмотреть файл

@@ -1865,13 +1865,13 @@ func testChannelStoreGetMemberForPost(t *testing.T, ss store.Store) {
}) })
require.Nil(t, err) require.Nil(t, err)
if r1 := <-ss.Channel().GetMemberForPost(p1.Id, m1.UserId); r1.Err != nil { if r1, err := ss.Channel().GetMemberForPost(p1.Id, m1.UserId); err != nil {
t.Fatal(r1.Err) t.Fatal(err)
} else if r1.Data.(*model.ChannelMember).ToJson() != m1.ToJson() { } else if r1.ToJson() != m1.ToJson() {
t.Fatal("invalid returned channel member") t.Fatal("invalid returned channel member")
} }
if r2 := <-ss.Channel().GetMemberForPost(p1.Id, model.NewId()); r2.Err == nil { if _, err := ss.Channel().GetMemberForPost(p1.Id, model.NewId()); err == nil {
t.Fatal("shouldn't have returned a member") t.Fatal("shouldn't have returned a member")
} }
} }

Просмотреть файл

@@ -705,19 +705,28 @@ func (_m *ChannelStore) GetMemberCountFromCache(channelId string) int64 {
} }
// GetMemberForPost provides a mock function with given fields: postId, userId // GetMemberForPost provides a mock function with given fields: postId, userId
func (_m *ChannelStore) GetMemberForPost(postId string, userId string) store.StoreChannel { func (_m *ChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) {
ret := _m.Called(postId, userId) ret := _m.Called(postId, userId)
var r0 store.StoreChannel var r0 *model.ChannelMember
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, string) *model.ChannelMember); ok {
r0 = rf(postId, userId) r0 = rf(postId, userId)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.ChannelMember)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
r1 = rf(postId, userId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetMembers provides a mock function with given fields: channelId, offset, limit // GetMembers provides a mock function with given fields: channelId, offset, limit