MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / buildExecuteContext

Function buildExecuteContext

cmd/cql-proxy/api/user_data.go:337–433  ·  view source on GitHub ↗
(c *gin.Context, tableName string)

Source from the content-addressed store, hash-verified

335}
336
337func buildExecuteContext(c *gin.Context, tableName string) (projectDB *gorp.DbMap, uid string, userState string,
338 vars map[string]interface{}, r *resolver.Rules, fields resolver.FieldMap, adminMode bool, err error) {
339 project := getCurrentProject(c)
340 projectDB, err = getCurrentProjectDB(c)
341 if err != nil {
342 err = errors.Wrapf(err, "load project database failed")
343 return
344 }
345
346 var (
347 userID = getUserID(c)
348 developerID = getDeveloperID(c)
349 userInfo *model.ProjectUser
350 )
351
352 if userID != 0 {
353 userInfo, err = model.GetProjectUser(projectDB, userID)
354 if err != nil {
355 err = errors.Wrapf(err, "get project user info failed")
356 return
357 }
358
359 uid = fmt.Sprint(userID)
360 }
361
362 if developerID != 0 && project.Developer == developerID {
363 // table accessing from admin mode, check admin project belonging
364 adminMode = true
365 }
366
367 // check if project is disabled, admin mode does not check whether project is enabled or not
368 if !adminMode {
369 var pmc *model.ProjectMiscConfig
370 _, pmc, err = model.GetProjectMiscConfig(projectDB)
371 if err != nil || !pmc.IsEnabled() {
372 err = ErrProjectIsDisabled
373 return
374 }
375 }
376
377 vars = map[string]interface{}{}
378
379 if userInfo == nil {
380 vars["user_id"] = 0
381 vars["user_name"] = nil
382 vars["user_email"] = nil
383 vars["user_provider"] = nil
384 vars["user_created"] = nil
385 vars["user_last_login"] = nil
386
387 userState = resolver.UserStateAnonymous
388 } else {
389 vars["user_id"] = userInfo.ID
390 vars["user_name"] = userInfo.Name
391 vars["user_email"] = userInfo.Email
392 vars["user_provider"] = userInfo.Provider
393 vars["user_created"] = userInfo.Created
394 vars["user_last_login"] = userInfo.LastLogin

Callers 5

userDataFindFunction · 0.85
userDataInsertFunction · 0.85
userDataUpdateFunction · 0.85
userDataRemoveFunction · 0.85
userDataCountFunction · 0.85

Calls 10

IsEnabledMethod · 0.95
GetProjectUserFunction · 0.92
GetProjectMiscConfigFunction · 0.92
GetProjectTableConfigFunction · 0.92
getCurrentProjectFunction · 0.85
getCurrentProjectDBFunction · 0.85
getUserIDFunction · 0.85
getDeveloperIDFunction · 0.85
loadRulesFunction · 0.85
NewMethod · 0.65

Tested by

no test coverage detected