本文整理汇总了Golang中github.com/mattermost/platform/model.TeamMember.Roles方法的典型用法代码示例。如果您正苦于以下问题:Golang TeamMember.Roles方法的具体用法?Golang TeamMember.Roles怎么用?Golang TeamMember.Roles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mattermost/platform/model.TeamMember
的用法示例。
在下文中一共展示了TeamMember.Roles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateMemberRoles
func updateMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.MapFromJson(r.Body)
userId := props["user_id"]
if len(userId) != 26 {
c.SetInvalidParam("updateMemberRoles", "user_id")
return
}
mchan := Srv.Store.Team().GetTeamsForUser(userId)
teamId := c.TeamId
newRoles := props["new_roles"]
if !(model.IsValidUserRoles(newRoles)) {
c.SetInvalidParam("updateMemberRoles", "new_roles")
return
}
if !HasPermissionToTeamContext(c, teamId, model.PERMISSION_MANAGE_ROLES) {
return
}
var member *model.TeamMember
if result := <-mchan; result.Err != nil {
c.Err = result.Err
return
} else {
members := result.Data.([]*model.TeamMember)
for _, m := range members {
if m.TeamId == teamId {
member = m
}
}
}
if member == nil {
c.Err = model.NewLocAppError("updateMemberRoles", "api.team.update_member_roles.not_a_member", nil, "userId="+userId+" teamId="+teamId)
c.Err.StatusCode = http.StatusBadRequest
return
}
member.Roles = newRoles
if result := <-Srv.Store.Team().UpdateMember(member); result.Err != nil {
c.Err = result.Err
return
}
RemoveAllSessionsForUserId(userId)
rdata := map[string]string{}
rdata["status"] = "ok"
w.Write([]byte(model.MapToJson(rdata)))
}
示例2: LeaveTeam
func LeaveTeam(team *model.Team, user *model.User) *model.AppError {
var teamMember model.TeamMember
if result := <-Srv.Store.Team().GetMember(team.Id, user.Id); result.Err != nil {
return model.NewLocAppError("RemoveUserFromTeam", "api.team.remove_user_from_team.missing.app_error", nil, result.Err.Error())
} else {
teamMember = result.Data.(model.TeamMember)
}
var channelMembers *model.ChannelList
if result := <-Srv.Store.Channel().GetChannels(team.Id, user.Id); result.Err != nil {
if result.Err.Id == "store.sql_channel.get_channels.not_found.app_error" {
channelMembers = &model.ChannelList{make([]*model.Channel, 0), make(map[string]*model.ChannelMember)}
} else {
return result.Err
}
} else {
channelMembers = result.Data.(*model.ChannelList)
}
for _, channel := range channelMembers.Channels {
if channel.Type != model.CHANNEL_DIRECT {
if result := <-Srv.Store.Channel().RemoveMember(channel.Id, user.Id); result.Err != nil {
return result.Err
}
InvalidateCacheForChannel(channel.Id)
}
}
teamMember.Roles = ""
teamMember.DeleteAt = model.GetMillis()
if result := <-Srv.Store.Team().UpdateMember(&teamMember); result.Err != nil {
return result.Err
}
if uua := <-Srv.Store.User().UpdateUpdateAt(user.Id); uua.Err != nil {
return uua.Err
}
RemoveAllSessionsForUserId(user.Id)
InvalidateCacheForUser(user.Id)
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_LEAVE_TEAM, team.Id, "", "", nil)
message.Add("user_id", user.Id)
go Publish(message)
return nil
}