mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-06 17:54:31 +02:00
rename display helper for user
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
236ad30d61
commit
c0f856256a
@ -513,7 +513,7 @@ func renderOIDCCallbackTemplate(
|
|||||||
) (*bytes.Buffer, error) {
|
) (*bytes.Buffer, error) {
|
||||||
var content bytes.Buffer
|
var content bytes.Buffer
|
||||||
if err := oidcCallbackTemplate.Execute(&content, oidcCallbackTemplateConfig{
|
if err := oidcCallbackTemplate.Execute(&content, oidcCallbackTemplateConfig{
|
||||||
User: user.DisplayNameOrUsername(),
|
User: user.Display(),
|
||||||
Verb: verb,
|
Verb: verb,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, fmt.Errorf("rendering OIDC callback template: %w", err)
|
return nil, fmt.Errorf("rendering OIDC callback template: %w", err)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||||
"github.com/juanfont/headscale/hscontrol/util"
|
"github.com/juanfont/headscale/hscontrol/util"
|
||||||
@ -18,6 +19,19 @@ import (
|
|||||||
|
|
||||||
type UserID uint64
|
type UserID uint64
|
||||||
|
|
||||||
|
type Users []User
|
||||||
|
|
||||||
|
func (u Users) String() string {
|
||||||
|
var sb strings.Builder
|
||||||
|
sb.WriteString("[ ")
|
||||||
|
for _, user := range u {
|
||||||
|
fmt.Fprintf(&sb, "%d: %s, ", user.ID, user.Name)
|
||||||
|
}
|
||||||
|
sb.WriteString(" ]")
|
||||||
|
|
||||||
|
return sb.String()
|
||||||
|
}
|
||||||
|
|
||||||
// User is the way Headscale implements the concept of users in Tailscale
|
// User is the way Headscale implements the concept of users in Tailscale
|
||||||
//
|
//
|
||||||
// At the end of the day, users in Tailscale are some kind of 'bubbles' or users
|
// At the end of the day, users in Tailscale are some kind of 'bubbles' or users
|
||||||
@ -74,12 +88,13 @@ func (u *User) Username() string {
|
|||||||
u.Email,
|
u.Email,
|
||||||
u.Name,
|
u.Name,
|
||||||
u.ProviderIdentifier.String,
|
u.ProviderIdentifier.String,
|
||||||
u.StringID())
|
u.StringID(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisplayNameOrUsername returns the DisplayName if it exists, otherwise
|
// Display returns the DisplayName if it exists, otherwise
|
||||||
// it will return the Username.
|
// it will return the Username.
|
||||||
func (u *User) DisplayNameOrUsername() string {
|
func (u *User) Display() string {
|
||||||
return cmp.Or(u.DisplayName, u.Username())
|
return cmp.Or(u.DisplayName, u.Username())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +106,7 @@ func (u *User) profilePicURL() string {
|
|||||||
func (u *User) TailscaleUser() *tailcfg.User {
|
func (u *User) TailscaleUser() *tailcfg.User {
|
||||||
user := tailcfg.User{
|
user := tailcfg.User{
|
||||||
ID: tailcfg.UserID(u.ID),
|
ID: tailcfg.UserID(u.ID),
|
||||||
DisplayName: u.DisplayNameOrUsername(),
|
DisplayName: u.Display(),
|
||||||
ProfilePicURL: u.profilePicURL(),
|
ProfilePicURL: u.profilePicURL(),
|
||||||
Created: u.CreatedAt,
|
Created: u.CreatedAt,
|
||||||
}
|
}
|
||||||
@ -101,11 +116,10 @@ func (u *User) TailscaleUser() *tailcfg.User {
|
|||||||
|
|
||||||
func (u *User) TailscaleLogin() *tailcfg.Login {
|
func (u *User) TailscaleLogin() *tailcfg.Login {
|
||||||
login := tailcfg.Login{
|
login := tailcfg.Login{
|
||||||
ID: tailcfg.LoginID(u.ID),
|
ID: tailcfg.LoginID(u.ID),
|
||||||
// TODO(kradalby): this should reflect registration method.
|
|
||||||
Provider: u.Provider,
|
Provider: u.Provider,
|
||||||
LoginName: u.Username(),
|
LoginName: u.Username(),
|
||||||
DisplayName: u.DisplayNameOrUsername(),
|
DisplayName: u.Display(),
|
||||||
ProfilePicURL: u.profilePicURL(),
|
ProfilePicURL: u.profilePicURL(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +130,7 @@ func (u *User) TailscaleUserProfile() tailcfg.UserProfile {
|
|||||||
return tailcfg.UserProfile{
|
return tailcfg.UserProfile{
|
||||||
ID: tailcfg.UserID(u.ID),
|
ID: tailcfg.UserID(u.ID),
|
||||||
LoginName: u.Username(),
|
LoginName: u.Username(),
|
||||||
DisplayName: u.DisplayNameOrUsername(),
|
DisplayName: u.Display(),
|
||||||
ProfilePicURL: u.profilePicURL(),
|
ProfilePicURL: u.profilePicURL(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user