// ValidateUser Validate User : Will validate user id is present in the given table or not
ValidateUser Validate User : Will validate user id is present in the given table or not
// ValidateUser Validate User : Will validate user id is present in the given table or not
func (validateUserInfo *ValidateUserInfo) ValidateUser() error {
	if !validateUserInfo.skipValidation {
		if err := validateUserInfo.validate(); err != nil {
			return err
		}
	}
	userInfo := FromContext(validateUserInfo.Ctx)
	if userInfo.Sub == "" {
		return status.Error(codes.PermissionDenied, "unauthenticated user")
	}
	if !validateUserInfo.SkipRootValidation {
		tx := validateUserInfo.Db.Where(validateUserInfo.RootTableTag+" = ?", userInfo.ID).First(validateUserInfo.RootTable)
		if tx.Error != nil {
			return status.Error(codes.PermissionDenied, "unauthenticated user")
		}
	}
	if !validateUserInfo.SkipArgsValidation {
		for tag, argTable := range validateUserInfo.Args {
			tx := validateUserInfo.Db.Where(tag+" = ?", userInfo.ID).First(argTable)
			if tx.Error != nil {
				return status.Error(codes.PermissionDenied, "unauthenticated user")
			}
		}
	}
	return nil
}
func ( validateUserInfo * ValidateUserInfo ) ValidateUser ( ) error { if ! validateUserInfo . skipValidation { if err := validateUserInfo . validate ( ) ; err != nil { return err } } userInfo := FromContext ( validateUserInfo . Ctx ) if userInfo . Sub == " " { return status . Error ( codes . PermissionDenied , " " ) } if ! validateUserInfo . SkipRootValidation { tx := validateUserInfo . Db . Where ( validateUserInfo . RootTableTag + " " , userInfo . ID ) . First ( validateUserInfo . RootTable ) if tx . Error != nil { return status . Error ( codes . PermissionDenied , " " ) } } if ! validateUserInfo . SkipArgsValidation { for tag , argTable := range validateUserInfo . Args { tx := validateUserInfo . Db . Where ( tag + " " , userInfo . ID ) . First ( argTable ) if tx . Error != nil { return status . Error ( codes . PermissionDenied , " " ) } } } return nil }
ValidateUser Validate User : Will validate user id is present in the given table or not
ValidateUser Validate User : Will validate user id is present in the given table or not
//Extract user id from context