Merge branch 'hotfix'

This commit is contained in:
Saurabh 2019-04-05 16:39:04 +05:30
commit fb4ef2e3d2
17 changed files with 116 additions and 45 deletions

View file

@ -24,7 +24,7 @@ if sys.version[0] == '2':
reload(sys)
sys.setdefaultencoding("utf-8")
__version__ = '11.1.18'
__version__ = '11.1.19'
__title__ = "Frappe Framework"
local = Local()
@ -188,6 +188,9 @@ def connect(site=None, db_name=None):
local.db = Database(user=db_name or local.conf.db_name)
set_user("Administrator")
for hook in get_hooks("connect") or []:
get_attr(hook)()
def connect_read_only():
from frappe.database import Database

View file

@ -71,7 +71,7 @@ def import_file_by_path(path, ignore_links=False, overwrite=False, submit=False,
def export_json(doctype, path, filters=None, or_filters=None, name=None, order_by="creation asc"):
def post_process(out):
del_keys = ('parent', 'parentfield', 'parenttype', 'modified_by', 'creation', 'owner', 'idx')
del_keys = ('modified_by', 'creation', 'owner', 'idx')
for doc in out:
for key in del_keys:
if key in doc:

View file

@ -46,10 +46,6 @@
<div class="usage-info-section" style="margin: 30px;">
<h4>{{ __("Space") }}</h4>
{% var database_percent = ((limits.space_usage.database_size / limits.space) * 100); %}
{% var files_percent = ((limits.space_usage.files_size / limits.space) * 100); %}
{% var backup_percent = ((limits.space_usage.backup_size / limits.space) * 100); %}
<div class="progress" style="margin-bottom: 0;">
<div class="progress-bar" style="width: {%= database_percent %}%; background-color: #5e64ff"></div>
<div class="progress-bar" style="width: {%= files_percent %}%; background-color: #743ee2"></div>
@ -66,12 +62,7 @@
{{ __("Backup Size:") }} {%= limits.space_usage.backup_size %} MB
</span>
<p>
<span class="{%= ((limits.space - limits.space_usage.total) > 50) ? "" : "text-warning" %}">
<b>{%= flt(limits.space - limits.space_usage.total, 2) %} MB</b></span>
available out of
<span><b>{%= limits.space %} MB</b></span>
</p>
<p>{{ usage_message }}</p>
</div>
{% endif %}
</div>

View file

@ -15,7 +15,33 @@ frappe.pages['usage-info'].on_page_load = function(wrapper) {
return;
}
$(frappe.render_template("usage_info", usage_info)).appendTo(page.main);
let limits = usage_info.limits;
let database_percent = (limits.space_usage.database_size / limits.space) * 100;
let files_percent = (limits.space_usage.files_size / limits.space) * 100;
let backup_percent = (limits.space_usage.backup_size / limits.space) * 100;
let total_consumed = database_percent + files_percent + backup_percent;
let last_part = backup_percent;
if (total_consumed > 100) {
last_part = backup_percent - (total_consumed - 100);
}
backup_percent = last_part;
let usage_message = '';
if (limits.space_usage.total > limits.space) {
usage_message = __('You have used up all of the space allotted to you. Please buy more space in your subscription.');
} else {
let available = flt(limits.space - limits.space_usage.total, 2);
usage_message = __('{0} available out of {1}', [(available + ' MB').bold(), (limits.space + ' MB').bold()]);
}
$(frappe.render_template("usage_info", Object.assign(usage_info, {
database_percent,
files_percent,
backup_percent,
usage_message
}))).appendTo(page.main);
var btn_text = usage_info.limits.users == 1 ? __("Upgrade") : __("Renew / Upgrade");
$(page.main).find('.btn-primary').html(btn_text).on('click', () => {

View file

@ -84,3 +84,4 @@ class RetryBackgroundJobError(Exception): pass
class DocumentLockedError(ValidationError): pass
class CircularLinkingError(ValidationError): pass
class SecurityException(Exception): pass
class IncompatibleApp(ValidationError): pass

View file

@ -83,7 +83,8 @@ def get_user_default_value(df, defaults, doctype_user_permissions, allowed_recor
if df.fieldtype == "Link" and df.options != "User":
# 1 - look in user permissions only for document_type==Setup
# We don't want to include permissions of transactions to be used for defaults.
if frappe.get_meta(df.options).document_type=="Setup" and len(allowed_records)==1:
if (frappe.get_meta(df.options).document_type=="Setup"
and len(allowed_records)==1 and not df.ignore_user_permissions):
return allowed_records[0]
# 2 - Look in user defaults

View file

@ -8,6 +8,7 @@ from __future__ import unicode_literals, print_function
import frappe, os, json
import frappe.utils
from frappe import _
from frappe.utils import cint
def export_module_json(doc, is_standard, module):
"""Make a folder for the given doc and add its json file (make it a standard
@ -39,11 +40,15 @@ def get_doc_module(module, doctype, name):
def export_customizations(module, doctype, sync_on_migrate=0, with_permissions=0):
"""Export Custom Field and Property Setter for the current document to the app folder.
This will be synced with bench migrate"""
sync_on_migrate = cint(sync_on_migrate)
with_permissions = cint(with_permissions)
if not frappe.get_conf().developer_mode:
raise Exception('Not developer mode')
custom = {'custom_fields': [], 'property_setters': [], 'custom_perms': [],
'doctype': doctype, 'sync_on_migrate': 1}
'doctype': doctype, 'sync_on_migrate': sync_on_migrate}
def add(_doctype):
custom['custom_fields'] += frappe.get_all('Custom Field',

View file

@ -28,7 +28,7 @@ def print_has_permission_check_logs(func):
# print only if access denied
# and if user is checking his own permission
if not result and self_perm_check:
msgprint(('<br>').join(frappe.flags['has_permission_check_logs']))
msgprint(('<br>').join(frappe.flags.get('has_permission_check_logs')))
frappe.flags.pop('has_permission_check_logs', None)
return result
return inner

View file

@ -68,8 +68,8 @@ frappe.ui.form.States = Class.extend({
},
show_actions: function() {
var added = false,
me = this;
var added = false;
var me = this;
this.frm.page.clear_actions_menu();
@ -103,10 +103,15 @@ frappe.ui.form.States = Class.extend({
});
}
});
this.setup_btn(added);
});
if(added) {
},
setup_btn: function(action_added) {
if(action_added) {
this.frm.page.btn_primary.addClass("hide");
this.frm.page.btn_secondary.addClass("hide");
this.frm.toolbar.current_status = "";
this.setup_help();
}

View file

@ -365,6 +365,7 @@ frappe.views.BaseList = class BaseList {
this.toggle_result_area();
this.before_render();
this.render();
this.after_render();
this.freeze(false);
});
}
@ -390,6 +391,10 @@ frappe.views.BaseList = class BaseList {
}
after_render() {
}
render() {
// for child classes
}

View file

@ -1,6 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
import deep_equal from "fast-deep-equal";
frappe.provide('frappe.utils');
Object.assign(frappe.utils, {
@ -668,6 +669,10 @@ Object.assign(frappe.utils, {
} else {
return null;
}
},
deep_equal(a, b) {
return deep_equal(a, b);
}
});

View file

@ -92,7 +92,8 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
this.load_report();
} else {
// same report
this.refresh_report();
// don't do anything to preserve state
// like filters and datatable column widths
}
}

View file

@ -76,7 +76,7 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
return super.before_refresh();
}
before_render() {
after_render() {
if (this.report_doc) {
this.set_dirty_state_for_custom_report();
} else {
@ -85,23 +85,25 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
}
set_dirty_state_for_custom_report() {
const json = JSON.stringify({
let current_settings = {
filters: this.filter_area.get(),
fields: this.fields,
order_by: this.sort_selector.get_sql_string(),
add_totals_row: this.add_totals_row,
page_length: this.page_length
});
page_length: this.page_length,
column_widths: this.get_column_widths()
}
const report_json = JSON.stringify({
let report_settings = {
filters: this.report_doc.json.filters,
fields: this.report_doc.json.fields,
order_by: this.report_doc.json.order_by,
add_totals_row: this.report_doc.json.add_totals_row,
page_length: this.report_doc.json.page_length
});
page_length: this.report_doc.json.page_length,
column_widths: this.report_doc.json.column_widths
}
if (json != report_json) {
if (!frappe.utils.deep_equal(current_settings, report_settings)) {
this.page.set_indicator(__('Not Saved'), 'orange');
} else {
this.page.clear_indicator();
@ -830,11 +832,16 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
return docfield.fieldtype === 'Date' ? 'right' : 'left';
})();
const width = (docfield ? cint(docfield.width) : null) || null;
// child table column
const id = doctype !== this.doctype ? `${doctype}:${fieldname}` : fieldname;
let width = (docfield ? cint(docfield.width) : null) || null;
if (this.report_doc) {
// load the user saved column width
let saved_column_widths = this.report_doc.json.column_widths || {};
width = saved_column_widths[id] || width;
}
let compareFn = null;
if (docfield.fieldtype === 'Date') {
compareFn = (cell, keyword) => {
@ -950,7 +957,8 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
fields: this.fields,
order_by: this.sort_selector.get_sql_string(),
add_totals_row: this.add_totals_row,
page_length: this.page_length
page_length: this.page_length,
column_widths: this.get_column_widths()
}
return frappe.call({
@ -975,6 +983,7 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
};
this.list_sidebar.setup_reports();
frappe.set_route('List', this.doctype, 'Report', r.message);
return;
}
// update state
@ -994,6 +1003,20 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
}
}
get_column_widths() {
if (this.datatable) {
return this.datatable
.datamanager
.getColumns(true)
.reduce((acc, curr) => {
acc[curr.id] = parseInt(curr.width);
return acc;
}, {});
}
return {};
}
get_report_doc() {
return new Promise(resolve => {
frappe.model.with_doc('Report', this.report_name, () => {

View file

@ -226,12 +226,11 @@ class Session:
self.insert_session_record()
# update user
frappe.db.sql("""UPDATE tabUser SET last_login = %(now)s, last_ip = %(ip)s, last_active = %(now)s
where name=%(name)s""", {
"now": frappe.utils.now(),
"ip": frappe.local.request_ip,
"name": self.data['user']
})
user = frappe.get_doc('User', self.data['user'])
user.last_login = frappe.utils.now()
user.last_ip = frappe.local.request_ip
user.last_active = frappe.utils.now()
user.save()
frappe.db.commit()

View file

@ -7,7 +7,7 @@ import frappe
from frappe import _
from frappe.website.website_generator import WebsiteGenerator
from frappe.website.render import clear_cache
from frappe.utils import today, cint, global_date_format, get_fullname, strip_html_tags, markdown
from frappe.utils import today, cint, global_date_format, get_fullname, strip_html_tags, markdown, sanitize_html
from frappe.website.utils import find_first_image, get_comment_list
class BlogPost(WebsiteGenerator):
@ -95,7 +95,7 @@ def get_list_context(context=None):
title = _('Blog')
)
category = frappe.local.form_dict.blog_category or frappe.local.form_dict.category
category = sanitize_html(frappe.local.form_dict.blog_category or frappe.local.form_dict.category)
if category:
category_title = get_blog_category(category)
list_context.sub_title = _("Posts filed under {0}").format(category_title)
@ -107,7 +107,7 @@ def get_list_context(context=None):
list_context.title = blogger
elif frappe.local.form_dict.txt:
list_context.sub_title = _('Filtered by "{0}"').format(frappe.local.form_dict.txt)
list_context.sub_title = _('Filtered by "{0}"').format(sanitize_html(frappe.local.form_dict.txt))
if list_context.sub_title:
list_context.parents = [{"name": _("Home"), "route": "/"},

View file

@ -19,7 +19,8 @@
"awesomplete": "^1.1.2",
"cookie": "^0.3.1",
"express": "^4.16.2",
"frappe-datatable": "^1.8.0",
"fast-deep-equal": "^2.0.1",
"frappe-datatable": "^1.11.0",
"frappe-gantt": "^0.1.0",
"fuse.js": "^3.2.0",
"highlight.js": "^9.12.0",

View file

@ -1110,6 +1110,11 @@ fast-deep-equal@^1.0.0:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614"
integrity sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=
fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
fast-diff@1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154"
@ -1219,10 +1224,10 @@ forwarded@~0.1.2:
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"
integrity sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=
frappe-datatable@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/frappe-datatable/-/frappe-datatable-1.8.0.tgz#7f789ed77bdf9800143fffb1bb28a24d5dbdc27c"
integrity sha512-j3DdmYtTjhcVXCVkYjKHdZOc8tSwZapanlujdx1xzXcL7Ueo+BFiPR5WptWRfH43K3nboh3m7clcAIX7LdQR4g==
frappe-datatable@^1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/frappe-datatable/-/frappe-datatable-1.11.0.tgz#e0f23659e2bb2e635ecd4f3eccadf1ed762a0629"
integrity sha512-tXjpNOywq3o6nMru47xhyzrH/sZ3PmrsLLOS+6+VJmqFsVC6TmlJDP1LRxSC+xCSDpumO8jjxfdwcwWWXKfDdw==
dependencies:
hyperlist "^1.0.0-beta"
lodash "^4.17.5"