mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-21 23:21:04 +08:00
@@ -378,3 +378,32 @@ func (dao *MemoryDAO) GetByFilter(userID string, tenantIDs []string, memoryTypes
|
||||
|
||||
return memories, total, nil
|
||||
}
|
||||
|
||||
// Accessible check if it is possible for user to access the memory
|
||||
func (dao *MemoryDAO) Accessible(userID, memoryID string) (bool, error) {
|
||||
memory, err := dao.GetByID(memoryID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if memory.TenantID == userID {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if memory.Permissions != string(entity.TenantPermissionTeam) {
|
||||
return false, fmt.Errorf("user %s have no access to this memory", userID)
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = DB.Table("user_tenant").
|
||||
Where("tenant_id = ? AND user_id = ? AND status = ?", memory.TenantID, userID, "1").
|
||||
Count(&count).Error
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if count > 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, fmt.Errorf("user %s have no access to this memory", userID)
|
||||
}
|
||||
|
||||
@@ -447,6 +447,9 @@ func (s *MemoryService) CreateMemory(tenantID string, req *CreateMemoryRequest)
|
||||
// resp, err := service.UpdateMemory("tenant123", "memory456", req)
|
||||
func (s *MemoryService) UpdateMemory(tenantID string, memoryID string, req *UpdateMemoryRequest) (*CreateMemoryResponse, error) {
|
||||
updateDict := make(map[string]interface{})
|
||||
if ok, err := s.memoryDAO.Accessible(tenantID, memoryID); !ok || err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
currentMemory, err := s.memoryDAO.GetByID(memoryID)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user