Skip to content

Commit

Permalink
Merge branch 'staging' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil28297 committed Dec 13, 2021
2 parents ec9a0dc + 7c25673 commit de30abb
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 21 deletions.
5 changes: 3 additions & 2 deletions frappe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
sys.setdefaultencoding("utf-8")

__frappe_version__ = '12.8.1'
__version__ = '2.7.0'
__version__ = '2.8.0'
__title__ = "Frappe Framework"

local = Local()
Expand Down Expand Up @@ -195,12 +195,13 @@ def connect_replica():
from frappe.database import get_db
user = local.conf.db_name
password = local.conf.db_password
port = local.conf.replica_db_port

if local.conf.different_credentials_for_replica:
user = local.conf.replica_db_name
password = local.conf.replica_db_password

local.replica_db = get_db(host=local.conf.replica_host, user=user, password=password)
local.replica_db = get_db(host=local.conf.replica_host, user=user, password=password, port=port)

# swap db connections
local.primary_db = local.db
Expand Down
2 changes: 1 addition & 1 deletion frappe/commands/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def move(dest_dir, site):
site_dump_exists = os.path.exists(final_new_path)
count = int(count or 0) + 1

os.rename(old_path, final_new_path)
shutil.move(old_path, final_new_path)
frappe.destroy()
return final_new_path

Expand Down
17 changes: 11 additions & 6 deletions frappe/core/doctype/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,16 +950,21 @@ def download_zip_files(filters):

doctype = filters.get('doctype')
docnames = filters.get('docnames')

label = filters.get('label')
output_filename = "{0}.zip".format(doctype)
output_path = frappe.get_site_path('private', 'files', output_filename)
if not frappe.db.exists("File", output_filename):
input_files = []
for docname in docnames:
attachments = get_attachments(doctype,docname['name'])
for d in attachments:
doc = frappe.get_doc("File", d.name)
if label == "Download":
for docname in docnames:
doc = frappe.get_doc("File", docname['name'])
input_files.append(doc.get_full_path())
else:
for docname in docnames:
attachments = get_attachments(doctype,docname['name'])
for d in attachments:
doc = frappe.get_doc("File", d.name)
input_files.append(doc.get_full_path())

#Creates a zip file containing all attachments
with zipfile.ZipFile(output_path, 'w') as output_zip:
Expand Down Expand Up @@ -997,4 +1002,4 @@ def update_existing_file_docs(doc):
message = _("File {0} has been made {1}.").format(" ".join(file_list), file_visibility)
else:
message = _("Files {0} have been made {1}.").format(" ".join(file_list), file_visibility)
frappe.msgprint(message)
frappe.msgprint(message)
32 changes: 30 additions & 2 deletions frappe/core/doctype/system_settings/system_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
"desk_include_js",
"chat",
"enable_chat",
"use_socketio_to_upload_file"
"use_socketio_to_upload_file",
"communication_composer_section",
"send_me_a_copy",
"send_read_receipt",
"attach_document_print"
],
"fields": [
{
Expand Down Expand Up @@ -418,11 +422,35 @@
"fieldtype": "Link",
"label": "Welcome Email Template",
"options": "Email Template"
},
{
"collapsible": 1,
"fieldname": "communication_composer_section",
"fieldtype": "Section Break",
"label": "Communication composer settings"
},
{
"default": "0",
"fieldname": "send_me_a_copy",
"fieldtype": "Check",
"label": "Send me a copy"
},
{
"default": "0",
"fieldname": "send_read_receipt",
"fieldtype": "Check",
"label": "Send Read Receipt"
},
{
"default": "0",
"fieldname": "attach_document_print",
"fieldtype": "Check",
"label": "Attach Document Print"
}
],
"icon": "fa fa-cog",
"issingle": 1,
"modified": "2021-03-16 02:40:26.846701",
"modified": "2021-11-03 01:03:03.079551",
"modified_by": "Administrator",
"module": "Core",
"name": "System Settings",
Expand Down
4 changes: 4 additions & 0 deletions frappe/core/doctype/system_settings/system_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ def load():
"timezones": get_all_timezones(),
"defaults": defaults
}

@frappe.whitelist()
def get_system_settings():
return frappe.get_cached_doc("System Settings")
12 changes: 12 additions & 0 deletions frappe/core/doctype/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def before_insert(self):

def after_insert(self):
create_notification_settings(self.name)
frappe.cache().delete_key('enabled_users')

def validate(self):
self.check_demo()
Expand Down Expand Up @@ -102,6 +103,8 @@ def on_update(self):
create_contact(self, ignore_mandatory=True)
if self.name not in ('Administrator', 'Guest') and not self.user_image:
frappe.enqueue('frappe.core.doctype.user.user.update_gravatar', name=self.name)
if self.has_value_changed('enabled'):
frappe.cache().delete_key('enabled_users')

def has_website_permission(self, ptype, user, verbose=False):
"""Returns true if current user is the session user"""
Expand Down Expand Up @@ -349,6 +352,8 @@ def on_trash(self):
set `user`=null
where `user`=%s""", (self.name))

frappe.cache().delete_key('enabled_users')


def before_rename(self, old_name, new_name, merge=False):
self.check_demo()
Expand Down Expand Up @@ -1146,3 +1151,10 @@ def job_rename_owner_modified_by(table, old_name, new_name):
sql = """UPDATE `{}` SET {} WHERE {}""".format(
table, ",".join(field_sql), " OR ".join(field_where))
frappe.db.sql(sql, dict(new_name=new_name, old_name=old_name))

def get_enabled_users():
def _get_enabled_users():
enabled_users = [d.name for d in frappe.get_all("User", filters={"enabled": "1"})]
return enabled_users

return frappe.cache().get_value("enabled_users", _get_enabled_users)
2 changes: 1 addition & 1 deletion frappe/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def get_single_value(self, doctype, fieldname, cache=False):
"""

if not doctype in self.value_cache:
self.value_cache = self.value_cache[doctype] = {}
self.value_cache[doctype] = {}

if fieldname in self.value_cache[doctype]:
return self.value_cache[doctype][fieldname]
Expand Down
29 changes: 29 additions & 0 deletions frappe/integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,32 @@ def create_payment_gateway(gateway, settings=None, controller=None):
def json_handler(obj):
if isinstance(obj, (datetime.date, datetime.timedelta, datetime.datetime)):
return text_type(obj)


def make_integration_request(doctype, docname, service=None, status="Queued", endpoint=None, error=None, output=None):
integration_request = frappe.get_doc({
"doctype": "Integration Request",
"integration_type": "Remote",
"integration_request_service": service,
"status": status,
"reference_doctype": doctype,
"reference_docname": docname,
"endpoint": endpoint,
"error": error,
"output": output
})
integration_request.insert(ignore_permissions=True)
frappe.db.commit()

return integration_request

def update_integration_request(integration_request, status=None, endpoint=None, error=None, response=None):
if status:
integration_request.status = status
if endpoint:
integration_request.endpoint = endpoint
if response:
integration_request.output = response
if error:
integration_request.error = error
integration_request.save(ignore_permissions=True)
5 changes: 5 additions & 0 deletions frappe/model/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ def update_child_table(self, fieldname, df=None):
def get_doc_before_save(self):
return getattr(self, '_doc_before_save', None)

def has_value_changed(self, fieldname):
'''Returns true if value is changed before and after saving'''
previous = self.get_doc_before_save()
return previous.get(fieldname)!=self.get(fieldname) if previous else True

def set_new_name(self, force=False):
"""Calls `frappe.naming.se_new_name` for parent and child docs."""
if self.flags.name_set and not force:
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/form/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ export default class Grid {
me.df.data = me.get_data();
me.df.data = me.df.data.filter((row)=> row.idx != doc.idx);
}
me.grid_rows_by_docname[doc.name].remove();
dirty = true;
return me.grid_rows_by_docname[doc.name] && me.grid_rows_by_docname[doc.name].remove();
});
tasks.push(() => frappe.timeout(0.1));
tasks.push(() => frappe.timeout(0));
});

if (!me.frm) {
Expand Down
6 changes: 4 additions & 2 deletions frappe/public/js/frappe/form/grid_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ export default class GridRow {
this.hide_form();
}

frappe.run_serially([
return frappe.run_serially([
() => {
return this.frm.script_manager.trigger("before_" + this.grid.df.fieldname + "_remove",
this.doc.doctype, this.doc.name);
},
() => {
frappe.model.clear_doc(this.doc.doctype, this.doc.name);

this.frm.script_manager.trigger(this.grid.df.fieldname + "_remove",
return this.frm.script_manager.trigger(this.grid.df.fieldname + "_remove",
this.doc.doctype, this.doc.name);
},
() => {
this.frm.dirty();
this.grid.refresh();
},
Expand Down
34 changes: 34 additions & 0 deletions frappe/public/js/frappe/list/list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,30 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
};
};

const bulk_download_files = (label_name) => {
return {
label: __(label_name),
action: () =>{
let filters = {
doctype: doctype,
docnames: this.get_checked_items(),
label: label_name
};
let w = window.open(
frappe.urllib.get_full_url(
"/api/method/frappe.core.doctype.file.file.download_zip_files?"
+ "filters=" + JSON.stringify(filters)
)
);
if (!w) {
frappe.msgprint(__("Please enable pop-ups")); return;
}
},
standard: true
};
};


const bulk_cancel = () => {
return {
label: __('Cancel'),
Expand Down Expand Up @@ -1455,6 +1479,15 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {

actions_menu_items.push(bulk_assignment_rule());

// bulk download
if (doctype == "File") {
actions_menu_items.push(bulk_download_files("Download"));
} else {
//bulk download Attachment
actions_menu_items.push(bulk_download_files("Download Attachment"));
}


// bulk printing
if (frappe.model.can_print(doctype)) {
actions_menu_items.push(bulk_printing());
Expand Down Expand Up @@ -1557,3 +1590,4 @@ frappe.get_list_view = (doctype) => {
let route = `List/${doctype}/List`;
return frappe.views.list_view[route];
};

16 changes: 12 additions & 4 deletions frappe/public/js/frappe/views/communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ frappe.views.CommunicationComposer = Class.extend({
init: function(opts) {
$.extend(this, opts);
let me = this;
me.make();
frappe.call({
method: 'frappe.core.doctype.system_settings.system_settings.get_system_settings',
callback: function(res) {
if(res && res.message) {
me.system_settings = res.message;
}
me.make();
}
});
},
make: function() {
var me = this;
Expand Down Expand Up @@ -131,9 +139,9 @@ frappe.views.CommunicationComposer = Class.extend({
this.dialog.set_value("recipients", this.recipients || '');
this.dialog.set_value("cc", this.cc || '');
this.dialog.set_value("bcc", this.bcc || '');
this.dialog.set_value("attach_document_print", this.frm.meta.attach_document_print);
this.dialog.set_value("send_me_a_copy", this.frm.meta.send_me_a_copy);
this.dialog.set_value("send_read_receipt", this.frm.meta.send_read_receipt);
this.dialog.set_value("attach_document_print", this.frm ? this.frm.meta.attach_document_print : this.system_settings.attach_document_print);
this.dialog.set_value("send_me_a_copy", this.frm ? this.frm.meta.send_me_a_copy : this.system_settings.send_me_a_copy);
this.dialog.set_value("send_read_receipt", this.frm ? this.frm.meta.send_read_receipt : this.system_settings.send_read_receipt);

if(this.dialog.fields_dict.sender) {
this.dialog.fields_dict.sender.set_value(this.sender || '');
Expand Down
24 changes: 24 additions & 0 deletions frappe/social/doctype/energy_point_log/test_energy_point_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,30 @@ def test_allow_creation_of_new_log_if_the_previous_log_was_reverted(self):
self.assertEqual(points_after_reverting_todo, points_after_closing_todo - rule_points)
self.assertEqual(points_after_saving_todo_again, points_after_reverting_todo + rule_points)

def test_energy_points_disabled_user(self):
frappe.set_user('[email protected]')
user = frappe.get_doc('User', '[email protected]')
user.enabled = 0
user.save()
todo_point_rule = create_energy_point_rule_for_todo()
energy_point_of_user = get_points('[email protected]')

created_todo = create_a_todo()

created_todo.status = 'Closed'
created_todo.save()
points_after_closing_todo = get_points('[email protected]')

# do not update energy points for disabled user
self.assertEqual(points_after_closing_todo, energy_point_of_user)

user.enabled = 1
user.save()

created_todo.save()
points_after_re_saving_todo = get_points('[email protected]')
self.assertEqual(points_after_re_saving_todo, energy_point_of_user + todo_point_rule.points)

def create_energy_point_rule_for_todo(multiplier_field=None, for_doc_event='Custom', max_points=None,
for_assigned_users=0, field_to_check=None, apply_once=False, user_field='owner'):
name = 'ToDo Closed'
Expand Down
8 changes: 7 additions & 1 deletion frappe/social/doctype/energy_point_rule/energy_point_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import frappe
from frappe import _
import frappe.cache_manager
from frappe.core.doctype.user.user import get_enabled_users
from frappe.model.document import Document
from frappe.social.doctype.energy_point_settings.energy_point_settings import is_energy_point_enabled
from frappe.social.doctype.energy_point_log.energy_point_log import \
Expand Down Expand Up @@ -44,7 +45,7 @@ def apply(self, doc):

try:
for user in users:
if not user or user in ['Administrator', 'Guest']: continue
if not is_eligible_user(user): continue
create_energy_points_log(reference_doctype, reference_name, {
'points': points,
'user': user,
Expand Down Expand Up @@ -118,3 +119,8 @@ def get_energy_point_doctypes():
d.reference_doctype for d in frappe.get_all('Energy Point Rule',
['reference_doctype'], {'enabled': 1})
]

def is_eligible_user(user):
'''Checks if user is eligible to get energy points'''
enabled_users = get_enabled_users()
return user and user in enabled_users and user not in ['Administrator', 'Guest']

0 comments on commit de30abb

Please sign in to comment.