Пример #1
0
def load_desktop_data(bootinfo):
	from frappe.config import get_modules_from_all_apps_for_user
	from frappe.desk.desktop import get_desk_sidebar_items
	bootinfo.allowed_modules = get_modules_from_all_apps_for_user()
	bootinfo.allowed_workspaces = get_desk_sidebar_items(flatten=True, cache=False)
	bootinfo.module_page_map = get_controller("Desk Page").get_module_page_map()
	bootinfo.dashboards = frappe.get_all("Dashboard")
Пример #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
Пример #3
0
def get_permission_query_conditions(user):
    if not user:
        user = frappe.session.user

    if user == "Administrator":
        return

    roles = frappe.get_roles(user)
    if "System Manager" in roles:
        return None

    doctype_condition = False
    report_condition = False
    module_condition = False

    allowed_doctypes = [
        frappe.db.escape(doctype)
        for doctype in frappe.permissions.get_doctypes_with_read()
    ]
    allowed_reports = [
        frappe.db.escape(key) if type(key) == str else key.encode("UTF8")
        for key in get_allowed_reports()
    ]
    allowed_modules = [
        frappe.db.escape(module.get("module_name"))
        for module in get_modules_from_all_apps_for_user()
    ]

    if allowed_doctypes:
        doctype_condition = "`tabDashboard Chart`.`document_type` in ({allowed_doctypes})".format(
            allowed_doctypes=",".join(allowed_doctypes))
    if allowed_reports:
        report_condition = "`tabDashboard Chart`.`report_name` in ({allowed_reports})".format(
            allowed_reports=",".join(allowed_reports))
    if allowed_modules:
        module_condition = """`tabDashboard Chart`.`module` in ({allowed_modules})
			or `tabDashboard Chart`.`module` is NULL""".format(
            allowed_modules=",".join(allowed_modules))

    return """
		((`tabDashboard Chart`.`chart_type` in ('Count', 'Sum', 'Average')
		and {doctype_condition})
		or
		(`tabDashboard Chart`.`chart_type` = 'Report'
		and {report_condition}))
		and
		({module_condition})
	""".format(
        doctype_condition=doctype_condition,
        report_condition=report_condition,
        module_condition=module_condition,
    )
Пример #4
0
def get_desktop_settings():
	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
Пример #5
0
def get_permission_query_conditions(user):
	if not user:
		user = frappe.session.user

	if user == 'Administrator':
		return

	roles = frappe.get_roles(user)
	if "System Manager" in roles:
		return None

	allowed_modules = [frappe.db.escape(module.get('module_name')) for module in get_modules_from_all_apps_for_user()]
	module_condition =  '`tabDashboard`.`module` in ({allowed_modules}) or `tabDashboard`.`module` is NULL'.format(
		allowed_modules=','.join(allowed_modules))

	return module_condition
Пример #6
0
def get_options_for_user_blocked_modules():
    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()

    hidden_modules = home_settings.hidden_modules or []

    options = []
    for module in all_modules:
        module = frappe._dict(module)
        options.append({
            'category': module.category,
            'label': module.label,
            'value': module.module_name,
            'checked': module.module_name not in hidden_modules
        })

    return options
Пример #7
0
def execute():
	users = frappe.get_all('User', fields=['name', 'home_settings'])

	for user in users:

		if not user.home_settings:
			continue

		home_settings = json.loads(user.home_settings)

		modules_by_category = home_settings.get('modules_by_category')
		if not modules_by_category:
			continue
		visible_modules = []
		category_to_check = []

		for category, modules in modules_by_category.items():
			visible_modules += modules
			category_to_check.append(category)

		all_modules = get_modules_from_all_apps_for_user(user.name)
		all_modules = set([m.get('name') or m.get('module_name') or m.get('label') \
			for m in all_modules if m.get('category') in category_to_check])

		hidden_modules = home_settings.get("hidden_modules", [])

		modules_in_home_settings = set(visible_modules + hidden_modules)

		all_modules = all_modules.union(modules_in_home_settings)

		missing_modules = all_modules - modules_in_home_settings

		if missing_modules:
			home_settings['hidden_modules'] = hidden_modules + list(missing_modules)
			home_settings = json.dumps(home_settings)
			frappe.set_value('User', user.name, 'home_settings', home_settings)

	frappe.cache().delete_key('home_settings')
Пример #8
0
def get_permission_query_conditions(user=None):
    if not user:
        user = frappe.session.user

    if user == 'Administrator':
        return

    roles = frappe.get_roles(user)
    if "System Manager" in roles:
        return None

    doctype_condition = False
    module_condition = False

    allowed_doctypes = [
        frappe.db.escape(doctype)
        for doctype in frappe.permissions.get_doctypes_with_read()
    ]
    allowed_modules = [
        frappe.db.escape(module.get('module_name'))
        for module in get_modules_from_all_apps_for_user()
    ]

    if allowed_doctypes:
        doctype_condition = '`tabNumber Card`.`document_type` in ({allowed_doctypes})'.format(
            allowed_doctypes=','.join(allowed_doctypes))
    if allowed_modules:
        module_condition = '''`tabNumber Card`.`module` in ({allowed_modules})
			or `tabNumber Card`.`module` is NULL'''.format(
            allowed_modules=','.join(allowed_modules))

    return '''
		{doctype_condition}
		and
		{module_condition}
	'''.format(doctype_condition=doctype_condition,
            module_condition=module_condition)
Пример #9
0
def load_desktop_icons(bootinfo):
    from frappe.config import get_modules_from_all_apps_for_user
    bootinfo.allowed_modules = get_modules_from_all_apps_for_user()