diff options
author | Michael Muré <batolettre@gmail.com> | 2020-02-26 07:38:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-26 07:38:13 +0100 |
commit | 0c791483286ce2ed845bbc77b2a2899149ad83c5 (patch) | |
tree | 6129d0a6e2efbfa81b26534ee5aeb65ba1261bfe /identity/bare.go | |
parent | 68acfa519ab6656648d1e976db2a4190bbeb5f44 (diff) | |
parent | 893de4f5c0e852fac9a73e0c0243bc038af75f17 (diff) | |
download | git-bug-0c791483286ce2ed845bbc77b2a2899149ad83c5.tar.gz |
Merge pull request #343 from MichaelMure/login-is-back
identity: bring back the login to hold that info from bridges
Diffstat (limited to 'identity/bare.go')
-rw-r--r-- | identity/bare.go | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/identity/bare.go b/identity/bare.go index 58c278be..3e6ca32f 100644 --- a/identity/bare.go +++ b/identity/bare.go @@ -27,6 +27,7 @@ type Bare struct { id entity.Id name string email string + login string avatarUrl string } @@ -34,8 +35,8 @@ func NewBare(name string, email string) *Bare { return &Bare{id: entity.UnsetId, name: name, email: email} } -func NewBareFull(name string, email string, avatarUrl string) *Bare { - return &Bare{id: entity.UnsetId, name: name, email: email, avatarUrl: avatarUrl} +func NewBareFull(name string, email string, login string, avatarUrl string) *Bare { + return &Bare{id: entity.UnsetId, name: name, email: email, login: login, avatarUrl: avatarUrl} } func deriveId(data []byte) entity.Id { @@ -46,7 +47,7 @@ func deriveId(data []byte) entity.Id { type bareIdentityJSON struct { Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` - Login string `json:"login,omitempty"` // Deprecated, only kept to have the same ID when reading an old value + Login string `json:"login,omitempty"` AvatarUrl string `json:"avatar_url,omitempty"` } @@ -54,6 +55,7 @@ func (i *Bare) MarshalJSON() ([]byte, error) { return json.Marshal(bareIdentityJSON{ Name: i.name, Email: i.email, + Login: i.login, AvatarUrl: i.avatarUrl, }) } @@ -70,6 +72,7 @@ func (i *Bare) UnmarshalJSON(data []byte) error { i.name = aux.Name i.email = aux.Email + i.login = aux.Login i.avatarUrl = aux.AvatarUrl return nil @@ -108,6 +111,11 @@ func (i *Bare) Email() string { return i.email } +// Login return the last version of the login +func (i *Bare) Login() string { + return i.login +} + // AvatarUrl return the last version of the Avatar URL func (i *Bare) AvatarUrl() string { return i.avatarUrl @@ -126,13 +134,22 @@ func (i *Bare) ValidKeysAtTime(_ lamport.Time) []*Key { // DisplayName return a non-empty string to display, representing the // identity, based on the non-empty values. func (i *Bare) DisplayName() string { - return i.name + switch { + case i.name == "" && i.login != "": + return i.login + case i.name != "" && i.login == "": + return i.name + case i.name != "" && i.login != "": + return fmt.Sprintf("%s (%s)", i.name, i.login) + } + + panic("invalid person data") } // Validate check if the Identity data is valid func (i *Bare) Validate() error { - if text.Empty(i.name) { - return fmt.Errorf("name is not set") + if text.Empty(i.name) && text.Empty(i.login) { + return fmt.Errorf("either name or login should be set") } if strings.Contains(i.name, "\n") { @@ -143,6 +160,14 @@ func (i *Bare) Validate() error { return fmt.Errorf("name is not fully printable") } + if strings.Contains(i.login, "\n") { + return fmt.Errorf("login should be a single line") + } + + if !text.Safe(i.login) { + return fmt.Errorf("login is not fully printable") + } + if strings.Contains(i.email, "\n") { return fmt.Errorf("email should be a single line") } |