fix(notifications): update and list password (#1951)

This commit is contained in:
ze0s 2025-01-25 18:34:49 +01:00 committed by GitHub
parent 3f8bc0140c
commit 9eff694a5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 37 deletions

View file

@ -30,7 +30,7 @@ func NewNotificationRepo(log logger.Logger, db *DB) domain.NotificationRepo {
func (r *NotificationRepo) Find(ctx context.Context, params domain.NotificationQueryParams) ([]domain.Notification, int, error) {
queryBuilder := r.db.squirrel.
Select("id", "name", "type", "enabled", "events", "webhook", "token", "api_key", "channel", "priority", "topic", "host", "username", "created_at", "updated_at", "COUNT(*) OVER() AS total_count").
Select("id", "name", "type", "enabled", "events", "webhook", "token", "api_key", "channel", "priority", "topic", "host", "username", "password", "created_at", "updated_at", "COUNT(*) OVER() AS total_count").
From("notification").
OrderBy("name")
@ -51,19 +51,20 @@ func (r *NotificationRepo) Find(ctx context.Context, params domain.NotificationQ
for rows.Next() {
var n domain.Notification
var webhook, token, apiKey, channel, host, topic, username sql.NullString
var webhook, token, apiKey, channel, host, topic, username, password sql.Null[string]
if err := rows.Scan(&n.ID, &n.Name, &n.Type, &n.Enabled, pq.Array(&n.Events), &webhook, &token, &apiKey, &channel, &n.Priority, &topic, &host, &username, &n.CreatedAt, &n.UpdatedAt, &totalCount); err != nil {
if err := rows.Scan(&n.ID, &n.Name, &n.Type, &n.Enabled, pq.Array(&n.Events), &webhook, &token, &apiKey, &channel, &n.Priority, &topic, &host, &username, &password, &n.CreatedAt, &n.UpdatedAt, &totalCount); err != nil {
return nil, 0, errors.Wrap(err, "error scanning row")
}
n.APIKey = apiKey.String
n.Webhook = webhook.String
n.Token = token.String
n.Channel = channel.String
n.Topic = topic.String
n.Host = host.String
n.Username = username.String
n.APIKey = apiKey.V
n.Webhook = webhook.V
n.Token = token.V
n.Channel = channel.V
n.Topic = topic.V
n.Host = host.V
n.Username = username.V
n.Password = password.V
notifications = append(notifications, n)
}
@ -87,24 +88,24 @@ func (r *NotificationRepo) List(ctx context.Context) ([]domain.Notification, err
var n domain.Notification
//var eventsSlice []string
var token, apiKey, webhook, title, icon, host, username, password, channel, targets, devices, topic sql.NullString
var token, apiKey, webhook, title, icon, host, username, password, channel, targets, devices, topic sql.Null[string]
if err := rows.Scan(&n.ID, &n.Name, &n.Type, &n.Enabled, pq.Array(&n.Events), &token, &apiKey, &webhook, &title, &icon, &host, &username, &password, &channel, &targets, &devices, &n.Priority, &topic, &n.CreatedAt, &n.UpdatedAt); err != nil {
return nil, errors.Wrap(err, "error scanning row")
}
//n.Events = ([]domain.NotificationEvent)(eventsSlice)
n.Token = token.String
n.APIKey = apiKey.String
n.Webhook = webhook.String
n.Title = title.String
n.Icon = icon.String
n.Host = host.String
n.Username = username.String
n.Password = password.String
n.Channel = channel.String
n.Targets = targets.String
n.Devices = devices.String
n.Topic = topic.String
n.Token = token.V
n.APIKey = apiKey.V
n.Webhook = webhook.V
n.Title = title.V
n.Icon = icon.V
n.Host = host.V
n.Username = username.V
n.Password = password.V
n.Channel = channel.V
n.Targets = targets.V
n.Devices = devices.V
n.Topic = topic.V
notifications = append(notifications, n)
}
@ -154,7 +155,7 @@ func (r *NotificationRepo) FindByID(ctx context.Context, id int) (*domain.Notifi
var n domain.Notification
var token, apiKey, webhook, title, icon, host, username, password, channel, targets, devices, topic sql.NullString
var token, apiKey, webhook, title, icon, host, username, password, channel, targets, devices, topic sql.Null[string]
if err := row.Scan(&n.ID, &n.Name, &n.Type, &n.Enabled, pq.Array(&n.Events), &token, &apiKey, &webhook, &title, &icon, &host, &username, &password, &channel, &targets, &devices, &n.Priority, &topic, &n.CreatedAt, &n.UpdatedAt); err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, domain.ErrRecordNotFound
@ -163,18 +164,18 @@ func (r *NotificationRepo) FindByID(ctx context.Context, id int) (*domain.Notifi
return nil, errors.Wrap(err, "error scanning row")
}
n.Token = token.String
n.APIKey = apiKey.String
n.Webhook = webhook.String
n.Title = title.String
n.Icon = icon.String
n.Host = host.String
n.Username = username.String
n.Password = password.String
n.Channel = channel.String
n.Targets = targets.String
n.Devices = devices.String
n.Topic = topic.String
n.Token = token.V
n.APIKey = apiKey.V
n.Webhook = webhook.V
n.Title = title.V
n.Icon = icon.V
n.Host = host.V
n.Username = username.V
n.Password = password.V
n.Channel = channel.V
n.Targets = targets.V
n.Devices = devices.V
n.Topic = topic.V
return &n, nil
}
@ -195,6 +196,7 @@ func (r *NotificationRepo) Store(ctx context.Context, notification *domain.Notif
"topic",
"host",
"username",
"password",
).
Values(
notification.Name,
@ -209,6 +211,7 @@ func (r *NotificationRepo) Store(ctx context.Context, notification *domain.Notif
toNullString(notification.Topic),
toNullString(notification.Host),
toNullString(notification.Username),
toNullString(notification.Password),
).
Suffix("RETURNING id").RunWith(r.db.handler)
@ -236,6 +239,7 @@ func (r *NotificationRepo) Update(ctx context.Context, notification *domain.Noti
Set("topic", toNullString(notification.Topic)).
Set("host", toNullString(notification.Host)).
Set("username", toNullString(notification.Username)).
Set("password", toNullString(notification.Password)).
Set("updated_at", sq.Expr("CURRENT_TIMESTAMP")).
Where(sq.Eq{"id": notification.ID})

View file

@ -575,6 +575,7 @@ interface InitialValues {
host?: string;
events: NotificationEvent[];
username?: string
password?: string
}
export function NotificationUpdateForm({ isOpen, toggle, data: notification }: UpdateFormProps<ServiceNotification>) {
@ -625,7 +626,8 @@ export function NotificationUpdateForm({ isOpen, toggle, data: notification }: U
topic: notification.topic,
host: notification.host,
events: notification.events || [],
username: notification.username
username: notification.username,
password: notification.password
};
return (

View file

@ -26,4 +26,5 @@ interface ServiceNotification {
topic?: string;
host?: string;
username?: string;
password?: string;
}