forked from baron/baron-sso
conent 이력 조회 soft delete 및 상태 필드 추가
This commit is contained in:
@@ -3423,6 +3423,12 @@ func (h *AuthHandler) ListLinkedRps(c *fiber.Ctx) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 삭제된 권한일 경우
|
||||||
|
status := "inactive"
|
||||||
|
if dc.DeletedAt.Valid {
|
||||||
|
status = "revoked"
|
||||||
|
}
|
||||||
|
|
||||||
// Hydra에서 클라이언트 정보 조회 (메타데이터용)
|
// Hydra에서 클라이언트 정보 조회 (메타데이터용)
|
||||||
client, err := h.Hydra.GetClient(c.Context(), dc.ClientID)
|
client, err := h.Hydra.GetClient(c.Context(), dc.ClientID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -3432,7 +3438,7 @@ func (h *AuthHandler) ListLinkedRps(c *fiber.Ctx) error {
|
|||||||
linkedRpSummary: linkedRpSummary{
|
linkedRpSummary: linkedRpSummary{
|
||||||
ID: dc.ClientID,
|
ID: dc.ClientID,
|
||||||
Name: dc.ClientID,
|
Name: dc.ClientID,
|
||||||
Status: "inactive",
|
Status: status,
|
||||||
Scopes: dc.GrantedScopes,
|
Scopes: dc.GrantedScopes,
|
||||||
},
|
},
|
||||||
lastAuth: dc.UpdatedAt,
|
lastAuth: dc.UpdatedAt,
|
||||||
@@ -3458,7 +3464,7 @@ func (h *AuthHandler) ListLinkedRps(c *fiber.Ctx) error {
|
|||||||
Name: name,
|
Name: name,
|
||||||
Logo: extractHydraClientLogo(client.Metadata),
|
Logo: extractHydraClientLogo(client.Metadata),
|
||||||
URL: clientURL,
|
URL: clientURL,
|
||||||
Status: "inactive",
|
Status: status,
|
||||||
Scopes: dc.GrantedScopes,
|
Scopes: dc.GrantedScopes,
|
||||||
},
|
},
|
||||||
lastAuth: dc.UpdatedAt,
|
lastAuth: dc.UpdatedAt,
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ type consentSummary struct {
|
|||||||
GrantedScopes []string `json:"grantedScopes"`
|
GrantedScopes []string `json:"grantedScopes"`
|
||||||
AuthenticatedAt string `json:"authenticatedAt,omitempty"`
|
AuthenticatedAt string `json:"authenticatedAt,omitempty"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
DeletedAt *time.Time `json:"deletedAt,omitempty"`
|
||||||
|
Status string `json:"status"`
|
||||||
TenantID string `json:"tenantId,omitempty"`
|
TenantID string `json:"tenantId,omitempty"`
|
||||||
TenantName string `json:"tenantName,omitempty"`
|
TenantName string `json:"tenantName,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -648,6 +650,7 @@ func (h *DevHandler) ListConsents(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
// [Isolation] Get admin tenant ID from header or locals
|
// [Isolation] Get admin tenant ID from header or locals
|
||||||
adminTenantID := c.Get("X-Tenant-ID") // Assume middleware sets this or trusted in dev
|
adminTenantID := c.Get("X-Tenant-ID") // Assume middleware sets this or trusted in dev
|
||||||
|
statusFilter := strings.ToLower(strings.TrimSpace(c.Query("status")))
|
||||||
|
|
||||||
var consents []domain.ClientConsentWithTenantInfo
|
var consents []domain.ClientConsentWithTenantInfo
|
||||||
var total int64
|
var total int64
|
||||||
@@ -686,6 +689,23 @@ func (h *DevHandler) ListConsents(c *fiber.Ctx) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deletedAt *time.Time
|
||||||
|
status := "active"
|
||||||
|
if consent.DeletedAt.Valid {
|
||||||
|
deletedAt = &consent.DeletedAt.Time
|
||||||
|
status = "revoked"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by status if requested
|
||||||
|
if statusFilter != "" && statusFilter != "all" {
|
||||||
|
if statusFilter == "active" && status != "active" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if statusFilter == "revoked" && status != "revoked" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
userName := ""
|
userName := ""
|
||||||
identity, err := h.KratosAdmin.GetIdentity(c.Context(), consent.Subject)
|
identity, err := h.KratosAdmin.GetIdentity(c.Context(), consent.Subject)
|
||||||
if err == nil && identity != nil {
|
if err == nil && identity != nil {
|
||||||
@@ -703,6 +723,8 @@ func (h *DevHandler) ListConsents(c *fiber.Ctx) error {
|
|||||||
GrantedScopes: consent.GrantedScopes,
|
GrantedScopes: consent.GrantedScopes,
|
||||||
AuthenticatedAt: consent.UpdatedAt.Format(time.RFC3339),
|
AuthenticatedAt: consent.UpdatedAt.Format(time.RFC3339),
|
||||||
CreatedAt: consent.CreatedAt,
|
CreatedAt: consent.CreatedAt,
|
||||||
|
DeletedAt: deletedAt,
|
||||||
|
Status: status,
|
||||||
TenantID: consent.TenantID,
|
TenantID: consent.TenantID,
|
||||||
TenantName: consent.TenantName,
|
TenantName: consent.TenantName,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ func NewClientConsentRepository(db *gorm.DB) ClientConsentRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *clientConsentRepo) Upsert(ctx context.Context, consent *domain.ClientConsent) error {
|
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).
|
Where("client_id = ? AND subject = ?", consent.ClientID, consent.Subject).
|
||||||
Assign(map[string]interface{}{
|
Assign(map[string]interface{}{
|
||||||
"granted_scopes": consent.GrantedScopes,
|
"granted_scopes": consent.GrantedScopes,
|
||||||
"updated_at": gorm.Expr("NOW()"),
|
"updated_at": gorm.Expr("NOW()"),
|
||||||
|
"deleted_at": nil,
|
||||||
}).
|
}).
|
||||||
FirstOrCreate(consent).Error
|
FirstOrCreate(consent).Error
|
||||||
}
|
}
|
||||||
@@ -44,13 +45,13 @@ func (r *clientConsentRepo) List(ctx context.Context, clientID string, limit, of
|
|||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
// Base query for counting
|
// 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 {
|
if err := countQuery.Count(&total).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query for fetching data
|
// Query for fetching data
|
||||||
query := r.db.WithContext(ctx).
|
query := r.db.WithContext(ctx).Unscoped().
|
||||||
Model(&domain.ClientConsent{}).
|
Model(&domain.ClientConsent{}).
|
||||||
Select("client_consents.*, users.tenant_id, tenants.name as tenant_name").
|
Select("client_consents.*, users.tenant_id, tenants.name as tenant_name").
|
||||||
Joins("LEFT JOIN users ON users.id::text = client_consents.subject").
|
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
|
var total int64
|
||||||
|
|
||||||
// Base query for counting
|
// Base query for counting
|
||||||
countQuery := r.db.WithContext(ctx).
|
countQuery := r.db.WithContext(ctx).Unscoped().
|
||||||
Model(&domain.ClientConsent{}).
|
Model(&domain.ClientConsent{}).
|
||||||
Joins("JOIN users ON users.id::text = client_consents.subject").
|
Joins("JOIN users ON users.id::text = client_consents.subject").
|
||||||
Where("client_consents.client_id = ? AND users.tenant_id = ?", clientID, tenantID)
|
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 for fetching data
|
||||||
query := r.db.WithContext(ctx).
|
query := r.db.WithContext(ctx).Unscoped().
|
||||||
Model(&domain.ClientConsent{}).
|
Model(&domain.ClientConsent{}).
|
||||||
Select("client_consents.*, users.tenant_id, tenants.name as tenant_name").
|
Select("client_consents.*, users.tenant_id, tenants.name as tenant_name").
|
||||||
Joins("JOIN users ON users.id::text = client_consents.subject").
|
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) {
|
func (r *clientConsentRepo) ListBySubject(ctx context.Context, subject string) ([]domain.ClientConsent, error) {
|
||||||
var consents []domain.ClientConsent
|
var consents []domain.ClientConsent
|
||||||
err := r.db.WithContext(ctx).
|
err := r.db.WithContext(ctx).Unscoped().
|
||||||
Where("subject = ?", subject).
|
Where("subject = ?", subject).
|
||||||
Order("updated_at DESC").
|
Order("updated_at DESC").
|
||||||
Find(&consents).Error
|
Find(&consents).Error
|
||||||
|
|||||||
Reference in New Issue
Block a user