~sircmpwn/sr.ht-dev

meta.sr.ht: api/graph: use core-go/webhooks.FilterWebhooks v1 APPLIED

Adnan Maolood: 1
 api/graph: use core-go/webhooks.FilterWebhooks

 2 files changed, 3 insertions(+), 22 deletions(-)
#670413 alpine.yml failed
#670414 archlinux.yml failed
#670415 debian.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/28205/mbox | git am -3
Learn more about email & git

[PATCH meta.sr.ht] api/graph: use core-go/webhooks.FilterWebhooks Export this patch

---
Note: this requires the patch to core-go to be accepted.
The core-go version in api/go.mod must also be updated.

 api/graph/resolver.go         | 19 -------------------
 api/graph/schema.resolvers.go |  6 +++---
 2 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/api/graph/resolver.go b/api/graph/resolver.go
index 7afa40d..a3097f9 100644
--- a/api/graph/resolver.go
+++ b/api/graph/resolver.go
@@ -15,8 +15,6 @@ import (
	"git.sr.ht/~sircmpwn/core-go/database"
	"git.sr.ht/~sircmpwn/core-go/email"
	"git.sr.ht/~sircmpwn/core-go/server"
	"git.sr.ht/~sircmpwn/core-go/webhooks"
	sq "github.com/Masterminds/squirrel"
	"github.com/emersion/go-message/mail"

	"git.sr.ht/~sircmpwn/meta.sr.ht/api/graph/model"
@@ -34,23 +32,6 @@ type AuthorizationPayload struct {
	UserID     int
}

func filterWebhooks(ctx context.Context) (sq.Sqlizer, error) {
	ac, err := webhooks.NewAuthConfig(ctx)
	if err != nil {
		return nil, err
	}
	if ac.ClientID != nil {
		// XXX: Should we maybe return all webhooks configured by client ID?
		return sq.And{
			sq.Expr(`NOW() at time zone 'utc' < expires`),
			sq.Expr(`token_hash = ?`, ac.TokenHash),
			sq.Expr(`client_id = ?`, *ac.ClientID),
		}, nil
	} else {
		return sq.Expr(`NOW() at time zone 'utc' < expires`), nil
	}
}

// Records an event in the authorized user's audit log.
func recordAuditLog(ctx context.Context, eventType, details string) {
	database.WithTx(ctx, nil, func(tx *sql.Tx) error {
diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go
index 40b3633..9fd0e9f 100644
--- a/api/graph/schema.resolvers.go
+++ b/api/graph/schema.resolvers.go
@@ -533,7 +533,7 @@ func (r *mutationResolver) CreateWebhook(ctx context.Context, config model.Profi
func (r *mutationResolver) DeleteWebhook(ctx context.Context, id int) (model.WebhookSubscription, error) {
	var sub model.ProfileWebhookSubscription

	filter, err := filterWebhooks(ctx)
	filter, err := corewebhooks.FilterWebhooks(ctx)
	if err != nil {
		return nil, err
	}
@@ -1484,7 +1484,7 @@ func (r *queryResolver) ProfileWebhooks(ctx context.Context, cursor *coremodel.C
		cursor = coremodel.NewCursor(nil)
	}

	filter, err := filterWebhooks(ctx)
	filter, err := corewebhooks.FilterWebhooks(ctx)
	if err != nil {
		return nil, err
	}
@@ -1511,7 +1511,7 @@ func (r *queryResolver) ProfileWebhooks(ctx context.Context, cursor *coremodel.C
func (r *queryResolver) ProfileWebhook(ctx context.Context, id int) (model.WebhookSubscription, error) {
	var sub model.ProfileWebhookSubscription

	filter, err := filterWebhooks(ctx)
	filter, err := corewebhooks.FilterWebhooks(ctx)
	if err != nil {
		return nil, err
	}
-- 
2.34.1
meta.sr.ht/patches: FAILED in 2m39s

[api/graph: use core-go/webhooks.FilterWebhooks][0] from [Adnan Maolood][1]

[0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/28205
[1]: mailto:me@adnano.co

✗ #670415 FAILED meta.sr.ht/patches/debian.yml    https://builds.sr.ht/~sircmpwn/job/670415
✗ #670414 FAILED meta.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/670414
✗ #670413 FAILED meta.sr.ht/patches/alpine.yml    https://builds.sr.ht/~sircmpwn/job/670413
Amended with the necessary go.mod update. Thanks!

To git@git.sr.ht:~sircmpwn/meta.sr.ht
   098c373..e4beb48  master -> master