This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
|
Active bool `json:"active"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
RateLimit model.RateLimit `json:"rate_limit"`
|
RateLimit model.RateLimit `json:"rate_limit"`
|
||||||
RateLimitStatus UserRateLimitStatus `json:"rate_limit_status"`
|
RateLimitStatus UserRateLimitStatus `json:"rate_limit_status"`
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ func (h *UserHandler) GetCurrentUser(ctx *gin.Context) {
|
|||||||
h.RespondWithData(ctx, &dto.UserInfo{
|
h.RespondWithData(ctx, &dto.UserInfo{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
|
Active: user.Active,
|
||||||
AvatarURL: profile.AvatarURL,
|
AvatarURL: profile.AvatarURL,
|
||||||
RateLimit: user.RateLimit,
|
RateLimit: user.RateLimit,
|
||||||
RateLimitStatus: dto.UserRateLimitStatus{
|
RateLimitStatus: dto.UserRateLimitStatus{
|
||||||
|
|||||||
@@ -24,5 +24,6 @@ type ApplicationCache struct {
|
|||||||
APIKey string `json:"api_key"`
|
APIKey string `json:"api_key"`
|
||||||
Permissions []Permission `json:"permissions"`
|
Permissions []Permission `json:"permissions"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
|
UserActive bool `json:"user_active"`
|
||||||
RateLimit RateLimit `json:"rate_limit"`
|
RateLimit RateLimit `json:"rate_limit"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ const (
|
|||||||
ErrEmptyAPIKey = "empty API key"
|
ErrEmptyAPIKey = "empty API key"
|
||||||
ErrEmptyService = "empty service name"
|
ErrEmptyService = "empty service name"
|
||||||
ErrEmptyPermission = "empty permission name"
|
ErrEmptyPermission = "empty permission name"
|
||||||
ErrAppInactive = "application is inactive"
|
ErrAppInactive = "application is disabled"
|
||||||
|
ErrUserInactive = "user is disabled"
|
||||||
ErrRateLimitExceeded = "rate limit exceeded"
|
ErrRateLimitExceeded = "rate limit exceeded"
|
||||||
ErrUnauthorized = "unauthorized request"
|
ErrUnauthorized = "unauthorized request"
|
||||||
)
|
)
|
||||||
@@ -55,6 +56,11 @@ func (d Dev) Validate(ctx context.Context, request *dev.APIValidationRequest) (*
|
|||||||
return errorResponse(err, http.StatusInternalServerError)
|
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
|
// Check if application is active
|
||||||
if !appCache.Active {
|
if !appCache.Active {
|
||||||
return buildResponse(appCache, &ratelimit.RateLimitStatus{}, false, ErrAppInactive, http.StatusForbidden), nil
|
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,
|
APIKey: app.APIKey,
|
||||||
Permissions: app.Permissions,
|
Permissions: app.Permissions,
|
||||||
Active: app.Active,
|
Active: app.Active,
|
||||||
|
UserActive: user.Active,
|
||||||
RateLimit: user.RateLimit,
|
RateLimit: user.RateLimit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user