Exemplo n.º 1
0
func (self *channelAPI) Blob_Permission(perma grapher.PermaNode, permission grapher.PermissionNode) {
	mutJson := map[string]interface{}{"perma": perma.BlobRef(), "seq": permission.SequenceNumber(), "type": "permission", "user": permission.UserName(), "allow": permission.AllowBits(), "deny": permission.DenyBits(), "blobref": permission.BlobRef()}
	switch permission.Action() {
	case grapher.PermAction_Invite:
		mutJson["action"] = "invite"
	case grapher.PermAction_Expel:
		mutJson["action"] = "expel"
	case grapher.PermAction_Change:
		mutJson["action"] = "change"
	default:
		panic("Unknown action")
	}
	schema, err := json.Marshal(mutJson)
	if err != nil {
		panic(err.String())
	}
	if self.bufferOnly {
		self.messageBuffer = append(self.messageBuffer, string(schema))
	} else {
		err = self.forwardToFollowers(perma.BlobRef(), string(schema))
	}
	if err != nil {
		log.Printf("Err Forward: %v", err)
	}
}