2026-03-04 19:17:16 +08:00
|
|
|
//
|
|
|
|
|
// 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 (
|
2026-03-27 19:25:18 +08:00
|
|
|
"ragflow/internal/entity"
|
2026-03-04 19:17:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// UserDAO user data access object
|
|
|
|
|
type UserDAO struct{}
|
|
|
|
|
|
|
|
|
|
// NewUserDAO create user DAO
|
|
|
|
|
func NewUserDAO() *UserDAO {
|
|
|
|
|
return &UserDAO{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create create user
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) Create(user *entity.User) error {
|
2026-03-04 19:17:16 +08:00
|
|
|
return DB.Create(user).Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetByID get user by ID
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) GetByID(id uint) (*entity.User, error) {
|
|
|
|
|
var user entity.User
|
2026-03-04 19:17:16 +08:00
|
|
|
err := DB.First(&user, id).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &user, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) GetByTenantID(tenantID string) (*entity.User, error) {
|
|
|
|
|
var user entity.User
|
2026-03-24 20:08:36 +08:00
|
|
|
err := DB.Where("id = ?", tenantID).First(&user).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &user, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 19:17:16 +08:00
|
|
|
// GetByEmail get user by email
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) GetByEmail(email string) (*entity.User, error) {
|
|
|
|
|
var user entity.User
|
2026-03-04 19:17:16 +08:00
|
|
|
query := DB.Where("email = ?", email)
|
|
|
|
|
err := query.First(&user).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &user, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetByAccessToken get user by access token
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) GetByAccessToken(token string) (*entity.User, error) {
|
|
|
|
|
var user entity.User
|
2026-03-04 19:17:16 +08:00
|
|
|
err := DB.Where("access_token = ?", token).First(&user).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &user, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update update user
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) Update(user *entity.User) error {
|
2026-03-04 19:17:16 +08:00
|
|
|
return DB.Save(user).Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateAccessToken update user's access token
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) UpdateAccessToken(user *entity.User, token string) error {
|
2026-03-04 19:17:16 +08:00
|
|
|
return DB.Model(user).Update("access_token", token).Error
|
|
|
|
|
}
|
|
|
|
|
|
Feat: Implement user creation, deletion, and permission management functionality. (#13519)
### What problem does this PR solve?
Feat: Implement user creation, deletion, and permission management
functionality.
- Added the `ListByEmail` method to `user.go` to query users by email
address.
- Updated the user activation status handling logic in `handler.go`,
adding input validation.
- Added RSA password decryption functionality to `password.go`.
- Implemented complete user management functionality in `service.go`,
including user creation, deletion, password modification, activation
status, and permission management.
- Added input validation and error handling logic.
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
2026-03-11 14:04:00 +08:00
|
|
|
// List list users (only active users with status != "0")
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) List(offset, limit int) ([]*entity.User, int64, error) {
|
|
|
|
|
var users []*entity.User
|
2026-03-04 19:17:16 +08:00
|
|
|
var total int64
|
|
|
|
|
|
Feat: Implement user creation, deletion, and permission management functionality. (#13519)
### What problem does this PR solve?
Feat: Implement user creation, deletion, and permission management
functionality.
- Added the `ListByEmail` method to `user.go` to query users by email
address.
- Updated the user activation status handling logic in `handler.go`,
adding input validation.
- Added RSA password decryption functionality to `password.go`.
- Implemented complete user management functionality in `service.go`,
including user creation, deletion, password modification, activation
status, and permission management.
- Added input validation and error handling logic.
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
2026-03-11 14:04:00 +08:00
|
|
|
// Only count users with status != "0" (not deleted)
|
2026-03-27 19:25:18 +08:00
|
|
|
if err := DB.Model(&entity.User{}).Count(&total).Error; err != nil {
|
2026-03-04 19:17:16 +08:00
|
|
|
return nil, 0, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 19:25:18 +08:00
|
|
|
query := DB.Model(&entity.User{})
|
2026-03-09 10:44:53 +08:00
|
|
|
if offset > 0 {
|
|
|
|
|
query = query.Offset(offset)
|
|
|
|
|
}
|
|
|
|
|
if limit > 0 {
|
|
|
|
|
query = query.Limit(limit)
|
|
|
|
|
}
|
|
|
|
|
err := query.Find(&users).Error
|
2026-03-04 19:17:16 +08:00
|
|
|
return users, total, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete delete user
|
|
|
|
|
func (dao *UserDAO) Delete(id uint) error {
|
2026-03-27 19:25:18 +08:00
|
|
|
return DB.Delete(&entity.User{}, id).Error
|
2026-03-04 19:17:16 +08:00
|
|
|
}
|
2026-03-06 16:42:49 +08:00
|
|
|
|
Feat: Implement user creation, deletion, and permission management functionality. (#13519)
### What problem does this PR solve?
Feat: Implement user creation, deletion, and permission management
functionality.
- Added the `ListByEmail` method to `user.go` to query users by email
address.
- Updated the user activation status handling logic in `handler.go`,
adding input validation.
- Added RSA password decryption functionality to `password.go`.
- Implemented complete user management functionality in `service.go`,
including user creation, deletion, password modification, activation
status, and permission management.
- Added input validation and error handling logic.
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
2026-03-11 14:04:00 +08:00
|
|
|
// DeleteByID delete user by string ID (soft delete - set status to 0)
|
2026-03-06 16:42:49 +08:00
|
|
|
func (dao *UserDAO) DeleteByID(id string) error {
|
2026-03-27 19:25:18 +08:00
|
|
|
return DB.Model(&entity.User{}).Where("id = ?", id).Update("status", "0").Error
|
2026-03-06 16:42:49 +08:00
|
|
|
}
|
Feat: Implement user creation, deletion, and permission management functionality. (#13519)
### What problem does this PR solve?
Feat: Implement user creation, deletion, and permission management
functionality.
- Added the `ListByEmail` method to `user.go` to query users by email
address.
- Updated the user activation status handling logic in `handler.go`,
adding input validation.
- Added RSA password decryption functionality to `password.go`.
- Implemented complete user management functionality in `service.go`,
including user creation, deletion, password modification, activation
status, and permission management.
- Added input validation and error handling logic.
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
2026-03-11 14:04:00 +08:00
|
|
|
|
2026-03-13 16:53:54 +08:00
|
|
|
// HardDelete hard delete user by string ID
|
|
|
|
|
func (dao *UserDAO) HardDelete(id string) error {
|
2026-03-27 19:25:18 +08:00
|
|
|
return DB.Unscoped().Where("id = ?", id).Delete(&entity.User{}).Error
|
2026-03-13 16:53:54 +08:00
|
|
|
}
|
|
|
|
|
|
Feat: Implement user creation, deletion, and permission management functionality. (#13519)
### What problem does this PR solve?
Feat: Implement user creation, deletion, and permission management
functionality.
- Added the `ListByEmail` method to `user.go` to query users by email
address.
- Updated the user activation status handling logic in `handler.go`,
adding input validation.
- Added RSA password decryption functionality to `password.go`.
- Implemented complete user management functionality in `service.go`,
including user creation, deletion, password modification, activation
status, and permission management.
- Added input validation and error handling logic.
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
2026-03-11 14:04:00 +08:00
|
|
|
// ListByEmail list users by email (only active users with status != "0")
|
|
|
|
|
// Returns all users matching the given email address
|
2026-03-27 19:25:18 +08:00
|
|
|
func (dao *UserDAO) ListByEmail(email string) ([]*entity.User, error) {
|
|
|
|
|
var users []*entity.User
|
2026-03-19 21:05:15 +08:00
|
|
|
err := DB.Where("email = ?", email).Find(&users).Error
|
Feat: Implement user creation, deletion, and permission management functionality. (#13519)
### What problem does this PR solve?
Feat: Implement user creation, deletion, and permission management
functionality.
- Added the `ListByEmail` method to `user.go` to query users by email
address.
- Updated the user activation status handling logic in `handler.go`,
adding input validation.
- Added RSA password decryption functionality to `password.go`.
- Implemented complete user management functionality in `service.go`,
including user creation, deletion, password modification, activation
status, and permission management.
- Added input validation and error handling logic.
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
2026-03-11 14:04:00 +08:00
|
|
|
return users, err
|
|
|
|
|
}
|