mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-03-19 05:37:51 +08:00
### What problem does this PR solve? Fix: Enhanced user management functionality and cascading data deletion. Added tenant and related data initialization functionality during user creation, including tenants, user-tenant relationships, LLM configuration, and root folder. Added cascading deletion logic for user deletion, ensuring that all associated data is cleaned up simultaneously when a user is deleted. Implemented a Werkzeug-compatible password hash algorithm (scrypt) and verification functionality. Added multiple DAO methods to support batch data operations and cascading deletion. Improved user login processing and added token signing functionality. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
74 lines
2.4 KiB
Go
74 lines
2.4 KiB
Go
//
|
|
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
package dao
|
|
|
|
import (
|
|
"ragflow/internal/model"
|
|
)
|
|
|
|
// APITokenDAO API token data access object
|
|
type APITokenDAO struct{}
|
|
|
|
// NewAPITokenDAO create API token DAO
|
|
func NewAPITokenDAO() *APITokenDAO {
|
|
return &APITokenDAO{}
|
|
}
|
|
|
|
// Create creates a new API token
|
|
func (dao *APITokenDAO) Create(apiToken *model.APIToken) error {
|
|
return DB.Create(apiToken).Error
|
|
}
|
|
|
|
// GetByTenantID gets API tokens by tenant ID
|
|
func (dao *APITokenDAO) GetByTenantID(tenantID string) ([]*model.APIToken, error) {
|
|
var tokens []*model.APIToken
|
|
err := DB.Where("tenant_id = ?", tenantID).Find(&tokens).Error
|
|
return tokens, err
|
|
}
|
|
|
|
// DeleteByTenantID deletes all API tokens by tenant ID (hard delete)
|
|
func (dao *APITokenDAO) DeleteByTenantID(tenantID string) (int64, error) {
|
|
result := DB.Unscoped().Where("tenant_id = ?", tenantID).Delete(&model.APIToken{})
|
|
return result.RowsAffected, result.Error
|
|
}
|
|
|
|
// DeleteByDialogIDs deletes API tokens by dialog IDs (hard delete)
|
|
func (dao *APITokenDAO) DeleteByDialogIDs(dialogIDs []string) (int64, error) {
|
|
if len(dialogIDs) == 0 {
|
|
return 0, nil
|
|
}
|
|
result := DB.Unscoped().Where("dialog_id IN ?", dialogIDs).Delete(&model.APIToken{})
|
|
return result.RowsAffected, result.Error
|
|
}
|
|
|
|
// API4ConversationDAO API for conversation data access object
|
|
type API4ConversationDAO struct{}
|
|
|
|
// NewAPI4ConversationDAO create API4Conversation DAO
|
|
func NewAPI4ConversationDAO() *API4ConversationDAO {
|
|
return &API4ConversationDAO{}
|
|
}
|
|
|
|
// DeleteByDialogIDs deletes API4Conversations by dialog IDs (hard delete)
|
|
func (dao *API4ConversationDAO) DeleteByDialogIDs(dialogIDs []string) (int64, error) {
|
|
if len(dialogIDs) == 0 {
|
|
return 0, nil
|
|
}
|
|
result := DB.Unscoped().Where("dialog_id IN ?", dialogIDs).Delete(&model.API4Conversation{})
|
|
return result.RowsAffected, result.Error
|
|
}
|