4f04323d5a
The nonshy website is changing the policy on profile pictures. From August 30, the square cropped avatar images will need to be publicly viewable to everyone. This implements the first pass of the rollout: * Add the Public Avatar Consent Page which explains the change to users and asks for their acknowledgement. The link is available from their User Settings page, near their Certification Photo link. * When users (with non-public avatars) accept the change: their square cropped avatar will become visible to everybody, instead of showing a placeholder avatar. * Users can change their mind and opt back out, which will again show the placeholder avatar. * The Certification Required middleware will automatically enforce the consent page once the scheduled go-live date arrives. Next steps are: 1. Post an announcement on the forum about the upcoming change and link users to the consent form if they want to check it out early. 2. Update the nonshy site to add banners to places like the User Dashboard for users who will be affected by the change, to link them to the forum post and the consent page.
138 lines
4.0 KiB
Go
138 lines
4.0 KiB
Go
package templates
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/config"
|
|
"code.nonshy.com/nonshy/website/pkg/log"
|
|
"code.nonshy.com/nonshy/website/pkg/models"
|
|
"code.nonshy.com/nonshy/website/pkg/session"
|
|
"code.nonshy.com/nonshy/website/pkg/worker"
|
|
)
|
|
|
|
// MergeVars mixes in globally available template variables. The http.Request is optional.
|
|
func MergeVars(r *http.Request, m map[string]interface{}) {
|
|
m["Title"] = config.Title
|
|
m["BuildHash"] = config.RuntimeBuild
|
|
m["BuildDate"] = config.RuntimeBuildDate
|
|
m["Subtitle"] = config.Subtitle
|
|
m["YYYY"] = time.Now().Year()
|
|
m["WebsiteTheme"] = ""
|
|
|
|
// Integrations
|
|
m["TurnstileCAPTCHA"] = config.Current.Turnstile
|
|
|
|
// Temporary? variables for migration efforts on PublicAvatar consent.
|
|
m["PublicAvatarEnforcementDate"] = config.PublicAvatarEnforcementDate
|
|
|
|
if r == nil {
|
|
return
|
|
}
|
|
|
|
m["Request"] = r
|
|
}
|
|
|
|
// MergeUserVars mixes in global template variables: LoggedIn and CurrentUser. The http.Request is optional.
|
|
func MergeUserVars(r *http.Request, m map[string]interface{}) {
|
|
// Defaults
|
|
m["LoggedIn"] = false
|
|
m["CurrentUser"] = nil
|
|
m["SessionImpersonated"] = false
|
|
|
|
// User notification counts for nav bar.
|
|
m["NavUnreadMessages"] = 0 // New messages
|
|
m["NavFriendRequests"] = 0 // Friend requests
|
|
m["NavUnreadNotifications"] = 0 // general notifications
|
|
m["NavTotalNotifications"] = 0 // Total of above
|
|
m["NavChatStatistics"] = worker.GetChatStatistics()
|
|
|
|
// Admin notification counts for nav bar.
|
|
m["NavCertificationPhotos"] = 0 // Cert. photos needing approval
|
|
m["NavAdminFeedback"] = 0 // Unacknowledged feedback
|
|
m["NavAdminNotifications"] = 0 // Total of above
|
|
|
|
if r == nil {
|
|
return
|
|
}
|
|
|
|
m["SessionImpersonated"] = session.Impersonated(r)
|
|
|
|
if user, err := session.CurrentUser(r); err == nil {
|
|
m["LoggedIn"] = true
|
|
m["CurrentUser"] = user
|
|
|
|
// User website preferences
|
|
m["WebsiteTheme"] = user.GetProfileField("website-theme")
|
|
|
|
// Get user recent notifications.
|
|
/*notifPager := &models.Pagination{
|
|
Page: 1,
|
|
PerPage: 10,
|
|
}
|
|
if notifs, err := models.PaginateNotifications(user, notifPager); err == nil {
|
|
m["Notifications"] = notifs
|
|
}*/
|
|
|
|
// Collect notification counts.
|
|
var (
|
|
// For users
|
|
countMessages int64
|
|
countFriendReqs int64
|
|
countNotifications int64
|
|
|
|
// For admins
|
|
countCertPhotos int64
|
|
countFeedback int64
|
|
)
|
|
|
|
// Get unread message count.
|
|
if count, err := models.CountUnreadMessages(user); err == nil {
|
|
m["NavUnreadMessages"] = count
|
|
countMessages = count
|
|
} else {
|
|
log.Error("MergeUserVars: couldn't CountUnreadMessages for %d: %s", user.ID, err)
|
|
}
|
|
|
|
// Get friend request count.
|
|
if count, err := models.CountFriendRequests(user.ID); err == nil {
|
|
m["NavFriendRequests"] = count
|
|
countFriendReqs = count
|
|
} else {
|
|
log.Error("MergeUserVars: couldn't CountFriendRequests for %d: %s", user.ID, err)
|
|
}
|
|
|
|
// Count other notifications.
|
|
if count, err := models.CountUnreadNotifications(user); err == nil {
|
|
m["NavUnreadNotifications"] = count
|
|
countNotifications = count
|
|
} else {
|
|
log.Error("MergeUserVars: couldn't CountFriendRequests for %d: %s", user.ID, err)
|
|
}
|
|
|
|
// Are we admin? Add notification counts if the current admin can respond to them.
|
|
if user.IsAdmin {
|
|
var countCertPhotos, countFeedback int64
|
|
|
|
// Any pending certification photos or feedback?
|
|
if user.HasAdminScope(config.ScopeCertificationApprove) {
|
|
countCertPhotos = models.CountCertificationPhotosNeedingApproval()
|
|
}
|
|
|
|
// Admin feedback available?
|
|
if user.HasAdminScope(config.ScopeFeedbackAndReports) {
|
|
countFeedback = models.CountUnreadFeedback()
|
|
}
|
|
|
|
m["NavCertificationPhotos"] = countCertPhotos
|
|
m["NavAdminFeedback"] = countFeedback
|
|
|
|
// Total notification count for admin actions.
|
|
m["NavAdminNotifications"] = countCertPhotos + countFeedback
|
|
}
|
|
|
|
// Total count for user notifications.
|
|
m["NavTotalNotifications"] = countMessages + countFriendReqs + countNotifications + countCertPhotos + countFeedback
|
|
}
|
|
}
|