<commit_before>package rest

import "github.com/lfq7413/tomato/auth"

// Find ...
func Find(
	auth *auth.Auth,
	className string,
	where map[string]interface{},
	options map[string]interface{},
) map[string]interface{} {

	enforceRoleSecurity("find", className, auth)
	query := NewQuery(auth, className, where, options)

	return query.Execute()
}

// Delete ...
func Delete(
	auth *auth.Auth,
	className string,
	objectID string,
) map[string]interface{} {

	if className == "_User" && auth.CouldUpdateUserID(objectID) == false {
		// TODO 权限不足
	}

	enforceRoleSecurity("delete", className, auth)

	var inflatedObject map[string]interface{}
	// TODO 获取要删除的对象

	destroy := NewDestroy(auth, className, map[string]interface{}{"objectId": objectID}, inflatedObject)

	return destroy.Execute()
}

// Create ...
func Create(
	auth *auth.Auth,
	className string,
	object map[string]interface{},
) map[string]interface{} {

	enforceRoleSecurity("create", className, auth)
	write := NewWrite(auth, className, nil, object, nil)

	return write.Execute()
}

// Update ...
func Update(
	auth *auth.Auth,
	className string,
	objectID string,
	object map[string]interface{},
) map[string]interface{} {

	enforceRoleSecurity("update", className, auth)

	var originalRestObject map[string]interface{}
	// TODO 获取要更新的对象

	write := NewWrite(auth, className, map[string]interface{}{"objectId": objectID}, object, originalRestObject)

	return write.Execute()
}

func enforceRoleSecurity(method string, className string, auth *auth.Auth) {
	if className == "_Role" && auth.IsMaster == false {
		// TODO 权限不足
	}
	if method == "delete" && className == "_Installation" && auth.IsMaster == false {
		// TODO 权限不足
	}
}<commit_msg>获取要删除的对象<commit_after>package rest

import "github.com/lfq7413/tomato/auth"
import "github.com/lfq7413/tomato/triggers"

// Find ...
func Find(
	auth *auth.Auth,
	className string,
	where map[string]interface{},
	options map[string]interface{},
) map[string]interface{} {

	enforceRoleSecurity("find", className, auth)
	query := NewQuery(auth, className, where, options)

	return query.Execute()
}

// Delete ...
func Delete(
	auth *auth.Auth,
	className string,
	objectID string,
) map[string]interface{} {

	if className == "_User" && auth.CouldUpdateUserID(objectID) == false {
		// TODO 权限不足
	}

	enforceRoleSecurity("delete", className, auth)

	var inflatedObject map[string]interface{}

	if triggers.TriggerExists(triggers.TypeBeforeDelete, className) ||
		triggers.TriggerExists(triggers.TypeAfterDelete, className) ||
		className == "_Session" {
		response := Find(auth, className, map[string]interface{}{"objectId": objectID}, map[string]interface{}{})
		if response == nil {
			// TODO 未找到要删除的对象
		}
		results := response["results"]
		if results == nil {
			// TODO 未找到要删除的对象
		}
		var result []interface{}
		if v, ok := results.([]interface{}); ok {
			result = v
		} else {
			// TODO 未找到要删除的对象
		}
		if len(result) == 0 {
			// TODO 未找到要删除的对象
		}
		if v, ok := result[0].(map[string]interface{}); ok {
			// TODO 删除sessionToken
			inflatedObject = v
		} else {
			// TODO 未找到要删除的对象
		}
	}

	destroy := NewDestroy(auth, className, map[string]interface{}{"objectId": objectID}, inflatedObject)

	return destroy.Execute()
}

// Create ...
func Create(
	auth *auth.Auth,
	className string,
	object map[string]interface{},
) map[string]interface{} {

	enforceRoleSecurity("create", className, auth)
	write := NewWrite(auth, className, nil, object, nil)

	return write.Execute()
}

// Update ...
func Update(
	auth *auth.Auth,
	className string,
	objectID string,
	object map[string]interface{},
) map[string]interface{} {

	enforceRoleSecurity("update", className, auth)

	var originalRestObject map[string]interface{}

	var response map[string]interface{}
	if triggers.TriggerExists(triggers.TypeBeforeSave, className) ||
		triggers.TriggerExists(triggers.TypeAfterSave, className) {
		response = Find(auth, className, map[string]interface{}{"objectId": objectID}, map[string]interface{}{})
	}
	var results interface{}
	if response != nil {
		results = response["results"]
	}
	var result []interface{}
	if results != nil {
		if v, ok := results.([]interface{}); ok {
			result = v
		}
	}
	if len(result) != 0 {
		if v, ok := result[0].(map[string]interface{}); ok {
			originalRestObject = v
		}
	}

	write := NewWrite(auth, className, map[string]interface{}{"objectId": objectID}, object, originalRestObject)

	return write.Execute()
}

func enforceRoleSecurity(method string, className string, auth *auth.Auth) {
	if className == "_Role" && auth.IsMaster == false {
		// TODO 权限不足
	}
	if method == "delete" && className == "_Installation" && auth.IsMaster == false {
		// TODO 权限不足
	}
}
{'fraction_non_alphanumeric': 0.15063829787234043, 'fraction_numerical': 0.003404255319148936, 'mean_word_length': 4.5964285714285715, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7167526', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1576, 'n_words': 362}