github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/app/export_converters.go (about)

     1  // Copyright (c) 2015-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  	"strings"
     9  )
    10  
    11  func ImportLineFromTeam(team *model.TeamForExport) *LineImportData {
    12  	return &LineImportData{
    13  		Type: "team",
    14  		Team: &TeamImportData{
    15  			Name:            &team.Name,
    16  			DisplayName:     &team.DisplayName,
    17  			Type:            &team.Type,
    18  			Description:     &team.Description,
    19  			AllowOpenInvite: &team.AllowOpenInvite,
    20  			Scheme:          team.SchemeName,
    21  		},
    22  	}
    23  }
    24  
    25  func ImportLineFromChannel(channel *model.ChannelForExport) *LineImportData {
    26  	return &LineImportData{
    27  		Type: "channel",
    28  		Channel: &ChannelImportData{
    29  			Team:        &channel.TeamName,
    30  			Name:        &channel.Name,
    31  			DisplayName: &channel.DisplayName,
    32  			Type:        &channel.Type,
    33  			Header:      &channel.Header,
    34  			Purpose:     &channel.Purpose,
    35  			Scheme:      channel.SchemeName,
    36  		},
    37  	}
    38  }
    39  
    40  func ImportLineFromUser(user *model.User) *LineImportData {
    41  	// Bulk Importer doesn't accept "empty string" for AuthService.
    42  	var authService *string
    43  	if user.AuthService != "" {
    44  		authService = &user.AuthService
    45  	}
    46  
    47  	return &LineImportData{
    48  		Type: "user",
    49  		User: &UserImportData{
    50  			Username:    &user.Username,
    51  			Email:       &user.Email,
    52  			AuthService: authService,
    53  			AuthData:    user.AuthData,
    54  			Nickname:    &user.Nickname,
    55  			FirstName:   &user.FirstName,
    56  			LastName:    &user.LastName,
    57  			Position:    &user.Position,
    58  			Roles:       &user.Roles,
    59  			Locale:      &user.Locale,
    60  		},
    61  	}
    62  }
    63  
    64  func ImportUserTeamDataFromTeamMember(member *model.TeamMemberForExport) *UserTeamImportData {
    65  	rolesList := strings.Fields(member.Roles)
    66  	if member.SchemeAdmin {
    67  		rolesList = append(rolesList, model.TEAM_ADMIN_ROLE_ID)
    68  	}
    69  	if member.SchemeUser {
    70  		rolesList = append(rolesList, model.TEAM_USER_ROLE_ID)
    71  	}
    72  	roles := strings.Join(rolesList, " ")
    73  	return &UserTeamImportData{
    74  		Name:  &member.TeamName,
    75  		Roles: &roles,
    76  	}
    77  }
    78  
    79  func ImportUserChannelDataFromChannelMember(member *model.ChannelMemberForExport) *UserChannelImportData {
    80  	rolesList := strings.Fields(member.Roles)
    81  	if member.SchemeAdmin {
    82  		rolesList = append(rolesList, model.CHANNEL_ADMIN_ROLE_ID)
    83  	}
    84  	if member.SchemeUser {
    85  		rolesList = append(rolesList, model.CHANNEL_USER_ROLE_ID)
    86  	}
    87  	roles := strings.Join(rolesList, " ")
    88  	return &UserChannelImportData{
    89  		Name:  &member.ChannelName,
    90  		Roles: &roles,
    91  	}
    92  }
    93  
    94  func ImportLineForPost(post *model.PostForExport) *LineImportData {
    95  	return &LineImportData{
    96  		Type: "post",
    97  		Post: &PostImportData{
    98  			Team:     &post.TeamName,
    99  			Channel:  &post.ChannelName,
   100  			User:     &post.Username,
   101  			Message:  &post.Message,
   102  			CreateAt: &post.CreateAt,
   103  		},
   104  	}
   105  }
   106  
   107  func ImportReplyFromPost(post *model.ReplyForExport) *ReplyImportData {
   108  	return &ReplyImportData{
   109  		User:     &post.Username,
   110  		Message:  &post.Message,
   111  		CreateAt: &post.CreateAt,
   112  	}
   113  }