This commit is contained in:
@@ -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"`
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user