AvatarURLPath returns the URL path to the user or organization avatar. If the user enables Gravatar-like service, then an external URL will be returned. TODO(unknwon): This is also used in templates, which should be fixed by having a dedicated type `template.User` and move this to the "userutil" pa
()
| 1371 | // having a dedicated type `template.User` and move this to the "userutil" |
| 1372 | // package. |
| 1373 | func (u *User) AvatarURLPath() string { |
| 1374 | defaultURLPath := conf.UserDefaultAvatarURLPath() |
| 1375 | if u.ID <= 0 { |
| 1376 | return defaultURLPath |
| 1377 | } |
| 1378 | |
| 1379 | hasCustomAvatar := osutil.IsFile(userutil.CustomAvatarPath(u.ID)) |
| 1380 | switch { |
| 1381 | case u.UseCustomAvatar: |
| 1382 | if !hasCustomAvatar { |
| 1383 | return defaultURLPath |
| 1384 | } |
| 1385 | return fmt.Sprintf("%s/%s/%d", conf.Server.Subpath, conf.UsersAvatarPathPrefix, u.ID) |
| 1386 | case conf.Picture.DisableGravatar: |
| 1387 | if !hasCustomAvatar { |
| 1388 | if err := userutil.GenerateRandomAvatar(u.ID, u.Name, u.Email); err != nil { |
| 1389 | log.Error("Failed to generate random avatar [user_id: %d]: %v", u.ID, err) |
| 1390 | } |
| 1391 | } |
| 1392 | return fmt.Sprintf("%s/%s/%d", conf.Server.Subpath, conf.UsersAvatarPathPrefix, u.ID) |
| 1393 | } |
| 1394 | return tool.AvatarLink(u.AvatarEmail) |
| 1395 | } |
| 1396 | |
| 1397 | // AvatarURL returns the full URL to the user or organization avatar. If the |
| 1398 | // user enables Gravatar-like service, then an external URL will be returned. |
no test coverage detected