Esempio n. 1
0
	def test_desktop_icon_for_domainification(self):
		"""desktop icon should be hidden if doctype's restrict to domain is not in active domains"""

		test_doctype = self.new_doctype("Test Domainification")
		test_doctype.restrict_to_domain = "_Test Domain 2"
		test_doctype.insert()

		self.add_active_domain("_Test Domain 2")
		add_user_icon("Test Domainification")

		icons = get_desktop_icons()

		doctypes = [
			icon.get("_doctype")
			for icon in icons
			if icon.get("_doctype") == "Test Domainification" and icon.get("blocked") == 0
		]
		self.assertTrue("Test Domainification" in doctypes)

		# doctype should be hidden from the desk
		self.remove_from_active_domains("_Test Domain 2")
		clear_desktop_icons_cache()  # clear cache to fetch the desktop icon according to new active domains
		icons = get_desktop_icons()

		doctypes = [
			icon.get("_doctype")
			for icon in icons
			if icon.get("_doctype") == "Test Domainification" and icon.get("blocked") == 0
		]
		self.assertFalse("Test Domainification" in doctypes)
Esempio n. 2
0
def get_desktop_settings():
    clear_desktop_icons_cache()
    from frappe.config import get_modules_from_all_apps_for_user
    all_modules = get_modules_from_all_apps_for_user()
    home_settings = get_home_settings()

    modules_by_name = {}
    for m in all_modules:
        modules_by_name[m['module_name']] = m

    module_categories = ['Modules', 'Domains', 'Places', 'Administration']
    user_modules_by_category = {}

    user_saved_modules_by_category = home_settings.modules_by_category or {}
    user_saved_links_by_module = home_settings.links_by_module or {}

    def apply_user_saved_links(module):
        module = frappe._dict(module)
        all_links = get_links(module.app, module.module_name)
        module_links_by_name = {}
        for link in all_links:
            module_links_by_name[link['name']] = link

        if module.module_name in user_saved_links_by_module:
            user_links = frappe.parse_json(
                user_saved_links_by_module[module.module_name])
            module.links = [
                module_links_by_name[l] for l in user_links
                if l in module_links_by_name
            ]

        return module

    for category in module_categories:
        if category in user_saved_modules_by_category:
            user_modules = user_saved_modules_by_category[category]
            user_modules_by_category[category] = [apply_user_saved_links(modules_by_name[m]) \
             for m in user_modules if modules_by_name.get(m)]
        else:
            user_modules_by_category[category] = [apply_user_saved_links(m) \
             for m in all_modules if m.get('category') == category]

    # filter out hidden modules
    if home_settings.hidden_modules:
        for category in user_modules_by_category:
            hidden_modules = []  #home_settings.hidden_modules or []
            modules = user_modules_by_category[category]
            user_modules_by_category[category] = [
                module for module in modules
                if module.module_name not in hidden_modules
            ]

    return user_modules_by_category
Esempio n. 3
0
def execute():
    desktop_icons = frappe.db.sql("""
		select name, label
		from
			`tabDesktop Icon` 
		where 
			_doctype is not null 
			and _doctype != '' 
			and _doctype != label""",
                                  as_dict=1)

    for d in desktop_icons:
        if not is_english(d.label):
            frappe.db.sql(
                """update `tabDesktop Icon` 
				set module_name=_doctype, label=_doctype where name=%s""", d.name)

    clear_desktop_icons_cache()
Esempio n. 4
0
	def test_block_desktop_icons_for_user(self):
		def test_unblock():
			user = frappe.get_doc('User', '*****@*****.**')
			user.block_modules = []
			user.save(ignore_permissions = 1)

			icon = self.get_icon('Desk')
			self.assertEqual(icon.hidden, 0)

		test_unblock()

		user = frappe.get_doc('User', '*****@*****.**')
		user.append('block_modules', {'module': 'Desk'})
		user.save(ignore_permissions = 1)
		clear_desktop_icons_cache(user.name)

		icon = self.get_icon('Desk')
		self.assertEqual(icon.hidden, 1)

		test_unblock()
Esempio n. 5
0
	def test_desktop_icon_for_domainification(self):
		""" desktop icon should be hidden if doctype's restrict to domain is not in active domains """

		test_doctype = self.new_doctype("Test Domainification")
		test_doctype.restrict_to_domain = "_Test Domain 2"
		test_doctype.insert()

		self.add_active_domain("_Test Domain 2")
		add_user_icon('Test Domainification')

		icons = get_desktop_icons()

		doctypes = [icon.get("_doctype") for icon in icons if icon.get("_doctype") == "Test Domainification" \
			and icon.get("blocked") == 0]
		self.assertTrue("Test Domainification" in doctypes)

		# doctype should be hidden from the desk
		self.remove_from_active_domains("_Test Domain 2")
		clear_desktop_icons_cache()		# clear cache to fetch the desktop icon according to new active domains
		icons = get_desktop_icons()

		doctypes = [icon.get("_doctype") for icon in icons if icon.get("_doctype") == "Test Domainification" \
			and icon.get("blocked") == 0]
		self.assertFalse("Test Domainification" in doctypes)
Esempio n. 6
0
def hide_module(module):
	set_hidden(module, frappe.session.user, 1)
	clear_desktop_icons_cache()
Esempio n. 7
0
def hide_module(module):
    set_hidden(module, frappe.session.user, 1)
    clear_desktop_icons_cache()