github.com/nhannv/mattermost-server@v5.11.1+incompatible/app/group.go (about)

     1  // Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"github.com/mattermost/mattermost-server/model"
     8  )
     9  
    10  func (a *App) GetGroup(id string) (*model.Group, *model.AppError) {
    11  	result := <-a.Srv.Store.Group().Get(id)
    12  	if result.Err != nil {
    13  		return nil, result.Err
    14  	}
    15  	return result.Data.(*model.Group), nil
    16  }
    17  
    18  func (a *App) GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) {
    19  	result := <-a.Srv.Store.Group().GetByRemoteID(remoteID, groupSource)
    20  	if result.Err != nil {
    21  		return nil, result.Err
    22  	}
    23  	return result.Data.(*model.Group), nil
    24  }
    25  
    26  func (a *App) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) {
    27  	result := <-a.Srv.Store.Group().GetAllBySource(groupSource)
    28  	if result.Err != nil {
    29  		return nil, result.Err
    30  	}
    31  	return result.Data.([]*model.Group), nil
    32  }
    33  
    34  func (a *App) CreateGroup(group *model.Group) (*model.Group, *model.AppError) {
    35  	result := <-a.Srv.Store.Group().Create(group)
    36  	if result.Err != nil {
    37  		return nil, result.Err
    38  	}
    39  	return result.Data.(*model.Group), nil
    40  }
    41  
    42  func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
    43  	result := <-a.Srv.Store.Group().Update(group)
    44  	if result.Err != nil {
    45  		return nil, result.Err
    46  	}
    47  	return result.Data.(*model.Group), nil
    48  }
    49  
    50  func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) {
    51  	result := <-a.Srv.Store.Group().Delete(groupID)
    52  	if result.Err != nil {
    53  		return nil, result.Err
    54  	}
    55  	return result.Data.(*model.Group), nil
    56  }
    57  
    58  func (a *App) GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppError) {
    59  	result := <-a.Srv.Store.Group().GetMemberUsers(groupID)
    60  	if result.Err != nil {
    61  		return nil, result.Err
    62  	}
    63  	return result.Data.([]*model.User), nil
    64  }
    65  
    66  func (a *App) GetGroupMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, int, *model.AppError) {
    67  	result := <-a.Srv.Store.Group().GetMemberUsersPage(groupID, page, perPage)
    68  	if result.Err != nil {
    69  		return nil, 0, result.Err
    70  	}
    71  	members := result.Data.([]*model.User)
    72  	result = <-a.Srv.Store.Group().GetMemberCount(groupID)
    73  	if result.Err != nil {
    74  		return nil, 0, result.Err
    75  	}
    76  	count := int(result.Data.(int64))
    77  	return members, count, nil
    78  }
    79  
    80  func (a *App) CreateOrRestoreGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
    81  	result := <-a.Srv.Store.Group().CreateOrRestoreMember(groupID, userID)
    82  	if result.Err != nil {
    83  		return nil, result.Err
    84  	}
    85  	return result.Data.(*model.GroupMember), nil
    86  }
    87  
    88  func (a *App) DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
    89  	result := <-a.Srv.Store.Group().DeleteMember(groupID, userID)
    90  	if result.Err != nil {
    91  		return nil, result.Err
    92  	}
    93  	return result.Data.(*model.GroupMember), nil
    94  }
    95  
    96  func (a *App) CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
    97  	result := <-a.Srv.Store.Group().CreateGroupSyncable(groupSyncable)
    98  	if result.Err != nil {
    99  		return nil, result.Err
   100  	}
   101  	return result.Data.(*model.GroupSyncable), nil
   102  }
   103  
   104  func (a *App) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
   105  	result := <-a.Srv.Store.Group().GetGroupSyncable(groupID, syncableID, syncableType)
   106  	if result.Err != nil {
   107  		return nil, result.Err
   108  	}
   109  	return result.Data.(*model.GroupSyncable), nil
   110  }
   111  
   112  func (a *App) GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) {
   113  	result := <-a.Srv.Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType)
   114  	if result.Err != nil {
   115  		return nil, result.Err
   116  	}
   117  	return result.Data.([]*model.GroupSyncable), nil
   118  }
   119  
   120  func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
   121  	result := <-a.Srv.Store.Group().UpdateGroupSyncable(groupSyncable)
   122  	if result.Err != nil {
   123  		return nil, result.Err
   124  	}
   125  	return result.Data.(*model.GroupSyncable), nil
   126  }
   127  
   128  func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
   129  	result := <-a.Srv.Store.Group().DeleteGroupSyncable(groupID, syncableID, syncableType)
   130  	if result.Err != nil {
   131  		return nil, result.Err
   132  	}
   133  	return result.Data.(*model.GroupSyncable), nil
   134  }
   135  
   136  func (a *App) PendingAutoAddTeamMembers(minGroupMembersCreateAt int64) ([]*model.UserTeamIDPair, *model.AppError) {
   137  	result := <-a.Srv.Store.Group().PendingAutoAddTeamMembers(minGroupMembersCreateAt)
   138  	if result.Err != nil {
   139  		return nil, result.Err
   140  	}
   141  	return result.Data.([]*model.UserTeamIDPair), nil
   142  }
   143  
   144  func (a *App) PendingAutoAddChannelMembers(minGroupMembersCreateAt int64) ([]*model.UserChannelIDPair, *model.AppError) {
   145  	result := <-a.Srv.Store.Group().PendingAutoAddChannelMembers(minGroupMembersCreateAt)
   146  	if result.Err != nil {
   147  		return nil, result.Err
   148  	}
   149  	return result.Data.([]*model.UserChannelIDPair), nil
   150  }