示例#1
0
文件: auth.go 项目: eluleci/dock
func getPermissionsOnObject(collection string, id string, roles []string) (permissions map[string]bool, err *utils.Error) {

	var model map[string]interface{}
	model, err = adapters.Get(collection, id)
	if err != nil {
		return
	}

	acl := model["_acl"]
	if acl != nil {
		permissions = make(map[string]bool)

		for _, v := range roles {
			p := acl.(map[string]interface{})[v]
			if p != nil {
				for kAcl, _ := range p.(map[string]interface{}) {
					permissions[kAcl] = true
				}
			}
		}
	} else {
		permissions = map[string]bool{
			"get":    true,
			"update": true,
			"delete": true,
		}
	}

	return
}
示例#2
0
文件: auth.go 项目: eluleci/dock
func getUser(requestWrapper messages.RequestWrapper) (user map[string]interface{}, err *utils.Error) {

	var userDataFromToken map[string]interface{}
	userDataFromToken, err = extractUserFromRequest(requestWrapper)

	if err != nil {
		return
	}

	if userDataFromToken != nil {
		userId := userDataFromToken["userId"].(string)
		user, err = adapters.Get(ClassUsers, userId)
		if err != nil {
			return
		}
	}

	return
}
示例#3
0
文件: modifier.go 项目: eluleci/dock
var isValidExpandConfig = func(config string) bool {
	return strings.Count(config, "(") == strings.Count(config, ")")
}

var fetchData = func(data map[string]interface{}) (object map[string]interface{}, err *utils.Error) {
	fieldType := reflect.TypeOf(data["_id"])

	var id string
	if fieldType.Kind() == reflect.String {
		id = data["_id"].(string)
	} else {
		id = data["_id"].(bson.ObjectId).Hex()
	}
	className := data["_class"].(string)

	object, err = adapters.Get(className, id)
	if err != nil {
		return
	}
	return
}

var isValidReference = func(reference interface{}) bool {
	if reference == nil {
		return false
	}

	if t := reflect.TypeOf(reference); t == nil || t.Kind() != reflect.Map {
		return false
	}
示例#4
0
文件: actor.go 项目: eluleci/dock
	}
	return
}

var handleGet = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message, err *utils.Error) {

	isFileClass := strings.EqualFold(a.class, ClassFiles)
	isObjectTypeActor := strings.EqualFold(a.actorType, ActorTypeModel)
	isCollectionTypeActor := strings.EqualFold(a.actorType, ActorTypeCollection)

	if isObjectTypeActor {
		id := requestWrapper.Message.Res[strings.LastIndex(requestWrapper.Message.Res, "/")+1:]
		if isFileClass { // get file by id
			response.RawBody, err = adapters.GetFile(id)
		} else { // get object by id
			response.Body, err = adapters.Get(a.class, id)
		}
	} else if isCollectionTypeActor { // query objects
		response.Body, err = adapters.Query(a.class, requestWrapper.Message.Parameters)
	}

	if err != nil {
		return
	}

	if requestWrapper.Message.Parameters["expand"] != nil {
		expandConfig := requestWrapper.Message.Parameters["expand"][0]
		if _, hasDataArray := response.Body["data"]; hasDataArray {
			response.Body, err = modifier.ExpandArray(response.Body, expandConfig)
		} else {
			response.Body, err = modifier.ExpandItem(response.Body, expandConfig)