# Copyright (c) 2015, JINGROW
# License: MIT. See LICENSE

import jingrow
from jingrow.model.page import Page


class HasRole(Page):
	# begin: auto-generated types
	# This code is auto-generated. Do not modify anything in this block.

	from typing import TYPE_CHECKING

	if TYPE_CHECKING:
		from jingrow.types import DF

		parent: DF.Data
		parentfield: DF.Data
		parenttype: DF.Data
		role: DF.Link | None

	# end: auto-generated types
	def before_insert(self):
		if jingrow.db.exists("Has Role", {"parent": self.parent, "role": self.role}):
			jingrow.throw(jingrow._("User '{0}' already has the role '{1}'").format(self.parent, self.role))
