From 174b1a03613f7cf73b580b78ba439b3f3398038f Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 17 Jun 2025 21:04:28 +0800 Subject: [PATCH] chore: fix linter --- proto/api/v1/activity_service.proto | 4 +--- server/router/api/v1/test/test_helper.go | 2 +- server/router/api/v1/test_auth.go | 10 +++++----- server/router/api/v1/webhook_service.go | 23 ++++++++++++----------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/proto/api/v1/activity_service.proto b/proto/api/v1/activity_service.proto index bb675fff6..7b33936f8 100644 --- a/proto/api/v1/activity_service.proto +++ b/proto/api/v1/activity_service.proto @@ -122,8 +122,6 @@ message GetActivityRequest { // Format: activities/{id}, id is the system generated auto-incremented id. string name = 1 [ (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "memos.api.v1/Activity" - } + (google.api.resource_reference) = {type: "memos.api.v1/Activity"} ]; } diff --git a/server/router/api/v1/test/test_helper.go b/server/router/api/v1/test/test_helper.go index a2fe0ea86..f4ea12f7e 100644 --- a/server/router/api/v1/test/test_helper.go +++ b/server/router/api/v1/test/test_helper.go @@ -75,7 +75,7 @@ func (ts *TestService) CreateRegularUser(ctx context.Context, username string) ( } // CreateUserContext creates a context with the given username for authentication. -func (ts *TestService) CreateUserContext(ctx context.Context, username string) context.Context { +func (*TestService) CreateUserContext(ctx context.Context, username string) context.Context { // Use the real context key from the parent package return apiv1.CreateTestUserContext(ctx, username) } diff --git a/server/router/api/v1/test_auth.go b/server/router/api/v1/test_auth.go index 7a1a36d75..840785200 100644 --- a/server/router/api/v1/test_auth.go +++ b/server/router/api/v1/test_auth.go @@ -6,14 +6,14 @@ import ( "github.com/usememos/memos/store" ) -// CreateTestUserContext creates a context with username for testing purposes -// This function is only intended for use in tests +// CreateTestUserContext creates a context with username for testing purposes. +// This function is only intended for use in tests. func CreateTestUserContext(ctx context.Context, username string) context.Context { return context.WithValue(ctx, usernameContextKey, username) } -// CreateTestUserContextWithUser creates a context and ensures the user exists for testing -// This function is only intended for use in tests -func CreateTestUserContextWithUser(ctx context.Context, s *APIV1Service, user *store.User) context.Context { +// CreateTestUserContextWithUser creates a context and ensures the user exists for testing. +// This function is only intended for use in tests. +func CreateTestUserContextWithUser(ctx context.Context, _ *APIV1Service, user *store.User) context.Context { return context.WithValue(ctx, usernameContextKey, user.Username) } diff --git a/server/router/api/v1/webhook_service.go b/server/router/api/v1/webhook_service.go index 9d84289ba..55a7765fb 100644 --- a/server/router/api/v1/webhook_service.go +++ b/server/router/api/v1/webhook_service.go @@ -25,19 +25,20 @@ func (s *APIV1Service) CreateWebhook(ctx context.Context, request *v1pb.CreateWe return nil, status.Errorf(codes.Unauthenticated, "user not authenticated") } + // Only host users can create webhooks + if !isSuperUser(currentUser) { + return nil, status.Errorf(codes.PermissionDenied, "permission denied") + } -// Only host users can create webhooks -if !isSuperUser(currentUser) { -return nil, status.Errorf(codes.PermissionDenied, "permission denied") -} + // Validate required fields + if request.Webhook == nil { + return nil, status.Errorf(codes.InvalidArgument, "webhook is required") + } + if strings.TrimSpace(request.Webhook.Url) == "" { + return nil, status.Errorf(codes.InvalidArgument, "webhook URL is required") + } -// Validate required fields -if request.Webhook == nil { -return nil, status.Errorf(codes.InvalidArgument, "webhook is required") -} -if strings.TrimSpace(request.Webhook.Url) == "" { -return nil, status.Errorf(codes.InvalidArgument, "webhook URL is required") -} // TODO: Handle webhook_id, validate_only, and request_id fields + // TODO: Handle webhook_id, validate_only, and request_id fields if request.ValidateOnly { // Perform validation checks without actually creating the webhook return &v1pb.Webhook{