mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-02-11 16:29:00 -06:00
Move logging out of limits checks
This commit is contained in:
@@ -53,10 +53,8 @@ func (sl *SubscriptionLimitsImpl) CheckOrgsLimit(ctx context.Context, userID int
|
||||
}
|
||||
|
||||
count := 0
|
||||
total := 0
|
||||
// NOTE: this should be freshly cached as we should have just rendered the dashboard
|
||||
if orgs, err := sl.store.Impl().RetrieveUserOrganizations(ctx, userID); err == nil {
|
||||
total = len(orgs)
|
||||
for _, org := range orgs {
|
||||
if org.Level == dbgen.AccessLevelOwner {
|
||||
count++
|
||||
@@ -68,10 +66,6 @@ func (sl *SubscriptionLimitsImpl) CheckOrgsLimit(ctx context.Context, userID int
|
||||
}
|
||||
|
||||
ok := (plan.OrgsLimit() == 0) || (count < plan.OrgsLimit())
|
||||
if !ok {
|
||||
slog.WarnContext(ctx, "Organizations limit check failed", "total", total, "owned", count, "userID", userID, "subscriptionID", subscr.ID,
|
||||
"plan", plan.Name(), "internal", isInternalSubscription)
|
||||
}
|
||||
|
||||
return ok, count - plan.OrgsLimit(), nil
|
||||
}
|
||||
@@ -95,10 +89,6 @@ func (sl *SubscriptionLimitsImpl) CheckOrgMembersLimit(ctx context.Context, orgI
|
||||
}
|
||||
|
||||
ok := (plan.OrgMembersLimit() == 0) || (len(members) < plan.OrgMembersLimit())
|
||||
if !ok {
|
||||
slog.WarnContext(ctx, "Organization members limit check failed", "members", len(members), "orgID", orgID, "subscriptionID", subscr.ID,
|
||||
"plan", plan.Name(), "internal", isInternalSubscription)
|
||||
}
|
||||
|
||||
return ok, len(members) - plan.OrgMembersLimit(), nil
|
||||
}
|
||||
@@ -122,10 +112,6 @@ func (sl *SubscriptionLimitsImpl) CheckPropertiesLimit(ctx context.Context, user
|
||||
}
|
||||
|
||||
ok := (plan.PropertiesLimit() == 0) || (count < int64(plan.PropertiesLimit()))
|
||||
if !ok {
|
||||
slog.WarnContext(ctx, "Properties limit check failed", "properties", count, "userID", userID, "subscriptionID", subscr.ID,
|
||||
"plan", plan.Name(), "internal", isInternalSubscription)
|
||||
}
|
||||
|
||||
return ok, int(count) - plan.PropertiesLimit(), nil
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (s *Server) validateOrgsLimit(ctx context.Context, user *dbgen.User) string
|
||||
}
|
||||
}
|
||||
|
||||
ok, _, err := s.SubscriptionLimits.CheckOrgsLimit(ctx, user.ID, subscr)
|
||||
ok, extra, err := s.SubscriptionLimits.CheckOrgsLimit(ctx, user.ID, subscr)
|
||||
if err != nil {
|
||||
if err == ErrNoActiveSubscription {
|
||||
return activeSubscriptionForOrgError
|
||||
@@ -44,6 +44,9 @@ func (s *Server) validateOrgsLimit(ctx context.Context, user *dbgen.User) string
|
||||
}
|
||||
|
||||
if !ok {
|
||||
slog.WarnContext(ctx, "Organizations limit check failed", "extra", extra, "userID", user.ID, "subscriptionID", subscr.ID,
|
||||
"internal", db.IsInternalSubscription(subscr.Source))
|
||||
|
||||
return "Organizations limit reached on your current plan, please upgrade to create more."
|
||||
}
|
||||
|
||||
@@ -125,7 +128,7 @@ func (s *Server) validateAddOrgMemberEmail(ctx context.Context, user *dbgen.User
|
||||
}
|
||||
}
|
||||
|
||||
ok, _, err := s.SubscriptionLimits.CheckOrgMembersLimit(ctx, org.ID, subscr)
|
||||
ok, extra, err := s.SubscriptionLimits.CheckOrgMembersLimit(ctx, org.ID, subscr)
|
||||
if err != nil {
|
||||
if err == ErrNoActiveSubscription {
|
||||
return errorMessageOrgSubscription
|
||||
@@ -134,6 +137,8 @@ func (s *Server) validateAddOrgMemberEmail(ctx context.Context, user *dbgen.User
|
||||
}
|
||||
|
||||
if !ok {
|
||||
slog.WarnContext(ctx, "Organization members limit check failed", "extra", extra, "orgID", org.ID, "subscriptionID", subscr.ID,
|
||||
"internal", db.IsInternalSubscription(subscr.Source))
|
||||
return errorMessageOrgMembersLimit
|
||||
}
|
||||
|
||||
@@ -164,7 +169,7 @@ func (s *Server) validateAddOrgMemberID(ctx context.Context, user *dbgen.User, o
|
||||
}
|
||||
}
|
||||
|
||||
ok, _, err := s.SubscriptionLimits.CheckOrgMembersLimit(ctx, org.ID, subscr)
|
||||
ok, extra, err := s.SubscriptionLimits.CheckOrgMembersLimit(ctx, org.ID, subscr)
|
||||
if err != nil {
|
||||
if err == ErrNoActiveSubscription {
|
||||
return errorMessageOrgSubscription
|
||||
@@ -173,6 +178,8 @@ func (s *Server) validateAddOrgMemberID(ctx context.Context, user *dbgen.User, o
|
||||
}
|
||||
|
||||
if !ok {
|
||||
slog.WarnContext(ctx, "Organization members limit check failed", "extra", extra, "orgID", org.ID, "subscriptionID", subscr.ID,
|
||||
"internal", db.IsInternalSubscription(subscr.Source))
|
||||
return errorMessageOrgMembersLimit
|
||||
}
|
||||
|
||||
|
||||
@@ -423,7 +423,7 @@ func (s *Server) validatePropertiesLimit(ctx context.Context, org *dbgen.Organiz
|
||||
}
|
||||
|
||||
func (s *Server) doValidatePropertiesLimit(ctx context.Context, subscr *dbgen.Subscription, userID int32, isOrgOwner bool) string {
|
||||
ok, _, err := s.SubscriptionLimits.CheckPropertiesLimit(ctx, userID, subscr)
|
||||
ok, extra, err := s.SubscriptionLimits.CheckPropertiesLimit(ctx, userID, subscr)
|
||||
if err != nil {
|
||||
if err == ErrNoActiveSubscription {
|
||||
if isOrgOwner {
|
||||
@@ -436,6 +436,9 @@ func (s *Server) doValidatePropertiesLimit(ctx context.Context, subscr *dbgen.Su
|
||||
}
|
||||
|
||||
if !ok {
|
||||
slog.WarnContext(ctx, "Properties limit check failed", "extra", extra, "userID", userID, "subscriptionID", subscr.ID,
|
||||
"orgOwner", isOrgOwner, "internal", db.IsInternalSubscription(subscr.Source))
|
||||
|
||||
if isOrgOwner {
|
||||
return "Properties limit reached on your current plan, please upgrade to create more."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user