@@ -13,7 +13,7 @@ import os, sys, importlib, inspect, json | |||
from .exceptions import * | |||
from .utils.jinja import get_jenv, get_template, render_template | |||
__version__ = '8.0.13' | |||
__version__ = '8.0.14' | |||
__title__ = "Frappe Framework" | |||
local = Local() | |||
@@ -95,46 +95,70 @@ def get_allowed_pages(): | |||
def get_allowed_reports(): | |||
return get_user_page_or_report('Report') | |||
def get_user_page_or_report(parent): | |||
roles = frappe.get_roles() | |||
has_role = {} | |||
column = get_column(parent) | |||
# get pages or reports set on custom role | |||
for p in frappe.db.sql("""select `tabCustom Role`.{field} as name, `tabCustom Role`.modified, `tabCustom Role`.ref_doctype | |||
from `tabCustom Role`, `tabHas Role` where | |||
`tabHas Role`.parent = `tabCustom Role`.name and | |||
`tabCustom Role`.{field} is not null and `tabHas Role`.role in ({roles}) | |||
""".format(field=parent.lower(), roles = ', '.join(['%s']*len(roles))), roles, as_dict=1): | |||
# get pages or reports set on custom role | |||
custom_roles = frappe.db.sql(""" | |||
select | |||
`tabCustom Role`.{field} as name, | |||
`tabCustom Role`.modified, | |||
`tabCustom Role`.ref_doctype | |||
from `tabCustom Role`, `tabHas Role` | |||
where | |||
`tabHas Role`.parent = `tabCustom Role`.name | |||
and `tabCustom Role`.{field} is not null | |||
and `tabHas Role`.role in ({roles}) | |||
""".format(field=parent.lower(), roles = ', '.join(['%s']*len(roles))), roles, as_dict=1) | |||
for p in custom_roles: | |||
has_role[p.name] = {"modified":p.modified, "title": p.name, "ref_doctype": p.ref_doctype} | |||
for p in frappe.db.sql("""select distinct | |||
tab{parent}.name, tab{parent}.modified, {column} | |||
from `tabHas Role`, `tab{parent}` | |||
where `tabHas Role`.role in ({roles}) | |||
and `tabHas Role`.parent = `tab{parent}`.name | |||
""".format(parent=parent, column=column, roles = ', '.join(['%s']*len(roles))), roles, as_dict=True): | |||
standard_roles = frappe.db.sql(""" | |||
select distinct | |||
tab{parent}.name, | |||
tab{parent}.modified, | |||
{column} | |||
from `tabHas Role`, `tab{parent}` | |||
where | |||
`tabHas Role`.role in ({roles}) | |||
and `tabHas Role`.parent = `tab{parent}`.name | |||
and tab{parent}.name not in ( | |||
select `tabCustom Role`.{field} from `tabCustom Role` | |||
where `tabCustom Role`.{field} is not null) | |||
""".format(parent=parent, column=column, | |||
roles = ', '.join(['%s']*len(roles)), field=parent.lower()), roles, as_dict=True) | |||
for p in standard_roles: | |||
if p.name not in has_role: | |||
has_role[p.name] = {"modified":p.modified, "title": p.title} | |||
if parent == "Report": | |||
has_role[p.name].update({'ref_doctype': p.ref_doctype}) | |||
# pages with no role are allowed | |||
if parent =="Page": | |||
pages_with_no_roles = frappe.db.sql(""" | |||
select | |||
`tab{parent}`.name, `tab{parent}`.modified, {column} | |||
from `tab{parent}` | |||
where | |||
(select count(*) from `tabHas Role` | |||
where `tabHas Role`.parent=tab{parent}.name) = 0 | |||
""".format(parent=parent, column=column), as_dict=1) | |||
for p in pages_with_no_roles: | |||
if p.name not in has_role: | |||
has_role[p.name] = {"modified":p.modified, "title": p.title} | |||
if parent == "Report": | |||
has_role[p.name].update({'ref_doctype': p.ref_doctype}) | |||
has_role[p.name].update({'report_type': p.report_type}) | |||
# pages or reports where role is not set are also allowed | |||
for p in frappe.db.sql("""select `tab{parent}`.name, `tab{parent}`.modified, {column} | |||
from `tab{parent}` where | |||
(select count(*) from `tabHas Role` | |||
where `tabHas Role`.parent=tab{parent}.name) = 0""".format(parent=parent, column=column), as_dict=1): | |||
if p.name not in has_role: | |||
has_role[p.name] = {"modified":p.modified, "title": p.title} | |||
if parent == "Report": | |||
has_role[p.name].update({'ref_doctype': p.ref_doctype}) | |||
has_role[p.name].update({'report_type': p.report_type}) | |||
has_role[p.name] = {"modified": p.modified, "title": p.title} | |||
elif parent == "Report": | |||
for report_name in has_role: | |||
has_role[report_name]["report_type"] = frappe.db.get_value("Report", report_name, "report_type") | |||
return has_role | |||
def get_column(doctype): | |||
column = "`tabPage`.title as title" | |||
if doctype == "Report": | |||
@@ -1,5 +1,6 @@ | |||
{ | |||
"allow_copy": 0, | |||
"allow_guest_to_view": 0, | |||
"allow_import": 0, | |||
"allow_rename": 1, | |||
"autoname": "field:page_name", | |||
@@ -12,6 +13,35 @@ | |||
"editable_grid": 0, | |||
"engine": "InnoDB", | |||
"fields": [ | |||
{ | |||
"allow_on_submit": 0, | |||
"bold": 0, | |||
"collapsible": 0, | |||
"columns": 0, | |||
"fieldname": "system_page", | |||
"fieldtype": "Check", | |||
"hidden": 0, | |||
"ignore_user_permissions": 0, | |||
"ignore_xss_filter": 0, | |||
"in_filter": 0, | |||
"in_global_search": 0, | |||
"in_list_view": 0, | |||
"in_standard_filter": 0, | |||
"label": "System Page", | |||
"length": 0, | |||
"no_copy": 0, | |||
"permlevel": 0, | |||
"precision": "", | |||
"print_hide": 0, | |||
"print_hide_if_no_value": 0, | |||
"read_only": 0, | |||
"remember_last_selected_value": 0, | |||
"report_hide": 0, | |||
"reqd": 0, | |||
"search_index": 0, | |||
"set_only_once": 0, | |||
"unique": 0 | |||
}, | |||
{ | |||
"allow_on_submit": 0, | |||
"bold": 0, | |||
@@ -276,18 +306,18 @@ | |||
"unique": 0 | |||
} | |||
], | |||
"has_web_view": 0, | |||
"hide_heading": 0, | |||
"hide_toolbar": 0, | |||
"icon": "fa fa-file", | |||
"idx": 1, | |||
"image_view": 0, | |||
"in_create": 0, | |||
"in_dialog": 0, | |||
"is_submittable": 0, | |||
"issingle": 0, | |||
"istable": 0, | |||
"max_attachments": 0, | |||
"modified": "2017-02-22 14:42:19.434501", | |||
"modified": "2017-04-12 16:39:15.179130", | |||
"modified_by": "Administrator", | |||
"module": "Core", | |||
"name": "Page", | |||
@@ -2,6 +2,10 @@ | |||
// For license information, please see license.txt | |||
frappe.ui.form.on('Role Permission for Page and Report', { | |||
setup: function(frm) { | |||
frm.trigger("set_queries") | |||
}, | |||
refresh: function(frm) { | |||
frm.disable_save(); | |||
frm.role_area.hide(); | |||
@@ -19,6 +23,16 @@ frappe.ui.form.on('Role Permission for Page and Report', { | |||
} | |||
}, | |||
set_queries: function(frm) { | |||
frm.set_query("page", function() { | |||
return { | |||
filters: { | |||
system_page: 0 | |||
} | |||
} | |||
}); | |||
}, | |||
set_role_for: function(frm) { | |||
frm.trigger("clear_fields") | |||
frm.toggle_display('roles_html', false) | |||
@@ -40,6 +40,9 @@ class RolePermissionforPageandReport(Document): | |||
'roles': self.get_roles() | |||
}) | |||
if self.report: | |||
args.update({'ref_doctype': frappe.db.get_value('Report', self.report, 'ref_doctype')}) | |||
if name: | |||
custom_role = frappe.get_doc("Custom Role", name) | |||
custom_role.set('roles', self.get_roles()) | |||
@@ -181,7 +181,7 @@ class TestUser(unittest.TestCase): | |||
user.new_password = 'testpassword' | |||
user.save() | |||
update_limits({'expiry': add_to_date(today(), days=-1)}) | |||
update_limits({'expiry': add_to_date(today(), days=-1), 'support_email': 'support@example.com'}) | |||
frappe.local.conf = _dict(frappe.get_site_config()) | |||
frappe.db.commit() | |||
@@ -194,10 +194,10 @@ class TestUser(unittest.TestCase): | |||
clear_limit("expiry") | |||
frappe.local.conf = _dict(frappe.get_site_config()) | |||
def test_deactivate_additional_users(self): | |||
update_limits({'users': get_total_users()+1}) | |||
if not frappe.db.exists("User", "test_deactivate_additional_users@example.com"): | |||
user = frappe.new_doc('User') | |||
user.email = 'test_deactivate_additional_users@example.com' | |||
@@ -207,10 +207,10 @@ class TestUser(unittest.TestCase): | |||
#update limits | |||
update_limits({"users": get_total_users()-1}) | |||
self.assertEqual(frappe.db.get_value("User", "test_deactivate_additional_users@example.com", "enabled"), 0) | |||
if frappe.db.exists("User", "test_deactivate_additional_users@example.com"): | |||
frappe.delete_doc('User', 'test_deactivate_additional_users@example.com') | |||
# Clear the user limit | |||
clear_limit('users') | |||
@@ -5,7 +5,7 @@ | |||
"doctype": "Page", | |||
"icon": "fa fa-cog", | |||
"idx": 1, | |||
"modified": "2016-02-26 00:21:05.501007", | |||
"modified": "2017-04-12 18:44:53.283640", | |||
"modified_by": "Administrator", | |||
"module": "Core", | |||
"name": "modules_setup", | |||
@@ -15,5 +15,6 @@ | |||
"script": null, | |||
"standard": "Yes", | |||
"style": null, | |||
"system_page": 1, | |||
"title": "Modules Setup" | |||
} |
@@ -1,22 +1,23 @@ | |||
{ | |||
"content": null, | |||
"creation": "2013-10-04 13:49:33", | |||
"docstatus": 0, | |||
"doctype": "Page", | |||
"idx": 1, | |||
"modified": "2016-06-15 13:07:32.651565", | |||
"modified_by": "Administrator", | |||
"module": "Desk", | |||
"name": "setup-wizard", | |||
"owner": "Administrator", | |||
"page_name": "setup-wizard", | |||
"content": null, | |||
"creation": "2013-10-04 13:49:33", | |||
"docstatus": 0, | |||
"doctype": "Page", | |||
"idx": 1, | |||
"modified": "2017-04-12 18:45:00.774654", | |||
"modified_by": "Administrator", | |||
"module": "Desk", | |||
"name": "setup-wizard", | |||
"owner": "Administrator", | |||
"page_name": "setup-wizard", | |||
"roles": [ | |||
{ | |||
"role": "System Manager" | |||
} | |||
], | |||
"script": null, | |||
"standard": "Yes", | |||
"style": null, | |||
], | |||
"script": null, | |||
"standard": "Yes", | |||
"style": null, | |||
"system_page": 1, | |||
"title": "Setup Wizard" | |||
} | |||
} |
@@ -69,7 +69,6 @@ frappe.email_defaults_pop = { | |||
frappe.ui.form.on("Email Account", { | |||
service: function(frm) { | |||
console.log(frm.doc.service, frappe.email_defaults[frm.doc.service]) | |||
$.each(frappe.email_defaults[frm.doc.service], function(key, value) { | |||
frm.set_value(key, value); | |||
}) | |||
@@ -189,4 +188,4 @@ frappe.ui.form.on("Email Account", { | |||
}); | |||
} | |||
} | |||
}); | |||
}); |
@@ -18,6 +18,11 @@ def check_if_expired(): | |||
return | |||
limits = get_limits() | |||
expiry = limits.get("expiry") | |||
if not expiry: | |||
return | |||
expires_on = formatdate(limits.get("expiry")) | |||
support_email = limits.get("support_email") | |||
@@ -28,7 +33,8 @@ def check_if_expired(): | |||
message = _("""Your subscription expired on {0}. To renew, please send an email to {1}.""").format(expires_on, support_email) | |||
else: | |||
message = _("""Your subscription expired on {0}""").format(expires_on) | |||
# no recourse just quit | |||
return | |||
frappe.throw(message, SiteExpiredError) | |||
@@ -175,4 +175,5 @@ frappe.patches.v8_0.setup_email_inbox #2017-03-29 | |||
frappe.patches.v8_0.newsletter_childtable_migrate | |||
execute:frappe.db.sql("delete from `tabDesktop Icon` where module_name='Communication'") | |||
execute:frappe.db.sql("update `tabDesktop Icon` set type='list' where _doctype='Communication'") | |||
frappe.patches.v8_0.fix_non_english_desktop_icons | |||
frappe.patches.v8_0.fix_non_english_desktop_icons # 2017-04-12 | |||
frappe.patches.v8_0.set_doctype_values_in_custom_role |
@@ -3,7 +3,7 @@ | |||
from __future__ import unicode_literals | |||
import frappe | |||
from frappe.core.doctype.custom_field.custom_field import create_custom_field | |||
from frappe.custom.doctype.custom_field.custom_field import create_custom_field | |||
def execute(): | |||
if "match" in frappe.db.get_table_columns("DocPerm"): | |||
@@ -6,28 +6,9 @@ from __future__ import unicode_literals | |||
import frappe | |||
from frappe.desk.doctype.desktop_icon.desktop_icon import clear_desktop_icons_cache | |||
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() | |||
def is_english(s): | |||
try: | |||
s.decode('ascii') | |||
except (UnicodeDecodeError, UnicodeEncodeError): | |||
return False | |||
else: | |||
return True | |||
def execute(): | |||
frappe.db.sql(""" | |||
update `tabDesktop Icon` | |||
set module_name=_doctype, label=_doctype | |||
where type = 'link' and _doctype != label and link like 'List/%' | |||
""") |
@@ -0,0 +1,13 @@ | |||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors | |||
# License: GNU General Public License v3. See license.txt | |||
from __future__ import unicode_literals | |||
import frappe | |||
def execute(): | |||
frappe.reload_doctype('Custom Role') | |||
# set ref doctype in custom role for reports | |||
frappe.db.sql(""" update `tabCustom Role` set | |||
`tabCustom Role`.ref_doctype = (select ref_doctype from `tabReport` where name = `tabCustom Role`.report) | |||
where `tabCustom Role`.report is not null""") |
@@ -0,0 +1,16 @@ | |||
import unittest, frappe | |||
from frappe.modules import patch_handler | |||
class TestPatches(unittest.TestCase): | |||
def test_patch_module_names(self): | |||
frappe.flags.final_patches = [] | |||
frappe.flags.in_install = True | |||
for patchmodule in patch_handler.get_all_patches(): | |||
if patchmodule.startswith("execute:"): | |||
pass | |||
else: | |||
if patchmodule.startswith("finally:"): | |||
patchmodule = patchmodule.split('finally:')[-1] | |||
self.assertTrue(frappe.get_attr(patchmodule.split()[0] + ".execute")) | |||
frappe.flags.in_install = False |