mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-05-11 23:41:03 -05:00
Add concept of adhoc system notification
This commit is contained in:
@@ -17,6 +17,9 @@ func (s *Server) createSystemNotificationContext(ctx context.Context, sess *sess
|
||||
renderCtx.Notification = notification.Message
|
||||
renderCtx.NotificationID = s.IDHasher.Encrypt(int(notification.ID))
|
||||
}
|
||||
} else if message, ok := sess.Get(ctx, session.KeyAdhocNotification).(string); ok && len(message) > 0 {
|
||||
renderCtx.Notification = message
|
||||
renderCtx.NotificationID = s.IDHasher.Encrypt(0)
|
||||
}
|
||||
|
||||
return renderCtx
|
||||
@@ -32,6 +35,7 @@ func (s *Server) dismissNotification(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id, value, err := common.IntPathArg(r, common.ParamID, s.IDHasher)
|
||||
if err == nil {
|
||||
slog.DebugContext(ctx, "About to dismiss system notification", "id", id)
|
||||
if id != 0 {
|
||||
if notificationID, ok := sess.Get(ctx, session.KeyNotificationID).(int32); ok {
|
||||
if notificationID != int32(id) {
|
||||
@@ -44,8 +48,10 @@ func (s *Server) dismissNotification(w http.ResponseWriter, r *http.Request) {
|
||||
slog.InfoContext(ctx, "Dismissed notification", "id", id)
|
||||
}
|
||||
} else {
|
||||
slog.DebugContext(ctx, "Skipping dismissing stub system notification")
|
||||
slog.Log(ctx, common.LevelTrace, "Dismissing ad-hoc system notification")
|
||||
_ = sess.Delete(ctx, session.KeyAdhocNotification)
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
logID := value
|
||||
|
||||
+1
-1
@@ -238,7 +238,7 @@ func (s *Server) createPortalBaseContext(ctx context.Context, orgID int32, sess
|
||||
|
||||
renderCtx := &portalBaseRenderContext{
|
||||
CsrfRenderContext: s.CreateCsrfContext(user),
|
||||
SystemNotificationContext: s.NotificationFunc(ctx, sess),
|
||||
SystemNotificationContext: s.createSystemNotificationContext(ctx, sess),
|
||||
Orgs: orgsToUserOrgs(orgs, s.IDHasher),
|
||||
CurrentOrg: stubUserOrg,
|
||||
Tab: tab,
|
||||
|
||||
@@ -65,7 +65,6 @@ type ViewModelHandler func(http.ResponseWriter, *http.Request) (*ViewModel, erro
|
||||
type AuditLogsConstructor func(context.Context, *dbgen.User, int, int) (*MainAuditLogsRenderContext, error)
|
||||
type PropertyRulesConstructor func(http.ResponseWriter, *http.Request) (Model, *common.AuditLogEvent, error)
|
||||
type OrgRulesConstructor func(http.ResponseWriter, *http.Request) (Model, *common.AuditLogEvent, error)
|
||||
type SystemNotificationConstructor func(context.Context, *session.Session) SystemNotificationContext
|
||||
|
||||
// AuditLogParser is a function type for parsing custom audit log types.
|
||||
// It receives the context, the raw audit log, and a pointer to the UserAuditLog to populate.
|
||||
@@ -174,7 +173,6 @@ type Server struct {
|
||||
TwoFactorDuration time.Duration
|
||||
LicenseService common.LicenseService
|
||||
Rules *RuleRegistry
|
||||
NotificationFunc SystemNotificationConstructor
|
||||
}
|
||||
|
||||
func (s *Server) createSettingsTabs() []*SettingsTab {
|
||||
@@ -230,7 +228,6 @@ func (s *Server) Init(ctx context.Context, templateBuilder *TemplatesBuilder, gi
|
||||
return s.CreateOrgRulesContext(w, r)
|
||||
}
|
||||
s.Rules = NewRuleRegistry()
|
||||
s.NotificationFunc = s.createSystemNotificationContext
|
||||
|
||||
platformCtx := &PlatformRenderContext{
|
||||
GitCommit: gitCommit,
|
||||
|
||||
@@ -35,6 +35,7 @@ const (
|
||||
KeyTwoFactorCodeTimestamp
|
||||
KeyOrgInviteID
|
||||
KeyFirstSession
|
||||
KeyAdhocNotification
|
||||
// Add new fields _above_
|
||||
SESSION_KEYS_COUNT
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user