gitlab.com/evatix-go/core@v1.3.55/coredata/corepayload/UserInfo.go (about)

     1  package corepayload
     2  
     3  type UserInfo struct {
     4  	User       *User `json:"User,omitempty"`       // refers to control panel or any kinds of virtual user
     5  	SystemUser *User `json:"SystemUser,omitempty"` // System or OS user
     6  }
     7  
     8  func (it *UserInfo) SetUserSystemUser(
     9  	user, systemUser *User,
    10  ) *UserInfo {
    11  	if it == nil {
    12  		return &UserInfo{
    13  			User:       user,
    14  			SystemUser: systemUser,
    15  		}
    16  	}
    17  
    18  	it.User = user
    19  	it.SystemUser = systemUser
    20  
    21  	return it
    22  }
    23  
    24  // SetUser
    25  //
    26  // on null creates new
    27  func (it *UserInfo) SetUser(
    28  	user *User,
    29  ) *UserInfo {
    30  	if it == nil {
    31  		return &UserInfo{
    32  			User: user,
    33  		}
    34  	}
    35  
    36  	it.User = user
    37  
    38  	return it
    39  }
    40  
    41  // SetSystemUser
    42  //
    43  // on null creates new
    44  func (it *UserInfo) SetSystemUser(
    45  	systemUser *User,
    46  ) *UserInfo {
    47  	if it == nil {
    48  		return &UserInfo{
    49  			SystemUser: systemUser,
    50  		}
    51  	}
    52  
    53  	it.SystemUser = systemUser
    54  
    55  	return it
    56  }
    57  
    58  func (it *UserInfo) HasUser() bool {
    59  	return it != nil && it.User.IsValidUser()
    60  }
    61  
    62  func (it *UserInfo) HasSystemUser() bool {
    63  	return it != nil && it.SystemUser.IsValidUser()
    64  }
    65  
    66  func (it *UserInfo) IsEmpty() bool {
    67  	return it == nil || it.User.IsEmpty() && it.SystemUser.IsEmpty()
    68  }
    69  
    70  func (it *UserInfo) IsUserEmpty() bool {
    71  	return it == nil || it.User.IsEmpty()
    72  }
    73  
    74  func (it *UserInfo) IsSystemUserEmpty() bool {
    75  	return it == nil || it.SystemUser.IsEmpty()
    76  }
    77  
    78  func (it *UserInfo) Clone() UserInfo {
    79  	return UserInfo{
    80  		User:       it.User.ClonePtr(),
    81  		SystemUser: it.SystemUser.ClonePtr(),
    82  	}
    83  }
    84  
    85  func (it *UserInfo) ClonePtr() *UserInfo {
    86  	if it == nil {
    87  		return nil
    88  	}
    89  
    90  	return it.Clone().Ptr()
    91  }
    92  
    93  func (it UserInfo) Ptr() *UserInfo {
    94  	return &it
    95  }
    96  
    97  func (it *UserInfo) ToNonPtr() UserInfo {
    98  	if it == nil {
    99  		return UserInfo{}
   100  	}
   101  
   102  	return *it
   103  }