mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:57:31 +00:00
feat: Notification providers config (#3212)
* feat: add login check lifetimes to login policy * feat: org features test * feat: debug notificatiaon events * feat: debug notification file/log commands * feat: add requests to proto * feat: add api for debug notification providers file/log * feat: add projection for debug notifiication providers * feat: requests * feat: merge v2 * feat: add settings proto to generate * feat: notifiaction providers * fix: remove unused code * Update iam_converter.go Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
112
internal/query/notification_provider.go
Normal file
112
internal/query/notification_provider.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
errs "errors"
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/query/projection"
|
||||
)
|
||||
|
||||
type DebugNotificationProvider struct {
|
||||
AggregateID string
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
ResourceOwner string
|
||||
State domain.NotificationProviderState
|
||||
Type domain.NotificationProviderType
|
||||
Compact bool
|
||||
}
|
||||
|
||||
var (
|
||||
notificationProviderTable = table{
|
||||
name: projection.DebugNotificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnAggID = Column{
|
||||
name: projection.DebugNotificationProviderAggIDCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnCreationDate = Column{
|
||||
name: projection.DebugNotificationProviderCreationDateCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnChangeDate = Column{
|
||||
name: projection.DebugNotificationProviderChangeDateCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnSequence = Column{
|
||||
name: projection.DebugNotificationProviderSequenceCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnResourceOwner = Column{
|
||||
name: projection.DebugNotificationProviderResourceOwnerCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnState = Column{
|
||||
name: projection.DebugNotificationProviderStateCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnType = Column{
|
||||
name: projection.DebugNotificationProviderTypeCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
NotificationProviderColumnCompact = Column{
|
||||
name: projection.DebugNotificationProviderCompactCol,
|
||||
table: notificationProviderTable,
|
||||
}
|
||||
)
|
||||
|
||||
func (q *Queries) NotificationProviderByIDAndType(ctx context.Context, aggID string, providerType domain.NotificationProviderType) (*DebugNotificationProvider, error) {
|
||||
query, scan := prepareDebugNotificationProviderQuery()
|
||||
stmt, args, err := query.Where(
|
||||
sq.Or{
|
||||
sq.Eq{
|
||||
LoginPolicyColumnOrgID.identifier(): aggID,
|
||||
},
|
||||
}).
|
||||
Limit(1).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "QUERY-f9jSf", "Errors.Query.SQLStatement")
|
||||
}
|
||||
|
||||
row := q.client.QueryRowContext(ctx, stmt, args...)
|
||||
return scan(row)
|
||||
}
|
||||
|
||||
func prepareDebugNotificationProviderQuery() (sq.SelectBuilder, func(*sql.Row) (*DebugNotificationProvider, error)) {
|
||||
return sq.Select(
|
||||
NotificationProviderColumnAggID.identifier(),
|
||||
NotificationProviderColumnCreationDate.identifier(),
|
||||
NotificationProviderColumnChangeDate.identifier(),
|
||||
NotificationProviderColumnSequence.identifier(),
|
||||
NotificationProviderColumnResourceOwner.identifier(),
|
||||
NotificationProviderColumnState.identifier(),
|
||||
NotificationProviderColumnType.identifier(),
|
||||
NotificationProviderColumnCompact.identifier(),
|
||||
).From(notificationProviderTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||
func(row *sql.Row) (*DebugNotificationProvider, error) {
|
||||
p := new(DebugNotificationProvider)
|
||||
err := row.Scan(
|
||||
&p.AggregateID,
|
||||
&p.CreationDate,
|
||||
&p.ChangeDate,
|
||||
&p.Sequence,
|
||||
&p.ResourceOwner,
|
||||
&p.State,
|
||||
&p.Type,
|
||||
&p.Compact,
|
||||
)
|
||||
if err != nil {
|
||||
if errs.Is(err, sql.ErrNoRows) {
|
||||
return nil, errors.ThrowNotFound(err, "QUERY-s9ujf", "Errors.NotificationProvider.NotFound")
|
||||
}
|
||||
return nil, errors.ThrowInternal(err, "QUERY-2liu0", "Errors.Internal")
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user