# Copyright (c) 2015, XhiveFramework Technologies and contributors
# License: MIT. See LICENSE

import xhiveframework
from xhiveframework.model.document import Document


class HasRole(Document):
	def before_insert(self):
		if xhiveframework.db.exists("Has Role", {"parent": self.parent, "role": self.role}):
			xhiveframework.throw(xhiveframework._("User '{0}' already has the role '{1}'").format(self.parent, self.role))
