本文整理汇总了Golang中github.com/mattermost/platform/model.ChannelMember类的典型用法代码示例。如果您正苦于以下问题:Golang ChannelMember类的具体用法?Golang ChannelMember怎么用?Golang ChannelMember使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChannelMember类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestChannelStoreUpdateLastViewedAt
func TestChannelStoreUpdateLastViewedAt(t *testing.T) {
Setup()
o1 := model.Channel{}
o1.TeamId = model.NewId()
o1.DisplayName = "Channel1"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
o1.TotalMsgCount = 25
Must(store.Channel().Save(&o1))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
err := (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, m1.UserId)).Err
if err != nil {
t.Fatal("failed to update", err)
}
err = (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, "missing id")).Err
if err != nil {
t.Fatal("failed to update")
}
}
示例2: SaveMember
func (s SqlChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
if result.Err = member.IsValid(); result.Err != nil {
storeChannel <- result
return
}
if err := s.GetMaster().Insert(member); err != nil {
if strings.Contains(err.Error(), "Duplicate entry") && strings.Contains(err.Error(), "for key 'ChannelId'") {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "A channel member with that id already exists", "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
} else {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "We couldn't save the channel member", "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
}
} else {
result.Data = member
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
示例3: SaveMember
func (s SqlChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
member.PreSave()
if result.Err = member.IsValid(); result.Err != nil {
storeChannel <- result
return
}
if err := s.GetMaster().Insert(member); err != nil {
if IsUniqueConstraintError(err.Error(), "ChannelId", "channelmembers_pkey") {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "A channel member with that id already exists", "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
} else {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "We couldn't save the channel member", "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
}
} else {
result.Data = member
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
示例4: UpdateMember
func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
member.PreUpdate()
if result.Err = member.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
if _, err := s.GetMaster().Update(member); err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.UpdateMember", "store.sql_channel.update_member.app_error", nil,
"channel_id="+member.ChannelId+", "+"user_id="+member.UserId+", "+err.Error())
} else {
result.Data = member
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
示例5: SaveDirectChannel
func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
var result StoreResult
if directchannel.Type != model.CHANNEL_DIRECT {
result.Err = model.NewLocAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.not_direct.app_error", nil, "")
} else {
if transaction, err := s.GetMaster().Begin(); err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.open_transaction.app_error", nil, err.Error())
} else {
directchannel.TeamId = ""
channelResult := s.saveChannelT(transaction, directchannel)
if channelResult.Err != nil {
transaction.Rollback()
result.Err = channelResult.Err
result.Data = channelResult.Data
} else {
newChannel := channelResult.Data.(*model.Channel)
// Members need new channel ID
member1.ChannelId = newChannel.Id
member2.ChannelId = newChannel.Id
member1Result := s.saveMemberT(transaction, member1, newChannel)
member2Result := s.saveMemberT(transaction, member2, newChannel)
if member1Result.Err != nil || member2Result.Err != nil {
transaction.Rollback()
details := ""
if member1Result.Err != nil {
details += "Member1Err: " + member1Result.Err.Message
}
if member2Result.Err != nil {
details += "Member2Err: " + member2Result.Err.Message
}
result.Err = model.NewLocAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.add_members.app_error", nil, details)
} else {
if err := transaction.Commit(); err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.commit.app_error", nil, err.Error())
} else {
result = channelResult
}
}
}
}
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
示例6: SaveDirectChannel
func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
var result StoreResult
if directchannel.Type != model.CHANNEL_DIRECT {
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "Not a direct channel attempted to be created with SaveDirectChannel", "")
} else {
if transaction, err := s.GetMaster().Begin(); err != nil {
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "Unable to open transaction", err.Error())
} else {
channelResult := s.saveChannelT(transaction, directchannel)
if channelResult.Err != nil {
transaction.Rollback()
result.Err = channelResult.Err
} else {
newChannel := channelResult.Data.(*model.Channel)
// Members need new channel ID
member1.ChannelId = newChannel.Id
member2.ChannelId = newChannel.Id
member1Result := s.saveMemberT(transaction, member1, newChannel)
member2Result := s.saveMemberT(transaction, member2, newChannel)
if member1Result.Err != nil || member2Result.Err != nil {
transaction.Rollback()
details := ""
if member1Result.Err != nil {
details += "Member1Err: " + member1Result.Err.Message
}
if member2Result.Err != nil {
details += "Member2Err: " + member2Result.Err.Message
}
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "Unable to add direct channel members", details)
} else {
if err := transaction.Commit(); err != nil {
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "Ubable to commit transaction", err.Error())
} else {
result = channelResult
}
}
}
}
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
示例7: HasPermissionToChannel
func HasPermissionToChannel(user *model.User, teamMember *model.TeamMember, channelMember *model.ChannelMember, permission *model.Permission) bool {
if channelMember == nil {
return false
}
roles := channelMember.GetRoles()
if CheckIfRolesGrantPermission(roles, permission.Id) {
return true
}
return HasPermissionToTeam(user, teamMember, permission)
}
示例8: TestChannelStoreGet
func TestChannelStoreGet(t *testing.T) {
Setup()
o1 := model.Channel{}
o1.TeamId = model.NewId()
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&o1))
if r1 := <-store.Channel().Get(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Channel).ToJson() != o1.ToJson() {
t.Fatal("invalid returned channel")
}
}
if err := (<-store.Channel().Get("")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = model.NewId()
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(&u2))
o2 := model.Channel{}
o2.TeamId = model.NewId()
o2.DisplayName = "Direct Name"
o2.Name = "a" + model.NewId() + "b"
o2.Type = model.CHANNEL_DIRECT
m1 := model.ChannelMember{}
m1.ChannelId = o2.Id
m1.UserId = u1.Id
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
m2 := model.ChannelMember{}
m2.ChannelId = o2.Id
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveDirectChannel(&o2, &m1, &m2))
if r2 := <-store.Channel().Get(o2.Id); r2.Err != nil {
t.Fatal(r2.Err)
} else {
if r2.Data.(*model.Channel).ToJson() != o2.ToJson() {
t.Fatal("invalid returned channel")
}
}
}
示例9: TestChannelStorePermissionsTo
func TestChannelStorePermissionsTo(t *testing.T) {
Setup()
o1 := model.Channel{}
o1.TeamId = model.NewId()
o1.DisplayName = "Channel1"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&o1))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
count := (<-store.Channel().CheckPermissionsTo(o1.TeamId, o1.Id, m1.UserId)).Data.(int64)
if count != 1 {
t.Fatal("should have permissions")
}
count = (<-store.Channel().CheckPermissionsTo("junk", o1.Id, m1.UserId)).Data.(int64)
if count != 0 {
t.Fatal("shouldn't have permissions")
}
count = (<-store.Channel().CheckPermissionsTo(o1.TeamId, "junk", m1.UserId)).Data.(int64)
if count != 0 {
t.Fatal("shouldn't have permissions")
}
count = (<-store.Channel().CheckPermissionsTo(o1.TeamId, o1.Id, "junk")).Data.(int64)
if count != 0 {
t.Fatal("shouldn't have permissions")
}
channelId := (<-store.Channel().CheckPermissionsToByName(o1.TeamId, o1.Name, m1.UserId)).Data.(string)
if channelId != o1.Id {
t.Fatal("should have permissions")
}
channelId = (<-store.Channel().CheckPermissionsToByName(o1.TeamId, "missing", m1.UserId)).Data.(string)
if channelId != "" {
t.Fatal("should not have permissions")
}
}
示例10: TestChannelDeleteMemberStore
func TestChannelDeleteMemberStore(t *testing.T) {
Setup()
c1 := model.Channel{}
c1.TeamId = model.NewId()
c1.DisplayName = "NameName"
c1.Name = "a" + model.NewId() + "b"
c1.Type = model.CHANNEL_OPEN
c1 = *Must(store.Channel().Save(&c1)).(*model.Channel)
c1t1 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
t1 := c1t1.ExtraUpdateAt
u1 := model.User{}
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(&u1))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u1.Id}))
u2 := model.User{}
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(&u2))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u2.Id}))
o1 := model.ChannelMember{}
o1.ChannelId = c1.Id
o1.UserId = u1.Id
o1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&o1))
o2 := model.ChannelMember{}
o2.ChannelId = c1.Id
o2.UserId = u2.Id
o2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&o2))
c1t2 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
t2 := c1t2.ExtraUpdateAt
if t2 <= t1 {
t.Fatal("Member update time incorrect")
}
count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
if count != 2 {
t.Fatal("should have saved 2 members")
}
Must(store.Channel().PermanentDeleteMembersByUser(o2.UserId))
count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
if count != 1 {
t.Fatal("should have removed 1 member")
}
}
示例11: updateChannelMemberRoles
func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
channelId := params["channel_id"]
props := model.MapFromJson(r.Body)
userId := props["user_id"]
if len(userId) != 26 {
c.SetInvalidParam("updateChannelMemberRoles", "user_id")
return
}
mchan := app.Srv.Store.Channel().GetMember(channelId, userId)
newRoles := props["new_roles"]
if !(model.IsValidUserRoles(newRoles)) {
c.SetInvalidParam("updateChannelMemberRoles", "new_roles")
return
}
if !HasPermissionToChannelContext(c, channelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
return
}
var member model.ChannelMember
if result := <-mchan; result.Err != nil {
c.Err = result.Err
return
} else {
member = result.Data.(model.ChannelMember)
}
member.Roles = newRoles
if result := <-app.Srv.Store.Channel().UpdateMember(&member); result.Err != nil {
c.Err = result.Err
return
}
app.InvalidateCacheForUser(userId)
rdata := map[string]string{}
rdata["status"] = "ok"
w.Write([]byte(model.MapToJson(rdata)))
}
示例12: TestChannelStoreSaveDirectChannel
func TestChannelStoreSaveDirectChannel(t *testing.T) {
Setup()
teamId := model.NewId()
o1 := model.Channel{}
o1.TeamId = teamId
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_DIRECT
u1 := &model.User{}
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(u1))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u1.Id}))
u2 := &model.User{}
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(u2))
Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u2.Id}))
m1 := model.ChannelMember{}
m1.ChannelId = o1.Id
m1.UserId = u1.Id
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err != nil {
t.Fatal("couldn't save direct channel", err)
}
members := (<-store.Channel().GetMembers(o1.Id)).Data.([]model.ChannelMember)
if len(members) != 2 {
t.Fatal("should have saved 2 members")
}
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
t.Fatal("shouldn't be able to update from save")
}
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
if err := (<-store.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
t.Fatal("Should not be able to save non-direct channel")
}
}
示例13: TestChannelMemberStore
func TestChannelMemberStore(t *testing.T) {
Setup()
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
u1.FullName = model.NewId()
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = model.NewId()
u2.Email = model.NewId()
u2.FullName = model.NewId()
Must(store.User().Save(&u2))
o1 := model.ChannelMember{}
o1.ChannelId = model.NewId()
o1.UserId = u1.Id
o1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
Must(store.Channel().SaveMember(&o1))
o2 := model.ChannelMember{}
o2.ChannelId = o1.ChannelId
o2.UserId = u2.Id
o2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
Must(store.Channel().SaveMember(&o2))
members := (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember)
if len(members) != 2 {
t.Fatal("should have saved 2 members")
}
Must(store.Channel().RemoveMember(o2.ChannelId, o2.UserId))
members = (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember)
if len(members) != 1 {
t.Fatal("should have removed 1 member")
}
member := (<-store.Channel().GetMember(o1.ChannelId, o1.UserId)).Data.(model.ChannelMember)
if member.ChannelId != o1.ChannelId {
t.Fatal("should have go member")
}
extraMembers := (<-store.Channel().GetExtraMembers(o1.ChannelId, 20)).Data.([]model.ExtraMember)
if len(extraMembers) != 1 {
t.Fatal("should have 1 extra members")
}
if err := (<-store.Channel().SaveMember(&o1)).Err; err == nil {
t.Fatal("Should have been a duplicate")
}
}
示例14: saveMemberT
func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *model.ChannelMember, channel *model.Channel) StoreResult {
result := StoreResult{}
member.PreSave()
if result.Err = member.IsValid(); result.Err != nil {
return result
}
if err := transaction.Insert(member); err != nil {
if IsUniqueConstraintError(err.Error(), "ChannelId", "channelmembers_pkey") {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "A channel member with that id already exists", "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
} else {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "We couldn't save the channel member", "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
}
} else {
result.Data = member
}
return result
}
示例15: saveMemberT
func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *model.ChannelMember, channel *model.Channel) StoreResult {
result := StoreResult{}
member.PreSave()
if result.Err = member.IsValid(); result.Err != nil {
return result
}
if err := transaction.Insert(member); err != nil {
if IsUniqueConstraintError(err.Error(), []string{"ChannelId", "channelmembers_pkey"}) {
result.Err = model.NewLocAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.exists.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
} else {
result.Err = model.NewLocAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.save.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
}
} else {
result.Data = member
}
return result
}