forked from baron/baron-sso
Merge commit 'ac778f836fb78550dce8088a567dc8bf5ffb8d2e' into feature/adminfront
This commit is contained in:
@@ -24,11 +24,12 @@ func NewClientConsentRepository(db *gorm.DB) ClientConsentRepository {
|
||||
}
|
||||
|
||||
func (r *clientConsentRepo) Upsert(ctx context.Context, consent *domain.ClientConsent) error {
|
||||
return r.db.WithContext(ctx).
|
||||
return r.db.WithContext(ctx).Unscoped().
|
||||
Where("client_id = ? AND subject = ?", consent.ClientID, consent.Subject).
|
||||
Assign(map[string]interface{}{
|
||||
"granted_scopes": consent.GrantedScopes,
|
||||
"updated_at": gorm.Expr("NOW()"),
|
||||
"deleted_at": nil,
|
||||
}).
|
||||
FirstOrCreate(consent).Error
|
||||
}
|
||||
@@ -44,13 +45,13 @@ func (r *clientConsentRepo) List(ctx context.Context, clientID string, limit, of
|
||||
var total int64
|
||||
|
||||
// Base query for counting
|
||||
countQuery := r.db.WithContext(ctx).Model(&domain.ClientConsent{}).Where("client_id = ?", clientID)
|
||||
countQuery := r.db.WithContext(ctx).Unscoped().Model(&domain.ClientConsent{}).Where("client_id = ?", clientID)
|
||||
if err := countQuery.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Query for fetching data
|
||||
query := r.db.WithContext(ctx).
|
||||
query := r.db.WithContext(ctx).Unscoped().
|
||||
Model(&domain.ClientConsent{}).
|
||||
Select("client_consents.*, users.tenant_id, tenants.name as tenant_name").
|
||||
Joins("LEFT JOIN users ON users.id::text = client_consents.subject").
|
||||
@@ -66,7 +67,7 @@ func (r *clientConsentRepo) ListByTenant(ctx context.Context, clientID, tenantID
|
||||
var total int64
|
||||
|
||||
// Base query for counting
|
||||
countQuery := r.db.WithContext(ctx).
|
||||
countQuery := r.db.WithContext(ctx).Unscoped().
|
||||
Model(&domain.ClientConsent{}).
|
||||
Joins("JOIN users ON users.id::text = client_consents.subject").
|
||||
Where("client_consents.client_id = ? AND users.tenant_id = ?", clientID, tenantID)
|
||||
@@ -76,7 +77,7 @@ func (r *clientConsentRepo) ListByTenant(ctx context.Context, clientID, tenantID
|
||||
}
|
||||
|
||||
// Query for fetching data
|
||||
query := r.db.WithContext(ctx).
|
||||
query := r.db.WithContext(ctx).Unscoped().
|
||||
Model(&domain.ClientConsent{}).
|
||||
Select("client_consents.*, users.tenant_id, tenants.name as tenant_name").
|
||||
Joins("JOIN users ON users.id::text = client_consents.subject").
|
||||
@@ -94,7 +95,7 @@ func (r *clientConsentRepo) ListByTenant(ctx context.Context, clientID, tenantID
|
||||
|
||||
func (r *clientConsentRepo) ListBySubject(ctx context.Context, subject string) ([]domain.ClientConsent, error) {
|
||||
var consents []domain.ClientConsent
|
||||
err := r.db.WithContext(ctx).
|
||||
err := r.db.WithContext(ctx).Unscoped().
|
||||
Where("subject = ?", subject).
|
||||
Order("updated_at DESC").
|
||||
Find(&consents).Error
|
||||
|
||||
Reference in New Issue
Block a user