Use display name instead of username for shared calendar owners
Add db.DisplayName(username), returning the user's display name if
set, otherwise the raw username. Use it everywhere a shared calendar's
owner is shown: the web calendar legend ("shared by ..."), the "new
event"/edit calendar select label, the dashboard's "Shared with you"
list, and the CalDAV-side description/name-collision disambiguation
("Name (Owner)") shown to CalDAV clients like DAVx5.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -382,7 +382,7 @@ func (b *Backend) calendarMeta(owner, realName, localName string) caldav.Calenda
|
|||||||
// their own calendars (see sharedDisplayName) — the Description still
|
// their own calendars (see sharedDisplayName) — the Description still
|
||||||
// always names the real calendar, only the client-visible Name changes.
|
// always names the real calendar, only the client-visible Name changes.
|
||||||
func (b *Backend) calendarMetaNamed(owner, realName, localName, displayName string) caldav.Calendar {
|
func (b *Backend) calendarMetaNamed(owner, realName, localName, displayName string) caldav.Calendar {
|
||||||
desc := fmt.Sprintf("%s's %s calendar", owner, realName)
|
desc := fmt.Sprintf("%s's %s calendar", b.dbase.DisplayName(owner), realName)
|
||||||
return caldav.Calendar{
|
return caldav.Calendar{
|
||||||
Path: calHomePath() + localName + "/",
|
Path: calHomePath() + localName + "/",
|
||||||
// The displayed name is always the plain calendar name (never the
|
// The displayed name is always the plain calendar name (never the
|
||||||
@@ -408,9 +408,10 @@ func (b *Backend) sharedDisplayName(requester, owner, realName string) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
b.logger.Warn("listing own calendars for disambiguation", "error", err)
|
b.logger.Warn("listing own calendars for disambiguation", "error", err)
|
||||||
}
|
}
|
||||||
|
ownerLabel := b.dbase.DisplayName(owner)
|
||||||
for _, c := range own {
|
for _, c := range own {
|
||||||
if c.Name == realName {
|
if c.Name == realName {
|
||||||
return fmt.Sprintf("%s (%s)", realName, owner)
|
return fmt.Sprintf("%s (%s)", realName, ownerLabel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,7 +424,7 @@ func (b *Backend) sharedDisplayName(requester, owner, realName string) string {
|
|||||||
continue // the calendar itself, not a collision
|
continue // the calendar itself, not a collision
|
||||||
}
|
}
|
||||||
if sh.CalendarName == realName {
|
if sh.CalendarName == realName {
|
||||||
return fmt.Sprintf("%s (%s)", realName, owner)
|
return fmt.Sprintf("%s (%s)", realName, ownerLabel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return realName
|
return realName
|
||||||
|
|||||||
@@ -90,6 +90,19 @@ func (d *DB) SetProfile(username, displayName, email string) error {
|
|||||||
return requireRowsAffected(res, ErrUserNotFound)
|
return requireRowsAffected(res, ErrUserNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DisplayName returns username's display name if one is set, otherwise
|
||||||
|
// username itself. This is the friendly label to show wherever a user's
|
||||||
|
// identity is surfaced in the UI (e.g. "shared by <name>"), instead of
|
||||||
|
// the raw login username.
|
||||||
|
func (d *DB) DisplayName(username string) string {
|
||||||
|
u, err := d.GetUser(username)
|
||||||
|
if err != nil || u.DisplayName == "" {
|
||||||
|
return username
|
||||||
|
}
|
||||||
|
return u.DisplayName
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DeleteUser removes username along with all of its calendars, address
|
// DeleteUser removes username along with all of its calendars, address
|
||||||
// books, and sharing grants (calendars/addressbooks cascade via foreign
|
// books, and sharing grants (calendars/addressbooks cascade via foreign
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ func (s *Server) collectCalendarEvents(username string, gridStart, gridEnd time.
|
|||||||
hasWritable = true
|
hasWritable = true
|
||||||
}
|
}
|
||||||
calSummaries = append(calSummaries, templates.CalendarSummary{
|
calSummaries = append(calSummaries, templates.CalendarSummary{
|
||||||
Ref: entry.Ref, Name: entry.Name, Owner: entry.Owner, Color: entry.Color,
|
Ref: entry.Ref, Name: entry.Name, Owner: s.dbase.DisplayName(entry.Owner), Color: entry.Color,
|
||||||
Shared: entry.Owner != username, Writable: entry.Writable, Virtual: entry.Virtual,
|
Shared: entry.Owner != username, Writable: entry.Writable, Virtual: entry.Virtual,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -565,7 +565,7 @@ func (s *Server) handleEventNew(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
label := e.Name
|
label := e.Name
|
||||||
if e.Owner != username {
|
if e.Owner != username {
|
||||||
label = e.Name + " (" + e.Owner + ")"
|
label = e.Name + " (" + s.dbase.DisplayName(e.Owner) + ")"
|
||||||
}
|
}
|
||||||
options = append(options, templates.CalendarOption{Ref: e.Ref, Label: label})
|
options = append(options, templates.CalendarOption{Ref: e.Ref, Label: label})
|
||||||
}
|
}
|
||||||
@@ -668,7 +668,7 @@ func (s *Server) handleEventEdit(w http.ResponseWriter, r *http.Request) {
|
|||||||
form.CalRef = ref
|
form.CalRef = ref
|
||||||
label := name
|
label := name
|
||||||
if owner != username {
|
if owner != username {
|
||||||
label = name + " (" + owner + ")"
|
label = name + " (" + s.dbase.DisplayName(owner) + ")"
|
||||||
}
|
}
|
||||||
form.CalendarLabel = label
|
form.CalendarLabel = label
|
||||||
form.Writable = owner == username
|
form.Writable = owner == username
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
for _, sh := range calShares {
|
for _, sh := range calShares {
|
||||||
sharedWithMe = append(sharedWithMe, templates.SharedWithMeItem{
|
sharedWithMe = append(sharedWithMe, templates.SharedWithMeItem{
|
||||||
Kind: "calendar", Owner: sh.Owner, Name: sh.CalendarName, Permission: string(sh.Permission),
|
Kind: "calendar", Owner: s.dbase.DisplayName(sh.Owner), Name: sh.CalendarName, Permission: string(sh.Permission),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
bookShares, err := s.dbase.AddressBooksSharedWith(username)
|
bookShares, err := s.dbase.AddressBooksSharedWith(username)
|
||||||
@@ -35,7 +35,7 @@ func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
for _, sh := range bookShares {
|
for _, sh := range bookShares {
|
||||||
sharedWithMe = append(sharedWithMe, templates.SharedWithMeItem{
|
sharedWithMe = append(sharedWithMe, templates.SharedWithMeItem{
|
||||||
Kind: "addressbook", Owner: sh.Owner, Name: sh.AddressBookName, Permission: string(sh.Permission),
|
Kind: "addressbook", Owner: s.dbase.DisplayName(sh.Owner), Name: sh.AddressBookName, Permission: string(sh.Permission),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user