(eid, userID int64, role int64, apiKey *model.APIKey)
| 177 | } |
| 178 | |
| 179 | func (s *APIKeyService) ensureAPIKeyManagePermission(eid, userID int64, role int64, apiKey *model.APIKey) error { |
| 180 | if apiKey == nil { |
| 181 | return errors.New("API密钥不存在") |
| 182 | } |
| 183 | |
| 184 | if apiKey.LibraryID != nil { |
| 185 | hasPerm, err := s.hasLibraryManagementPermission(eid, userID, *apiKey.LibraryID) |
| 186 | if err != nil { |
| 187 | return err |
| 188 | } |
| 189 | if !hasPerm { |
| 190 | return errors.New("您没有权限管理此API密钥") |
| 191 | } |
| 192 | return nil |
| 193 | } |
| 194 | |
| 195 | if role < model.RoleAdminUser { |
| 196 | return errors.New("您没有权限管理全局API密钥") |
| 197 | } |
| 198 | return nil |
| 199 | } |
| 200 | |
| 201 | func (s *APIKeyService) hasLibraryManagementPermission(eid, userID, libraryID int64) (bool, error) { |
| 202 | permission, err := core.GetUserPermission(eid, model.RESOURCE_TYPE_LIBRARY, libraryID, userID) |
no test coverage detected