Exemple #1
0
    def restrict_roles_and_modules(self):
        '''Disable all restricted roles and set `restrict_to_domain` property in Module Def'''
        active_domains = frappe.get_active_domains()
        all_domains = (frappe.get_hooks('domains') or {}).keys()

        def remove_role(role):
            frappe.db.sql('delete from `tabHas Role` where role=%s', role)
            frappe.set_value('Role', role, 'disabled', 1)

        for domain in all_domains:
            domain = _(domain)
            data = frappe.get_domain_data(domain)
            if not frappe.db.get_value('Domain', domain):
                frappe.get_doc(dict(doctype='Domain', domain=domain)).insert()
            if 'modules' in data:
                for module in data.get('modules'):
                    frappe.db.set_value('Module Def', module,
                                        'restrict_to_domain', domain)

            if 'restricted_roles' in data:
                for role in data['restricted_roles']:
                    if not frappe.db.get_value('Role', role):
                        frappe.get_doc(dict(doctype='Role',
                                            role_name=role)).insert()
                    frappe.db.set_value('Role', role, 'restrict_to_domain',
                                        domain)

                    if domain not in active_domains:
                        remove_role(role)
	def restrict_roles_and_modules(self):
		'''Disable all restricted roles and set `restrict_to_domain` property in Module Def'''
		active_domains = frappe.get_active_domains()
		all_domains = list((frappe.get_hooks('domains') or {}))

		def remove_role(role):
			frappe.db.delete("Has Role", {"role": role})
			frappe.set_value('Role', role, 'disabled', 1)

		for domain in all_domains:
			data = frappe.get_domain_data(domain)
			if not frappe.db.get_value('Domain', domain):
				frappe.get_doc(dict(doctype='Domain', domain=domain)).insert()
			if 'modules' in data:
				for module in data.get('modules'):
					frappe.db.set_value('Module Def', module, 'restrict_to_domain', domain)

			if 'restricted_roles' in data:
				for role in data['restricted_roles']:
					if not frappe.db.get_value('Role', role):
						frappe.get_doc(dict(doctype='Role', role_name=role)).insert()
					frappe.db.set_value('Role', role, 'restrict_to_domain', domain)

					if domain not in active_domains:
						remove_role(role)

			if 'custom_fields' in data:
				if domain not in active_domains:
					inactive_domain = frappe.get_doc("Domain", domain)
					inactive_domain.setup_data()
					inactive_domain.remove_custom_field()
Exemple #3
0
	def restrict_roles_and_modules(self):
		"""Disable all restricted roles and set `restrict_to_domain` property in Module Def"""
		active_domains = frappe.get_active_domains()
		all_domains = list((frappe.get_hooks("domains") or {}))

		def remove_role(role):
			frappe.db.sql("delete from `tabHas Role` where role=%s", role)
			frappe.set_value("Role", role, "disabled", 1)

		for domain in all_domains:
			data = frappe.get_domain_data(domain)
			if not frappe.db.get_value("Domain", domain):
				frappe.get_doc(dict(doctype="Domain", domain=domain)).insert()
			if "modules" in data:
				for module in data.get("modules"):
					frappe.db.set_value("Module Def", module, "restrict_to_domain", domain)

			if "restricted_roles" in data:
				for role in data["restricted_roles"]:
					if not frappe.db.get_value("Role", role):
						frappe.get_doc(dict(doctype="Role", role_name=role)).insert()
					frappe.db.set_value("Role", role, "restrict_to_domain", domain)

					if domain not in active_domains:
						remove_role(role)

			if "custom_fields" in data:
				if domain not in active_domains:
					inactive_domain = frappe.get_doc("Domain", domain)
					inactive_domain.setup_data()
					inactive_domain.remove_custom_field()
	def restrict_roles_and_modules(self):
		'''Disable all restricted roles and set `restrict_to_domain` property in Module Def'''
		active_domains = frappe.get_active_domains()
		all_domains = (frappe.get_hooks('domains') or {}).keys()

		def remove_role(role):
			frappe.db.sql('delete from `tabHas Role` where role=%s', role)
			frappe.set_value('Role', role, 'disabled', 1)

		for domain in all_domains:
			data = frappe.get_domain_data(domain)
			if not frappe.db.get_value('Domain', domain):
				frappe.get_doc(dict(doctype='Domain', domain=domain)).insert()
			if 'modules' in data:
				for module in data.get('modules'):
					frappe.db.set_value('Module Def', module, 'restrict_to_domain', domain)

			if 'restricted_roles' in data:
				for role in data['restricted_roles']:
					if not frappe.db.get_value('Role', role):
						frappe.get_doc(dict(doctype='Role', role_name=role)).insert()
					frappe.db.set_value('Role', role, 'restrict_to_domain', domain)

					if domain not in active_domains:
						remove_role(role)
Exemple #5
0
 def setup_data(self, domain=None):
     '''Load domain info via hooks'''
     self.data = frappe.get_domain_data(self.name)
Exemple #6
0
	def setup_data(self, domain=None):
		'''Load domain info via hooks'''
		self.data = frappe.get_domain_data(self.name)