def apply_permissions(data):
	default_country = frappe.db.get_default("country")

	user = frappe.get_user()
	user.build_permissions()

	allowed_pages = get_allowed_pages()

	new_data = []
	for section in data:
		new_items = []

		for item in (section.get("items") or []):
			item = frappe._dict(item)

			if item.country and item.country!=default_country:
				continue

			if ((item.type=="doctype" and item.name in user.can_read)
				or (item.type=="page" and item.name in allowed_pages)
				or (item.type=="report" and item.doctype in user.can_get_report)
				or item.type=="help"):

				new_items.append(item)

		if new_items:
			new_section = section.copy()
			new_section["items"] = new_items
			new_data.append(new_section)

	return new_data
Example #2
0
def apply_permissions(data):
    default_country = frappe.db.get_default("country")

    user = frappe.get_user()
    user.build_permissions()

    allowed_pages = get_allowed_pages()
    allowed_reports = get_allowed_reports()

    new_data = []
    for section in data:
        new_items = []

        for item in (section.get("items") or []):
            item = frappe._dict(item)

            if item.country and item.country != default_country:
                continue

            if ((item.type == "doctype" and item.name in user.can_read)
                    or (item.type == "page" and item.name in allowed_pages)
                    or (item.type == "report" and item.name in allowed_reports)
                    or item.type == "help"):

                new_items.append(item)

        if new_items:
            new_section = section.copy()
            new_section["items"] = new_items
            new_data.append(new_section)

    return new_data
Example #3
0
def get_user_icons(user):
	'''Get user icons for module setup page'''
	user_perms = UserPermissions(user)
	user_perms.build_permissions()

	from frappe.boot import get_allowed_pages

	allowed_pages = get_allowed_pages()

	icons = []
	for icon in get_desktop_icons(user):
		add = True
		if icon.hidden_in_standard:
			add = False

		if not icon.custom:
			if icon.module_name=='Learn':
				pass

			elif icon.type=="page" and icon.link not in allowed_pages:
				add = False

			elif icon.type=="module" and icon.module_name not in user_perms.allow_modules:
				add = False

		if add:
			icons.append(icon)

	return icons
Example #4
0
    def __init__(self, page_name):
        self.page_name = page_name
        self.extended_cards = []
        self.extended_charts = []
        self.extended_shortcuts = []

        self.user = frappe.get_user()
        self.allowed_modules = self.get_cached_value('user_allowed_modules',
                                                     self.get_allowed_modules)
        self.doc = self.get_page_for_user()

        if self.doc.module not in self.allowed_modules:
            raise frappe.PermissionError

        self.can_read = self.get_cached_value('user_perm_can_read',
                                              self.get_can_read_items)

        self.allowed_pages = get_allowed_pages(cache=True)
        self.allowed_reports = get_allowed_reports(cache=True)
        self.onboarding_doc = self.get_onboarding_doc()
        self.onboarding = None

        self.table_counts = get_table_with_counts()
        self.restricted_doctypes = frappe.cache().get_value(
            "domain_restricted_doctypes"
        ) or build_domain_restriced_doctype_cache()
        self.restricted_pages = frappe.cache().get_value(
            "domain_restricted_pages") or build_domain_restriced_page_cache()
Example #5
0
def get_user_icons(user):
    '''Get user icons for module setup page'''
    user_perms = UserPermissions(user)
    user_perms.build_permissions()

    from frappe.boot import get_allowed_pages
    allowed_pages = get_allowed_pages()

    icons = []
    for icon in get_desktop_icons(user):
        add = True
        if icon.hidden_in_standard:
            add = False

        if not icon.custom:
            if icon.module_name == 'Learn':
                pass

            elif icon.type == "page" and icon.link not in allowed_pages:
                add = False

            elif icon.type == "module" and icon.module_name not in user_perms.allow_modules:
                add = False

        if add:
            icons.append(icon)

    return icons
Example #6
0
    def __init__(self, page, minimal=False):
        self.page_name = page.get('name')
        self.page_title = page.get('title')
        self.public_page = page.get('public')
        self.extended_links = []
        self.extended_charts = []
        self.extended_shortcuts = []
        self.workspace_manager = "Workspace Manager" in frappe.get_roles()

        self.user = frappe.get_user()
        self.allowed_modules = self.get_cached('user_allowed_modules',
                                               self.get_allowed_modules)

        self.doc = frappe.get_cached_doc("Workspace", self.page_name)

        if self.doc and self.doc.module and self.doc.module not in self.allowed_modules and not self.workspace_manager:
            raise frappe.PermissionError

        self.can_read = self.get_cached('user_perm_can_read',
                                        self.get_can_read_items)

        self.allowed_pages = get_allowed_pages(cache=True)
        self.allowed_reports = get_allowed_reports(cache=True)

        if not minimal:
            if self.doc.content:
                self.onboarding_list = [
                    x['data']['onboarding_name']
                    for x in loads(self.doc.content)
                    if x['type'] == 'onboarding'
                ]
            self.onboardings = []

            self.table_counts = get_table_with_counts()
        self.restricted_doctypes = frappe.cache().get_value(
            "domain_restricted_doctypes"
        ) or build_domain_restriced_doctype_cache()
        self.restricted_pages = frappe.cache().get_value(
            "domain_restricted_pages") or build_domain_restriced_page_cache()