Browse Source

refactor(allowed_modules): use the new modules API

version-14
Prateeksha Singh 6 years ago
parent
commit
466de4f19b
5 changed files with 63 additions and 48 deletions
  1. +2
    -2
      frappe/boot.py
  2. +56
    -0
      frappe/config/__init__.py
  3. +3
    -3
      frappe/core/doctype/user/user.json
  4. +2
    -2
      frappe/core/doctype/user/user.py
  5. +0
    -41
      frappe/desk/doctype/desktop_icon/desktop_icon.py

+ 2
- 2
frappe/boot.py View File

@@ -96,8 +96,8 @@ def load_conf_settings(bootinfo):
if key in conf: bootinfo[key] = conf.get(key)

def load_desktop_icons(bootinfo):
from frappe.desk.doctype.desktop_icon.desktop_icon import get_modules_from_all_apps
bootinfo.allowed_modules = get_modules_from_all_apps()
from frappe.config import get_modules_from_all_apps_for_user
bootinfo.allowed_modules = get_modules_from_all_apps_for_user()

def get_allowed_pages():
return get_user_pages_or_reports('Page')


+ 56
- 0
frappe/config/__init__.py View File

@@ -0,0 +1,56 @@
from __future__ import unicode_literals
from frappe import _
import frappe
from six import iteritems

def get_modules_from_all_apps_for_user(user=None):
if not user:
user = frappe.session.user

all_modules = get_modules_from_all_apps()
user_blocked_modules = frappe.get_doc('User', user).get_blocked_modules()

allowed_modules_list = [m for m in all_modules if m.get("module_name") not in user_blocked_modules]

return allowed_modules_list

def get_modules_from_all_apps():
modules_list = []
for app in frappe.get_installed_apps():
modules_list += get_modules_from_app(app)
return modules_list

def get_modules_from_app(app):
try:
modules = frappe.get_attr(app + '.config.desktop.get_data')() or {}
except ImportError:
return []

# Only newly formatted modules that have a category to be shown on desk
modules = [m for m in modules if m.get("category")]

active_domains = frappe.get_active_domains()

if isinstance(modules, dict):
active_modules_list = []
for m, desktop_icon in iteritems(modules):
desktop_icon['module_name'] = m
active_modules_list.append(desktop_icon)
else:
active_modules_list = []
for m in modules:
to_add = True
module_name = m.get("module_name")

# Check Domain
if is_domain(m):
if module_name not in active_domains:
to_add = False

if to_add:
active_modules_list.append(m)

return active_modules_list

def is_domain(module):
return module.get("category") == "Domains"

+ 3
- 3
frappe/core/doctype/user/user.json View File

@@ -1511,7 +1511,7 @@
"columns": 0,
"default": "",
"description": "",
"fieldname": "desktop_icon_access",
"fieldname": "sb_allow_modules",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
@@ -1520,7 +1520,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Allow Desktop Icon",
"label": "Allow Modules",
"length": 0,
"no_copy": 0,
"permlevel": 1,
@@ -2303,7 +2303,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 5,
"modified": "2018-11-21 12:34:57.652854",
"modified": "2019-01-30 13:56:10.732154",
"modified_by": "Administrator",
"module": "Core",
"name": "User",


+ 2
- 2
frappe/core/doctype/user/user.py View File

@@ -36,9 +36,9 @@ class User(Document):
self.name = self.email

def onload(self):
from frappe.config import get_modules_from_all_apps
self.set_onload('all_modules',
[m.module_name for m in frappe.db.get_all('Desktop Icon',
fields=['module_name'], filters={'standard': 1}, order_by="module_name")])
[m.get("module_name") for m in get_modules_from_all_apps()])

def before_insert(self):
self.flags.in_insert = True


+ 0
- 41
frappe/desk/doctype/desktop_icon/desktop_icon.py View File

@@ -487,44 +487,3 @@ def hide(name, user = None):
return False

return True

@frappe.whitelist()
def get_modules_from_all_apps():
modules_list = []
for app in frappe.get_installed_apps():
modules_list += get_modules_from_app(app)
return modules_list

def get_modules_from_app(app):
try:
modules = frappe.get_attr(app + '.config.desktop.get_data')() or {}
except ImportError:
return []

# Only newly formatted modules that have a category to be shown on desk
modules = [m for m in modules if m.get("category")]

active_domains = frappe.get_active_domains()

if isinstance(modules, dict):
allowed_modules_list = []
for m, desktop_icon in iteritems(modules):
desktop_icon['module_name'] = m
allowed_modules_list.append(desktop_icon)
else:
allowed_modules_list = []
for m in modules:
to_add = True

# Check Domain
if is_domain(m):
if m.get("module_name") not in active_domains:
to_add = False

if to_add:
allowed_modules_list.append(m)

return allowed_modules_list

def is_domain(module):
return module.get("category") == "Domains"

Loading…
Cancel
Save