MCPcopy Create free account
hub / github.com/53AI/53AIHub / ensureAPIKeyManagePermission

Method ensureAPIKeyManagePermission

api/service/mcp/key_service.go:179–199  ·  view source on GitHub ↗
(eid, userID int64, role int64, apiKey *model.APIKey)

Source from the content-addressed store, hash-verified

177}
178
179func (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
201func (s *APIKeyService) hasLibraryManagementPermission(eid, userID, libraryID int64) (bool, error) {
202 permission, err := core.GetUserPermission(eid, model.RESOURCE_TYPE_LIBRARY, libraryID, userID)

Callers 2

DeleteAPIKeyMethod · 0.95
SetAPIKeyStatusMethod · 0.95

Calls 2

NewMethod · 0.45

Tested by

no test coverage detected