Add new functions to channel, permissions, post and team services

Этот коммит содержится в:
Giorgi Bochorishvili
2022-12-13 19:47:01 +04:00
родитель 9668733615
Коммит df1865001e
5 изменённых файлов: 78 добавлений и 0 удалений

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

@@ -64,6 +64,43 @@ func (s *channelsWrapper) UpdateChannelSidebarCategories(userID, teamID string,
return s.app.UpdateSidebarCategories(request.EmptyContext(s.srv.Log()), userID, teamID, categories)
}
func (s *channelsWrapper) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
return s.app.CreateChannel(request.EmptyContext(s.srv.Log()), channel, false)
}
func (s *channelsWrapper) AddUserToChannel(channelID, userID, asUserID string) (*model.ChannelMember, *model.AppError) {
ctx := request.EmptyContext(s.srv.Log())
channel, err := s.app.GetChannel(ctx, channelID)
if err != nil {
return nil, err
}
return s.app.AddChannelMember(ctx, userID, channel, ChannelMemberOpts{
UserRequestorID: asUserID,
})
}
func (s *channelsWrapper) UpdateChannelMemberRoles(channelID, userID, newRoles string) (*model.ChannelMember, *model.AppError) {
return s.app.UpdateChannelMemberRoles(request.EmptyContext(s.srv.Log()), channelID, userID, newRoles)
}
func (s *channelsWrapper) DeleteChannelMember(channelID, userID string) *model.AppError {
return s.app.LeaveChannel(request.EmptyContext(s.srv.Log()), channelID, userID)
}
func (s *channelsWrapper) AddChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError) {
channel, err := s.GetChannelByID(channelID)
if err != nil {
return nil, err
}
return s.app.AddChannelMember(request.EmptyContext(s.srv.Log()), userID, channel, ChannelMemberOpts{
// For now, don't allow overriding these via the plugin API.
UserRequestorID: "",
PostRootID: "",
})
}
// Ensure the wrapper implements the product service.
var _ product.ChannelService = (*channelsWrapper)(nil)

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

@@ -41,6 +41,10 @@ func (s *permissionsServiceWrapper) HasPermissionToChannel(askingUserID string,
return s.app.HasPermissionToChannel(request.EmptyContext(s.app.Log()), askingUserID, channelID, permission)
}
func (s *permissionsServiceWrapper) RolesGrantPermission(roleNames []string, permissionId string) bool {
return s.app.RolesGrantPermission(roleNames, permissionId)
}
func (a *App) ResetPermissionsSystem() *model.AppError {
// Reset all Teams to not have a scheme.
if err := a.Srv().Store().Team().ResetAllTeamSchemes(); err != nil {

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

@@ -54,6 +54,18 @@ func (s *postServiceWrapper) SendEphemeralPost(ctx *request.Context, userID stri
return s.app.SendEphemeralPost(ctx, userID, post)
}
func (s *postServiceWrapper) GetPost(postID string) (*model.Post, *model.AppError) {
return s.app.GetSinglePost(postID, false)
}
func (s *postServiceWrapper) DeletePost(ctx *request.Context, postID, productID string) (*model.Post, *model.AppError) {
return s.app.DeletePost(ctx, postID, productID)
}
func (s *postServiceWrapper) UpdatePost(ctx *request.Context, post *model.Post, safeUpdate bool) (*model.Post, *model.AppError) {
return s.app.UpdatePost(ctx, post, false)
}
func (a *App) CreatePostAsUser(c request.CTX, post *model.Post, currentSessionId string, setOnline bool) (*model.Post, *model.AppError) {
// Check that channel has not been deleted
channel, errCh := a.Srv().Store().Channel().Get(post.ChannelId, true)

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

@@ -44,6 +44,19 @@ func (w *teamServiceWrapper) CreateMember(ctx *request.Context, teamID, userID s
return w.app.AddTeamMember(ctx, teamID, userID)
}
func (w *teamServiceWrapper) GetGroup(groupID string) (*model.Group, *model.AppError) {
return w.app.GetGroup(groupID, nil, nil)
}
func (w *teamServiceWrapper) GetTeam(teamID string) (*model.Team, *model.AppError) {
return w.app.GetTeam(teamID)
}
func (w *teamServiceWrapper) GetGroupMemberUsers(groupID string, page, perPage int) ([]*model.User, *model.AppError) {
users, _, err := w.app.GetGroupMemberUsersPage(groupID, page, perPage, nil)
return users, err
}
// Ensure the wrapper implements the product service.
var _ product.TeamService = (*teamServiceWrapper)(nil)

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

@@ -33,6 +33,9 @@ type PostService interface {
CreatePost(context *request.Context, post *model.Post) (*model.Post, *model.AppError)
GetPostsByIds(postIDs []string) ([]*model.Post, int64, *model.AppError)
SendEphemeralPost(ctx *request.Context, userID string, post *model.Post) *model.Post
GetPost(postID string) (*model.Post, *model.AppError)
DeletePost(ctx *request.Context, postID, productID string) (*model.Post, *model.AppError)
UpdatePost(c *request.Context, post *model.Post, safeUpdate bool) (*model.Post, *model.AppError)
}
// PermissionService provides permissions related utilities. For now, the service implementation
@@ -44,6 +47,7 @@ type PermissionService interface {
HasPermissionTo(userID string, permission *model.Permission) bool
HasPermissionToTeam(userID, teamID string, permission *model.Permission) bool
HasPermissionToChannel(askingUserID string, channelID string, permission *model.Permission) bool
RolesGrantPermission(roleNames []string, permissionID string) bool
}
// ClusterService enables to publish cluster events. In addition to that, It's being used for
@@ -69,6 +73,11 @@ type ChannelService interface {
GetChannelMembers(channelID string, page, perPage int) (model.ChannelMembers, *model.AppError)
CreateChannelSidebarCategory(userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError)
UpdateChannelSidebarCategories(userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError)
CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
AddUserToChannel(channelID, userID, asUserID string) (*model.ChannelMember, *model.AppError)
UpdateChannelMemberRoles(channelID, userID, newRoles string) (*model.ChannelMember, *model.AppError)
DeleteChannelMember(channelID, userID string) *model.AppError
AddChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError)
}
// LicenseService provides license related utilities.
@@ -99,6 +108,9 @@ type UserService interface {
type TeamService interface {
GetMember(teamID, userID string) (*model.TeamMember, *model.AppError)
CreateMember(ctx *request.Context, teamID, userID string) (*model.TeamMember, *model.AppError)
GetGroup(groupId string) (*model.Group, *model.AppError)
GetTeam(teamID string) (*model.Team, *model.AppError)
GetGroupMemberUsers(groupID string, page, perPage int) ([]*model.User, *model.AppError)
}
// BotService is just a copy implementation of mattermost-plugin-api EnsureBot method.