Add user active check
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-06-27 23:57:28 -04:00
parent 4cf59e46f9
commit d832734f0d
4 changed files with 11 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import (
type UserInfo struct {
ID uint64 `json:"id"`
Username string `json:"username"`
Active bool `json:"active"`
AvatarURL string `json:"avatar_url"`
RateLimit model.RateLimit `json:"rate_limit"`
RateLimitStatus UserRateLimitStatus `json:"rate_limit_status"`

View File

@@ -72,6 +72,7 @@ func (h *UserHandler) GetCurrentUser(ctx *gin.Context) {
h.RespondWithData(ctx, &dto.UserInfo{
ID: user.ID,
Username: user.Username,
Active: user.Active,
AvatarURL: profile.AvatarURL,
RateLimit: user.RateLimit,
RateLimitStatus: dto.UserRateLimitStatus{

View File

@@ -24,5 +24,6 @@ type ApplicationCache struct {
APIKey string `json:"api_key"`
Permissions []Permission `json:"permissions"`
Active bool `json:"active"`
UserActive bool `json:"user_active"`
RateLimit RateLimit `json:"rate_limit"`
}

View File

@@ -19,7 +19,8 @@ const (
ErrEmptyAPIKey = "empty API key"
ErrEmptyService = "empty service name"
ErrEmptyPermission = "empty permission name"
ErrAppInactive = "application is inactive"
ErrAppInactive = "application is disabled"
ErrUserInactive = "user is disabled"
ErrRateLimitExceeded = "rate limit exceeded"
ErrUnauthorized = "unauthorized request"
)
@@ -55,6 +56,11 @@ func (d Dev) Validate(ctx context.Context, request *dev.APIValidationRequest) (*
return errorResponse(err, http.StatusInternalServerError)
}
// Check if user is disabled
if !appCache.UserActive {
return buildResponse(appCache, &ratelimit.RateLimitStatus{}, false, ErrUserInactive, http.StatusForbidden), nil
}
// Check if application is active
if !appCache.Active {
return buildResponse(appCache, &ratelimit.RateLimitStatus{}, false, ErrAppInactive, http.StatusForbidden), nil
@@ -157,6 +163,7 @@ func (d Dev) getApplicationData(ctx context.Context, apiKey string) (*model.Appl
APIKey: app.APIKey,
Permissions: app.Permissions,
Active: app.Active,
UserActive: user.Active,
RateLimit: user.RateLimit,
}