(eid, userID int64, role int64, libraryID *int64)
| 149 | } |
| 150 | |
| 151 | func (s *APIKeyService) resolveAPIKeyScope(eid, userID int64, role int64, libraryID *int64) (*int64, error) { |
| 152 | if libraryID == nil { |
| 153 | if role < model.RoleAdminUser { |
| 154 | return nil, errors.New("您没有权限创建全局API密钥,请指定知识库ID") |
| 155 | } |
| 156 | return nil, nil |
| 157 | } |
| 158 | |
| 159 | hasPerm, err := s.hasLibraryManagementPermission(eid, userID, *libraryID) |
| 160 | if err != nil { |
| 161 | return nil, err |
| 162 | } |
| 163 | if !hasPerm { |
| 164 | return nil, errors.New("您没有权限为此知识库创建API密钥") |
| 165 | } |
| 166 | |
| 167 | library, err := model.GetLibraryByID(eid, *libraryID) |
| 168 | if err != nil { |
| 169 | return nil, fmt.Errorf("获取知识库信息失败: %w", err) |
| 170 | } |
| 171 | if library == nil { |
| 172 | return nil, errors.New("知识库不存在") |
| 173 | } |
| 174 | |
| 175 | spaceID := library.SpaceID |
| 176 | return &spaceID, nil |
| 177 | } |
| 178 | |
| 179 | func (s *APIKeyService) ensureAPIKeyManagePermission(eid, userID int64, role int64, apiKey *model.APIKey) error { |
| 180 | if apiKey == nil { |
no test coverage detected