From 39f504be23c97175231e44cf10b08bb962c3b5fe Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Thu, 10 Jun 2021 13:51:29 +0530 Subject: [PATCH 001/137] fix: number format converting to decimals --- frappe/public/js/frappe/form/controls/int.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/int.js b/frappe/public/js/frappe/form/controls/int.js index 12652bf86e..1aa4a49b9a 100644 --- a/frappe/public/js/frappe/form/controls/int.js +++ b/frappe/public/js/frappe/form/controls/int.js @@ -10,12 +10,11 @@ frappe.ui.form.ControlInt = class ControlInt extends frappe.ui.form.ControlData super.make_input(); this.$input // .addClass("text-right") - .on("focus", function () { + .on("focusout", function () { setTimeout(function () { if (!document.activeElement) return; document.activeElement.value = me.validate(document.activeElement.value); - document.activeElement.select(); }, 100); return false; }); From 7ad1e2d11db2261dc34693d68526104e0a51ce78 Mon Sep 17 00:00:00 2001 From: shariquerik Date: Tue, 22 Jun 2021 17:13:20 +0530 Subject: [PATCH 002/137] fix: Webform Permission for custom doctypem --- frappe/www/list.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frappe/www/list.py b/frappe/www/list.py index 5e4e491c80..975347adac 100644 --- a/frappe/www/list.py +++ b/frappe/www/list.py @@ -161,6 +161,14 @@ def get_list_context(context, doctype, web_form_name=None): module = load_doctype_module(doctype) list_context = update_context_from_module(module, list_context) + # get context for custom doctype + if meta.custom: + get_custom_website_context = frappe.get_hooks('get_custom_website_context') + if get_custom_website_context: + out = frappe._dict(frappe.get_attr(get_custom_website_context[0])() or {}) + if out: + list_context = out + # get context from web form module if web_form_name: web_form = frappe.get_doc('Web Form', web_form_name) From d39a389fd5a066bb08b5805550f6b86d0b4618d3 Mon Sep 17 00:00:00 2001 From: shariquerik Date: Mon, 12 Jul 2021 17:01:30 +0530 Subject: [PATCH 003/137] fix: app check condition for getting correct list_context --- frappe/www/list.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frappe/www/list.py b/frappe/www/list.py index 975347adac..3ed103b69d 100644 --- a/frappe/www/list.py +++ b/frappe/www/list.py @@ -161,11 +161,11 @@ def get_list_context(context, doctype, web_form_name=None): module = load_doctype_module(doctype) list_context = update_context_from_module(module, list_context) - # get context for custom doctype - if meta.custom: - get_custom_website_context = frappe.get_hooks('get_custom_website_context') - if get_custom_website_context: - out = frappe._dict(frappe.get_attr(get_custom_website_context[0])() or {}) + # get context for custom webform + if meta.custom and web_form_name: + list_context_for_custom_webform = frappe.get_hooks('get_list_context_for_custom_webform') + if list_context_for_custom_webform: + out = frappe._dict(frappe.get_attr(list_context_for_custom_webform[0])(meta.module) or {}) if out: list_context = out From 52941e55b105a64da970de33b7c340422540fbab Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Tue, 27 Jul 2021 00:29:01 +0530 Subject: [PATCH 004/137] fix: no need for focusout in favour of onchange --- frappe/public/js/frappe/form/controls/int.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/int.js b/frappe/public/js/frappe/form/controls/int.js index 1aa4a49b9a..ce2336bb82 100644 --- a/frappe/public/js/frappe/form/controls/int.js +++ b/frappe/public/js/frappe/form/controls/int.js @@ -8,16 +8,6 @@ frappe.ui.form.ControlInt = class ControlInt extends frappe.ui.form.ControlData make_input () { var me = this; super.make_input(); - this.$input - // .addClass("text-right") - .on("focusout", function () { - setTimeout(function () { - if (!document.activeElement) return; - document.activeElement.value - = me.validate(document.activeElement.value); - }, 100); - return false; - }); } validate (value) { return this.parse(value); From f0cc541a716ca892f4772c022e8f4ac87fb38da0 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 17 Aug 2021 12:36:54 +0530 Subject: [PATCH 005/137] feat: Add util to convert compressed tables to DYNAMIC NOTE: This shouldn't be considered as a finished command. Only run this if you understand what you're doing --- frappe/commands/utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index f2395ae490..54ee559cf5 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -512,6 +512,29 @@ def console(context): IPython.embed(display_banner="", header="", colors="neutral") +@click.command('convert-database') +@pass_context +def convert_database(context): + "convert row_formats to DNAMIC from older formats -- innodb mariadb v10.6.3" + site = get_site(context) + frappe.init(site=site) + frappe.connect() + + information_schema = frappe.qb.Schema("information_schema") + queried_tables = frappe.qb.from_( + information_schema.tables + ).select("table_name").where( + information_schema.tables.row_format=="Compressed" + ).run() + tables = [x[0] for x in queried_tables] + + for table in tables: + frappe.db.sql(f"ALTER TABLE `{table}` ROW_FORMAT=DYNAMIC") + + frappe.db.commit() + frappe.destroy() + + @click.command('run-tests') @click.option('--app', help="For App") @click.option('--doctype', help="For DocType") @@ -796,6 +819,7 @@ commands = [ build, clear_cache, clear_website_cache, + convert_database, jupyter, console, destroy_all_sessions, From f8826750d4016c606eebb55ea7bf5fbde5b734d5 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 17 Aug 2021 12:38:19 +0530 Subject: [PATCH 006/137] chore: Use DYNAMIC row_format instead of deprecated COMPRESSED refs: * MariaDB 10.6 gets rid of the COMPRESSED row_format * https://dev.mysql.com/worklog/task/?id=8307 * https://stackoverflow.com/questions/24321896/mysql-row-format-compressed-vs-dynamic --- frappe/database/mariadb/database.py | 2 +- frappe/database/mariadb/framework_mariadb.sql | 22 +++++++++---------- frappe/database/mariadb/schema.py | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/frappe/database/mariadb/database.py b/frappe/database/mariadb/database.py index d4a119804b..9fc485e133 100644 --- a/frappe/database/mariadb/database.py +++ b/frappe/database/mariadb/database.py @@ -195,7 +195,7 @@ class MariaDBDatabase(Database): `password` TEXT NOT NULL, `encrypted` INT(1) NOT NULL DEFAULT 0, PRIMARY KEY (`doctype`, `name`, `fieldname`) - ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci""") + ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci""") def create_global_search_table(self): if not '__global_search' in self.get_tables(): diff --git a/frappe/database/mariadb/framework_mariadb.sql b/frappe/database/mariadb/framework_mariadb.sql index f8841e9417..426fae6d3e 100644 --- a/frappe/database/mariadb/framework_mariadb.sql +++ b/frappe/database/mariadb/framework_mariadb.sql @@ -71,7 +71,7 @@ CREATE TABLE `tabDocField` ( KEY `label` (`label`), KEY `fieldtype` (`fieldtype`), KEY `fieldname` (`fieldname`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- @@ -108,7 +108,7 @@ CREATE TABLE `tabDocPerm` ( `email` int(1) NOT NULL DEFAULT 1, PRIMARY KEY (`name`), KEY `parent` (`parent`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Table structure for table `tabDocType Action` @@ -132,7 +132,7 @@ CREATE TABLE `tabDocType Action` ( PRIMARY KEY (`name`), KEY `parent` (`parent`), KEY `modified` (`modified`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; -- -- Table structure for table `tabDocType Action` @@ -155,7 +155,7 @@ CREATE TABLE `tabDocType Link` ( PRIMARY KEY (`name`), KEY `parent` (`parent`), KEY `modified` (`modified`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; -- -- Table structure for table `tabDocType` @@ -226,7 +226,7 @@ CREATE TABLE `tabDocType` ( `sender_field` varchar(255) DEFAULT NULL, PRIMARY KEY (`name`), KEY `parent` (`parent`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Table structure for table `tabSeries` @@ -237,7 +237,7 @@ CREATE TABLE `tabSeries` ( `name` varchar(100), `current` int(10) NOT NULL DEFAULT 0, PRIMARY KEY(`name`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- @@ -254,7 +254,7 @@ CREATE TABLE `tabSessions` ( `device` varchar(255) DEFAULT 'desktop', `status` varchar(20) DEFAULT NULL, KEY `sid` (`sid`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- @@ -267,7 +267,7 @@ CREATE TABLE `tabSingles` ( `field` varchar(255) DEFAULT NULL, `value` text, KEY `singles_doctype_field_index` (`doctype`, `field`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Table structure for table `__Auth` @@ -281,7 +281,7 @@ CREATE TABLE `__Auth` ( `password` TEXT NOT NULL, `encrypted` INT(1) NOT NULL DEFAULT 0, PRIMARY KEY (`doctype`, `name`, `fieldname`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Table structure for table `tabFile` @@ -309,7 +309,7 @@ CREATE TABLE `tabFile` ( KEY `parent` (`parent`), KEY `attached_to_name` (`attached_to_name`), KEY `attached_to_doctype` (`attached_to_doctype`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Table structure for table `tabDefaultValue` @@ -332,4 +332,4 @@ CREATE TABLE `tabDefaultValue` ( PRIMARY KEY (`name`), KEY `parent` (`parent`), KEY `defaultvalue_parent_defkey_index` (`parent`,`defkey`) -) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/frappe/database/mariadb/schema.py b/frappe/database/mariadb/schema.py index b40af59286..c5091cfe8f 100644 --- a/frappe/database/mariadb/schema.py +++ b/frappe/database/mariadb/schema.py @@ -29,7 +29,7 @@ class MariaDBTable(DBTable): %sindex parent(parent), index modified(modified)) ENGINE={engine} - ROW_FORMAT=COMPRESSED + ROW_FORMAT=DYNAMIC CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci""".format(varchar_len=frappe.db.VARCHAR_LEN, engine=self.meta.get("engine") or 'InnoDB') % (self.table_name, add_text)) From 7f338edca11fb367e6126e5c9f0e33112965c9f4 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 17 Aug 2021 12:50:11 +0530 Subject: [PATCH 007/137] feat: Command to trim tables Maintenance command to get rid of extra columns in your DocType tables. These columns are remnants of "deleted" fields through customizations or upgrades --- frappe/commands/site.py | 28 +++++++++++++++- frappe/database/mariadb/database.py | 4 +-- frappe/model/meta.py | 50 ++++++++++++++++++++--------- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 9098e31738..27e8e737ea 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -738,6 +738,31 @@ def build_search_index(context): finally: frappe.destroy() +@click.command('trim-tables') +@click.option('--dry-run', is_flag=True, default=False, help='Show what would be deleted') +@click.option('--format', default='table', type=click.Choice(['json', 'table']), help='Output format') +@pass_context +def trim_tables(context, dry_run, format): + from frappe.model.meta import trim_tables + + for site in context.sites: + frappe.init(site=site) + frappe.connect() + try: + trimmed_data = trim_tables(dry_run=dry_run) + handle_data(trimmed_data, format=format) + finally: + frappe.destroy() + +def handle_data(data: dict, format='json'): + if format == 'json': + import json + print(json.dumps({frappe.local.site: data}, indent=1, sort_keys=True)) + else: + click.secho(f"Site {frappe.local.site}", fg='green') + for table, columns in data.items(): + print(f"{table}: {', '.join(columns)}") + commands = [ add_system_manager, backup, @@ -766,5 +791,6 @@ commands = [ add_to_hosts, start_ngrok, build_search_index, - partial_restore + partial_restore, + trim_tables, ] diff --git a/frappe/database/mariadb/database.py b/frappe/database/mariadb/database.py index d4a119804b..0bf6450cda 100644 --- a/frappe/database/mariadb/database.py +++ b/frappe/database/mariadb/database.py @@ -135,8 +135,8 @@ class MariaDBDatabase(Database): table_name = get_table_name(doctype) return self.sql(f"DESC `{table_name}`") - def change_column_type(self, table: str, column: str, type: str) -> Union[List, Tuple]: - table_name = get_table_name(table) + def change_column_type(self, doctype: str, column: str, type: str) -> Union[List, Tuple]: + table_name = get_table_name(doctype) return self.sql(f"ALTER TABLE `{table_name}` MODIFY `{column}` {type} NOT NULL") # exception types diff --git a/frappe/model/meta.py b/frappe/model/meta.py index de794ba77f..f42cac59c3 100644 --- a/frappe/model/meta.py +++ b/frappe/model/meta.py @@ -15,6 +15,7 @@ Example: ''' from datetime import datetime +import click import frappe, json, os from frappe.utils import cstr, cint, cast_fieldtype from frappe.model import default_fields, no_value_fields, optional_fields, data_fieldtypes, table_fields @@ -658,27 +659,44 @@ def get_default_df(fieldname): fieldtype = "Data" ) -def trim_tables(doctype=None): +def trim_tables(doctype=None, dry_run=False): """ Removes database fields that don't exist in the doctype (json or custom field). This may be needed as maintenance since removing a field in a DocType doesn't automatically delete the db field. """ - ignore_fields = default_fields + optional_fields - - filters={ "issingle": 0 } + UPDATED_TABLES = {} + filters = {"issingle": 0} if doctype: filters["name"] = doctype - for doctype in frappe.db.get_all("DocType", filters=filters): - doctype = doctype.name - columns = frappe.db.get_table_columns(doctype) - fields = frappe.get_meta(doctype).get_fieldnames_with_value() - columns_to_remove = [f for f in list(set(columns) - set(fields)) if f not in ignore_fields - and not f.startswith("_")] - if columns_to_remove: - print(doctype, "columns removed:", columns_to_remove) - columns_to_remove = ", ".join("drop `{0}`".format(c) for c in columns_to_remove) - query = """alter table `tab{doctype}` {columns}""".format( - doctype=doctype, columns=columns_to_remove) - frappe.db.sql_ddl(query) + for doctype in frappe.db.get_all("DocType", filters=filters, pluck="name"): + try: + dropped_columns = trim_table(doctype, dry_run=dry_run) + if dropped_columns: + UPDATED_TABLES[doctype] = dropped_columns + except frappe.db.TableMissingError: + click.secho(f"Ignoring missing table for DocType: {doctype}", fg="yellow", err=True) + click.secho(f"Consider removing record in the DocType table for {doctype}", fg="yellow", err=True) + except Exception as e: + click.echo(e, err=True) + + return UPDATED_TABLES + + +def trim_table(doctype, dry_run=True): + ignore_fields = default_fields + optional_fields + columns = frappe.db.get_table_columns(doctype) + fields = frappe.get_meta(doctype, cached=False).get_fieldnames_with_value() + is_internal = lambda f: f not in ignore_fields and not f.startswith("_") + columns_to_remove = [ + f for f in list(set(columns) - set(fields)) if is_internal(f) + ] + DROPPED_COLUMNS = columns_to_remove[:] + + if columns_to_remove and not dry_run: + columns_to_remove = ", ".join(f"DROP `{c}`" for c in columns_to_remove) + frappe.db.sql_ddl(f"ALTER TABLE `tab{doctype}` {columns_to_remove}") + # frappe.clear_cache(doctype=doctype) + + return DROPPED_COLUMNS From 41b30b7442015e76f3996b94fcc61669a9a319d0 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 30 Aug 2021 12:26:18 +0530 Subject: [PATCH 008/137] feat: Handle site restores to MariaDB 10.6 --- frappe/installer.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frappe/installer.py b/frappe/installer.py index d4d8117fcb..41fd7b1cf0 100755 --- a/frappe/installer.py +++ b/frappe/installer.py @@ -445,9 +445,21 @@ def extract_sql_from_archive(sql_file_path): else: decompressed_file_name = sql_file_path + # convert archive sql to latest compatible + convert_archive_content(decompressed_file_name) + return decompressed_file_name +def convert_archive_content(sql_file_path): + if frappe.conf.db_type == "mariadb": + # ever since mariaDB 10.6, row_format COMPRESSED has been deprecated and removed + # this step is added to ease restoring sites depending on older mariaDB servers + contents = open(sql_file_path).read() + with open(sql_file_path, "w") as f: + f.write(contents.replace("ROW_FORMAT=COMPRESSED", "ROW_FORMAT=DYNAMIC")) + + def extract_sql_gzip(sql_gz_path): import subprocess @@ -457,7 +469,7 @@ def extract_sql_gzip(sql_gz_path): decompressed_file = original_file.rstrip(".gz") cmd = 'gzip -dvf < {0} > {1}'.format(original_file, decompressed_file) subprocess.check_call(cmd, shell=True) - except: + except Exception: raise return decompressed_file From 895520885e08e216da52bcc8e7f668170f0bd408 Mon Sep 17 00:00:00 2001 From: Shariq Ansari <30859809+shariquerik@users.noreply.github.com> Date: Tue, 31 Aug 2021 11:27:33 +0530 Subject: [PATCH 009/137] chore: Better naming convention Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- frappe/www/list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/www/list.py b/frappe/www/list.py index 3ed103b69d..74fadfb70f 100644 --- a/frappe/www/list.py +++ b/frappe/www/list.py @@ -163,7 +163,7 @@ def get_list_context(context, doctype, web_form_name=None): # get context for custom webform if meta.custom and web_form_name: - list_context_for_custom_webform = frappe.get_hooks('get_list_context_for_custom_webform') + webform_list_contexts = frappe.get_hooks('webform_list_context') if list_context_for_custom_webform: out = frappe._dict(frappe.get_attr(list_context_for_custom_webform[0])(meta.module) or {}) if out: From d8d25bdf19819633715bf558ecf41e55db859e00 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Tue, 31 Aug 2021 11:34:42 +0530 Subject: [PATCH 010/137] chore: Better naming convention --- frappe/www/list.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/www/list.py b/frappe/www/list.py index 74fadfb70f..f8e4a4eb93 100644 --- a/frappe/www/list.py +++ b/frappe/www/list.py @@ -164,8 +164,8 @@ def get_list_context(context, doctype, web_form_name=None): # get context for custom webform if meta.custom and web_form_name: webform_list_contexts = frappe.get_hooks('webform_list_context') - if list_context_for_custom_webform: - out = frappe._dict(frappe.get_attr(list_context_for_custom_webform[0])(meta.module) or {}) + if webform_list_contexts: + out = frappe._dict(frappe.get_attr(webform_list_contexts[0])(meta.module) or {}) if out: list_context = out From 765a255a009dfd5dcbc3ee46ebb23415ce6d6b5d Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 31 Aug 2021 18:26:15 +0530 Subject: [PATCH 011/137] ci: use ubuntu-latest for all jobs --- .github/workflows/patch-mariadb-tests.yml | 2 +- .github/workflows/server-mariadb-tests.yml | 4 ++-- .github/workflows/server-postgres-tests.yml | 2 +- .github/workflows/translation_linter.yml | 22 --------------------- .github/workflows/ui-tests.yml | 2 +- 5 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/translation_linter.yml diff --git a/.github/workflows/patch-mariadb-tests.yml b/.github/workflows/patch-mariadb-tests.yml index 0dd4cd51d8..3ac5cfa349 100644 --- a/.github/workflows/patch-mariadb-tests.yml +++ b/.github/workflows/patch-mariadb-tests.yml @@ -9,7 +9,7 @@ concurrency: jobs: test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest name: Patch Test diff --git a/.github/workflows/server-mariadb-tests.yml b/.github/workflows/server-mariadb-tests.yml index fb6e56037c..9187aa3c30 100644 --- a/.github/workflows/server-mariadb-tests.yml +++ b/.github/workflows/server-mariadb-tests.yml @@ -13,7 +13,7 @@ concurrency: jobs: test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest strategy: fail-fast: false @@ -146,7 +146,7 @@ jobs: name: Coverage Wrap Up needs: test container: python:3-slim - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v1 with: diff --git a/.github/workflows/server-postgres-tests.yml b/.github/workflows/server-postgres-tests.yml index 1539e8c2d5..539cf53f65 100644 --- a/.github/workflows/server-postgres-tests.yml +++ b/.github/workflows/server-postgres-tests.yml @@ -10,7 +10,7 @@ concurrency: jobs: test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/.github/workflows/translation_linter.yml b/.github/workflows/translation_linter.yml deleted file mode 100644 index 4becaebd6b..0000000000 --- a/.github/workflows/translation_linter.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Frappe Linter -on: - pull_request: - branches: - - develop - - version-12-hotfix - - version-11-hotfix -jobs: - check_translation: - name: Translation Syntax Check - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - name: Setup python3 - uses: actions/setup-python@v1 - with: - python-version: 3.6 - - name: Validating Translation Syntax - run: | - git fetch origin $GITHUB_BASE_REF:$GITHUB_BASE_REF -q - files=$(git diff --name-only --diff-filter=d $GITHUB_BASE_REF) - python $GITHUB_WORKSPACE/.github/helper/translation.py $files diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml index 2a55546ec4..0727b06043 100644 --- a/.github/workflows/ui-tests.yml +++ b/.github/workflows/ui-tests.yml @@ -12,7 +12,7 @@ concurrency: jobs: test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest strategy: fail-fast: false From c663ab7d4493be0ad2e738519f4135114f0f2a7a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 31 Aug 2021 21:59:06 +0530 Subject: [PATCH 012/137] test: improve test failure message --- frappe/tests/test_commands.py | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/frappe/tests/test_commands.py b/frappe/tests/test_commands.py index 1797698a11..564ddafe54 100644 --- a/frappe/tests/test_commands.py +++ b/frappe/tests/test_commands.py @@ -63,6 +63,28 @@ def clean(value): return value +def missing_in_backup(doctypes, file): + """Checks if the list of doctypes exist in the database.sql.gz file supplied + + Args: + doctypes (list): List of DocTypes to be checked + file (str): Path of the database file + + Returns: + doctypes(list): doctypes that are missing in backup + """ + predicate = ( + 'COPY public."tab{}"' + if frappe.conf.db_type == "postgres" + else "CREATE TABLE `tab{}`" + ) + with gzip.open(file, "rb") as f: + content = f.read().decode("utf8").lower() + + return [doctype for doctype in doctypes + if predicate.format(doctype).lower() not in content] + + def exists_in_backup(doctypes, file): """Checks if the list of doctypes exist in the database.sql.gz file supplied @@ -73,14 +95,8 @@ def exists_in_backup(doctypes, file): Returns: bool: True if all tables exist """ - predicate = ( - 'COPY public."tab{}"' - if frappe.conf.db_type == "postgres" - else "CREATE TABLE `tab{}`" - ) - with gzip.open(file, "rb") as f: - content = f.read().decode("utf8") - return all(predicate.format(doctype).lower() in content.lower() for doctype in doctypes) + missing_doctypes = missing_in_backup(doctypes, file) + return len(missing_doctypes) == 0 class BaseTestCommands(unittest.TestCase): @@ -222,7 +238,7 @@ class TestCommands(BaseTestCommands): self.execute("bench --site {site} backup --verbose") self.assertEqual(self.returncode, 0) database = fetch_latest_backups(partial=True)["database"] - self.assertTrue(exists_in_backup(backup["includes"]["includes"], database)) + self.assertEqual([], missing_in_backup(backup["includes"]["includes"], database)) # test 8: take a backup with frappe.conf.backup.excludes self.execute( @@ -233,7 +249,7 @@ class TestCommands(BaseTestCommands): self.assertEqual(self.returncode, 0) database = fetch_latest_backups(partial=True)["database"] self.assertFalse(exists_in_backup(backup["excludes"]["excludes"], database)) - self.assertTrue(exists_in_backup(backup["includes"]["includes"], database)) + self.assertEqual([], missing_in_backup(backup["includes"]["includes"], database)) # test 9: take a backup with --include (with frappe.conf.excludes still set) self.execute( @@ -242,7 +258,7 @@ class TestCommands(BaseTestCommands): ) self.assertEqual(self.returncode, 0) database = fetch_latest_backups(partial=True)["database"] - self.assertTrue(exists_in_backup(backup["includes"]["includes"], database)) + self.assertEqual([], missing_in_backup(backup["includes"]["includes"], database)) # test 10: take a backup with --exclude self.execute( @@ -257,7 +273,7 @@ class TestCommands(BaseTestCommands): self.execute("bench --site {site} backup --ignore-backup-conf") self.assertEqual(self.returncode, 0) database = fetch_latest_backups()["database"] - self.assertTrue(exists_in_backup(backup["excludes"]["excludes"], database)) + self.assertEqual([], missing_in_backup(backup["excludes"]["excludes"], database)) def test_restore(self): # step 0: create a site to run the test on From 3f2d0ac0cfc4b7ded6fad83c82d35e009d6cce8b Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 1 Sep 2021 13:37:01 +0530 Subject: [PATCH 013/137] feat(cli): New command 'db-console' Don't remember what db console you have to open for what site! How to use: `bench --site framework.io db-console` --- frappe/commands/utils.py | 44 +++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 54ee559cf5..490671b66a 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -408,20 +408,47 @@ def bulk_rename(context, doctype, path): frappe.destroy() +@click.command('db-console') +@pass_context +def database(context): + """ + Enter into the Database console for given site. + """ + site = get_site(context) + if not site: + raise SiteNotSpecifiedError + frappe.init(site=site) + if not frappe.conf.db_type or frappe.conf.db_type == "mariadb": + _mariadb() + elif frappe.conf.db_type == "postgres": + _psql() + + @click.command('mariadb') @pass_context def mariadb(context): """ Enter into mariadb console for a given site. """ - import os - site = get_site(context) if not site: raise SiteNotSpecifiedError frappe.init(site=site) + _mariadb() - # This is assuming you're within the bench instance. + +@click.command('postgres') +@pass_context +def postgres(context): + """ + Enter into postgres console for a given site. + """ + site = get_site(context) + frappe.init(site=site) + _psql() + + +def _mariadb(): mysql = find_executable('mysql') os.execv(mysql, [ mysql, @@ -434,15 +461,7 @@ def mariadb(context): "-A"]) -@click.command('postgres') -@pass_context -def postgres(context): - """ - Enter into postgres console for a given site. - """ - site = get_site(context) - frappe.init(site=site) - # This is assuming you're within the bench instance. +def _psql(): psql = find_executable('psql') subprocess.run([ psql, '-d', frappe.conf.db_name]) @@ -819,6 +838,7 @@ commands = [ build, clear_cache, clear_website_cache, + database, convert_database, jupyter, console, From c472fd359f0c5f402a284c7dcc4c299e8eb5b893 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Sep 2021 12:53:07 +0530 Subject: [PATCH 014/137] feat: Transform tables for given site * Ability to update ROW_FORMAT for mentioned tables in --table option * Failfast to stop on first error occured * Show progressbar for overall conversion progress (remaining tales) --- frappe/commands/utils.py | 61 +++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 490671b66a..5ca6bd6d3f 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -531,26 +531,59 @@ def console(context): IPython.embed(display_banner="", header="", colors="neutral") -@click.command('convert-database') +@click.command('transform-database') +@click.option('--table', default="all") +@click.option('--row_format', default="DYNAMIC", type=click.Choice(["DYNAMIC", "COMPACT", "REDUNDANT", "COMPRESSED"])) +@click.option('--failfast', is_flag=True, default=False) @pass_context -def convert_database(context): - "convert row_formats to DNAMIC from older formats -- innodb mariadb v10.6.3" +def transform_database(context, table, row_format, failfast): + "Transform site database through given parameters" site = get_site(context) + check_table = [] + add_line = False + skipped = 0 frappe.init(site=site) + + if frappe.conf.db_type and frappe.conf.db_type != "mariadb": + click.secho("This command only has support for MariaDB databases at this point", fg="yellow") + sys.exit(1) + frappe.connect() - information_schema = frappe.qb.Schema("information_schema") - queried_tables = frappe.qb.from_( - information_schema.tables - ).select("table_name").where( - information_schema.tables.row_format=="Compressed" - ).run() - tables = [x[0] for x in queried_tables] + if table == "all": + information_schema = frappe.qb.Schema("information_schema") + queried_tables = frappe.qb.from_( + information_schema.tables + ).select("table_name").where( + (information_schema.tables.row_format != row_format) + & (information_schema.tables.table_schema == frappe.conf.db_name) + ).run() + tables = [x[0] for x in queried_tables] + else: + tables = [x.strip() for x in table.split(",")] - for table in tables: - frappe.db.sql(f"ALTER TABLE `{table}` ROW_FORMAT=DYNAMIC") + total = len(tables) + + for current, table in enumerate(tables): + try: + frappe.db.sql(f"ALTER TABLE `{table}` ROW_FORMAT={row_format}") + update_progress_bar("Updating table schema", current - skipped, total) + add_line = True + except Exception as e: + check_table.append([table, e.args]) + skipped += 1 + + if failfast: + break + + if add_line: + print() + + for errored_table in check_table: + table, err = errored_table + err_msg = f"{table}: ERROR {err[0]}: {err[1]}" + click.secho(err_msg, fg="yellow") - frappe.db.commit() frappe.destroy() @@ -839,7 +872,7 @@ commands = [ clear_cache, clear_website_cache, database, - convert_database, + transform_database, jupyter, console, destroy_all_sessions, From 6c847987f124ec0408a1ee0075878fdcf615d844 Mon Sep 17 00:00:00 2001 From: Youssef Date: Wed, 1 Sep 2021 10:07:49 +0000 Subject: [PATCH 015/137] feat: Choose Letter Head when printing multiple documents from List /Report (cherry picked from commit 1c6688fd9c39008e86e88617ce901ba02b9076de) # Conflicts: # frappe/public/js/frappe/list/bulk_operations.js --- .../public/js/frappe/list/bulk_operations.js | 82 +++++++++++++------ 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/frappe/public/js/frappe/list/bulk_operations.js b/frappe/public/js/frappe/list/bulk_operations.js index 3b99560411..3bb7b33853 100644 --- a/frappe/public/js/frappe/list/bulk_operations.js +++ b/frappe/public/js/frappe/list/bulk_operations.js @@ -4,7 +4,7 @@ export default class BulkOperations { this.doctype = doctype; } - print(docs) { + print (docs) { const print_settings = frappe.model.get_doc(':Print Settings', 'Print Settings'); const allow_print_for_draft = cint(print_settings.allow_print_for_draft); const is_submittable = frappe.model.is_submittable(this.doctype); @@ -27,31 +27,38 @@ export default class BulkOperations { if (valid_docs.length > 0) { const dialog = new frappe.ui.Dialog({ title: __('Print Documents'), - fields: [{ - 'fieldtype': 'Check', - 'label': __('With Letterhead'), - 'fieldname': 'with_letterhead' - }, - { - 'fieldtype': 'Select', - 'label': __('Print Format'), - 'fieldname': 'print_sel', - options: frappe.meta.get_print_formats(this.doctype) - }] + fields: [ + { + 'fieldtype': 'Select', + 'label': __('Letter Head'), + 'fieldname': 'letter_sel', + 'default': __('No Letterhead'), + options: this.get_letterhead_options() + }, + { + 'fieldtype': 'Select', + 'label': __('Print Format'), + 'fieldname': 'print_sel', + options: frappe.meta.get_print_formats(this.doctype) + } + ] }); dialog.set_primary_action(__('Print'), args => { if (!args) return; const default_print_format = frappe.get_meta(this.doctype).default_print_format; - const with_letterhead = args.with_letterhead ? 1 : 0; + const with_letterhead = args.letter_sel == __("No Letterhead") ? 0 : 1; const print_format = args.print_sel ? args.print_sel : default_print_format; const json_string = JSON.stringify(valid_docs); - + const letterhead = args.letter_sel; const w = window.open('/api/method/frappe.utils.print_format.download_multi_pdf?' + 'doctype=' + encodeURIComponent(this.doctype) + '&name=' + encodeURIComponent(json_string) + '&format=' + encodeURIComponent(print_format) + - '&no_letterhead=' + (with_letterhead ? '0' : '1')); + '&no_letterhead=' + (with_letterhead ? '0' : '1') + + '&letterhead=' + encodeURIComponent(letterhead) + ); + if (!w) { frappe.msgprint(__('Please enable pop-ups')); return; @@ -64,7 +71,28 @@ export default class BulkOperations { } } - delete(docnames, done = null) { + get_letterhead_options () { + const letterhead_options = [__("No Letterhead")]; + frappe.call({ + method: "frappe.client.get_list", + args: { + doctype: 'Letter Head', + fields: ['name', 'is_default'], + limit: 0 + }, + async: false, + callback (r) { + if (r.message) { + r.message.forEach(letterhead => { + letterhead_options.push(letterhead.name); + }); + } + } + }); + return letterhead_options; + } + + delete (docnames, done = null) { frappe .call({ method: 'frappe.desk.reportview.delete_items', @@ -88,7 +116,7 @@ export default class BulkOperations { }); } - assign(docnames, done) { + assign (docnames, done) { if (docnames.length > 0) { const assign_to = new frappe.ui.form.AssignToDialog({ obj: this, @@ -106,7 +134,7 @@ export default class BulkOperations { } } - apply_assignment_rule(docnames, done) { + apply_assignment_rule (docnames, done) { if (docnames.length > 0) { frappe.call('frappe.automation.doctype.assignment_rule.assignment_rule.bulk_apply', { doctype: this.doctype, @@ -115,7 +143,7 @@ export default class BulkOperations { } } - submit_or_cancel(docnames, action='submit', done=null) { + submit_or_cancel (docnames, action = 'submit', done = null) { action = action.toLowerCase(); frappe .call({ @@ -140,7 +168,7 @@ export default class BulkOperations { }); } - edit(docnames, field_mappings, done) { + edit (docnames, field_mappings, done) { let field_options = Object.keys(field_mappings).sort(); const status_regex = /status/i; @@ -198,16 +226,16 @@ export default class BulkOperations { if (default_field) set_value_field(dialog); // to set `Value` df based on default `Field` - function set_value_field(dialogObj) { + function set_value_field (dialogObj) { const new_df = Object.assign({}, field_mappings[dialogObj.get_value('field')]); /* if the field label has status in it and if it has select fieldtype with no default value then set a default value from the available option. */ - if(new_df.label.match(status_regex) && + if (new_df.label.match(status_regex) && new_df.fieldtype === 'Select' && !new_df.default) { let options = []; - if(typeof new_df.options==="string") { + if (typeof new_df.options === "string") { options = new_df.options.split("\n"); } //set second option as default if first option is an empty string @@ -224,7 +252,7 @@ export default class BulkOperations { } - add_tags(docnames, done) { + add_tags (docnames, done) { const dialog = new frappe.ui.Dialog({ title: __('Add Tags'), fields: [ @@ -233,7 +261,7 @@ export default class BulkOperations { fieldname: 'tags', label: __("Tags"), reqd: true, - get_data: function(txt) { + get_data: function (txt) { return frappe.db.get_link_options("Tag", txt); } }, @@ -261,6 +289,7 @@ export default class BulkOperations { }); dialog.show(); } +<<<<<<< HEAD export(doctype, docnames) { frappe.require('data_import_tools.bundle.js', () => { @@ -272,3 +301,6 @@ export default class BulkOperations { }); } } +======= +} +>>>>>>> 1c6688fd9c (feat: Choose Letter Head when printing multiple documents from List /Report) From ba07f3bc95bffad45edcbd8d8a4f7fcaeb8b79fb Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Thu, 2 Sep 2021 11:30:57 +0200 Subject: [PATCH 016/137] fix: resolve merge conflicts --- frappe/public/js/frappe/list/bulk_operations.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/frappe/public/js/frappe/list/bulk_operations.js b/frappe/public/js/frappe/list/bulk_operations.js index 3bb7b33853..931f2cf587 100644 --- a/frappe/public/js/frappe/list/bulk_operations.js +++ b/frappe/public/js/frappe/list/bulk_operations.js @@ -251,7 +251,6 @@ export default class BulkOperations { dialog.show(); } - add_tags (docnames, done) { const dialog = new frappe.ui.Dialog({ title: __('Add Tags'), @@ -289,9 +288,8 @@ export default class BulkOperations { }); dialog.show(); } -<<<<<<< HEAD - export(doctype, docnames) { + export (doctype, docnames) { frappe.require('data_import_tools.bundle.js', () => { const data_exporter = new frappe.data_import.DataExporter(doctype, 'Insert New Records'); data_exporter.dialog.set_value('export_records', 'by_filter'); @@ -301,6 +299,3 @@ export default class BulkOperations { }); } } -======= -} ->>>>>>> 1c6688fd9c (feat: Choose Letter Head when printing multiple documents from List /Report) From 6ccf73026fc23ee874e1e3a9cc02436871179517 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Sep 2021 15:33:27 +0530 Subject: [PATCH 017/137] feat(minor): transform-tables - Update table engine --- frappe/commands/utils.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 5ca6bd6d3f..19bc355034 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -532,11 +532,12 @@ def console(context): @click.command('transform-database') -@click.option('--table', default="all") -@click.option('--row_format', default="DYNAMIC", type=click.Choice(["DYNAMIC", "COMPACT", "REDUNDANT", "COMPRESSED"])) +@click.option('--table', required=True) +@click.option('--engine', default=None, type=click.Choice(["InnoDB", "MyISAM"])) +@click.option('--row_format', default=None, type=click.Choice(["DYNAMIC", "COMPACT", "REDUNDANT", "COMPRESSED"])) @click.option('--failfast', is_flag=True, default=False) @pass_context -def transform_database(context, table, row_format, failfast): +def transform_database(context, table, engine, row_format, failfast): "Transform site database through given parameters" site = get_site(context) check_table = [] @@ -548,6 +549,10 @@ def transform_database(context, table, row_format, failfast): click.secho("This command only has support for MariaDB databases at this point", fg="yellow") sys.exit(1) + if not (engine or row_format): + click.secho("Values for `--engine` or `--row_format` must be set") + sys.exit(1) + frappe.connect() if table == "all": @@ -566,9 +571,15 @@ def transform_database(context, table, row_format, failfast): for current, table in enumerate(tables): try: - frappe.db.sql(f"ALTER TABLE `{table}` ROW_FORMAT={row_format}") + if engine: + frappe.db.sql(f"ALTER TABLE `{table}` ENGINE={engine}") + + if row_format: + frappe.db.sql(f"ALTER TABLE `{table}` ROW_FORMAT={row_format}") + update_progress_bar("Updating table schema", current - skipped, total) add_line = True + except Exception as e: check_table.append([table, e.args]) skipped += 1 From 71dc7f474ff695839de253d41b95bef11fa98ad2 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Sep 2021 15:51:49 +0530 Subject: [PATCH 018/137] perf: Single query to update a table --- frappe/commands/utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 2dba0dd678..bad26944b6 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -583,13 +583,14 @@ def transform_database(context, table, engine, row_format, failfast): total = len(tables) for current, table in enumerate(tables): + values_to_set = "" + if engine: + values_to_set += f" ENGINE={engine}" + if row_format: + values_to_set += f" ROW_FORMAT={row_format}" + try: - if engine: - frappe.db.sql(f"ALTER TABLE `{table}` ENGINE={engine}") - - if row_format: - frappe.db.sql(f"ALTER TABLE `{table}` ROW_FORMAT={row_format}") - + frappe.db.sql(f"ALTER TABLE `{table}`{values_to_set}") update_progress_bar("Updating table schema", current - skipped, total) add_line = True From a1c8a7b5f2866a76ba62351711fa402f55e03622 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Sep 2021 16:00:07 +0530 Subject: [PATCH 019/137] fix(restore): Initialize site before decompressing file --- frappe/commands/site.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 9098e31738..9b0ecee896 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -67,6 +67,9 @@ def restore(context, sql_file_path, mariadb_root_username=None, mariadb_root_pas validate_database_sql ) + site = get_site(context) + frappe.init(site=site) + force = context.force or force decompressed_file_name = extract_sql_from_archive(sql_file_path) @@ -85,9 +88,6 @@ def restore(context, sql_file_path, mariadb_root_username=None, mariadb_root_pas # check if valid SQL file validate_database_sql(decompressed_file_name, _raise=not force) - site = get_site(context) - frappe.init(site=site) - # dont allow downgrading to older versions of frappe without force if not force and is_downgrade(decompressed_file_name, verbose=True): warn_message = ( From ab09ebf696df84aa4cea00756e72695700439efc Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Thu, 2 Sep 2021 20:46:19 +0530 Subject: [PATCH 020/137] fix: Dashboard Setting already exist error and linter fixes --- .../js/frappe/views/workspace/workspace.js | 26 +++++----- frappe/public/scss/desk/desktop.scss | 52 +++++++++---------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/frappe/public/js/frappe/views/workspace/workspace.js b/frappe/public/js/frappe/views/workspace/workspace.js index b14b2eddfa..1e0143c2a8 100644 --- a/frappe/public/js/frappe/views/workspace/workspace.js +++ b/frappe/public/js/frappe/views/workspace/workspace.js @@ -155,7 +155,7 @@ frappe.views.Workspace = class Workspace { }); // Scroll sidebar to selected page if it is not in viewport. - !frappe.dom.is_element_in_viewport(this.sidebar.find('.selected')) + !frappe.dom.is_element_in_viewport(this.sidebar.find('.selected')) && this.sidebar.find('.selected')[0].scrollIntoView(); } @@ -185,7 +185,7 @@ frappe.views.Workspace = class Workspace { } append_item(item, container) { - let is_current_page = frappe.router.slug(item.title) == frappe.router.slug(this.get_page_to_show().name) + let is_current_page = frappe.router.slug(item.title) == frappe.router.slug(this.get_page_to_show().name) && item.public == this.get_page_to_show().public; if (is_current_page) { item.selected = true; @@ -253,11 +253,13 @@ frappe.views.Workspace = class Workspace { if (!this.page_data || Object.keys(this.page_data).length === 0) return; return frappe.dashboard_utils.get_dashboard_settings().then(settings => { - let chart_config = settings.chart_config ? JSON.parse(settings.chart_config) : {}; - if (this.page_data.charts && this.page_data.charts.items) { - this.page_data.charts.items.map(chart => { - chart.chart_settings = chart_config[chart.chart_name] || {}; - }); + if (settings) { + let chart_config = settings.chart_config ? JSON.parse(settings.chart_config) : {}; + if (this.page_data.charts && this.page_data.charts.items) { + this.page_data.charts.items.map(chart => { + chart.chart_settings = chart_config[chart.chart_name] || {}; + }); + } } }); }); @@ -560,7 +562,7 @@ frappe.views.Workspace = class Workspace { fieldname: 'is_public', depends_on: `eval:${this.has_access}`, onchange: function() { - d.set_df_property('parent', 'options', + d.set_df_property('parent', 'options', this.get_value() ? me.public_parent_pages : me.private_parent_pages); } }, @@ -704,9 +706,9 @@ frappe.views.Workspace = class Workspace { } }); - let blocks = outputData.blocks.filter( - item => item.type != 'card' || - (item.data.card_name !== 'Custom Documents' && + let blocks = outputData.blocks.filter( + item => item.type != 'card' || + (item.data.card_name !== 'Custom Documents' && item.data.card_name !== 'Custom Reports') ); @@ -752,4 +754,4 @@ frappe.views.Workspace = class Workspace { this.setup_pages(); this.undo.readOnly = true; } -}; \ No newline at end of file +}; diff --git a/frappe/public/scss/desk/desktop.scss b/frappe/public/scss/desk/desktop.scss index 49ed07bbce..1257d9b3a4 100644 --- a/frappe/public/scss/desk/desktop.scss +++ b/frappe/public/scss/desk/desktop.scss @@ -17,10 +17,10 @@ body { } .standard-sidebar-section { - margin-top: var(--margin-xl); + margin-bottom: var(--margin-xl); - &:first-of-type { - margin-top: var(--margin-sm); + &:last-of-type { + margin-bottom: var(--margin-sm); } } } @@ -143,7 +143,7 @@ body { font-weight: 500; line-height: 1.3em; color: var(--heading-color); - + svg { flex: none; margin-right: 6px; @@ -863,7 +863,7 @@ body { .drag-handle { display: inline-block; } - + .delete-page { display: inline-block; margin-right: 8px; @@ -888,44 +888,44 @@ body { .codex-editor { min-height: 630px; - + .codex-editor__redactor{ display: flex; flex-wrap: wrap; flex-direction: row; margin: 0px -7px; padding-bottom: 20px !important; - + .ce-block{ width: 100%; padding-left: 0; padding-right: 0; - + &.ce-block--selected { .ce-block__content { background-color: inherit; } } - + .ce-block__content { max-width: 100%; height: 100%; padding: 7px; - + &> div { height: 100%; } - + .tune-btn > * { pointer-events: none; } - + .ce-header { padding: 0 !important; margin-bottom: 0 !important; flex: 1; } - + .widget{ &.header { display: flex; @@ -938,11 +938,11 @@ body { background-color: var(--control-bg); color: var(--text-muted); } - + &:focus { outline: none; } - + &.new-widget { align-items: inherit; } @@ -959,7 +959,7 @@ body { gap: 5px; background-color: var(--card-bg); padding-left: 5px; - + .drag-handle { cursor: all-scroll; cursor: -webkit-grabbing; @@ -969,22 +969,22 @@ body { } } } - + svg { fill: none; } - + .ce-toolbar { svg { fill: currentColor; } - + .icon { stroke: none; width: fit-content; height: fit-content; } - + .ce-settings { width: fit-content; @@ -1011,18 +1011,18 @@ body { border-radius: 0 4px 4px 0;z-index: 0; } } - + .ce-toolbar__settings-btn { display: none; } } - + .ce-inline-tool, .ce-inline-toolbar__dropdown { .icon { fill: currentColor; } } - + @media (min-width: 1199px) { .ce-toolbar__content { max-width: 930px; @@ -1033,14 +1033,14 @@ body { max-width: 760px; } } - + @media (max-width: 1199px) { .ce-block.col-4 { flex: 0 0 50%; max-width: 50%; } } - + @media (max-width: 750px) { .ce-block.col-4 { flex: 0 0 100%; @@ -1053,6 +1053,6 @@ body { max-width: 100%; } } - + } } From b20e543de91cf49c5df9d9967b97dc92bcc47524 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Fri, 3 Sep 2021 16:55:44 +0530 Subject: [PATCH 021/137] test: test hook to get website_list_context --- frappe/tests/test_webform.py | 67 +++++++++++++++++++++++++++++++ frappe/www/_test/_test_webform.py | 6 +++ 2 files changed, 73 insertions(+) create mode 100644 frappe/tests/test_webform.py create mode 100644 frappe/www/_test/_test_webform.py diff --git a/frappe/tests/test_webform.py b/frappe/tests/test_webform.py new file mode 100644 index 0000000000..92dc441bdf --- /dev/null +++ b/frappe/tests/test_webform.py @@ -0,0 +1,67 @@ +import unittest + +import frappe +from frappe.www.list import get_list_context + + +class TestWebsite(unittest.TestCase): + def test_get_context_hook_of_webform(self): + create_custom_doctype() + create_webform() + + # check context for apps without any hook + context_list = get_list_context("", "Custom Doctype", "test-webform") + self.assertFalse(context_list) + + # create a hook to get webform_context + set_webform_hook( + "webform_list_context", + "frappe.www._test._test_webform.webform_list_context", + ) + # check context for apps with hook + context_list = get_list_context("", "Custom Doctype", "test-webform") + self.assertTrue(context_list) + + +def create_custom_doctype(): + frappe.get_doc( + { + "doctype": "DocType", + "name": "Custom Doctype", + "module": "Core", + "custom": 1, + "fields": [{"label": "Title", "fieldname": "title", "fieldtype": "Data"}], + } + ).insert(ignore_if_duplicate=True) + + +def create_webform(): + frappe.get_doc( + { + "doctype": "Web Form", + "module": "Core", + "title": "Test Webform", + "route": "test-webform", + "doc_type": "Custom Doctype", + "web_form_fields": [ + { + "doctype": "Web Form Field", + "fieldname": "title", + "fieldtype": "Data", + "label": "Title", + } + ], + } + ).insert(ignore_if_duplicate=True) + + +def set_webform_hook(key, value): + from frappe import hooks + + # reset hooks + for hook in "webform_list_context": + if hasattr(hooks, hook): + delattr(hooks, hook) + + setattr(hooks, key, value) + frappe.cache().delete_key("app_hooks") diff --git a/frappe/www/_test/_test_webform.py b/frappe/www/_test/_test_webform.py new file mode 100644 index 0000000000..3209e3e03c --- /dev/null +++ b/frappe/www/_test/_test_webform.py @@ -0,0 +1,6 @@ +def webform_list_context(module): + return {"get_list": get_webform_context_list} + + +def get_webform_context_list(): + pass From 1c1320c6844f37dfb6f93f5c511231c899a93d75 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 3 Sep 2021 18:59:29 +0530 Subject: [PATCH 022/137] fix: backup before trimming a site database --- frappe/commands/site.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 27e8e737ea..c0b6ac2187 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -741,13 +741,19 @@ def build_search_index(context): @click.command('trim-tables') @click.option('--dry-run', is_flag=True, default=False, help='Show what would be deleted') @click.option('--format', default='table', type=click.Choice(['json', 'table']), help='Output format') +@click.option('--no-backup', is_flag=True, default=False, help='Do not backup the site') @pass_context -def trim_tables(context, dry_run, format): +def trim_tables(context, dry_run, format, no_backup): from frappe.model.meta import trim_tables + from frappe.utils.backups import scheduled_backup for site in context.sites: frappe.init(site=site) frappe.connect() + + if not (no_backup or dry_run): + scheduled_backup(ignore_files=False, force=True) + try: trimmed_data = trim_tables(dry_run=dry_run) handle_data(trimmed_data, format=format) From 4127f0f135edc3ab25791697da45e26abdc320e4 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 3 Sep 2021 18:59:56 +0530 Subject: [PATCH 023/137] fix: Clear table columns cache to fetch accurate results --- frappe/model/meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/model/meta.py b/frappe/model/meta.py index f42cac59c3..ab3dd9ab97 100644 --- a/frappe/model/meta.py +++ b/frappe/model/meta.py @@ -685,6 +685,7 @@ def trim_tables(doctype=None, dry_run=False): def trim_table(doctype, dry_run=True): + frappe.cache().hdel('table_columns', f"tab{doctype}") ignore_fields = default_fields + optional_fields columns = frappe.db.get_table_columns(doctype) fields = frappe.get_meta(doctype, cached=False).get_fieldnames_with_value() @@ -697,6 +698,5 @@ def trim_table(doctype, dry_run=True): if columns_to_remove and not dry_run: columns_to_remove = ", ".join(f"DROP `{c}`" for c in columns_to_remove) frappe.db.sql_ddl(f"ALTER TABLE `tab{doctype}` {columns_to_remove}") - # frappe.clear_cache(doctype=doctype) return DROPPED_COLUMNS From 28d1d58944ac249a2e8893908a9055ee9dde8fde Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 3 Sep 2021 20:02:44 +0530 Subject: [PATCH 024/137] feat: bench trim-database Get rid of ghost tables in the site's database --- frappe/commands/site.py | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index c0b6ac2187..6f66c3628b 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -738,6 +738,59 @@ def build_search_index(context): finally: frappe.destroy() +@click.command('trim-database') +@click.option('--dry-run', is_flag=True, default=False, help='Show what would be deleted') +@click.option('--no-backup', is_flag=True, default=False, help='Do not backup the site') +@pass_context +def trim_database(context, dry_run, no_backup): + from frappe.utils.backups import scheduled_backup + + for site in context.sites: + frappe.init(site=site) + frappe.connect() + + TABLES_TO_DROPPED = [] + STANDARD_TABLES = get_standard_tables() + information_schema = frappe.qb.Schema("information_schema") + queried_result = frappe.qb.from_( + information_schema.tables + ).select("table_name").where( + information_schema.tables.table_schema == frappe.conf.db_name + ).run() + database_tables = [x[0] for x in queried_result] + doctype_tables = frappe.get_all("DocType", pluck="name") + + for x in database_tables: + doctype = x.lstrip("tab") + if not (doctype in doctype_tables or x.startswith("__") or x in STANDARD_TABLES): + TABLES_TO_DROPPED.append(x) + + if not TABLES_TO_DROPPED: + click.secho(f"No ghost tables found in {frappe.local.site}...Great!", fg="green") + else: + if not (no_backup or dry_run): + click.secho(f"Taking backup for {frappe.local.site}", fg="green") + odb = scheduled_backup(ignore_files=False, force=True) + odb.print_summary() + + for table in TABLES_TO_DROPPED: + print(f"* dropping Table '{table}'...") + if not dry_run: + frappe.db.sql_ddl(f"drop table `{table}`") + + frappe.destroy() + +def get_standard_tables(): + import re + tables = [] + sql_file = os.path.join("..", "apps", "frappe", "frappe", "database", frappe.conf.db_type, f'framework_{frappe.conf.db_type}.sql') + content = open(sql_file).read().splitlines() + for line in content: + beep = re.search("""CREATE TABLE ("|`)(.*)?("|`) \(""", line) + if beep: + tables.append(beep.group(2)) + return tables + @click.command('trim-tables') @click.option('--dry-run', is_flag=True, default=False, help='Show what would be deleted') @click.option('--format', default='table', type=click.Choice(['json', 'table']), help='Output format') @@ -799,4 +852,5 @@ commands = [ build_search_index, partial_restore, trim_tables, + trim_database, ] From b833e40b804fd1d62b5721d31db329e2390fc0c0 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 3 Sep 2021 20:04:15 +0530 Subject: [PATCH 025/137] fix: Show backup status in trim-tables command --- frappe/commands/site.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index 6f66c3628b..0cd965557c 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -805,7 +805,9 @@ def trim_tables(context, dry_run, format, no_backup): frappe.connect() if not (no_backup or dry_run): - scheduled_backup(ignore_files=False, force=True) + click.secho(f"Taking backup for {frappe.local.site}", fg="green") + odb = scheduled_backup(ignore_files=False, force=True) + odb.print_summary() try: trimmed_data = trim_tables(dry_run=dry_run) From 62593c49fb40b71f9189eab457d8f6012b82d282 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 3 Sep 2021 20:14:40 +0530 Subject: [PATCH 026/137] refactor: Rename arg table to doctype This change was made to be "more accurate" about how the internal magic handled --- frappe/database/postgres/database.py | 4 ++-- frappe/patches/v13_0/increase_password_length.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/database/postgres/database.py b/frappe/database/postgres/database.py index 00e60fb8d2..b4dd7fa9e5 100644 --- a/frappe/database/postgres/database.py +++ b/frappe/database/postgres/database.py @@ -182,8 +182,8 @@ class PostgresDatabase(Database): table_name = get_table_name(doctype) return self.sql(f"SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = '{table_name}'") - def change_column_type(self, table: str, column: str, type: str) -> Union[List, Tuple]: - table_name = get_table_name(table) + def change_column_type(self, doctype: str, column: str, type: str) -> Union[List, Tuple]: + table_name = get_table_name(doctype) return self.sql(f'ALTER TABLE "{table_name}" ALTER COLUMN "{column}" TYPE {type}') def create_auth_table(self): diff --git a/frappe/patches/v13_0/increase_password_length.py b/frappe/patches/v13_0/increase_password_length.py index 62ca2ed779..deb7d7e98a 100644 --- a/frappe/patches/v13_0/increase_password_length.py +++ b/frappe/patches/v13_0/increase_password_length.py @@ -1,4 +1,4 @@ import frappe def execute(): - frappe.db.change_column_type(table="__Auth", column="password", type="TEXT") + frappe.db.change_column_type("__Auth", column="password", type="TEXT") From 20dea906706180afe8461e38a9978edea3ea11ef Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Sun, 5 Sep 2021 22:01:55 +0530 Subject: [PATCH 027/137] feat(minor): Packages! also cleanup of DocField and other minor fixes --- frappe/core/doctype/docfield/docfield.json | 132 ++-- frappe/core/doctype/doctype/doctype.js | 64 ++ frappe/core/doctype/doctype/doctype.json | 10 +- frappe/core/doctype/doctype/doctype.py | 23 +- frappe/core/doctype/file/file.py | 5 +- frappe/core/doctype/module_def/module_def.js | 3 + .../core/doctype/module_def/module_def.json | 64 +- frappe/core/doctype/package/__init__.py | 0 .../GNU Affero General Public License.md | 614 +++++++++++++++++ .../licenses/GNU General Public License.md | 617 ++++++++++++++++++ .../doctype/package/licenses/MIT License.md | 17 + frappe/core/doctype/package/package.js | 17 + frappe/core/doctype/package/package.json | 76 +++ frappe/core/doctype/package/package.py | 17 + frappe/core/doctype/package/test_package.py | 87 +++ .../core/doctype/package_import/__init__.py | 0 .../doctype/package_import/package_import.js | 8 + .../package_import/package_import.json | 65 ++ .../doctype/package_import/package_import.py | 56 ++ .../package_import/test_package_import.py | 8 + .../core/doctype/package_release/__init__.py | 0 .../package_release/package_release.js | 8 + .../package_release/package_release.json | 95 +++ .../package_release/package_release.py | 79 +++ .../package_release/test_package_release.py | 8 + .../doctype/server_script/server_script.json | 9 +- .../doctype/server_script/server_script.py | 5 + frappe/core/workspace/build/build.json | 32 +- .../doctype/client_script/client_script.json | 19 +- .../doctype/custom_field/custom_field.json | 9 +- .../property_setter/property_setter.json | 14 +- frappe/database/database.py | 17 + frappe/database/mariadb/framework_mariadb.sql | 2 + .../database/postgres/framework_postgres.sql | 2 + frappe/model/naming.py | 2 +- frappe/model/sync.py | 8 +- frappe/modules.txt | 4 +- frappe/modules/export_file.py | 63 +- frappe/modules/import_file.py | 113 ++-- frappe/public/js/frappe/form/controls/code.js | 6 +- frappe/public/js/frappe/form/controls/text.js | 3 + frappe/tests/test_db.py | 8 +- frappe/utils/safe_exec.py | 7 +- frappe/website/doctype/web_page/web_page.json | 22 +- .../doctype/web_template/web_template.json | 11 +- 45 files changed, 2291 insertions(+), 138 deletions(-) create mode 100644 frappe/core/doctype/package/__init__.py create mode 100644 frappe/core/doctype/package/licenses/GNU Affero General Public License.md create mode 100644 frappe/core/doctype/package/licenses/GNU General Public License.md create mode 100644 frappe/core/doctype/package/licenses/MIT License.md create mode 100644 frappe/core/doctype/package/package.js create mode 100644 frappe/core/doctype/package/package.json create mode 100644 frappe/core/doctype/package/package.py create mode 100644 frappe/core/doctype/package/test_package.py create mode 100644 frappe/core/doctype/package_import/__init__.py create mode 100644 frappe/core/doctype/package_import/package_import.js create mode 100644 frappe/core/doctype/package_import/package_import.json create mode 100644 frappe/core/doctype/package_import/package_import.py create mode 100644 frappe/core/doctype/package_import/test_package_import.py create mode 100644 frappe/core/doctype/package_release/__init__.py create mode 100644 frappe/core/doctype/package_release/package_release.js create mode 100644 frappe/core/doctype/package_release/package_release.json create mode 100644 frappe/core/doctype/package_release/package_release.py create mode 100644 frappe/core/doctype/package_release/test_package_release.py diff --git a/frappe/core/doctype/docfield/docfield.json b/frappe/core/doctype/docfield/docfield.json index ce62adc8be..b240d29446 100644 --- a/frappe/core/doctype/docfield/docfield.json +++ b/frappe/core/doctype/docfield/docfield.json @@ -18,46 +18,53 @@ "hide_seconds", "reqd", "search_index", - "in_list_view", - "in_standard_filter", - "in_global_search", - "in_preview", - "allow_in_quick_entry", - "bold", - "translatable", - "collapsible", - "collapsible_depends_on", - "column_break_6", + "column_break_18", "options", + "defaults_section", "default", + "column_break_6", "fetch_from", "fetch_if_empty", - "permissions", - "depends_on", + "visibility_section", "hidden", + "bold", + "allow_in_quick_entry", + "translatable", + "print_hide", + "print_hide_if_no_value", + "report_hide", + "column_break_28", + "depends_on", + "collapsible", + "collapsible_depends_on", + "hide_border", + "list__search_settings_section", + "in_list_view", + "in_standard_filter", + "in_preview", + "column_break_35", + "in_filter", + "in_global_search", + "permissions", "read_only", - "unique", - "set_only_once", + "allow_on_submit", + "ignore_user_permissions", "allow_bulk_edit", "column_break_13", "permlevel", - "ignore_user_permissions", - "allow_on_submit", - "report_hide", - "remember_last_selected_value", "ignore_xss_filter", - "hide_border", - "property_depends_on_section", - "mandatory_depends_on", + "constraints_section", + "unique", + "no_copy", + "set_only_once", + "remember_last_selected_value", "column_break_38", + "mandatory_depends_on", "read_only_depends_on", "display", - "in_filter", - "no_copy", - "print_hide", - "print_hide_if_no_value", "print_width", "width", + "max_height", "columns", "column_break_22", "description", @@ -153,7 +160,7 @@ "default": "0", "fieldname": "in_standard_filter", "fieldtype": "Check", - "label": "In Standard Filter" + "label": "In List Filter" }, { "default": "0", @@ -197,10 +204,11 @@ "length": 255 }, { - "depends_on": "eval:doc.fieldtype==\"Section Break\"", + "depends_on": "eval:doc.fieldtype==\"Section Break\" && doc.collapsible", "fieldname": "collapsible_depends_on", "fieldtype": "Code", - "label": "Collapsible Depends On", + "label": "Collapsible Depends On (JS)", + "max_height": "3rem", "options": "JS" }, { @@ -220,6 +228,7 @@ "fieldname": "default", "fieldtype": "Small Text", "label": "Default", + "max_height": "3rem", "oldfieldname": "default", "oldfieldtype": "Text" }, @@ -230,10 +239,9 @@ }, { "default": "0", - "description": "If checked, this field will be not overwritten based on Fetch From if a value already exists.", "fieldname": "fetch_if_empty", "fieldtype": "Check", - "label": "Fetch If Empty" + "label": "Fetch only if value is not set" }, { "fieldname": "permissions", @@ -243,8 +251,9 @@ { "fieldname": "depends_on", "fieldtype": "Code", - "label": "Display Depends On", + "label": "Display Depends On (JS)", "length": 255, + "max_height": "3rem", "oldfieldname": "depends_on", "oldfieldtype": "Data", "options": "JS" @@ -275,10 +284,9 @@ }, { "default": "0", - "description": "Do not allow user to change after set the first time", "fieldname": "set_only_once", "fieldtype": "Check", - "label": "Set Only Once" + "label": "Set only once" }, { "default": "0", @@ -303,7 +311,6 @@ }, { "default": "0", - "description": "User permissions should not apply for this Link", "fieldname": "ignore_user_permissions", "fieldtype": "Check", "label": "Ignore User Permissions" @@ -388,12 +395,14 @@ { "fieldname": "print_width", "fieldtype": "Data", - "label": "Print Width" + "label": "Print Width", + "length": 10 }, { "fieldname": "width", "fieldtype": "Data", "label": "Width", + "length": 10, "oldfieldname": "width", "oldfieldtype": "Data", "print_width": "50px", @@ -436,20 +445,17 @@ { "fieldname": "mandatory_depends_on", "fieldtype": "Code", - "label": "Mandatory Depends On", + "label": "Mandatory Depends On (JS)", + "max_height": "3rem", "options": "JS" }, { "fieldname": "read_only_depends_on", "fieldtype": "Code", - "label": "Read Only Depends On", + "label": "Read Only Depends On (JS)", + "max_height": "3rem", "options": "JS" }, - { - "fieldname": "property_depends_on_section", - "fieldtype": "Section Break", - "label": "Property Depends On" - }, { "fieldname": "column_break_38", "fieldtype": "Column Break" @@ -481,16 +487,56 @@ "fieldname": "non_negative", "fieldtype": "Check", "label": "Non Negative" + }, + { + "fieldname": "column_break_18", + "fieldtype": "Column Break" + }, + { + "fieldname": "defaults_section", + "fieldtype": "Section Break", + "label": "Defaults", + "max_height": "2rem" + }, + { + "fieldname": "visibility_section", + "fieldtype": "Section Break", + "label": "Visibility" + }, + { + "fieldname": "column_break_28", + "fieldtype": "Column Break" + }, + { + "fieldname": "constraints_section", + "fieldtype": "Section Break", + "label": "Constraints" + }, + { + "fieldname": "max_height", + "fieldtype": "Data", + "label": "Max Height", + "length": 10 + }, + { + "fieldname": "list__search_settings_section", + "fieldtype": "Section Break", + "label": "List / Search Settings" + }, + { + "fieldname": "column_break_35", + "fieldtype": "Column Break" } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-07-10 21:56:04.167745", + "modified": "2021-09-04 19:41:53.684094", "modified_by": "Administrator", "module": "Core", "name": "DocField", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/frappe/core/doctype/doctype/doctype.js b/frappe/core/doctype/doctype/doctype.js index 3f1b5bb7ad..a6b46a9dc0 100644 --- a/frappe/core/doctype/doctype/doctype.js +++ b/frappe/core/doctype/doctype/doctype.js @@ -61,9 +61,73 @@ frappe.ui.form.on('DocType', { __('In Grid View') : __('In List View'); frm.events.autoname(frm); + frm.events.set_naming_rule_description(frm); + }, + + naming_rule: function(frm) { + // set the "autoname" property based on naming_rule + if (frm.doc.naming_rule && !frm.__from_autoname) { + + // flag to avoid recursion + frm.__from_naming_rule = true; + + if (frm.doc.naming_rule=='Set by user') { + frm.set_value('autoname', 'Prompt'); + } else if (frm.doc.naming_rule=='By fieldname') { + frm.set_value('autoname', 'field:'); + } else if (frm.doc.naming_rule=='By "Naming Series" field') { + frm.set_value('autoname', 'naming_series:'); + } else if (frm.doc.naming_rule=='Expression') { + frm.set_value('autoname', 'format:'); + } else if (frm.doc.naming_rule=='Expression (old style)') { + // pass + } else if (frm.doc.naming_rule=='Random') { + frm.set_value('autoname', 'hash'); + } + setTimeout(() =>frm.__from_naming_rule = false, 500); + + frm.events.set_naming_rule_description(frm); + } + + }, + + set_naming_rule_description(frm) { + let naming_rule_description = { + 'Set by user': '', + 'By fieldname': 'Format: field:[fieldname]. Valid fieldname must exist', + 'By "Naming Series" field': 'Format: naming_series:[fieldname]. Fieldname called naming_series must exist', + 'Expression': 'Format: format:EXAMPLE-{MM}morewords{fieldname1}-{fieldname2}-{#####} - Replace all braced words (fieldnames, date words (DD, MM, YY), series) with their value. Outside braces, any characters can be used.', + 'Expression (old style)': 'Format: EXAMPLE-.##### Series by prefix (separated by a dot)', + 'Random': '', + 'By script': '' + } + + if (frm.doc.naming_rule) { + frm.get_field('autoname').set_description(naming_rule_description[frm.doc.naming_rule]) + } }, autoname: function(frm) { + // set naming_rule based on autoname (for old doctypes where its not been set) + if (frm.doc.autoname && !frm.doc.naming_rule && !frm.__from_naming_rule) { + // flag to avoid recursion + frm.__from_autoname = true; + if (frm.doc.autoname.toLowerCase() === 'prompt') { + frm.set_value('naming_rule', 'Set by user'); + } else if (frm.doc.autoname.startsWith('field:')) { + frm.set_value('naming_rule', 'By fieldname'); + } else if (frm.doc.autoname.startsWith('naming_series:')) { + frm.set_value('naming_rule', 'By "Naming Series" field'); + } else if (frm.doc.autoname.startsWith('format:')) { + frm.set_value('naming_rule', 'Expression'); + } else if (frm.doc.autoname.toLowerCase() === 'hash') { + frm.set_value('naming_rule', 'Random'); + } else { + frm.set_value('naming_rule', 'Expression (old style)'); + } + setTimeout(() => frm.__from_autoname = false, 500); + } + frm.set_df_property('fields', 'reqd', frm.doc.autoname !== 'Prompt'); } }); diff --git a/frappe/core/doctype/doctype/doctype.json b/frappe/core/doctype/doctype/doctype.json index 63e0426eb3..18435f8873 100644 --- a/frappe/core/doctype/doctype/doctype.json +++ b/frappe/core/doctype/doctype/doctype.json @@ -26,6 +26,7 @@ "fields_section_break", "fields", "sb1", + "naming_rule", "autoname", "name_case", "allow_rename", @@ -554,6 +555,13 @@ "fieldname": "website_search_field", "fieldtype": "Data", "label": "Website Search Field" + }, + { + "fieldname": "naming_rule", + "fieldtype": "Select", + "label": "Naming Rule", + "length": 40, + "options": "\nSet by user\nBy fieldname\nBy \"Naming Series\" field\nExpression\nExpression (old style)\nRandom\nBy script" } ], "icon": "fa fa-bolt", @@ -635,7 +643,7 @@ "link_fieldname": "reference_doctype" } ], - "modified": "2021-08-31 15:26:19.077164", + "modified": "2021-09-05 15:39:13.233403", "modified_by": "Administrator", "module": "Core", "name": "DocType", diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 1050ccb460..70153268f5 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -493,6 +493,9 @@ class DocType(Document): # retain order of 'fields' table and change order in 'field_order' docdict["field_order"] = [f.fieldname for f in self.fields] + if self.custom: + return + path = get_file_path(self.module, "DocType", self.name) if os.path.exists(path): try: @@ -719,20 +722,20 @@ def validate_links_table_fieldnames(meta): for index, link in enumerate(meta.links): link_meta = frappe.get_meta(link.link_doctype) if not link_meta.get_field(link.link_fieldname): - message = _("Row #{0}: Could not find field {1} in {2} DocType").format(index+1, frappe.bold(link.link_fieldname), frappe.bold(link.link_doctype)) + message = _("Document Links Row #{0}: Could not find field {1} in {2} DocType").format(index+1, frappe.bold(link.link_fieldname), frappe.bold(link.link_doctype)) frappe.throw(message, InvalidFieldNameError, _("Invalid Fieldname")) if link.is_child_table and not meta.get_field(link.table_fieldname): - message = _("Row #{0}: Could not find field {1} in {2} DocType").format(index+1, frappe.bold(link.table_fieldname), frappe.bold(meta.name)) + message = _("Document Links Row #{0}: Could not find field {1} in {2} DocType").format(index+1, frappe.bold(link.table_fieldname), frappe.bold(meta.name)) frappe.throw(message, frappe.ValidationError, _("Invalid Table Fieldname")) if link.is_child_table: if not link.parent_doctype: - message = _("Row #{0}: Parent DocType is mandatory for internal links").format(index+1) + message = _("Document Links Row #{0}: Parent DocType is mandatory for internal links").format(index+1) frappe.throw(message, frappe.ValidationError, _("Parent Missing")) if not link.table_fieldname: - message = _("Row #{0}: Table Fieldname is mandatory for internal links").format(index+1) + message = _("Document Links Row #{0}: Table Fieldname is mandatory for internal links").format(index+1) frappe.throw(message, frappe.ValidationError, _("Table Fieldname Missing")) def validate_fields_for_doctype(doctype): @@ -1027,6 +1030,9 @@ def validate_fields(meta): frappe.throw(_('Option {0} for field {1} is not a child table') .format(frappe.bold(doctype), frappe.bold(docfield.fieldname)), title=_("Invalid Option")) + def check_max_height(docfield): + if getattr(docfield, 'max_height', None) and (docfield.max_height[-2:] not in ('px', 'em')): + frappe.throw('Max for {1} height must be in px, em, rem'.format(frappe.bold(docfield.fieldname))) fields = meta.get("fields") fieldname_list = [d.fieldname for d in fields] @@ -1060,6 +1066,7 @@ def validate_fields(meta): scrub_options_in_select(d) scrub_fetch_from(d) validate_data_field_type(d) + check_max_height(d) check_fold(fields) check_search_fields(meta, fields) @@ -1216,8 +1223,14 @@ def make_module_and_roles(doc, perm_fieldname="permissions"): if ("tabModule Def" in frappe.db.get_tables() and not frappe.db.exists("Module Def", doc.module)): m = frappe.get_doc({"doctype": "Module Def", "module_name": doc.module}) - m.app_name = frappe.local.module_app[frappe.scrub(doc.module)] + if frappe.scrub(doc.module) in frappe.local.module_app: + m.app_name = frappe.local.module_app[frappe.scrub(doc.module)] + else: + m.app_name = 'frappe' m.flags.ignore_mandatory = m.flags.ignore_permissions = True + if frappe.flags.package: + m.package = frappe.flags.package.name + m.custom = 1 m.insert() default_roles = ["Administrator", "Guest", "All"] diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index ebbcdcee17..d9ecd85533 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -254,10 +254,11 @@ class File(Document): return file_name = self.file_url.split('/')[-1] try: - with open(get_files_path(file_name, is_private=self.is_private), "rb") as f: + file_path = get_files_path(file_name, is_private=self.is_private) + with open(file_path, "rb") as f: self.content_hash = get_content_hash(f.read()) except IOError: - frappe.throw(_("File {0} does not exist").format(self.file_url)) + frappe.throw(_("File {0} does not exist").format(file_path)) def on_trash(self): if self.is_home_folder or self.is_attachments_folder: diff --git a/frappe/core/doctype/module_def/module_def.js b/frappe/core/doctype/module_def/module_def.js index c7a6cf85f9..73d2d6562c 100644 --- a/frappe/core/doctype/module_def/module_def.js +++ b/frappe/core/doctype/module_def/module_def.js @@ -5,6 +5,9 @@ frappe.ui.form.on('Module Def', { refresh: function(frm) { frappe.xcall('frappe.core.doctype.module_def.module_def.get_installed_apps').then(r => { frm.set_df_property('app_name', 'options', JSON.parse(r)); + if (!frm.doc.app_name) { + frm.set_value('app_name', 'frappe'); + } }); } }); diff --git a/frappe/core/doctype/module_def/module_def.json b/frappe/core/doctype/module_def/module_def.json index 4de046bbb6..7ddc55fce5 100644 --- a/frappe/core/doctype/module_def/module_def.json +++ b/frappe/core/doctype/module_def/module_def.json @@ -8,6 +8,7 @@ "field_order": [ "module_name", "custom", + "package", "app_name", "restrict_to_domain" ], @@ -23,6 +24,7 @@ "unique": 1 }, { + "depends_on": "eval:!doc.custom", "fieldname": "app_name", "fieldtype": "Select", "in_list_view": 1, @@ -41,24 +43,84 @@ "fieldname": "custom", "fieldtype": "Check", "label": "Custom" + }, + { + "depends_on": "custom", + "fieldname": "package", + "fieldtype": "Link", + "label": "Package", + "options": "Package" } ], "icon": "fa fa-sitemap", "idx": 1, "links": [ { + "group": "DocType", "link_doctype": "DocType", "link_fieldname": "module" }, { + "group": "DocType", + "link_doctype": "Client Script", + "link_fieldname": "module" + }, + { + "group": "DocType", + "link_doctype": "Server Script", + "link_fieldname": "module" + }, + { + "group": "Website", + "link_doctype": "Web Page", + "link_fieldname": "module" + }, + { + "group": "Website", + "link_doctype": "Web Template", + "link_fieldname": "module" + }, + { + "group": "Website", + "link_doctype": "Website Theme", + "link_fieldname": "module" + }, + { + "group": "Website", + "link_doctype": "Web Form", + "link_fieldname": "module" + }, + { + "group": "Customization", "link_doctype": "Workspace", "link_fieldname": "module" + }, + { + "group": "Customization", + "link_doctype": "Custom Field", + "link_fieldname": "module" + }, + { + "group": "Customization", + "link_doctype": "Property Setter", + "link_fieldname": "module" + }, + { + "group": "Customization", + "link_doctype": "Print Format", + "link_fieldname": "module" + }, + { + "group": "Customization", + "link_doctype": "Notification", + "link_fieldname": "module" } ], - "modified": "2021-06-02 13:04:53.118716", + "modified": "2021-09-05 21:58:40.253909", "modified_by": "Administrator", "module": "Core", "name": "Module Def", + "naming_rule": "By fieldname", "owner": "Administrator", "permissions": [ { diff --git a/frappe/core/doctype/package/__init__.py b/frappe/core/doctype/package/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/core/doctype/package/licenses/GNU Affero General Public License.md b/frappe/core/doctype/package/licenses/GNU Affero General Public License.md new file mode 100644 index 0000000000..c7f159aed8 --- /dev/null +++ b/frappe/core/doctype/package/licenses/GNU Affero General Public License.md @@ -0,0 +1,614 @@ +### GNU AFFERO GENERAL PUBLIC LICENSE + +Version 3, 19 November 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + +### Preamble + +The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + +The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains +free software for all its users. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + +Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + +A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + +The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + +An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing +under this license. + +The precise terms and conditions for copying, distribution and +modification follow. + +### TERMS AND CONDITIONS + +#### 0. Definitions. + +"This License" refers to version 3 of the GNU Affero General Public +License. + +"Copyright" also means copyright-like laws that apply to other kinds +of works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of +an exact copy. The resulting work is called a "modified version" of +the earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based +on the Program. + +To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user +through a computer network, with no transfer of a copy, is not +conveying. + +An interactive user interface displays "Appropriate Legal Notices" to +the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +#### 1. Source Code. + +The "source code" for a work means the preferred form of the work for +making modifications to it. "Object code" means any non-source form of +a work. + +A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can +regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same +work. + +#### 2. Basic Permissions. + +All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, +without conditions so long as your license otherwise remains in force. +You may convey covered works to others for the sole purpose of having +them make modifications exclusively for you, or provide you with +facilities for running those works, provided that you comply with the +terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for +you must do so exclusively on your behalf, under your direction and +control, on terms that prohibit them from making any copies of your +copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the +conditions stated below. Sublicensing is not allowed; section 10 makes +it unnecessary. + +#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + +When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such +circumvention is effected by exercising rights under this License with +respect to the covered work, and you disclaim any intention to limit +operation or modification of the work as a means of enforcing, against +the work's users, your or third parties' legal rights to forbid +circumvention of technological measures. + +#### 4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + +#### 5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these +conditions: + +- a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. +- b) The work must carry prominent notices stating that it is + released under this License and any conditions added under + section 7. This requirement modifies the requirement in section 4 + to "keep intact all notices". +- c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. +- d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + +A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + +#### 6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms of +sections 4 and 5, provided that you also convey the machine-readable +Corresponding Source under the terms of this License, in one of these +ways: + +- a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. +- b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the Corresponding + Source from a network server at no charge. +- c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. +- d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. +- e) Convey the object code using peer-to-peer transmission, + provided you inform other peers where the object code and + Corresponding Source of the work are being offered to the general + public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, +family, or household purposes, or (2) anything designed or sold for +incorporation into a dwelling. In determining whether a product is a +consumer product, doubtful cases shall be resolved in favor of +coverage. For a particular product received by a particular user, +"normally used" refers to a typical or common use of that class of +product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected +to use, the product. A product is a consumer product regardless of +whether the product has substantial commercial, industrial or +non-consumer uses, unless such uses represent the only significant +mode of use of the product. + +"Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to +install and execute modified versions of a covered work in that User +Product from a modified version of its Corresponding Source. The +information must suffice to ensure that the continued functioning of +the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + +The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or +updates for a work that has been modified or installed by the +recipient, or for the User Product in which it has been modified or +installed. Access to a network may be denied when the modification +itself materially and adversely affects the operation of the network +or violates the rules and protocols for communication across the +network. + +Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + +#### 7. Additional Terms. + +"Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders +of that material) supplement the terms of this License with terms: + +- a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or +- b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or +- c) Prohibiting misrepresentation of the origin of that material, + or requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or +- d) Limiting the use for publicity purposes of names of licensors + or authors of the material; or +- e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or +- f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions + of it) with contractual assumptions of liability to the recipient, + for any liability that these contractual assumptions directly + impose on those licensors and authors. + +All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; the +above requirements apply either way. + +#### 8. Termination. + +You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + +However, if you cease all violation of this License, then your license +from a particular copyright holder is reinstated (a) provisionally, +unless and until the copyright holder explicitly and finally +terminates your license, and (b) permanently, if the copyright holder +fails to notify you of the violation by some reasonable means prior to +60 days after the cessation. + +Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + +#### 9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run +a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + +#### 10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + +#### 11. Patents. + +A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims owned +or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + +If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + +A patent license is "discriminatory" if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on +the non-exercise of one or more of the rights that are specifically +granted under this License. You may not convey a covered work if you +are a party to an arrangement with a third party that is in the +business of distributing software, under which you make payment to the +third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties +who would receive the covered work from you, a discriminatory patent +license (a) in connection with copies of the covered work conveyed by +you (or copies made from those copies), or (b) primarily for and in +connection with specific products or compilations that contain the +covered work, unless you entered into that arrangement, or that patent +license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + +#### 12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under +this License and any other pertinent obligations, then as a +consequence you may not convey it at all. For example, if you agree to +terms that obligate you to collect a royalty for further conveying +from those to whom you convey the Program, the only way you could +satisfy both those terms and this License would be to refrain entirely +from conveying the Program. + +#### 13. Remote Network Interaction; Use with the GNU General Public License. + +Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your +version supports such interaction) an opportunity to receive the +Corresponding Source of your version by providing access to the +Corresponding Source from a network server at no charge, through some +standard or customary means of facilitating copying of software. This +Corresponding Source shall include the Corresponding Source for any +work covered by version 3 of the GNU General Public License that is +incorporated pursuant to the following paragraph. + +Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + +#### 14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions +of the GNU Affero General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever +published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions +of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + +Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + +#### 15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT +WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND +PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR +CORRECTION. + +#### 16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR +CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT +NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR +LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM +TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER +PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +#### 17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. diff --git a/frappe/core/doctype/package/licenses/GNU General Public License.md b/frappe/core/doctype/package/licenses/GNU General Public License.md new file mode 100644 index 0000000000..c4580f2eb6 --- /dev/null +++ b/frappe/core/doctype/package/licenses/GNU General Public License.md @@ -0,0 +1,617 @@ +### GNU GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + +### Preamble + +The GNU General Public License is a free, copyleft license for +software and other kinds of works. + +The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom +to share and change all versions of a program--to make sure it remains +free software for all its users. We, the Free Software Foundation, use +the GNU General Public License for most of our software; it applies +also to any other work released this way by its authors. You can apply +it to your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you +have certain responsibilities if you distribute copies of the +software, or if you modify it: responsibilities to respect the freedom +of others. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + +Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + +Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the +manufacturer can do so. This is fundamentally incompatible with the +aim of protecting users' freedom to change the software. The +systematic pattern of such abuse occurs in the area of products for +individuals to use, which is precisely where it is most unacceptable. +Therefore, we have designed this version of the GPL to prohibit the +practice for those products. If such problems arise substantially in +other domains, we stand ready to extend this provision to those +domains in future versions of the GPL, as needed to protect the +freedom of users. + +Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish +to avoid the special danger that patents applied to a free program +could make it effectively proprietary. To prevent this, the GPL +assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and +modification follow. + +### TERMS AND CONDITIONS + +#### 0. Definitions. + +"This License" refers to version 3 of the GNU General Public License. + +"Copyright" also means copyright-like laws that apply to other kinds +of works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of +an exact copy. The resulting work is called a "modified version" of +the earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based +on the Program. + +To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user +through a computer network, with no transfer of a copy, is not +conveying. + +An interactive user interface displays "Appropriate Legal Notices" to +the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +#### 1. Source Code. + +The "source code" for a work means the preferred form of the work for +making modifications to it. "Object code" means any non-source form of +a work. + +A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can +regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same +work. + +#### 2. Basic Permissions. + +All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, +without conditions so long as your license otherwise remains in force. +You may convey covered works to others for the sole purpose of having +them make modifications exclusively for you, or provide you with +facilities for running those works, provided that you comply with the +terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for +you must do so exclusively on your behalf, under your direction and +control, on terms that prohibit them from making any copies of your +copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the +conditions stated below. Sublicensing is not allowed; section 10 makes +it unnecessary. + +#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + +When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such +circumvention is effected by exercising rights under this License with +respect to the covered work, and you disclaim any intention to limit +operation or modification of the work as a means of enforcing, against +the work's users, your or third parties' legal rights to forbid +circumvention of technological measures. + +#### 4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + +#### 5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these +conditions: + +- a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. +- b) The work must carry prominent notices stating that it is + released under this License and any conditions added under + section 7. This requirement modifies the requirement in section 4 + to "keep intact all notices". +- c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. +- d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + +A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + +#### 6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms of +sections 4 and 5, provided that you also convey the machine-readable +Corresponding Source under the terms of this License, in one of these +ways: + +- a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. +- b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the Corresponding + Source from a network server at no charge. +- c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. +- d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. +- e) Convey the object code using peer-to-peer transmission, + provided you inform other peers where the object code and + Corresponding Source of the work are being offered to the general + public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, +family, or household purposes, or (2) anything designed or sold for +incorporation into a dwelling. In determining whether a product is a +consumer product, doubtful cases shall be resolved in favor of +coverage. For a particular product received by a particular user, +"normally used" refers to a typical or common use of that class of +product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected +to use, the product. A product is a consumer product regardless of +whether the product has substantial commercial, industrial or +non-consumer uses, unless such uses represent the only significant +mode of use of the product. + +"Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to +install and execute modified versions of a covered work in that User +Product from a modified version of its Corresponding Source. The +information must suffice to ensure that the continued functioning of +the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + +The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or +updates for a work that has been modified or installed by the +recipient, or for the User Product in which it has been modified or +installed. Access to a network may be denied when the modification +itself materially and adversely affects the operation of the network +or violates the rules and protocols for communication across the +network. + +Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + +#### 7. Additional Terms. + +"Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders +of that material) supplement the terms of this License with terms: + +- a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or +- b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or +- c) Prohibiting misrepresentation of the origin of that material, + or requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or +- d) Limiting the use for publicity purposes of names of licensors + or authors of the material; or +- e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or +- f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions + of it) with contractual assumptions of liability to the recipient, + for any liability that these contractual assumptions directly + impose on those licensors and authors. + +All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; the +above requirements apply either way. + +#### 8. Termination. + +You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + +However, if you cease all violation of this License, then your license +from a particular copyright holder is reinstated (a) provisionally, +unless and until the copyright holder explicitly and finally +terminates your license, and (b) permanently, if the copyright holder +fails to notify you of the violation by some reasonable means prior to +60 days after the cessation. + +Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + +#### 9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run +a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + +#### 10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + +#### 11. Patents. + +A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims owned +or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + +If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + +A patent license is "discriminatory" if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on +the non-exercise of one or more of the rights that are specifically +granted under this License. You may not convey a covered work if you +are a party to an arrangement with a third party that is in the +business of distributing software, under which you make payment to the +third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties +who would receive the covered work from you, a discriminatory patent +license (a) in connection with copies of the covered work conveyed by +you (or copies made from those copies), or (b) primarily for and in +connection with specific products or compilations that contain the +covered work, unless you entered into that arrangement, or that patent +license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + +#### 12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under +this License and any other pertinent obligations, then as a +consequence you may not convey it at all. For example, if you agree to +terms that obligate you to collect a royalty for further conveying +from those to whom you convey the Program, the only way you could +satisfy both those terms and this License would be to refrain entirely +from conveying the Program. + +#### 13. Use with the GNU Affero General Public License. + +Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + +#### 14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions +of the GNU General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in +detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies that a certain numbered version of the GNU General Public +License "or any later version" applies to it, you have the option of +following the terms and conditions either of that numbered version or +of any later version published by the Free Software Foundation. If the +Program does not specify a version number of the GNU General Public +License, you may choose any version ever published by the Free +Software Foundation. + +If the Program specifies that a proxy can decide which future versions +of the GNU General Public License can be used, that proxy's public +statement of acceptance of a version permanently authorizes you to +choose that version for the Program. + +Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + +#### 15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT +WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND +PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR +CORRECTION. + +#### 16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR +CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT +NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR +LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM +TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER +PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +#### 17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. diff --git a/frappe/core/doctype/package/licenses/MIT License.md b/frappe/core/doctype/package/licenses/MIT License.md new file mode 100644 index 0000000000..c038ee76ae --- /dev/null +++ b/frappe/core/doctype/package/licenses/MIT License.md @@ -0,0 +1,17 @@ +### MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/frappe/core/doctype/package/package.js b/frappe/core/doctype/package/package.js new file mode 100644 index 0000000000..90e2eed1e3 --- /dev/null +++ b/frappe/core/doctype/package/package.js @@ -0,0 +1,17 @@ +// Copyright (c) 2021, Frappe Technologies and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Package', { + validate: function(frm) { + if (!frm.doc.package_name) { + frm.set_value('package_name', frm.doc.name.toLowerCase().replace(' ', '-')); + } + }, + + license_type: function(frm) { + frappe.call('frappe.core.doctype.package.package.get_license_text', + {'license_type': frm.doc.license_type}).then(r => { + frm.set_value('license', r.message); + }); + } +}); diff --git a/frappe/core/doctype/package/package.json b/frappe/core/doctype/package/package.json new file mode 100644 index 0000000000..285e17a5bb --- /dev/null +++ b/frappe/core/doctype/package/package.json @@ -0,0 +1,76 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "Prompt", + "creation": "2021-09-04 11:54:35.155687", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "package_name", + "readme", + "license_type", + "license" + ], + "fields": [ + { + "fieldname": "readme", + "fieldtype": "Markdown Editor", + "label": "Readme" + }, + { + "fieldname": "package_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Package Name", + "reqd": 1 + }, + { + "fieldname": "license_type", + "fieldtype": "Select", + "label": "License Type", + "options": "\nMIT License\nGNU General Public License\nGNU Affero General Public License" + }, + { + "fieldname": "license", + "fieldtype": "Markdown Editor", + "label": "License" + } + ], + "index_web_pages_for_search": 1, + "links": [ + { + "group": "Modules", + "link_doctype": "Module Def", + "link_fieldname": "package" + }, + { + "group": "Release", + "link_doctype": "Package Release", + "link_fieldname": "package" + } + ], + "modified": "2021-09-05 13:15:01.130982", + "modified_by": "Administrator", + "module": "Core", + "name": "Package", + "naming_rule": "Set by user", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/frappe/core/doctype/package/package.py b/frappe/core/doctype/package/package.py new file mode 100644 index 0000000000..340496079d --- /dev/null +++ b/frappe/core/doctype/package/package.py @@ -0,0 +1,17 @@ +# Copyright (c) 2021, Frappe Technologies and contributors +# For license information, please see license.txt + +import frappe, os +from frappe.model.document import Document + +class Package(Document): + def validate(self): + if not self.package_name: + self.package_name = self.name.lower().replace(' ', '-') + +@frappe.whitelist() +def get_license_text(license_type): + with open(os.path.join(os.path.dirname(__file__), 'licenses', + license_type + '.md'), 'r') as textfile: + return textfile.read() + diff --git a/frappe/core/doctype/package/test_package.py b/frappe/core/doctype/package/test_package.py new file mode 100644 index 0000000000..21ae50d250 --- /dev/null +++ b/frappe/core/doctype/package/test_package.py @@ -0,0 +1,87 @@ +# Copyright (c) 2021, Frappe Technologies and Contributors +# See license.txt + +import frappe, os, json +import unittest + +class TestPackage(unittest.TestCase): + def test_package_release(self): + make_test_package() + make_test_module() + make_test_doctype() + make_test_server_script() + make_test_web_page() + + # make release + frappe.get_doc(dict( + doctype = 'Package Release', + package = 'Test Package', + publish = 1 + )).insert() + + self.assertTrue(os.path.exists(frappe.get_site_path('packages', 'test-package'))) + self.assertTrue(os.path.exists(frappe.get_site_path('packages', 'test-package', 'test_module_for_package'))) + self.assertTrue(os.path.exists(frappe.get_site_path('packages', 'test-package', 'test_module_for_package', 'doctype', 'test_doctype_for_package'))) + with open(frappe.get_site_path('packages', 'test-package', 'test_module_for_package', + 'doctype', 'test_doctype_for_package', 'test_doctype_for_package.json')) as f: + doctype = json.loads(f.read()) + self.assertEqual(doctype['doctype'], 'DocType') + self.assertEqual(doctype['name'], 'Test DocType for Package') + self.assertEqual(doctype['fields'][0]['fieldname'], 'test_field') + + +def make_test_package(): + if not frappe.db.exists('Package', 'Test Package'): + frappe.get_doc(dict( + doctype = 'Package', + name = 'Test Package', + package_name = 'test-package', + readme = '# Test Package' + )).insert() + +def make_test_module(): + if not frappe.db.exists('Module Def', 'Test Module for Package'): + frappe.get_doc(dict( + doctype = 'Module Def', + module_name = 'Test Module for Package', + custom = 1, + app_name = 'frappe', + package = 'Test Package' + )).insert() + +def make_test_doctype(): + if not frappe.db.exists('DocType', 'Test DocType for Package'): + frappe.get_doc(dict( + doctype = 'DocType', + name = 'Test DocType for Package', + custom = 1, + module = 'Test Module for Package', + autoname = 'Prompt', + fields = [dict( + fieldname = 'test_field', + fieldtype = 'Data', + label = 'Test Field' + )] + )).insert() + +def make_test_server_script(): + if not frappe.db.exists('Server Script', 'Test Script for Package'): + frappe.get_doc(dict( + doctype = 'Server Script', + name = 'Test Script for Package', + module = 'Test Module for Package', + script_type = 'DocType Event', + reference_doctype = 'Test DocType for Package', + doctype_event = 'Before Save', + script = 'frappe.msgprint("Test")' + )).insert() + +def make_test_web_page(): + if not frappe.db.exists('Web Page', 'test-web-page-for-package'): + frappe.get_doc(dict( + doctype = "Web Page", + module = 'Test Module for Package', + main_section = "Some content", + published = 1, + title = "Test Web Page for Package" + )).insert() diff --git a/frappe/core/doctype/package_import/__init__.py b/frappe/core/doctype/package_import/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/core/doctype/package_import/package_import.js b/frappe/core/doctype/package_import/package_import.js new file mode 100644 index 0000000000..c01a6266cc --- /dev/null +++ b/frappe/core/doctype/package_import/package_import.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, Frappe Technologies and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Package Import', { + // refresh: function(frm) { + + // } +}); diff --git a/frappe/core/doctype/package_import/package_import.json b/frappe/core/doctype/package_import/package_import.json new file mode 100644 index 0000000000..f3c6168f8d --- /dev/null +++ b/frappe/core/doctype/package_import/package_import.json @@ -0,0 +1,65 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "format:Package Import at {creation}", + "creation": "2021-09-05 16:36:46.680094", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "attach_package", + "activate", + "force", + "log" + ], + "fields": [ + { + "fieldname": "attach_package", + "fieldtype": "Attach", + "label": "Attach Package" + }, + { + "default": "0", + "fieldname": "activate", + "fieldtype": "Check", + "label": "Activate" + }, + { + "fieldname": "log", + "fieldtype": "Code", + "label": "Log", + "read_only": 1 + }, + { + "default": "0", + "fieldname": "force", + "fieldtype": "Check", + "label": "Force" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-09-05 21:30:04.796090", + "modified_by": "Administrator", + "module": "Core", + "name": "Package Import", + "naming_rule": "Expression", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/frappe/core/doctype/package_import/package_import.py b/frappe/core/doctype/package_import/package_import.py new file mode 100644 index 0000000000..b307a3bff9 --- /dev/null +++ b/frappe/core/doctype/package_import/package_import.py @@ -0,0 +1,56 @@ +# Copyright (c) 2021, Frappe Technologies and contributors +# For license information, please see license.txt + +import frappe, os, json +import subprocess +from frappe.model.document import Document +from frappe.desk.form.load import get_attachments +from frappe.model.sync import get_doc_files +from frappe.modules.import_file import import_file_by_path, import_doc + +class PackageImport(Document): + def validate(self): + if self.activate: + self.import_package() + + def import_package(self): + attachment = get_attachments(self.doctype, self.name) + + if not attachment: + frappe.throw('Please attach the package') + + attachment = attachment[0] + + # get package_name from file (package_name-0.0.0.tar.gz) + package_name = attachment.file_name.split('.')[0].rsplit('-', 1)[0] + if not os.path.exists(frappe.get_site_path('packages')): + os.makedirs(frappe.get_site_path('packages')) + + # extract + subprocess.check_output(['tar', 'xzf', + frappe.get_site_path(attachment.file_url.strip('/')), '-C', + frappe.get_site_path('packages')]) + + package_path = frappe.get_site_path('packages', package_name) + + # import Package + with open(os.path.join(package_path, package_name + '.json'), 'r') as packagefile: + doc_dict = json.loads(packagefile.read()) + + frappe.flags.package = import_doc(doc_dict) + + # collect modules + files = [] + log = [] + for module in os.listdir(package_path): + module_path = os.path.join(package_path, module) + if os.path.isdir(module_path): + get_doc_files(files, module_path) + + # import files + for file in files: + import_file_by_path(file, force=self.force, ignore_version=True, + for_sync=True) + log.append('Imported {}'.format(file)) + + self.log = '\n'.join(log) diff --git a/frappe/core/doctype/package_import/test_package_import.py b/frappe/core/doctype/package_import/test_package_import.py new file mode 100644 index 0000000000..04628fed93 --- /dev/null +++ b/frappe/core/doctype/package_import/test_package_import.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Frappe Technologies and Contributors +# See license.txt + +# import frappe +import unittest + +class TestPackageImport(unittest.TestCase): + pass diff --git a/frappe/core/doctype/package_release/__init__.py b/frappe/core/doctype/package_release/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/core/doctype/package_release/package_release.js b/frappe/core/doctype/package_release/package_release.js new file mode 100644 index 0000000000..9eabe36839 --- /dev/null +++ b/frappe/core/doctype/package_release/package_release.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, Frappe Technologies and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Package Release', { + // refresh: function(frm) { + + // } +}); diff --git a/frappe/core/doctype/package_release/package_release.json b/frappe/core/doctype/package_release/package_release.json new file mode 100644 index 0000000000..b651d699c4 --- /dev/null +++ b/frappe/core/doctype/package_release/package_release.json @@ -0,0 +1,95 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2021-09-05 12:59:01.932327", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "package", + "publish", + "path", + "column_break_3", + "major", + "minor", + "patch", + "section_break_7", + "release_notes" + ], + "fields": [ + { + "fieldname": "package", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Package", + "options": "Package", + "reqd": 1 + }, + { + "fieldname": "major", + "fieldtype": "Int", + "label": "Major" + }, + { + "fieldname": "minor", + "fieldtype": "Int", + "label": "Minor" + }, + { + "fieldname": "patch", + "fieldtype": "Int", + "label": "Patch", + "no_copy": 1 + }, + { + "fieldname": "path", + "fieldtype": "Small Text", + "label": "Path", + "read_only": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_7", + "fieldtype": "Section Break" + }, + { + "fieldname": "release_notes", + "fieldtype": "Markdown Editor", + "label": "Release Notes" + }, + { + "default": "0", + "fieldname": "publish", + "fieldtype": "Check", + "label": "Publish" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-09-05 16:04:32.860988", + "modified_by": "Administrator", + "module": "Core", + "name": "Package Release", + "naming_rule": "By script", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/frappe/core/doctype/package_release/package_release.py b/frappe/core/doctype/package_release/package_release.py new file mode 100644 index 0000000000..ea6906a190 --- /dev/null +++ b/frappe/core/doctype/package_release/package_release.py @@ -0,0 +1,79 @@ +# Copyright (c) 2021, Frappe Technologies and contributors +# For license information, please see license.txt + +import frappe +from frappe.model.document import Document +from frappe.modules.export_file import export_doc +import os, subprocess + +class PackageRelease(Document): + def set_version(self): + # set the next patch release by default + if not self.major: + self.major = frappe.db.max('Package Release', 'major', dict(package=self.package)) + if not self.minor: + self.minor = frappe.db.max('Package Release', 'minor', dict(package=self.package)) + if not self.patch: + self.patch = frappe.db.max('Package Release', 'patch', dict(package=self.package)) + 1 + + def autoname(self): + self.set_version() + self.name = '{}-{}.{}.{}'.format( + frappe.db.get_value('Package', self.package, 'package_name'), + self.major, self.minor, self.patch) + + def validate(self): + if self.publish: + self.export_files() + + def export_files(self): + '''Export all the documents in this package to site/packages folder''' + package = frappe.get_doc('Package', self.package) + + self.export_modules() + self.export_package_files(package) + self.make_tarfile(package) + + def export_modules(self): + for m in frappe.db.get_all('Module Def', dict(package=self.package)): + module = frappe.get_doc('Module Def', m.name) + for l in module.meta.links: + if l.link_doctype == 'Module Def': continue + # all documents of the type in the module + for d in frappe.get_all(l.link_doctype, dict(module=m.name)): + export_doc(frappe.get_doc(l.link_doctype, d.name)) + + def export_package_files(self, package): + # write readme + with open(frappe.get_site_path('packages', package.package_name, 'README.md'), 'w') as readme: + readme.write(package.readme) + + # write license + if package.license: + with open(frappe.get_site_path('packages', package.package_name, 'LICENSE.md'), 'w') as license: + license.write(package.license) + + # write package.json as `frappe_package.json` + with open(frappe.get_site_path('packages', package.package_name, package.package_name + '.json'), 'w') as packagefile: + packagefile.write(frappe.as_json(package.as_dict(no_nulls=True))) + + def make_tarfile(self, package): + # make tarfile + filename = '{}.tar.gz'.format(self.name) + subprocess.check_output(['tar', 'czf', filename, package.package_name], + cwd=frappe.get_site_path('packages')) + + # move file + subprocess.check_output(['mv', frappe.get_site_path('packages', filename), + frappe.get_site_path('public', 'files')]) + + # make attachment + file = frappe.get_doc(dict( + doctype = 'File', + file_url = '/' + os.path.join('files', filename), + attached_to_doctype = self.doctype, + attached_to_name = self.name + )) + + file.flags.ignore_duplicate_entry_error = True + file.insert() diff --git a/frappe/core/doctype/package_release/test_package_release.py b/frappe/core/doctype/package_release/test_package_release.py new file mode 100644 index 0000000000..6a15e8625b --- /dev/null +++ b/frappe/core/doctype/package_release/test_package_release.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Frappe Technologies and Contributors +# See license.txt + +# import frappe +import unittest + +class TestPackageRelease(unittest.TestCase): + pass diff --git a/frappe/core/doctype/server_script/server_script.json b/frappe/core/doctype/server_script/server_script.json index b7e49673f8..520c0008c5 100644 --- a/frappe/core/doctype/server_script/server_script.json +++ b/frappe/core/doctype/server_script/server_script.json @@ -13,6 +13,7 @@ "api_method", "allow_guest", "column_break_3", + "module", "disabled", "section_break_8", "script", @@ -93,6 +94,12 @@ "label": "Event Frequency", "mandatory_depends_on": "eval:doc.script_type == \"Scheduler Event\"", "options": "All\nHourly\nDaily\nWeekly\nMonthly\nYearly\nHourly Long\nDaily Long\nWeekly Long\nMonthly Long" + }, + { + "fieldname": "module", + "fieldtype": "Link", + "label": "Module (for export)", + "options": "Module Def" } ], "index_web_pages_for_search": 1, @@ -102,7 +109,7 @@ "link_fieldname": "server_script" } ], - "modified": "2021-02-18 12:36:19.803425", + "modified": "2021-09-04 12:02:43.671240", "modified_by": "Administrator", "module": "Core", "name": "Server Script", diff --git a/frappe/core/doctype/server_script/server_script.py b/frappe/core/doctype/server_script/server_script.py index 036e3638af..79fe7a9140 100644 --- a/frappe/core/doctype/server_script/server_script.py +++ b/frappe/core/doctype/server_script/server_script.py @@ -27,6 +27,11 @@ class ServerScript(Document): for job in self.scheduled_jobs: frappe.delete_doc("Scheduled Job Type", job.name) + def get_code_fields(self): + return { + 'script': 'py' + } + @property def scheduled_jobs(self) -> List[Dict[str, str]]: return frappe.get_all( diff --git a/frappe/core/workspace/build/build.json b/frappe/core/workspace/build/build.json index 464052ba39..8536c807d2 100644 --- a/frappe/core/workspace/build/build.json +++ b/frappe/core/workspace/build/build.json @@ -2,7 +2,7 @@ "cards_label": "Elements", "category": "", "charts": [], - "content": "[{\"type\": \"header\", \"data\": {\"text\": \"Your Shortcuts\", \"level\": 4, \"col\": 12}}, {\"type\": \"shortcut\", \"data\": {\"shortcut_name\": \"DocType\", \"col\": 4}}, {\"type\": \"shortcut\", \"data\": {\"shortcut_name\": \"Workspace\", \"col\": 4}}, {\"type\": \"shortcut\", \"data\": {\"shortcut_name\": \"Report\", \"col\": 4}}, {\"type\": \"spacer\", \"data\": {\"col\": 12}}, {\"type\": \"header\", \"data\": {\"text\": \"Elements\", \"level\": 4, \"col\": 12}}, {\"type\": \"card\", \"data\": {\"card_name\": \"Modules\", \"col\": 4}}, {\"type\": \"card\", \"data\": {\"card_name\": \"Models\", \"col\": 4}}, {\"type\": \"card\", \"data\": {\"card_name\": \"Views\", \"col\": 4}}, {\"type\": \"card\", \"data\": {\"card_name\": \"Scripting\", \"col\": 4}}]", + "content": "[{\"type\":\"header\",\"data\":{\"text\":\"Your Shortcuts\",\"level\":4,\"col\":12}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"DocType\",\"col\":4}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Workspace\",\"col\":4}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Report\",\"col\":4}},{\"type\":\"spacer\",\"data\":{\"col\":12}},{\"type\":\"header\",\"data\":{\"text\":\"Elements\",\"level\":4,\"col\":12}},{\"type\":\"card\",\"data\":{\"card_name\":\"Modules\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Models\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Views\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Scripting\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Packages\",\"col\":4}}]", "creation": "2021-01-02 10:51:16.579957", "developer_mode_only": 0, "disable_user_customization": 0, @@ -200,9 +200,37 @@ "onboard": 0, "only_for": "", "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Packages", + "link_count": 2, + "onboard": 0, + "type": "Card Break" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Package", + "link_count": 0, + "link_to": "Package", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, + { + "hidden": 0, + "is_query_report": 0, + "label": "Package Import", + "link_count": 0, + "link_to": "Package Import", + "link_type": "DocType", + "onboard": 0, + "type": "Link" } ], - "modified": "2021-08-05 12:15:55.793022", + "modified": "2021-09-05 21:14:52.384815", "modified_by": "Administrator", "module": "Core", "name": "Build", diff --git a/frappe/custom/doctype/client_script/client_script.json b/frappe/custom/doctype/client_script/client_script.json index db02d8d4bc..50f6bf3cc4 100644 --- a/frappe/custom/doctype/client_script/client_script.json +++ b/frappe/custom/doctype/client_script/client_script.json @@ -9,7 +9,10 @@ "field_order": [ "dt", "view", + "column_break_3", + "module", "enabled", + "section_break_6", "script", "sample" ], @@ -53,13 +56,27 @@ "label": "Apply To", "options": "List\nForm", "set_only_once": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "module", + "fieldtype": "Link", + "label": "Module (for export)", + "options": "Module Def" + }, + { + "fieldname": "section_break_6", + "fieldtype": "Section Break" } ], "icon": "fa fa-glass", "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2021-03-16 20:33:51.400191", + "modified": "2021-09-04 12:03:27.029815", "modified_by": "Administrator", "module": "Custom", "name": "Client Script", diff --git a/frappe/custom/doctype/custom_field/custom_field.json b/frappe/custom/doctype/custom_field/custom_field.json index 55a7ec5963..a8b1fb0e23 100644 --- a/frappe/custom/doctype/custom_field/custom_field.json +++ b/frappe/custom/doctype/custom_field/custom_field.json @@ -8,6 +8,7 @@ "engine": "InnoDB", "field_order": [ "dt", + "module", "label", "label_help", "fieldname", @@ -411,13 +412,19 @@ "fieldname": "non_negative", "fieldtype": "Check", "label": "Non Negative" + }, + { + "fieldname": "module", + "fieldtype": "Link", + "label": "Module (for export)", + "options": "Module Def" } ], "icon": "fa fa-glass", "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2021-07-12 05:54:13.042319", + "modified": "2021-09-04 12:45:22.810120", "modified_by": "Administrator", "module": "Custom", "name": "Custom Field", diff --git a/frappe/custom/doctype/property_setter/property_setter.json b/frappe/custom/doctype/property_setter/property_setter.json index b318d92c5a..fcb36637fe 100644 --- a/frappe/custom/doctype/property_setter/property_setter.json +++ b/frappe/custom/doctype/property_setter/property_setter.json @@ -13,6 +13,8 @@ "field_name", "row_name", "column_break0", + "module", + "section_break_9", "property", "property_type", "value", @@ -91,13 +93,23 @@ "fieldname": "row_name", "fieldtype": "Data", "label": "Row Name" + }, + { + "fieldname": "module", + "fieldtype": "Link", + "label": "Module (for export)", + "options": "Module Def" + }, + { + "fieldname": "section_break_9", + "fieldtype": "Section Break" } ], "icon": "fa fa-glass", "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2020-09-24 14:42:38.599684", + "modified": "2021-09-04 12:46:17.860769", "modified_by": "Administrator", "module": "Custom", "name": "Property Setter", diff --git a/frappe/database/database.py b/frappe/database/database.py index 227530e415..7a2d3e8b70 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -839,6 +839,23 @@ class Database(object): return count + def sum(self, dt, fieldname, filters=None): + return self._get_aggregation('SUM', dt, fieldname, filters) + + def avg(self, dt, fieldname, filters=None): + return self._get_aggregation('AVG', dt, fieldname, filters) + + def min(self, dt, fieldname, filters=None): + return self._get_aggregation('MIN', dt, fieldname, filters) + + def max(self, dt, fieldname, filters=None): + return self._get_aggregation('MAX', dt, fieldname, filters) + + def _get_aggregation(self, function, dt, fieldname, filters=None): + if not self.has_column(dt, fieldname): + frappe.throw('Invalid column', self.InvalidColumnName) + return self.get_all(dt, fields = ['%s(%s) as value' % (function, fieldname)], filters=filters)[0].get('value') or 0 + @staticmethod def format_date(date): return getdate(date).strftime("%Y-%m-%d") diff --git a/frappe/database/mariadb/framework_mariadb.sql b/frappe/database/mariadb/framework_mariadb.sql index f8841e9417..777e036049 100644 --- a/frappe/database/mariadb/framework_mariadb.sql +++ b/frappe/database/mariadb/framework_mariadb.sql @@ -61,6 +61,7 @@ CREATE TABLE `tabDocField` ( `in_preview` int(1) NOT NULL DEFAULT 0, `read_only` int(1) NOT NULL DEFAULT 0, `precision` varchar(255) DEFAULT NULL, + `max_height` varchar(10) DEFAULT NULL, `length` int(11) NOT NULL DEFAULT 0, `translatable` int(1) NOT NULL DEFAULT 0, `hide_border` int(1) NOT NULL DEFAULT 0, @@ -183,6 +184,7 @@ CREATE TABLE `tabDocType` ( `restrict_to_domain` varchar(255) DEFAULT NULL, `app` varchar(255) DEFAULT NULL, `autoname` varchar(255) DEFAULT NULL, + `naming_rule` varchar(40) DEFAULT NULL, `name_case` varchar(255) DEFAULT NULL, `title_field` varchar(255) DEFAULT NULL, `image_field` varchar(255) DEFAULT NULL, diff --git a/frappe/database/postgres/framework_postgres.sql b/frappe/database/postgres/framework_postgres.sql index a4e94aa326..868f98fc98 100644 --- a/frappe/database/postgres/framework_postgres.sql +++ b/frappe/database/postgres/framework_postgres.sql @@ -61,6 +61,7 @@ CREATE TABLE "tabDocField" ( "in_preview" smallint NOT NULL DEFAULT 0, "read_only" smallint NOT NULL DEFAULT 0, "precision" varchar(255) DEFAULT NULL, + "max_height" varchar(10) DEFAULT NULL, "length" bigint NOT NULL DEFAULT 0, "translatable" smallint NOT NULL DEFAULT 0, "hide_border" smallint NOT NULL DEFAULT 0, @@ -188,6 +189,7 @@ CREATE TABLE "tabDocType" ( "restrict_to_domain" varchar(255) DEFAULT NULL, "app" varchar(255) DEFAULT NULL, "autoname" varchar(255) DEFAULT NULL, + "naming_rule" varchar(40) DEFAULT NULL, "name_case" varchar(255) DEFAULT NULL, "title_field" varchar(255) DEFAULT NULL, "image_field" varchar(255) DEFAULT NULL, diff --git a/frappe/model/naming.py b/frappe/model/naming.py index 2e7f54938f..71ff281642 100644 --- a/frappe/model/naming.py +++ b/frappe/model/naming.py @@ -346,7 +346,7 @@ def _prompt_autoname(autoname, doc): """ # set from __newname in save.py if not doc.name: - frappe.throw(_("Name not set via prompt")) + frappe.throw(_("Please set the document name")) def _format_autoname(autoname, doc): """ diff --git a/frappe/model/sync.py b/frappe/model/sync.py index c2e3fcac08..138f9eaad4 100644 --- a/frappe/model/sync.py +++ b/frappe/model/sync.py @@ -80,9 +80,11 @@ def get_doc_files(files, start_path): # load in sequence - warning for devs document_types = ['doctype', 'page', 'report', 'dashboard_chart_source', 'print_format', - 'website_theme', 'web_form', 'web_template', 'notification', 'print_style', - 'data_migration_mapping', 'data_migration_plan', 'workspace', - 'onboarding_step', 'module_onboarding', 'form_tour'] + 'web_page', 'website_theme', 'web_form', 'web_template', + 'notification', 'print_style', + 'data_migration_mapping', 'data_migration_plan', + 'workspace', 'onboarding_step', 'module_onboarding', 'form_tour', + 'client_script', 'server_script', 'custom_field', 'property_setter'] for doctype in document_types: doctype_path = os.path.join(start_path, doctype) diff --git a/frappe/modules.txt b/frappe/modules.txt index ae10c3ad55..d45817409d 100644 --- a/frappe/modules.txt +++ b/frappe/modules.txt @@ -12,4 +12,6 @@ Data Migration Chat Social Automation -Event Streaming \ No newline at end of file +Event Streaming +Test Module +Test Module for Package \ No newline at end of file diff --git a/frappe/modules/export_file.py b/frappe/modules/export_file.py index 4a00295022..17e84ee488 100644 --- a/frappe/modules/export_file.py +++ b/frappe/modules/export_file.py @@ -6,7 +6,7 @@ import frappe.model from frappe.modules import scrub, get_module_path, scrub_dt_dn def export_doc(doc): - export_to_files([[doc.doctype, doc.name]]) + write_document_file(doc) def export_to_files(record_list=None, record_module=None, verbose=0, create_init=None): """ @@ -21,16 +21,10 @@ def export_to_files(record_list=None, record_module=None, verbose=0, create_init write_document_file(frappe.get_doc(record[0], record[1]), record_module, create_init=create_init, folder_name=folder_name) def write_document_file(doc, record_module=None, create_init=True, folder_name=None): - newdoc = doc.as_dict(no_nulls=True) - doc.run_method("before_export", newdoc) - - # strip out default fields from children - for df in doc.meta.get_table_fields(): - for d in newdoc.get(df.fieldname): - for fieldname in frappe.model.default_fields: - if fieldname in d: - del d[fieldname] + doc_export = doc.as_dict(no_nulls=True) + doc.run_method("before_export", doc_export) + strip_default_fields(doc, doc_export) module = record_module or get_module_name(doc) # create folder @@ -39,10 +33,33 @@ def write_document_file(doc, record_module=None, create_init=True, folder_name=N else: folder = create_folder(module, doc.doctype, doc.name, create_init) - # write the data file fname = scrub(doc.name) + write_code_files(folder, fname, doc, doc_export) + + # write the data file with open(os.path.join(folder, fname + ".json"), 'w+') as txtfile: - txtfile.write(frappe.as_json(newdoc)) + txtfile.write(frappe.as_json(doc_export)) + +def strip_default_fields(doc, doc_export): + # strip out default fields from children + for df in doc.meta.get_table_fields(): + for d in doc_export.get(df.fieldname): + for fieldname in frappe.model.default_fields: + if fieldname in d: + del d[fieldname] + +def write_code_files(folder, fname, doc, doc_export): + '''Export code files and strip from values''' + if hasattr(doc, 'get_code_fields'): + for key, extn in doc.get_code_fields().items(): + if doc.get(key): + with open(os.path.join(folder, fname + "." + extn), 'w+') as txtfile: + txtfile.write(doc.get(key)) + + # remove from exporting + del doc_export[key] + + def get_module_name(doc): if doc.doctype == 'Module Def': @@ -57,7 +74,10 @@ def get_module_name(doc): return module def create_folder(module, dt, dn, create_init): - module_path = get_module_path(module) + if frappe.db.get_value('Module Def', module, 'custom'): + module_path = get_custom_module_path(module) + else: + module_path = get_module_path(module) dt, dn = scrub_dt_dn(dt, dn) @@ -72,6 +92,23 @@ def create_folder(module, dt, dn, create_init): return folder +def get_custom_module_path(module): + package = frappe.db.get_value('Module Def', module, 'package') + if not package: + frappe.throw('Package must be set for custom Module {module}'.format(module=module)) + + path = os.path.join(get_package_path(package), scrub(module)) + if not os.path.exists(path): + os.makedirs(path) + + return path + +def get_package_path(package): + path = os.path.join(frappe.get_site_path('packages'), frappe.db.get_value('Package', package, 'package_name')) + if not os.path.exists(path): + os.makedirs(path) + return path + def create_init_py(module_path, dt, dn): def create_if_not_exists(path): initpy = os.path.join(path, '__init__.py') diff --git a/frappe/modules/import_file.py b/frappe/modules/import_file.py index e398e384e3..ecef0a2cc5 100644 --- a/frappe/modules/import_file.py +++ b/frappe/modules/import_file.py @@ -54,31 +54,26 @@ def import_file_by_path(path, force=False, data_import=False, pre_process=None, docs = [docs] for doc in docs: - if not force: - # check if timestamps match - db_modified = frappe.db.get_value(doc['doctype'], doc['name'], 'modified') - if db_modified and doc.get('modified')==get_datetime_str(db_modified): - return False + if not force and not is_changed(doc): + return False original_modified = doc.get("modified") - frappe.flags.in_import = True import_doc(doc, force=force, data_import=data_import, pre_process=pre_process, - ignore_version=ignore_version, reset_permissions=reset_permissions) - frappe.flags.in_import = False + ignore_version=ignore_version, reset_permissions=reset_permissions, path=path) if original_modified: - # since there is a new timestamp on the file, update timestamp in - if doc["doctype"] == doc["name"] and doc["name"]!="DocType": - frappe.db.sql("""update tabSingles set value=%s where field="modified" and doctype=%s""", - (original_modified, doc["name"])) - else: - frappe.db.sql("update `tab%s` set modified=%s where name=%s" % \ - (doc['doctype'], '%s', '%s'), - (original_modified, doc['name'])) + update_modified(original_modified, doc) return True +def is_changed(doc): + # check if timestamps match + db_modified = frappe.db.get_value(doc['doctype'], doc['name'], 'modified') + if db_modified and doc.get('modified')==get_datetime_str(db_modified): + return False + return True + def read_doc_from_file(path): doc = None if os.path.exists(path): @@ -93,8 +88,18 @@ def read_doc_from_file(path): return doc +def update_modified(original_modified, doc): + # since there is a new timestamp on the file, update timestamp in + if doc["doctype"] == doc["name"] and doc["name"]!="DocType": + frappe.db.sql("""update tabSingles set value=%s where field="modified" and doctype=%s""", + (original_modified, doc["name"])) + else: + frappe.db.sql("update `tab%s` set modified=%s where name=%s" % \ + (doc['doctype'], '%s', '%s'), + (original_modified, doc['name'])) + def import_doc(docdict, force=False, data_import=False, pre_process=None, - ignore_version=None, reset_permissions=False): + ignore_version=None, reset_permissions=False, path=None): frappe.flags.in_import = True docdict["__islocal"] = 1 @@ -104,14 +109,8 @@ def import_doc(docdict, force=False, data_import=False, pre_process=None, doc = frappe.get_doc(docdict) - # Note on Tree DocTypes: - # The tree structure is maintained in the database via the fields "lft" and - # "rgt". They are automatically set and kept up-to-date. Importing them - # would destroy any existing tree structure. - if getattr(doc.meta, 'is_tree', None) and any([doc.lft, doc.rgt]): - print('Ignoring values of `lft` and `rgt` for {} "{}"'.format(doc.doctype, doc.name)) - doc.lft = None - doc.rgt = None + reset_tree_properties(doc) + load_code_properties(doc, path) doc.run_method("before_import") @@ -119,27 +118,9 @@ def import_doc(docdict, force=False, data_import=False, pre_process=None, if pre_process: pre_process(doc) - ignore = [] - if frappe.db.exists(doc.doctype, doc.name): + delete_old_doc(doc, reset_permissions) - old_doc = frappe.get_doc(doc.doctype, doc.name) - - if doc.doctype in ignore_values: - # update ignore values - for key in ignore_values.get(doc.doctype) or []: - doc.set(key, old_doc.get(key)) - - # update ignored docs into new doc - for df in doc.meta.get_table_fields(): - if df.options in ignore_doctypes and not reset_permissions: - doc.set(df.fieldname, []) - ignore.append(df.options) - - # delete old - frappe.delete_doc(doc.doctype, doc.name, force=1, ignore_doctypes=ignore, for_reload=True) - - doc.flags.ignore_children_type = ignore doc.flags.ignore_links = True if not data_import: doc.flags.ignore_validate = True @@ -149,3 +130,47 @@ def import_doc(docdict, force=False, data_import=False, pre_process=None, doc.insert() frappe.flags.in_import = False + + return doc + +def load_code_properties(doc, path): + '''Load code files stored in separate files with extensions''' + if path: + if hasattr(doc, 'get_code_fields'): + dirname, filename = os.path.split(path) + for key, extn in doc.get_code_fields().items(): + codefile = os.path.join(dirname, filename.split('.')[0]+'.'+extn) + if os.path.exists(codefile): + with open(codefile,'r') as txtfile: + doc.set(key, txtfile.read()) + + +def delete_old_doc(doc, reset_permissions): + ignore = [] + old_doc = frappe.get_doc(doc.doctype, doc.name) + + if doc.doctype in ignore_values: + # update ignore values + for key in ignore_values.get(doc.doctype) or []: + doc.set(key, old_doc.get(key)) + + # update ignored docs into new doc + for df in doc.meta.get_table_fields(): + if df.options in ignore_doctypes and not reset_permissions: + doc.set(df.fieldname, []) + ignore.append(df.options) + + # delete old + frappe.delete_doc(doc.doctype, doc.name, force=1, ignore_doctypes=ignore, for_reload=True) + + doc.flags.ignore_children_type = ignore + +def reset_tree_properties(doc): + # Note on Tree DocTypes: + # The tree structure is maintained in the database via the fields "lft" and + # "rgt". They are automatically set and kept up-to-date. Importing them + # would destroy any existing tree structure. + if getattr(doc.meta, 'is_tree', None) and any([doc.lft, doc.rgt]): + print('Ignoring values of `lft` and `rgt` for {} "{}"'.format(doc.doctype, doc.name)) + doc.lft = None + doc.rgt = None diff --git a/frappe/public/js/frappe/form/controls/code.js b/frappe/public/js/frappe/form/controls/code.js index 5fbfa28073..60805b75de 100644 --- a/frappe/public/js/frappe/form/controls/code.js +++ b/frappe/public/js/frappe/form/controls/code.js @@ -14,11 +14,15 @@ frappe.ui.form.ControlCode = class ControlCode extends frappe.ui.form.ControlTex this.ace_editor_target.addClass('border rounded'); this.ace_editor_target.css('height', 300); + if (this.df.max_height) { + this.ace_editor_target.css('max-height', this.df.max_height); + } + // initialize const ace = window.ace; this.editor = ace.edit(this.ace_editor_target.get(0)); - if (this.df.max_lines || this.df.min_lines) { + if (this.df.max_lines || this.df.min_lines || this.df.max_height) { if (this.df.max_lines) this.editor.setOption("maxLines", this.df.max_lines); if (this.df.min_lines) diff --git a/frappe/public/js/frappe/form/controls/text.js b/frappe/public/js/frappe/form/controls/text.js index 3156df6d1c..ccf9a85feb 100644 --- a/frappe/public/js/frappe/form/controls/text.js +++ b/frappe/public/js/frappe/form/controls/text.js @@ -8,6 +8,9 @@ frappe.ui.form.ControlText = class ControlText extends frappe.ui.form.ControlDat make_input() { super.make_input(); this.$input.css({'height': '300px'}); + if (this.df.max_height) { + this.$input.css({'max-height': this.df.max_height}); + } } }; diff --git a/frappe/tests/test_db.py b/frappe/tests/test_db.py index 069ec25cca..73bb3e122f 100644 --- a/frappe/tests/test_db.py +++ b/frappe/tests/test_db.py @@ -43,10 +43,15 @@ class TestDB(unittest.TestCase): self.assertEqual(frappe.db.get_value('ToDo', todo1.name, 'description'), 'change 2') self.assertEqual(frappe.db.get_value('ToDo', todo2.name, 'description'), 'change 2') - def test_escape(self): frappe.db.escape("香港濟生堂製藥有限公司 - IT".encode("utf-8")) + def test_aggregation(self): + self.assertTrue(type(frappe.db.sum('DocField', 'permlevel')) in (int, float)) + self.assertTrue(type(frappe.db.avg('DocField', 'permlevel')) in (int, float)) + self.assertTrue(type(frappe.db.min('DocField', 'permlevel')) in (int, float)) + self.assertTrue(type(frappe.db.max('DocField', 'permlevel')) in (int, float)) + def test_get_single_value(self): #setup values_dict = { @@ -286,3 +291,4 @@ class TestDDLCommandsPost(unittest.TestCase): ) self.assertGreater(len(check_change), 0) self.assertIn("character varying", check_change[0]) + diff --git a/frappe/utils/safe_exec.py b/frappe/utils/safe_exec.py index 7ccd80e346..e18c498b3c 100644 --- a/frappe/utils/safe_exec.py +++ b/frappe/utils/safe_exec.py @@ -147,7 +147,12 @@ def get_safe_globals(): get_single_value = frappe.db.get_single_value, get_default = frappe.db.get_default, escape = frappe.db.escape, - sql = read_sql + sql = read_sql, + sum = frappe.db.sum, + avg = frappe.db.avg, + count = frappe.db.count, + min = frappe.db.min, + max = frappe.db.max ) if frappe.response: diff --git a/frappe/website/doctype/web_page/web_page.json b/frappe/website/doctype/web_page/web_page.json index 1ff3dcc359..2852d93705 100644 --- a/frappe/website/doctype/web_page/web_page.json +++ b/frappe/website/doctype/web_page/web_page.json @@ -11,16 +11,15 @@ "section_title", "title", "route", - "dynamic_route", - "slideshow", - "cb1", "published", - "full_width", - "show_title", + "dynamic_route", + "cb1", + "module", "start_date", "end_date", "sb1", "content_type", + "slideshow", "dynamic_template", "main_section", "main_section_md", @@ -34,7 +33,9 @@ "insert_style", "text_align", "css", + "full_width", "settings", + "show_title", "section_break_17", "show_sidebar", "website_sidebar", @@ -75,6 +76,7 @@ "unique": 1 }, { + "depends_on": "eval:doc.content_type=='Slideshow'", "fieldname": "slideshow", "fieldtype": "Link", "label": "Slideshow", @@ -118,7 +120,7 @@ "fieldname": "content_type", "fieldtype": "Select", "label": "Content Type", - "options": "Rich Text\nMarkdown\nHTML\nPage Builder" + "options": "Rich Text\nMarkdown\nHTML\nPage Builder\nSlideshow" }, { "depends_on": "eval:doc.content_type==='Rich Text'", @@ -305,6 +307,12 @@ "fieldtype": "Code", "label": "Context Script", "options": "Python" + }, + { + "fieldname": "module", + "fieldtype": "Link", + "label": "Module (for export)", + "options": "Module Def" } ], "has_web_view": 1, @@ -314,7 +322,7 @@ "is_published_field": "published", "links": [], "max_attachments": 20, - "modified": "2021-04-13 10:23:28.681197", + "modified": "2021-09-04 12:11:56.070994", "modified_by": "Administrator", "module": "Website", "name": "Web Page", diff --git a/frappe/website/doctype/web_template/web_template.json b/frappe/website/doctype/web_template/web_template.json index 3f7cd9b312..d2b909f950 100644 --- a/frappe/website/doctype/web_template/web_template.json +++ b/frappe/website/doctype/web_template/web_template.json @@ -45,7 +45,6 @@ "options": "Component\nSection\nNavbar\nFooter" }, { - "depends_on": "standard", "fieldname": "module", "fieldtype": "Link", "label": "Module", @@ -54,16 +53,12 @@ } ], "index_web_pages_for_search": 1, - "links": [ - { - "link_doctype": "Web Page", - "link_fieldname": "web_template" - } - ], - "modified": "2020-10-26 17:22:55.459453", + "links": [], + "modified": "2021-09-04 12:38:27.656042", "modified_by": "Administrator", "module": "Website", "name": "Web Template", + "naming_rule": "Set by user", "owner": "Administrator", "permissions": [ { From c2e93256f294aea5e7469a8eacc7e080825cd635 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Sun, 5 Sep 2021 22:14:24 +0530 Subject: [PATCH 028/137] fix(minor): remove test modules --- frappe/modules.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/frappe/modules.txt b/frappe/modules.txt index d45817409d..1229116a2e 100644 --- a/frappe/modules.txt +++ b/frappe/modules.txt @@ -13,5 +13,3 @@ Chat Social Automation Event Streaming -Test Module -Test Module for Package \ No newline at end of file From 5befc80cd4ed9f17bf821c50a340aeb3ed7dcc77 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Sun, 5 Sep 2021 22:30:09 +0530 Subject: [PATCH 029/137] fix(minor): linting --- frappe/core/doctype/doctype/doctype.js | 4 ++-- frappe/core/doctype/doctype/doctype.py | 2 +- frappe/core/doctype/package/package.py | 3 ++- frappe/core/doctype/package/test_package.py | 4 +++- frappe/core/doctype/package_import/package_import.py | 6 ++++-- frappe/core/doctype/package_release/package_release.py | 6 ++++-- frappe/database/database.py | 2 +- frappe/modules/import_file.py | 5 ++--- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/frappe/core/doctype/doctype/doctype.js b/frappe/core/doctype/doctype/doctype.js index a6b46a9dc0..262a6efd90 100644 --- a/frappe/core/doctype/doctype/doctype.js +++ b/frappe/core/doctype/doctype/doctype.js @@ -100,10 +100,10 @@ frappe.ui.form.on('DocType', { 'Expression (old style)': 'Format: EXAMPLE-.##### Series by prefix (separated by a dot)', 'Random': '', 'By script': '' - } + }; if (frm.doc.naming_rule) { - frm.get_field('autoname').set_description(naming_rule_description[frm.doc.naming_rule]) + frm.get_field('autoname').set_description(naming_rule_description[frm.doc.naming_rule]); } }, diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 70153268f5..9bf21690fc 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -1032,7 +1032,7 @@ def validate_fields(meta): def check_max_height(docfield): if getattr(docfield, 'max_height', None) and (docfield.max_height[-2:] not in ('px', 'em')): - frappe.throw('Max for {1} height must be in px, em, rem'.format(frappe.bold(docfield.fieldname))) + frappe.throw('Max for {} height must be in px, em, rem'.format(frappe.bold(docfield.fieldname))) fields = meta.get("fields") fieldname_list = [d.fieldname for d in fields] diff --git a/frappe/core/doctype/package/package.py b/frappe/core/doctype/package/package.py index 340496079d..aa9735c061 100644 --- a/frappe/core/doctype/package/package.py +++ b/frappe/core/doctype/package/package.py @@ -1,7 +1,8 @@ # Copyright (c) 2021, Frappe Technologies and contributors # For license information, please see license.txt -import frappe, os +import frappe +import os from frappe.model.document import Document class Package(Document): diff --git a/frappe/core/doctype/package/test_package.py b/frappe/core/doctype/package/test_package.py index 21ae50d250..3fb8d48274 100644 --- a/frappe/core/doctype/package/test_package.py +++ b/frappe/core/doctype/package/test_package.py @@ -1,7 +1,9 @@ # Copyright (c) 2021, Frappe Technologies and Contributors # See license.txt -import frappe, os, json +import frappe +import os +import json import unittest class TestPackage(unittest.TestCase): diff --git a/frappe/core/doctype/package_import/package_import.py b/frappe/core/doctype/package_import/package_import.py index b307a3bff9..f4a2d666dd 100644 --- a/frappe/core/doctype/package_import/package_import.py +++ b/frappe/core/doctype/package_import/package_import.py @@ -1,7 +1,9 @@ # Copyright (c) 2021, Frappe Technologies and contributors # For license information, please see license.txt -import frappe, os, json +import frappe +import os +import json import subprocess from frappe.model.document import Document from frappe.desk.form.load import get_attachments @@ -17,7 +19,7 @@ class PackageImport(Document): attachment = get_attachments(self.doctype, self.name) if not attachment: - frappe.throw('Please attach the package') + frappe.throw(frappe._('Please attach the package')) attachment = attachment[0] diff --git a/frappe/core/doctype/package_release/package_release.py b/frappe/core/doctype/package_release/package_release.py index ea6906a190..1fb8796882 100644 --- a/frappe/core/doctype/package_release/package_release.py +++ b/frappe/core/doctype/package_release/package_release.py @@ -4,7 +4,8 @@ import frappe from frappe.model.document import Document from frappe.modules.export_file import export_doc -import os, subprocess +import os +import subprocess class PackageRelease(Document): def set_version(self): @@ -38,7 +39,8 @@ class PackageRelease(Document): for m in frappe.db.get_all('Module Def', dict(package=self.package)): module = frappe.get_doc('Module Def', m.name) for l in module.meta.links: - if l.link_doctype == 'Module Def': continue + if l.link_doctype == 'Module Def': + continue # all documents of the type in the module for d in frappe.get_all(l.link_doctype, dict(module=m.name)): export_doc(frappe.get_doc(l.link_doctype, d.name)) diff --git a/frappe/database/database.py b/frappe/database/database.py index 7a2d3e8b70..45a496a621 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -853,7 +853,7 @@ class Database(object): def _get_aggregation(self, function, dt, fieldname, filters=None): if not self.has_column(dt, fieldname): - frappe.throw('Invalid column', self.InvalidColumnName) + frappe.throw(frappe._('Invalid column'), self.InvalidColumnName) return self.get_all(dt, fields = ['%s(%s) as value' % (function, fieldname)], filters=filters)[0].get('value') or 0 @staticmethod diff --git a/frappe/modules/import_file.py b/frappe/modules/import_file.py index ecef0a2cc5..e7a1f5f97c 100644 --- a/frappe/modules/import_file.py +++ b/frappe/modules/import_file.py @@ -94,9 +94,8 @@ def update_modified(original_modified, doc): frappe.db.sql("""update tabSingles set value=%s where field="modified" and doctype=%s""", (original_modified, doc["name"])) else: - frappe.db.sql("update `tab%s` set modified=%s where name=%s" % \ - (doc['doctype'], '%s', '%s'), - (original_modified, doc['name'])) + frappe.db.sql("update `tab%s` set modified=%s where name=%s" % (doc['doctype'], + '%s', '%s'), (original_modified, doc['name'])) def import_doc(docdict, force=False, data_import=False, pre_process=None, ignore_version=None, reset_permissions=False, path=None): From d807e3b1e2ac1a442149287c18d171b43f467400 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 6 Sep 2021 09:11:58 +0530 Subject: [PATCH 030/137] fix(minor): fix for aggregate functions, use special query --- frappe/database/database.py | 9 ++++++++- frappe/tests/test_db.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/frappe/database/database.py b/frappe/database/database.py index 45a496a621..84bfa76cd7 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -854,7 +854,14 @@ class Database(object): def _get_aggregation(self, function, dt, fieldname, filters=None): if not self.has_column(dt, fieldname): frappe.throw(frappe._('Invalid column'), self.InvalidColumnName) - return self.get_all(dt, fields = ['%s(%s) as value' % (function, fieldname)], filters=filters)[0].get('value') or 0 + + query = f'SELECT {function}({fieldname}) AS value FROM `tab{dt}`' + values = () + if filters: + conditions, values = self.build_conditions(filters) + query = f"{query} WHERE {conditions}" + + return self.sql(query, values)[0][0] or 0 @staticmethod def format_date(date): diff --git a/frappe/tests/test_db.py b/frappe/tests/test_db.py index 73bb3e122f..e153220a1d 100644 --- a/frappe/tests/test_db.py +++ b/frappe/tests/test_db.py @@ -47,7 +47,7 @@ class TestDB(unittest.TestCase): frappe.db.escape("香港濟生堂製藥有限公司 - IT".encode("utf-8")) def test_aggregation(self): - self.assertTrue(type(frappe.db.sum('DocField', 'permlevel')) in (int, float)) + self.assertTrue(type(frappe.db.sum('DocField', 'permlevel', dict(parent=('like', 'doc')))) in (int, float)) self.assertTrue(type(frappe.db.avg('DocField', 'permlevel')) in (int, float)) self.assertTrue(type(frappe.db.min('DocField', 'permlevel')) in (int, float)) self.assertTrue(type(frappe.db.max('DocField', 'permlevel')) in (int, float)) From 5ccda1d5ac8d32f33c9095aed05f5ac5379cdd52 Mon Sep 17 00:00:00 2001 From: leela Date: Mon, 6 Sep 2021 10:27:10 +0530 Subject: [PATCH 031/137] fix: RTL support for text editor (cherry picked from commit 99f914698f7b86048c25087eb74dbd1fae707ac4) --- frappe/public/js/frappe/form/controls/comment.js | 2 ++ frappe/public/js/frappe/form/controls/text_editor.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/frappe/public/js/frappe/form/controls/comment.js b/frappe/public/js/frappe/form/controls/comment.js index 7c10b61366..b9b2d6a987 100644 --- a/frappe/public/js/frappe/form/controls/comment.js +++ b/frappe/public/js/frappe/form/controls/comment.js @@ -104,8 +104,10 @@ frappe.ui.form.ControlComment = class ControlComment extends frappe.ui.form.Cont return [ ['bold', 'italic', 'underline'], ['blockquote', 'code-block'], + [{ 'direction': "rtl" }], ['link', 'image'], [{ 'list': 'ordered' }, { 'list': 'bullet' }], + [{ 'align': [] }], ['clean'] ]; } diff --git a/frappe/public/js/frappe/form/controls/text_editor.js b/frappe/public/js/frappe/form/controls/text_editor.js index 99e87c5f21..2ce8fd1046 100644 --- a/frappe/public/js/frappe/form/controls/text_editor.js +++ b/frappe/public/js/frappe/form/controls/text_editor.js @@ -164,8 +164,11 @@ frappe.ui.form.ControlTextEditor = class ControlTextEditor extends frappe.ui.for ['bold', 'italic', 'underline', 'clean'], [{ 'color': [] }, { 'background': [] }], ['blockquote', 'code-block'], + // Adding Direction tool to give the user the ability to change text direction. + [{ 'direction': "rtl" }], ['link', 'image'], [{ 'list': 'ordered' }, { 'list': 'bullet' }, { 'list': 'check' }], + [{ 'align': [] }], [{ 'indent': '-1'}, { 'indent': '+1' }], [{'table': [ 'insert-table', From 46c617afde8dd3792b78cb35ba17e061ad93daaf Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Mon, 6 Sep 2021 11:28:32 +0530 Subject: [PATCH 032/137] fix(UI): Checked icon not visible in PDF --- frappe/templates/print_formats/standard_macros.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/templates/print_formats/standard_macros.html b/frappe/templates/print_formats/standard_macros.html index f8dc6c370c..ec60af1ce0 100644 --- a/frappe/templates/print_formats/standard_macros.html +++ b/frappe/templates/print_formats/standard_macros.html @@ -135,7 +135,7 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" {% elif df.fieldtype=="Check" and doc[df.fieldname] %} From 768e4052f9de0d5bde38e11475617c3a4a69c677 Mon Sep 17 00:00:00 2001 From: leela Date: Fri, 3 Sep 2021 12:32:05 +0530 Subject: [PATCH 033/137] fix: node creation from tree view (cherry picked from commit f8cd2ad388c96eefff4730ce130806231bc0d87e) --- frappe/desk/treeview.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/frappe/desk/treeview.py b/frappe/desk/treeview.py index 704e5d8ed6..f40c135653 100644 --- a/frappe/desk/treeview.py +++ b/frappe/desk/treeview.py @@ -69,13 +69,11 @@ def make_tree_args(**kwarg): doctype = kwarg['doctype'] parent_field = 'parent_' + doctype.lower().replace(' ', '_') - name_field = kwarg.get('name_field', doctype.lower().replace(' ', '_') + '_name') if kwarg['is_root'] == 'false': kwarg['is_root'] = False if kwarg['is_root'] == 'true': kwarg['is_root'] = True kwarg.update({ - name_field: kwarg[name_field], parent_field: kwarg.get("parent") or kwarg.get(parent_field) }) From 62a205fe2efd9763b31e67009edce46fee2cad3f Mon Sep 17 00:00:00 2001 From: Saqib Date: Mon, 6 Sep 2021 12:43:17 +0530 Subject: [PATCH 034/137] feat: change custom button type (#14074) * feat: change custom button type using frm --- frappe/public/js/frappe/form/form.js | 4 ++++ frappe/public/js/frappe/ui/page.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js index 3588923527..8a691e8012 100644 --- a/frappe/public/js/frappe/form/form.js +++ b/frappe/public/js/frappe/form/form.js @@ -1152,6 +1152,10 @@ frappe.ui.form.Form = class FrappeForm { return btn; } + change_custom_button_type(label, group, type) { + this.page.change_inner_button_type(label, group, type); + } + clear_custom_buttons() { this.page.clear_inner_toolbar(); this.page.clear_user_actions(); diff --git a/frappe/public/js/frappe/ui/page.js b/frappe/public/js/frappe/ui/page.js index 320227b258..c299edb7db 100644 --- a/frappe/public/js/frappe/ui/page.js +++ b/frappe/public/js/frappe/ui/page.js @@ -618,6 +618,23 @@ frappe.ui.Page = class Page { } } + change_inner_button_type(label, group, type) { + let btn; + + if (group) { + var $group = this.get_inner_group_button(__(group)); + if ($group.length) { + btn = $group.find(`.dropdown-item[data-label="${encodeURIComponent(label)}"]`); + } + } else { + btn = this.inner_toolbar.find(`button[data-label="${encodeURIComponent(label)}"]`); + } + + if (btn) { + btn.removeClass().addClass(`btn btn-${type} ellipsis`); + } + } + add_inner_message(message) { let $message = $(`${message}`); this.inner_toolbar.find('.inner-page-message').remove(); From f4d260de0d771fda0c66314d832d253f49aa2e77 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 6 Sep 2021 14:16:27 +0530 Subject: [PATCH 035/137] fix: Problems while using translations via Globe Symbol (#14128) Co-authored-by: Vama Mehta (cherry picked from commit 40f2e915918860ade1e514c8b0bb4cf1bb6d0b2b) Co-authored-by: vama --- frappe/public/js/frappe/form/controls/base_control.js | 2 +- frappe/translate.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/form/controls/base_control.js b/frappe/public/js/frappe/form/controls/base_control.js index d6c268a28a..6a14637f33 100644 --- a/frappe/public/js/frappe/form/controls/base_control.js +++ b/frappe/public/js/frappe/form/controls/base_control.js @@ -131,7 +131,7 @@ frappe.ui.form.Control = class BaseControl { if (!this.doc.__islocal) { new frappe.views.TranslationManager({ 'df': this.df, - 'source_text': value, + 'source_text': this.value, 'target_language': this.doc.language, 'doc': this.doc }); diff --git a/frappe/translate.py b/frappe/translate.py index f1dbfdec59..6f3ed81dc2 100644 --- a/frappe/translate.py +++ b/frappe/translate.py @@ -821,6 +821,9 @@ def update_translations_for_source(source=None, translation_dict=None): translation_dict = json.loads(translation_dict) + if is_html(source): + source = strip_html_tags(source) + # for existing records translation_records = frappe.db.get_values('Translation', { 'source_text': source From 5669d9c5591fd266bbd7346339b184128b0802cd Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 28 Aug 2021 01:42:20 +0530 Subject: [PATCH 036/137] fix: pass distinct as argument in set_modules --- frappe/core/doctype/user_type/user_type.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/user_type/user_type.py b/frappe/core/doctype/user_type/user_type.py index 82ffb090f1..abcaf0fea9 100644 --- a/frappe/core/doctype/user_type/user_type.py +++ b/frappe/core/doctype/user_type/user_type.py @@ -36,8 +36,11 @@ class UserType(Document): if not self.user_doctypes: return - modules = frappe.get_all('DocType', fields=['distinct module as module'], - filters={'name': ('in', [d.document_type for d in self.user_doctypes])}) + modules = frappe.get_all('DocType', + fields=['module'], + filters={'name': ('in', [d.document_type for d in self.user_doctypes])}, + distinct=True + ) self.set('user_type_modules', []) for row in modules: From 08b7430ba216b994bde2eba866b962253752aaa4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 2 Sep 2021 18:15:21 +0530 Subject: [PATCH 037/137] fix: change fieldname for postgres create index --- frappe/database/postgres/database.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/database/postgres/database.py b/frappe/database/postgres/database.py index 00e60fb8d2..78df54a48a 100644 --- a/frappe/database/postgres/database.py +++ b/frappe/database/postgres/database.py @@ -263,9 +263,9 @@ class PostgresDatabase(Database): Index name will be `fieldname1_fieldname2_index`""" index_name = index_name or self.get_index_name(fields) table_name = 'tab' + doctype - + fields_str = re.sub(r"\(.*\)", "", '", "'.join(fields)) self.commit() - self.sql("""CREATE INDEX IF NOT EXISTS "{}" ON `{}`("{}")""".format(index_name, table_name, '", "'.join(fields))) + self.sql(f'CREATE INDEX IF NOT EXISTS "{index_name}" ON `{table_name}`("{fields_str}")') def add_unique(self, doctype, fields, constraint_name=None): if isinstance(fields, str): From 6f0a02aaa533bdf7a0848f46547d2aab61399dfc Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 6 Sep 2021 19:37:39 +0530 Subject: [PATCH 038/137] fix: Handle multiple comment types in get_comments --- frappe/desk/form/load.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/frappe/desk/form/load.py b/frappe/desk/form/load.py index c86efbcefd..80c0b2d471 100644 --- a/frappe/desk/form/load.py +++ b/frappe/desk/form/load.py @@ -1,6 +1,7 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: MIT. See LICENSE +from typing import Dict, List, Union import frappe, json import frappe.utils import frappe.share @@ -138,10 +139,11 @@ def get_communications(doctype, name, start=0, limit=20): return _get_communications(doctype, name, start, limit) -def get_comments(doctype, name, comment_type='Comment'): - comment_types = [comment_type] +def get_comments(doctype: str, name: str, comment_type : Union[str, List[str]] = "Comment") -> List[frappe._dict]: + if isinstance(comment_type, list): + comment_types = comment_type - if comment_type == 'share': + elif comment_type == 'share': comment_types = ['Shared', 'Unshared'] elif comment_type == 'assignment': @@ -150,15 +152,21 @@ def get_comments(doctype, name, comment_type='Comment'): elif comment_type == 'attachment': comment_types = ['Attachment', 'Attachment Removed'] - comments = frappe.get_all('Comment', fields = ['name', 'creation', 'content', 'owner', 'comment_type'], filters=dict( - reference_doctype = doctype, - reference_name = name, - comment_type = ['in', comment_types] - )) + else: + comment_types = [comment_type] + + comments = frappe.get_all("Comment", + fields=["name", "creation", "content", "owner", "comment_type"], + filters={ + "reference_doctype": doctype, + "reference_name": name, + "comment_type": ['in', comment_types], + } + ) # convert to markdown (legacy ?) - if comment_type == 'Comment': - for c in comments: + for c in comments: + if c.comment_type == "Comment": c.content = frappe.utils.markdown(c.content) return comments From a233bf1061ac7ad1deb9df9b169dfcd3a6e63f7d Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 6 Sep 2021 19:39:08 +0530 Subject: [PATCH 039/137] fix: Add workflow comments in form timeline * Add Edit, Label along with Info timeline logs * Added title field for timeline icon --- frappe/desk/form/load.py | 3 ++- .../js/frappe/form/footer/form_timeline.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/frappe/desk/form/load.py b/frappe/desk/form/load.py index 80c0b2d471..d276a9707f 100644 --- a/frappe/desk/form/load.py +++ b/frappe/desk/form/load.py @@ -106,9 +106,10 @@ def get_docinfo(doc=None, doctype=None, name=None): "assignment_logs": get_comments(doc.doctype, doc.name, 'assignment'), "permissions": get_doc_permissions(doc), "shared": frappe.share.get_users(doc.doctype, doc.name), - "info_logs": get_comments(doc.doctype, doc.name, 'Info'), + "info_logs": get_comments(doc.doctype, doc.name, comment_type=['Info', 'Edit', 'Label']), "share_logs": get_comments(doc.doctype, doc.name, 'share'), "like_logs": get_comments(doc.doctype, doc.name, 'Like'), + "workflow_logs": get_comments(doc.doctype, doc.name, comment_type="Workflow"), "views": get_view_logs(doc.doctype, doc.name), "energy_point_logs": get_point_logs(doc.doctype, doc.name), "additional_timeline_content": get_additional_timeline_content(doc.doctype, doc.name), diff --git a/frappe/public/js/frappe/form/footer/form_timeline.js b/frappe/public/js/frappe/form/footer/form_timeline.js index 115a62e098..adffce7c9c 100644 --- a/frappe/public/js/frappe/form/footer/form_timeline.js +++ b/frappe/public/js/frappe/form/footer/form_timeline.js @@ -136,6 +136,7 @@ class FormTimeline extends BaseTimeline { this.timeline_items.push(...this.get_energy_point_timeline_contents()); this.timeline_items.push(...this.get_version_timeline_contents()); this.timeline_items.push(...this.get_share_timeline_contents()); + this.timeline_items.push(...this.get_workflow_timeline_contents()); this.timeline_items.push(...this.get_like_timeline_contents()); this.timeline_items.push(...this.get_custom_timeline_contents()); this.timeline_items.push(...this.get_assignment_timeline_contents()); @@ -339,11 +340,26 @@ class FormTimeline extends BaseTimeline { icon_size: 'sm', creation: like_log.creation, content: __('{0} Liked', [this.get_user_link(like_log.owner)]), + title: "Like", }); }); return like_timeline_contents; } + get_workflow_timeline_contents() { + let workflow_timeline_contents = []; + (this.doc_info.workflow_logs || []).forEach(workflow_log => { + workflow_timeline_contents.push({ + icon: 'branch', + icon_size: 'sm', + creation: workflow_log.creation, + content: __(workflow_log.content), + title: "Workflow", + }); + }); + return workflow_timeline_contents; + } + get_custom_timeline_contents() { let custom_timeline_contents = []; (this.doc_info.additional_timeline_content || []).forEach(custom_item => { From f0b9eb5f7c848fa7e81e9ab25c427964674b96e3 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 6 Sep 2021 19:40:45 +0530 Subject: [PATCH 040/137] fix: Update available Frappe icons * Added icons for milestone * Updated Workflow and Branch icons for consistency --- frappe/public/icons/timeless/symbol-defs.svg | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frappe/public/icons/timeless/symbol-defs.svg b/frappe/public/icons/timeless/symbol-defs.svg index b2f1428967..b878f713e9 100644 --- a/frappe/public/icons/timeless/symbol-defs.svg +++ b/frappe/public/icons/timeless/symbol-defs.svg @@ -35,10 +35,13 @@ - + + + + @@ -680,7 +683,7 @@ - + From ab7dee13cfe31fa4882b6a1f4cc313d2c92ed893 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Sep 2021 02:12:19 +0530 Subject: [PATCH 041/137] chore: Added return type for DatabaseQuery.execute --- frappe/model/db_query.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frappe/model/db_query.py b/frappe/model/db_query.py index ae159c1a69..fd74a8cfe4 100644 --- a/frappe/model/db_query.py +++ b/frappe/model/db_query.py @@ -2,6 +2,7 @@ # License: MIT. See LICENSE """build query for doclistview and return results""" +from typing import List import frappe.defaults import frappe.share from frappe import _ @@ -33,7 +34,7 @@ class DatabaseQuery(object): join='left join', distinct=False, start=None, page_length=None, limit=None, ignore_ifnull=False, save_user_settings=False, save_user_settings_fields=False, update=None, add_total_row=None, user_settings=None, reference_doctype=None, - return_query=False, strict=True, pluck=None, ignore_ddl=False): + return_query=False, strict=True, pluck=None, ignore_ddl=False) -> List: if not ignore_permissions and \ not frappe.has_permission(self.doctype, "select", user=user) and \ not frappe.has_permission(self.doctype, "read", user=user): From d55254e7dc204c1d22685c26f3552da3c2e9d382 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 6 Sep 2021 19:45:44 +0530 Subject: [PATCH 042/137] feat(minor): Show title for form timeline icons --- frappe/public/js/frappe/form/footer/base_timeline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/form/footer/base_timeline.js b/frappe/public/js/frappe/form/footer/base_timeline.js index ab4ad95a81..702d964442 100644 --- a/frappe/public/js/frappe/form/footer/base_timeline.js +++ b/frappe/public/js/frappe/form/footer/base_timeline.js @@ -86,7 +86,7 @@ class BaseTimeline { }); if (item.icon) { timeline_item.append(` -
+
${frappe.utils.icon(item.icon, item.icon_size || 'md')}
`); From 8b252d493aecf2a5ee6f0d99cd5b98a1087d9a98 Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Mon, 6 Sep 2021 22:49:48 +0530 Subject: [PATCH 043/137] ci: Conditionally run codecov upload --- .github/workflows/server-mariadb-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/server-mariadb-tests.yml b/.github/workflows/server-mariadb-tests.yml index 57a7fa304d..72b085c495 100644 --- a/.github/workflows/server-mariadb-tests.yml +++ b/.github/workflows/server-mariadb-tests.yml @@ -121,6 +121,7 @@ jobs: ORCHESTRATOR_URL: http://test-orchestrator.frappe.io - name: Upload coverage data + if: ${{ steps.check-build.outputs.build == 'strawberry' }} uses: codecov/codecov-action@v2 with: name: MariaDB From fba196484c4efc184f3997779e57dccdb24c7adc Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Mon, 6 Sep 2021 22:50:42 +0530 Subject: [PATCH 044/137] ci: Conditionally run codecov upload --- .github/workflows/server-postgres-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/server-postgres-tests.yml b/.github/workflows/server-postgres-tests.yml index 57ac9c6c60..ddc41c049c 100644 --- a/.github/workflows/server-postgres-tests.yml +++ b/.github/workflows/server-postgres-tests.yml @@ -124,6 +124,7 @@ jobs: ORCHESTRATOR_URL: http://test-orchestrator.frappe.io - name: Upload coverage data + if: ${{ steps.check-build.outputs.build == 'strawberry' }} uses: codecov/codecov-action@v2 with: name: Postgres From 3594890eb283c7b1b8144d5029bb69551da01f61 Mon Sep 17 00:00:00 2001 From: leela Date: Mon, 6 Sep 2021 19:57:09 +0530 Subject: [PATCH 045/137] fix: customizing print formats Currently system managers can only customize the print formats even though the other roles has a permissions to do so. Fixed it to show customize button based on permissions. (cherry picked from commit f9486fce5fb24402fce31e3d36370120c4524a9b) --- .../doctype/print_format/print_format.js | 30 ++++++++++--------- frappe/printing/page/print/print.js | 2 +- frappe/public/js/frappe/views/pageview.js | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/frappe/printing/doctype/print_format/print_format.js b/frappe/printing/doctype/print_format/print_format.js index 786f8f97ab..adc5e2363c 100644 --- a/frappe/printing/doctype/print_format/print_format.js +++ b/frappe/printing/doctype/print_format/print_format.js @@ -36,21 +36,23 @@ frappe.ui.form.on("Print Format", { else if (frm.doc.custom_format && !frm.doc.raw_printing) { frm.set_df_property("html", "reqd", 1); } - frappe.db.get_value('DocType', frm.doc.doc_type, 'default_print_format', (r) => { - if (r.default_print_format != frm.doc.name) { - frm.add_custom_button(__("Set as Default"), function () { - frappe.call({ - method: "frappe.printing.doctype.print_format.print_format.make_default", - args: { - name: frm.doc.name - }, - callback: function() { - frm.refresh(); - } + if (frappe.perm.has_perm('DocType', 0, 'read', frm.doc.doc_type)) { + frappe.db.get_value('DocType', frm.doc.doc_type, 'default_print_format', (r) => { + if (r.default_print_format != frm.doc.name) { + frm.add_custom_button(__("Set as Default"), function () { + frappe.call({ + method: "frappe.printing.doctype.print_format.print_format.make_default", + args: { + name: frm.doc.name + }, + callback: function() { + frm.refresh(); + } + }); }); - }); - } - }); + } + }); + } } }, custom_format: function (frm) { diff --git a/frappe/printing/page/print/print.js b/frappe/printing/page/print/print.js index ca2a340661..da34dfda96 100644 --- a/frappe/printing/page/print/print.js +++ b/frappe/printing/page/print/print.js @@ -174,7 +174,7 @@ frappe.ui.form.PrintView = class { }); } - if (frappe.user.has_role('System Manager')) { + if (frappe.perm.has_perm('Print Format', 0, 'create')) { this.page.add_menu_item(__('Customize'), () => this.edit_print_format() ); diff --git a/frappe/public/js/frappe/views/pageview.js b/frappe/public/js/frappe/views/pageview.js index 705d13b7f0..c8944e272a 100644 --- a/frappe/public/js/frappe/views/pageview.js +++ b/frappe/public/js/frappe/views/pageview.js @@ -148,4 +148,4 @@ frappe.show_message_page = function(opts) { ); frappe.container.change_to(opts.page_name); -}; \ No newline at end of file +}; From 2178ea7c965250a2251543d7177d043c39b12bfa Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 7 Sep 2021 11:08:02 +0530 Subject: [PATCH 046/137] style: Fix indentation for get_all query --- frappe/core/doctype/user_type/user_type.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frappe/core/doctype/user_type/user_type.py b/frappe/core/doctype/user_type/user_type.py index abcaf0fea9..d385b8665b 100644 --- a/frappe/core/doctype/user_type/user_type.py +++ b/frappe/core/doctype/user_type/user_type.py @@ -36,11 +36,11 @@ class UserType(Document): if not self.user_doctypes: return - modules = frappe.get_all('DocType', - fields=['module'], - filters={'name': ('in', [d.document_type for d in self.user_doctypes])}, - distinct=True - ) + modules = frappe.get_all("DocType", + fields=["module"], + filters={"name": ("in", [d.document_type for d in self.user_doctypes])}, + distinct=True, + ) self.set('user_type_modules', []) for row in modules: From 07c5d0a28c7e554f774cd98bc1284f02f3aea07c Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 7 Sep 2021 11:27:38 +0530 Subject: [PATCH 047/137] fix(db_pg): Strip index size from each field --- frappe/database/postgres/database.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frappe/database/postgres/database.py b/frappe/database/postgres/database.py index 78df54a48a..a40c48c4c8 100644 --- a/frappe/database/postgres/database.py +++ b/frappe/database/postgres/database.py @@ -261,11 +261,11 @@ class PostgresDatabase(Database): def add_index(self, doctype, fields, index_name=None): """Creates an index with given fields if not already created. Index name will be `fieldname1_fieldname2_index`""" + table_name = get_table_name(doctype) index_name = index_name or self.get_index_name(fields) - table_name = 'tab' + doctype - fields_str = re.sub(r"\(.*\)", "", '", "'.join(fields)) - self.commit() - self.sql(f'CREATE INDEX IF NOT EXISTS "{index_name}" ON `{table_name}`("{fields_str}")') + fields_str = '", "'.join(re.sub(r"\(.*\)", "", field) for field in fields) + + self.sql_ddl(f'CREATE INDEX IF NOT EXISTS "{index_name}" ON `{table_name}` ("{fields_str}")') def add_unique(self, doctype, fields, constraint_name=None): if isinstance(fields, str): From b4bb4c039fb156557c9eb0d861282b544abe71ea Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 7 Sep 2021 15:24:32 +0530 Subject: [PATCH 048/137] test: Update click_sidebar_button to accept btn_name - to make tests cases readable --- cypress/integration/sidebar.js | 15 +++++++-------- cypress/support/commands.js | 10 ++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/cypress/integration/sidebar.js b/cypress/integration/sidebar.js index e05f1877bf..cd771430c6 100644 --- a/cypress/integration/sidebar.js +++ b/cypress/integration/sidebar.js @@ -6,12 +6,12 @@ context('Sidebar', () => { }); it('Test for checking "Assigned To" counter value, adding filter and adding & removing an assignment', () => { - cy.click_sidebar_button(0); + cy.click_sidebar_button("Assigned To"); //To check if no filter is available in "Assigned To" dropdown cy.get('.empty-state').should('contain', 'No filters found'); - cy.click_sidebar_button(1); + cy.click_sidebar_button("Created By"); //To check if "Created By" dropdown contains filter cy.get('.group-by-item > .dropdown-item').should('contain', 'Me'); @@ -22,7 +22,7 @@ context('Sidebar', () => { cy.get_field('assign_to_me', 'Check').click(); cy.get('.modal-footer > .standard-actions > .btn-primary').click(); cy.visit('/app/doctype'); - cy.click_sidebar_button(0); + cy.click_sidebar_button("Assigned To"); //To check if filter is added in "Assigned To" dropdown after assignment cy.get('.group-by-field.show > .dropdown-menu > .group-by-item > .dropdown-item').should('contain', '1'); @@ -38,20 +38,19 @@ context('Sidebar', () => { cy.get('.fieldname-select-area > .awesomplete > .form-control').should('have.value', 'Assigned To'); cy.get('.condition').should('have.value', 'like'); cy.get('.filter-field > .form-group > .input-with-feedback').should('have.value', '%Administrator%'); + cy.click_filter_button(); //To remove the applied filter - cy.get('.filter-action-buttons > div > .btn-secondary').contains('Clear Filters').click(); - cy.click_filter_button(); - cy.get('.filter-selector > .btn').should('contain', 'Filter'); + cy.clear_filters(); //To remove the assignment cy.visit('/app/doctype'); cy.click_listview_row_item(0); cy.get('.assignments > .avatar-group > .avatar > .avatar-frame').click(); cy.get('.remove-btn').click({force: true}); - cy.get('.modal.show > .modal-dialog > .modal-content > .modal-header > .modal-actions > .btn-modal-close').click(); + cy.hide_dialog(); cy.visit('/app/doctype'); - cy.click_sidebar_button(0); + cy.click_sidebar_button("Assigned To"); cy.get('.empty-state').should('contain', 'No filters found'); }); }); \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c941652487..c48d6dee89 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -324,16 +324,14 @@ Cypress.Commands.add('clear_filters', () => { cy.window().its('cur_list').then(cur_list => { cur_list && cur_list.filter_area && cur_list.filter_area.clear(); }); - - }); Cypress.Commands.add('click_modal_primary_button', (btn_name) => { cy.get('.modal-footer > .standard-actions > .btn-primary').contains(btn_name).trigger('click', {force: true}); }); -Cypress.Commands.add('click_sidebar_button', (btn_no) => { - cy.get('.list-group-by-fields > .group-by-field > .btn').eq(btn_no).click(); +Cypress.Commands.add('click_sidebar_button', (btn_name) => { + cy.get('.list-group-by-fields .list-link > a').contains(btn_name).click({force: true}); }); Cypress.Commands.add('click_listview_row_item', (row_no) => { @@ -348,6 +346,6 @@ Cypress.Commands.add('click_listview_primary_button', (btn_name) => { cy.get('.primary-action').contains(btn_name).click({force: true}); }); -Cypress.Commands.add('click_timeline_action_btn', (btn_no) => { - cy.get('.timeline-content > .timeline-message-box > .justify-between > .actions > .btn').eq(btn_no).first().click(); +Cypress.Commands.add('click_timeline_action_btn', (btn_name) => { + cy.get('.timeline-content > .timeline-message-box > .justify-between > .actions > .btn').contains(btn_name).click(); }); \ No newline at end of file From 3aed8f9e22e2e2f64a1748f271cbd87c398d31ec Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 7 Sep 2021 16:19:27 +0530 Subject: [PATCH 049/137] test: Miscellaneous fixes to avoid flaky tests --- cypress/integration/list_view.js | 4 ++-- cypress/integration/timeline.js | 10 +++++----- cypress/support/commands.js | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cypress/integration/list_view.js b/cypress/integration/list_view.js index 633d1335ab..298bb20432 100644 --- a/cypress/integration/list_view.js +++ b/cypress/integration/list_view.js @@ -7,11 +7,11 @@ context('List View', () => { }); }); it('enables "Actions" button', () => { - const actions = ['Approve', 'Reject', 'Edit', 'Assign To', 'Apply Assignment Rule', 'Add Tags', 'Print', 'Delete']; + const actions = ['Approve', 'Reject', 'Edit', 'Export', 'Assign To', 'Apply Assignment Rule', 'Add Tags', 'Print', 'Delete']; cy.go_to_list('ToDo'); cy.get('.list-row-container:contains("Pending") .list-row-checkbox').click({ multiple: true, force: true }); cy.get('.actions-btn-group button').contains('Actions').should('be.visible').click(); - cy.get('.dropdown-menu li:visible .dropdown-item').should('have.length', 8).each((el, index) => { + cy.get('.dropdown-menu li:visible .dropdown-item').should('have.length', 9).each((el, index) => { cy.wrap(el).contains(actions[index]); }).then((elements) => { cy.intercept({ diff --git a/cypress/integration/timeline.js b/cypress/integration/timeline.js index 7a8f3a159b..6387485220 100644 --- a/cypress/integration/timeline.js +++ b/cypress/integration/timeline.js @@ -4,11 +4,11 @@ context('Timeline', () => { before(() => { cy.visit('/login'); cy.login(); - cy.visit('/app/todo'); }); it('Adding new ToDo, adding new comment, verifying comment addition & deletion and deleting ToDo', () => { //Adding new ToDo + cy.visit('/app/todo'); cy.click_listview_primary_button('Add ToDo'); cy.findByRole('button', {name: 'Edit in full page'}).click(); cy.get('[data-fieldname="description"] .ql-editor').eq(0).type('Test ToDo', {force: true}); @@ -28,15 +28,15 @@ context('Timeline', () => { cy.get('.timeline-content').should('contain', 'Testing Timeline'); //Editing comment - cy.click_timeline_action_btn(0); + cy.click_timeline_action_btn("Edit"); cy.get('.timeline-content [data-fieldname="comment"] .ql-editor').first().type(' 123'); - cy.click_timeline_action_btn(0); + cy.click_timeline_action_btn("Save"); //To check if the edited comment text is visible in timeline content cy.get('.timeline-content').should('contain', 'Testing Timeline 123'); //Discarding comment - cy.click_timeline_action_btn(0); + cy.click_timeline_action_btn("Edit"); cy.findByRole('button', {name: 'Dismiss'}).click(); //To check if after discarding the timeline content is same as previous @@ -81,7 +81,7 @@ context('Timeline', () => { cy.visit('/app/custom-submittable-doctype'); cy.get('.list-subject > .select-like > .list-row-checkbox').eq(0).click(); cy.findByRole('button', {name: 'Actions'}).click(); - cy.get('.actions-btn-group > .dropdown-menu > li > .grey-link').eq(7).click(); + cy.get('.actions-btn-group > .dropdown-menu > li > .dropdown-item').contains("Delete").click(); cy.click_modal_primary_button('Yes', {force: true, delay: 700}); //Deleting the custom doctype diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c48d6dee89..00415b487d 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -252,7 +252,8 @@ Cypress.Commands.add('new_form', doctype => { }); Cypress.Commands.add('go_to_list', doctype => { - cy.visit(`/app/list/${doctype}/list`); + let dt_in_route = doctype.toLowerCase().replace(/ /g, '-'); + cy.visit(`/app/${dt_in_route}`); }); Cypress.Commands.add('clear_cache', () => { From c8d1c26ac159dcc83a39447ef6773f72934c6603 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Tue, 7 Sep 2021 16:42:52 +0530 Subject: [PATCH 050/137] fix: Dashboard Setting already exist error --- .../js/frappe/views/workspace/workspace.js | 83 +++++++++---------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/frappe/public/js/frappe/views/workspace/workspace.js b/frappe/public/js/frappe/views/workspace/workspace.js index 1e0143c2a8..46aa0d389d 100644 --- a/frappe/public/js/frappe/views/workspace/workspace.js +++ b/frappe/public/js/frappe/views/workspace/workspace.js @@ -35,42 +35,6 @@ frappe.views.Workspace = class Workspace { 'My Workspaces', 'Public' ]; - this.tools = { - header: { - class: this.blocks['header'], - inlineToolbar: true - }, - paragraph: { - class: this.blocks['paragraph'], - inlineToolbar: true - }, - chart: { - class: this.blocks['chart'], - config: { - page_data: this.page_data || [] - } - }, - card: { - class: this.blocks['card'], - config: { - page_data: this.page_data || [] - } - }, - shortcut: { - class: this.blocks['shortcut'], - config: { - page_data: this.page_data || [] - } - }, - onboarding: { - class: this.blocks['onboarding'], - config: { - page_data: this.page_data || [] - } - }, - spacer: this.blocks['spacer'], - spacingTune: frappe.wspace_block.tunes['spacing_tune'], - }; this.prepare_container(); this.setup_pages(); @@ -86,7 +50,7 @@ frappe.views.Workspace = class Workspace { this.body = this.wrapper.find(".layout-main-section"); } - setup_pages() { + setup_pages(reload) { this.get_pages().then(pages => { this.all_pages = pages.pages; this.has_access = pages.has_access; @@ -115,7 +79,7 @@ frappe.views.Workspace = class Workspace { this.new_page = null; } this.make_sidebar(); - frappe.router.route(); + reload && this.show(); } }); } @@ -236,10 +200,7 @@ frappe.views.Workspace = class Workspace { return; } - let page = { - name: this.get_page_to_show().name, - public: this.get_page_to_show().public - }; + let page = this.get_page_to_show(); this.page.set_title(`${__(page.name)}`); this.show_page(page); @@ -670,6 +631,42 @@ frappe.views.Workspace = class Workspace { } initialize_editorjs(blocks) { + this.tools = { + header: { + class: this.blocks['header'], + inlineToolbar: true + }, + paragraph: { + class: this.blocks['paragraph'], + inlineToolbar: true + }, + chart: { + class: this.blocks['chart'], + config: { + page_data: this.page_data || [] + } + }, + card: { + class: this.blocks['card'], + config: { + page_data: this.page_data || [] + } + }, + shortcut: { + class: this.blocks['shortcut'], + config: { + page_data: this.page_data || [] + } + }, + onboarding: { + class: this.blocks['onboarding'], + config: { + page_data: this.page_data || [] + } + }, + spacer: this.blocks['spacer'], + spacingTune: frappe.wspace_block.tunes['spacing_tune'], + }; this.editor = new EditorJS({ data: { blocks: blocks || [] @@ -751,7 +748,7 @@ frappe.views.Workspace = class Workspace { reload() { this.$page.prepend(frappe.render_template('workspace_loading_skeleton')); this.$page.find('.codex-editor').addClass('hidden'); - this.setup_pages(); + this.setup_pages(true); this.undo.readOnly = true; } }; From 74d6ed32d69991ce7c1f100ea974771b2fdbf2cd Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 7 Sep 2021 17:40:55 +0530 Subject: [PATCH 051/137] test: add frappe.db.add_index --- frappe/database/mariadb/database.py | 4 +-- frappe/database/postgres/database.py | 2 +- frappe/tests/test_db.py | 40 ++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/frappe/database/mariadb/database.py b/frappe/database/mariadb/database.py index d4a119804b..71acefe17c 100644 --- a/frappe/database/mariadb/database.py +++ b/frappe/database/mariadb/database.py @@ -256,11 +256,11 @@ class MariaDBDatabase(Database): index_name=index_name )) - def add_index(self, doctype, fields, index_name=None): + def add_index(self, doctype: str, fields: List, index_name: str = None): """Creates an index with given fields if not already created. Index name will be `fieldname1_fieldname2_index`""" index_name = index_name or self.get_index_name(fields) - table_name = 'tab' + doctype + table_name = get_table_name(doctype) if not self.has_index(table_name, index_name): self.commit() self.sql("""ALTER TABLE `%s` diff --git a/frappe/database/postgres/database.py b/frappe/database/postgres/database.py index a40c48c4c8..264d3bbf14 100644 --- a/frappe/database/postgres/database.py +++ b/frappe/database/postgres/database.py @@ -258,7 +258,7 @@ class PostgresDatabase(Database): return self.sql("""SELECT 1 FROM pg_indexes WHERE tablename='{table_name}' and indexname='{index_name}' limit 1""".format(table_name=table_name, index_name=index_name)) - def add_index(self, doctype, fields, index_name=None): + def add_index(self, doctype: str, fields: List, index_name: str = None): """Creates an index with given fields if not already created. Index name will be `fieldname1_fieldname2_index`""" table_name = get_table_name(doctype) diff --git a/frappe/tests/test_db.py b/frappe/tests/test_db.py index 044ce455d9..741c355ad8 100644 --- a/frappe/tests/test_db.py +++ b/frappe/tests/test_db.py @@ -75,7 +75,7 @@ class TestDB(unittest.TestCase): frappe.db.set_value("Print Settings", "Print Settings", fieldname, inp["value"]) self.assertEqual(frappe.db.get_single_value("Print Settings", fieldname), inp["value"]) - #teardown + #teardown clear_custom_fields("Print Settings") def test_log_touched_tables(self): @@ -192,6 +192,7 @@ class TestDB(unittest.TestCase): frappe.delete_doc(test_doctype, doc) clear_custom_fields(test_doctype) + @run_only_if(db_type_is.MARIADB) class TestDDLCommandsMaria(unittest.TestCase): test_table_name = "TestNotes" @@ -200,7 +201,7 @@ class TestDDLCommandsMaria(unittest.TestCase): frappe.db.commit() frappe.db.sql( f""" - CREATE TABLE `tab{self.test_table_name}` (`id` INT NULL,PRIMARY KEY (`id`)); + CREATE TABLE `tab{self.test_table_name}` (`id` INT NULL, content TEXT, PRIMARY KEY (`id`)); """ ) @@ -225,7 +226,10 @@ class TestDDLCommandsMaria(unittest.TestCase): def test_describe(self) -> None: self.assertEqual( - (("id", "int(11)", "NO", "PRI", None, ""),), + ( + ("id", "int(11)", "NO", "PRI", None, ""), + ("content", "text", "YES", "", None, ""), + ), frappe.db.describe(self.test_table_name), ) @@ -235,6 +239,17 @@ class TestDDLCommandsMaria(unittest.TestCase): self.assertGreater(len(test_table_description), 0) self.assertIn("varchar(255)", test_table_description[0]) + def test_add_index(self) -> None: + index_name = "test_index" + frappe.db.add_index(self.test_table_name, ["id", "content(50)"], index_name) + indexs_in_table = frappe.db.sql( + f""" + SHOW INDEX FROM tab{self.test_table_name} + WHERE Key_name = '{index_name}'; + """ + ) + self.assertEquals(len(indexs_in_table), 2) + @run_only_if(db_type_is.POSTGRES) class TestDDLCommandsPost(unittest.TestCase): @@ -243,7 +258,7 @@ class TestDDLCommandsPost(unittest.TestCase): def setUp(self) -> None: frappe.db.sql( f""" - CREATE TABLE "tab{self.test_table_name}" ("id" INT NULL,PRIMARY KEY ("id")) + CREATE TABLE "tab{self.test_table_name}" ("id" INT NULL, content text, PRIMARY KEY ("id")) """ ) @@ -268,7 +283,9 @@ class TestDDLCommandsPost(unittest.TestCase): self.test_table_name = new_table_name def test_describe(self) -> None: - self.assertEqual([("id",)], frappe.db.describe(self.test_table_name)) + self.assertEqual( + [("id",), ("content",)], frappe.db.describe(self.test_table_name) + ) def test_change_type(self) -> None: frappe.db.change_column_type(self.test_table_name, "id", "varchar(255)") @@ -286,3 +303,16 @@ class TestDDLCommandsPost(unittest.TestCase): ) self.assertGreater(len(check_change), 0) self.assertIn("character varying", check_change[0]) + + def test_add_index(self) -> None: + index_name = "test_index" + frappe.db.add_index(self.test_table_name, ["id", "content(50)"], index_name) + indexs_in_table = frappe.db.sql( + f""" + SELECT indexname + FROM pg_indexes + WHERE tablename = 'tab{self.test_table_name}' + AND indexname = '{index_name}' ; + """, + ) + self.assertEquals(len(indexs_in_table), 1) From a69020f2f3dd15d5dc10811567c10706556916aa Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Tue, 7 Sep 2021 19:01:41 +0530 Subject: [PATCH 052/137] fix: Page load optimization --- frappe/desk/doctype/workspace/workspace.py | 6 ++--- .../js/frappe/views/workspace/workspace.js | 27 ++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/frappe/desk/doctype/workspace/workspace.py b/frappe/desk/doctype/workspace/workspace.py index 25dd9b26d2..a0a22a43fc 100644 --- a/frappe/desk/doctype/workspace/workspace.py +++ b/frappe/desk/doctype/workspace/workspace.py @@ -208,17 +208,17 @@ def save_page(title, icon, parent, public, sb_public_items, sb_private_items, de if loads(deleted_pages): return delete_pages(loads(deleted_pages)) - return {"name": title, "public": public} + return {"name": title, "public": public, "label": doc.label} def delete_pages(deleted_pages): for page in deleted_pages: if page.get("public") and "Workspace Manager" not in frappe.get_roles(): - return {"name": page.get("title"), "public": 1} + return {"name": page.get("title"), "public": 1, "label": page.get("label")} if frappe.db.exists("Workspace", page.get("name")): frappe.get_doc("Workspace", page.get("name")).delete(ignore_permissions=True) - return {"name": "Home", "public": 1} + return {"name": "Home", "public": 1, "label": "Home"} def sort_pages(sb_public_items, sb_private_items): wspace_public_pages = get_page_list(['name', 'title'], {'public': 1}) diff --git a/frappe/public/js/frappe/views/workspace/workspace.js b/frappe/public/js/frappe/views/workspace/workspace.js index 46aa0d389d..36b2988935 100644 --- a/frappe/public/js/frappe/views/workspace/workspace.js +++ b/frappe/public/js/frappe/views/workspace/workspace.js @@ -23,6 +23,7 @@ frappe.views.Workspace = class Workspace { this.blocks = frappe.wspace_block.blocks; this.is_read_only = true; this.new_page = null; + this.pages = {}; this.sorted_public_items = []; this.sorted_private_items = []; this.deleted_sidebar_items = []; @@ -211,6 +212,11 @@ frappe.views.Workspace = class Workspace { page: page }).then(data => { this.page_data = data; + + // caching page data + this.pages[page.name] && delete this.pages[page.name]; + this.pages[page.name] = data; + if (!this.page_data || Object.keys(this.page_data).length === 0) return; return frappe.dashboard_utils.get_dashboard_settings().then(settings => { @@ -221,6 +227,7 @@ frappe.views.Workspace = class Workspace { chart.chart_settings = chart_config[chart.chart_name] || {}; }); } + this.pages[page.name] = this.page_data; } }); }); @@ -242,7 +249,7 @@ frappe.views.Workspace = class Workspace { return { name: page, public: is_public }; } - show_page(page) { + async show_page(page) { let section = this.current_page.public ? 'public' : 'private'; if (this.sidebar_items && this.sidebar_items[section] && this.sidebar_items[section][this.current_page.name]) { this.sidebar_items[section][this.current_page.name][0].firstElementChild.classList.remove("selected"); @@ -277,12 +284,17 @@ frappe.views.Workspace = class Workspace { this.add_custom_cards_in_content(); $('.item-anchor').addClass('disable-click'); - this.get_data(this_page).then(() => { - this.prepare_editorjs(); - $('.item-anchor').removeClass('disable-click'); - this.$page.find('.codex-editor').removeClass('hidden'); - this.$page.find('.workspace-skeleton').remove(); - }); + + if (this.pages && this.pages[this_page.name]) { + this.page_data = this.pages[this_page.name]; + } else { + await this.get_data(this_page); + } + + this.prepare_editorjs(); + $('.item-anchor').removeClass('disable-click'); + this.$page.find('.codex-editor').removeClass('hidden'); + this.$page.find('.workspace-skeleton').remove(); } } @@ -727,6 +739,7 @@ frappe.views.Workspace = class Workspace { frappe.dom.unfreeze(); if (res.message) { me.new_page = res.message; + me.pages[res.message.label] && delete me.pages[res.message.label]; me.title = ''; me.icon = ''; me.parent = ''; From a56b117ca409ccceb78e082a0ddbb60ee407f6f2 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 7 Sep 2021 19:23:32 +0530 Subject: [PATCH 053/137] test: Wait for filter save on clear filter --- cypress/support/commands.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 00415b487d..f3260bd6be 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -317,7 +317,11 @@ Cypress.Commands.add('add_filter', () => { }); Cypress.Commands.add('clear_filters', () => { - cy.get('.filter-section .filter-button').click(); + cy.intercept({ + method: 'POST', + url: 'api/method/frappe.model.utils.user_settings.save' + }).as('filter-saved'); + cy.get('.filter-section .filter-button').click({force: true}); cy.wait(300); cy.get('.filter-popover').should('exist'); cy.get('.filter-popover').find('.clear-filters').click(); @@ -325,6 +329,7 @@ Cypress.Commands.add('clear_filters', () => { cy.window().its('cur_list').then(cur_list => { cur_list && cur_list.filter_area && cur_list.filter_area.clear(); }); + cy.wait('@filter-saved'); }); Cypress.Commands.add('click_modal_primary_button', (btn_name) => { From 8e9a46fff9f230f00c6dfb29bcfda2ceeec2c38a Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 7 Sep 2021 19:57:57 +0530 Subject: [PATCH 054/137] test: Miscellaneous fixes to avoid flaky tests --- cypress/integration/api.js | 11 ++++++++--- .../datetime_field_form_validation.js | 17 +++++++---------- frappe/tests/ui_test_helpers.py | 11 +++++------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cypress/integration/api.js b/cypress/integration/api.js index 7a5b1611b0..e8c39e6e25 100644 --- a/cypress/integration/api.js +++ b/cypress/integration/api.js @@ -31,8 +31,13 @@ context('API Resources', () => { }); it('Removes the Comments', () => { - cy.get_list('Comment').then(body => body.data.forEach(comment => { - cy.remove_doc('Comment', comment.name); - })); + cy.get_list('Comment').then(body => { + let comment_names = []; + body.data.map(comment => comment_names.push(comment.name)); + comment_names = [...new Set(comment_names)]; // remove duplicates + comment_names.forEach((comment_name) => { + cy.remove_doc('Comment', comment_name); + }); + }); }); }); diff --git a/cypress/integration/datetime_field_form_validation.js b/cypress/integration/datetime_field_form_validation.js index 66fdde6863..cb862152b4 100644 --- a/cypress/integration/datetime_field_form_validation.js +++ b/cypress/integration/datetime_field_form_validation.js @@ -2,18 +2,15 @@ context('Datetime Field Validation', () => { before(() => { cy.login(); cy.visit('/app/communication'); - cy.window().its('frappe').then(frappe => { - frappe.call("frappe.tests.ui_test_helpers.create_communication_records"); - }); }); - // validating datetime field value when value is set from backend and get validated on form load. it('datetime field form validation', () => { - cy.visit('/app/communication'); - cy.get('a[title="Test Form Communication 1"]').invoke('attr', 'data-name') - .then((name) => { - cy.visit(`/app/communication/${name}`); - cy.get('.indicator-pill').should('contain', 'Open').should('have.class', 'red'); - }); + // validating datetime field value when value is set from backend and get validated on form load. + cy.window().its('frappe').then(frappe => { + return frappe.xcall("frappe.tests.ui_test_helpers.create_communication_record"); + }).then(doc => { + cy.visit(`/app/communication/${doc.name}`); + cy.get('.indicator-pill').should('contain', 'Open').should('have.class', 'red'); + }); }); }); \ No newline at end of file diff --git a/frappe/tests/ui_test_helpers.py b/frappe/tests/ui_test_helpers.py index d8ad728136..9f6ad70a35 100644 --- a/frappe/tests/ui_test_helpers.py +++ b/frappe/tests/ui_test_helpers.py @@ -62,16 +62,15 @@ def create_todo_records(): }).insert() @frappe.whitelist() -def create_communication_records(): - if frappe.db.get_all('Communication', {'subject': 'Test Form Communication 1'}): - return - - frappe.get_doc({ +def create_communication_record(): + doc = frappe.get_doc({ "doctype": "Communication", "recipients": "test@gmail.com", "subject": "Test Form Communication 1", "communication_date": frappe.utils.now_datetime(), - }).insert() + }) + doc.insert() + return doc @frappe.whitelist() def setup_workflow(): From fd18da985d0786fd65c8720e6ea12e45a8f31d7b Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Tue, 7 Sep 2021 20:22:45 +0530 Subject: [PATCH 055/137] fix: Add page to sidebar minor fix --- frappe/public/js/frappe/views/workspace/workspace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/views/workspace/workspace.js b/frappe/public/js/frappe/views/workspace/workspace.js index 36b2988935..8989814349 100644 --- a/frappe/public/js/frappe/views/workspace/workspace.js +++ b/frappe/public/js/frappe/views/workspace/workspace.js @@ -625,7 +625,7 @@ frappe.views.Workspace = class Workspace { let $sidebar_section = is_public ? $sidebar[1] : $sidebar[0]; if (!parent) { - !is_public && $sidebar.last().removeClass('hidden'); + !is_public && $sidebar.first().removeClass('hidden'); $sidebar_item.appendTo($sidebar_section); } else { let $item_container = $($sidebar_section).find(`[item-name="${parent}"]`); From 5f9340fda29d74a943be3993cfe788a4c345dc35 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 7 Sep 2021 20:33:08 +0530 Subject: [PATCH 056/137] test: Set delay for fill_field --- cypress/support/commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index f3260bd6be..47c37a56a0 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -187,7 +187,7 @@ Cypress.Commands.add('fill_field', (fieldname, value, fieldtype = 'Data') => { if (fieldtype === 'Select') { cy.get('@input').select(value); } else { - cy.get('@input').type(value, {waitForAnimations: false, force: true}); + cy.get('@input').type(value, {waitForAnimations: false, force: true, delay: 100}); } return cy.get('@input'); }); From 3fb93b9b3dee5ab93d1edf2250a358283f3be3ed Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Tue, 7 Sep 2021 20:34:31 +0530 Subject: [PATCH 057/137] ci: Update threshold for codecov --- codecov.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index eb81252b61..41b22001a5 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,9 +1,13 @@ codecov: require_ci_to_pass: yes + +coverage: status: project: default: + target: auto threshold: 0.5% + comment: - layout: "diff, flags, files" + layout: "diff" require_changes: true From 4441eb7d903fc326f4e109be7497672ecace8de3 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Wed, 8 Sep 2021 11:45:15 +0530 Subject: [PATCH 058/137] test: Fix test_request_language_resolution_with_cookie --- frappe/tests/test_translate.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frappe/tests/test_translate.py b/frappe/tests/test_translate.py index 9620978c4f..949e4f9d77 100644 --- a/frappe/tests/test_translate.py +++ b/frappe/tests/test_translate.py @@ -63,11 +63,12 @@ class TestTranslate(unittest.TestCase): Case 2: frappe.form_dict._lang is not set, but preferred_language cookie is """ - with patch.object(frappe.translate, "get_preferred_language_cookie", return_value=second_lang): - set_request(method="POST", path="/", headers=[("Accept-Language", third_lang)]) + with patch.object(frappe.translate, "get_preferred_language_cookie", return_value='fr'): + set_request(method="POST", path="/", headers=[("Accept-Language", 'hr')]) return_val = get_language() - - self.assertNotIn(return_val, [second_lang, get_parent_language(second_lang)]) + # system default language + self.assertEqual(return_val, 'en') + self.assertNotIn(return_val, [second_lang, get_parent_language(second_lang)]) def test_guest_request_language_resolution_with_cookie(self): """Test for frappe.translate.get_language From 842f947301d9d691c77ff4203b783b124188e764 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Wed, 8 Sep 2021 11:49:22 +0530 Subject: [PATCH 059/137] test: Comment out a flaky test case - It is flaky possibly because of different timezone in CI --- .../datetime_field_form_validation.js | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/cypress/integration/datetime_field_form_validation.js b/cypress/integration/datetime_field_form_validation.js index cb862152b4..ef47a0fbf7 100644 --- a/cypress/integration/datetime_field_form_validation.js +++ b/cypress/integration/datetime_field_form_validation.js @@ -1,16 +1,19 @@ -context('Datetime Field Validation', () => { - before(() => { - cy.login(); - cy.visit('/app/communication'); - }); +// TODO: Enable this again +// currently this is flaky possibly because of different timezone in CI - it('datetime field form validation', () => { - // validating datetime field value when value is set from backend and get validated on form load. - cy.window().its('frappe').then(frappe => { - return frappe.xcall("frappe.tests.ui_test_helpers.create_communication_record"); - }).then(doc => { - cy.visit(`/app/communication/${doc.name}`); - cy.get('.indicator-pill').should('contain', 'Open').should('have.class', 'red'); - }); - }); -}); \ No newline at end of file +// context('Datetime Field Validation', () => { +// before(() => { +// cy.login(); +// cy.visit('/app/communication'); +// }); + +// it('datetime field form validation', () => { +// // validating datetime field value when value is set from backend and get validated on form load. +// cy.window().its('frappe').then(frappe => { +// return frappe.xcall("frappe.tests.ui_test_helpers.create_communication_record"); +// }).then(doc => { +// cy.visit(`/app/communication/${doc.name}`); +// cy.get('.indicator-pill').should('contain', 'Open').should('have.class', 'red'); +// }); +// }); +// }); \ No newline at end of file From 646ceb4c9e022d6ee28bd19e1d43d96d3a88e947 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Wed, 8 Sep 2021 12:31:05 +0530 Subject: [PATCH 060/137] fix: not checked cell should be empty and make check centered --- frappe/templates/print_formats/standard_macros.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frappe/templates/print_formats/standard_macros.html b/frappe/templates/print_formats/standard_macros.html index ec60af1ce0..55c76a00c2 100644 --- a/frappe/templates/print_formats/standard_macros.html +++ b/frappe/templates/print_formats/standard_macros.html @@ -140,6 +140,8 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" style="width: 12px; height: 12px; margin-top: 5px;"> + {% elif df.fieldtype=="Check" and not doc[df.fieldname] %} + {% elif df.fieldtype in ("Image", "Attach Image") and frappe.utils.is_image(doc[doc.meta.get_field(df.fieldname).options]) %} = 3 %}{{ "" }} {%- elif df.align -%}{{ "text-" + df.align }} - {%- elif df.fieldtype in ("Int", "Float", "Currency", "Check", "Percent") -%}{{ "text-right" }} + {%- elif df.fieldtype in ("Int", "Float", "Currency", "Percent") -%}{{ "text-right" }} + {%- elif df.fieldtype in ("Check") -%}{{ "text-center" }} {%- else -%}{{ "" }} {%- endif -%} {% endmacro %} From 61d067710ffd1819f0ed26548ea64d915a8cbc45 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 8 Sep 2021 13:25:19 +0530 Subject: [PATCH 061/137] feat: @frappe.write_only When would you want to use it? Typically if you want to be sure that "this" particular thing will be make WRITES to the database. If this were to be called via a function wrapped with @frappe.read_only. This will momentarily switch the connection from replica to primary --- frappe/__init__.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/frappe/__init__.py b/frappe/__init__.py index 7c6005a350..c9b2c2edb9 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -629,6 +629,31 @@ def read_only(): return wrapper_fn return innfn +def write_only(): + # if replica connection exists, we have to replace it momentarily with the primary connection + def innfn(fn): + def wrapper_fn(*args, **kwargs): + # switch to primary connection + primary_db = getattr(local, "primary_db", None) + replica_db = getattr(local, "replica_db", None) + in_read_only = getattr(local, "db", None) != primary_db + + if in_read_only and primary_db: + local.db = local.primary_db + + try: + retval = fn(*args, **get_newargs(fn, kwargs)) + except: + raise + finally: + # switch back to replica connection + if in_read_only and replica_db: + local.db = replica_db + + return retval + return wrapper_fn + return innfn + def only_for(roles, message=False): """Raise `frappe.PermissionError` if the user does not have any of the given **Roles**. From 70ac05025b274d70cd6f63e4ef165ac985c0b234 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 8 Sep 2021 13:44:00 +0530 Subject: [PATCH 062/137] fix: Make `make_access_log` write only Write to primary db if connection is currently set to replica --- frappe/__init__.py | 2 +- frappe/core/doctype/access_log/access_log.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index c9b2c2edb9..0d009b426f 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -633,11 +633,11 @@ def write_only(): # if replica connection exists, we have to replace it momentarily with the primary connection def innfn(fn): def wrapper_fn(*args, **kwargs): - # switch to primary connection primary_db = getattr(local, "primary_db", None) replica_db = getattr(local, "replica_db", None) in_read_only = getattr(local, "db", None) != primary_db + # switch to primary connection if in_read_only and primary_db: local.db = local.primary_db diff --git a/frappe/core/doctype/access_log/access_log.py b/frappe/core/doctype/access_log/access_log.py index 0f5776ce2f..d93da02d25 100644 --- a/frappe/core/doctype/access_log/access_log.py +++ b/frappe/core/doctype/access_log/access_log.py @@ -9,6 +9,7 @@ class AccessLog(Document): @frappe.whitelist() +@frappe.write_only() def make_access_log(doctype=None, document=None, method=None, file_type=None, report_name=None, filters=None, page=None, columns=None): From 309eaabcf96f35906e0a16a4ba35ccb3049e055b Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 8 Sep 2021 14:01:38 +0530 Subject: [PATCH 063/137] fix: Get rid of pointless except: raise --- frappe/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 0d009b426f..38904c68d0 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -618,8 +618,6 @@ def read_only(): try: retval = fn(*args, **get_newargs(fn, kwargs)) - except: - raise finally: if local and hasattr(local, 'primary_db'): local.db.close() @@ -643,8 +641,6 @@ def write_only(): try: retval = fn(*args, **get_newargs(fn, kwargs)) - except: - raise finally: # switch back to replica connection if in_read_only and replica_db: From 2b00bdb37f30c1208d5b536eae019f98a4ded7b6 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 8 Sep 2021 14:03:33 +0530 Subject: [PATCH 064/137] fix(Web Form): Add fields to row that haven't been added yet --- frappe/website/doctype/web_form/web_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/website/doctype/web_form/web_form.js b/frappe/website/doctype/web_form/web_form.js index 4d38d11891..d69d21c64d 100644 --- a/frappe/website/doctype/web_form/web_form.js +++ b/frappe/website/doctype/web_form/web_form.js @@ -47,7 +47,7 @@ frappe.ui.form.on("Web Form", { frm.add_custom_button(__('Get Fields'), () => { let webform_fieldtypes = frappe.meta.get_field('Web Form Field', 'fieldtype').options.split('\n'); - let fieldnames = (frm.doc.fields || []).map(d => d.fieldname); + let fieldnames = (frm.doc.web_form_fields || []).map(d => d.fieldname); frappe.model.with_doctype(frm.doc.doc_type, () => { let meta = frappe.get_meta(frm.doc.doc_type); for (let field of meta.fields) { From 9eff8bee21de05ac23e92457353f005ccb2207d1 Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Date: Wed, 8 Sep 2021 15:02:56 +0530 Subject: [PATCH 065/137] test: tests for float control --- cypress/integration/control_float.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 cypress/integration/control_float.js diff --git a/cypress/integration/control_float.js b/cypress/integration/control_float.js new file mode 100644 index 0000000000..25b1d65523 --- /dev/null +++ b/cypress/integration/control_float.js @@ -0,0 +1,28 @@ +context('Control Float', () => { + before(() => { + cy.login(); + cy.visit('/app/website'); + cy.window().its('frappe').then(frappe => { + frappe.boot.sysdefaults.number_format = '#.###,##' + }); + }); + + function get_dialog_with_float() { + return cy.dialog({ + title: 'Float Check', + fields: [{ + 'fieldname': 'float_number', + 'fieldtype': 'Float', + 'Label': 'Float', + }] + }); + } + + it('check value changes', () => { + get_dialog_with_float().as('dialog'); + cy.get_field('float_number', 'Float').clear() + cy.fill_field('float_number', '36487,334', 'Float').blur(); + cy.get_field('float_number', 'Float').should('have.value', '36.487,334'); + + }); +}); From 8aea1254f9023d013fab81bc1f29ce2347a95a7c Mon Sep 17 00:00:00 2001 From: Mohammad Hasnain Date: Wed, 8 Sep 2021 15:15:47 +0530 Subject: [PATCH 066/137] chore: add semi colon --- cypress/integration/control_float.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/control_float.js b/cypress/integration/control_float.js index 25b1d65523..45edff0346 100644 --- a/cypress/integration/control_float.js +++ b/cypress/integration/control_float.js @@ -3,7 +3,7 @@ context('Control Float', () => { cy.login(); cy.visit('/app/website'); cy.window().its('frappe').then(frappe => { - frappe.boot.sysdefaults.number_format = '#.###,##' + frappe.boot.sysdefaults.number_format = '#.###,##'; }); }); From fd264159931aa5b6d8966bb93eb1940b20e09608 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Wed, 8 Sep 2021 16:57:10 +0530 Subject: [PATCH 067/137] fix: Show login page instantly --- frappe/public/scss/login.bundle.scss | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frappe/public/scss/login.bundle.scss b/frappe/public/scss/login.bundle.scss index 25fc6662e3..17f33b0a67 100644 --- a/frappe/public/scss/login.bundle.scss +++ b/frappe/public/scss/login.bundle.scss @@ -4,12 +4,17 @@ body { background-color: var(--bg-light-gray); } -.for-login, .for-forgot, .for-signup, .for-email-login { display: none; - margin: 70px 0; +} + +.for-login, +.for-forgot, +.for-signup, +.for-email-login { + padding: max(15vh, 70px) 0; @include media-breakpoint-up(sm) { .page-card { From 7f7ab7647958dad62c2580b2712d3607fc72e292 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Wed, 8 Sep 2021 16:59:50 +0530 Subject: [PATCH 068/137] fix: Update login page & footer style --- frappe/public/scss/common/global.scss | 4 ++++ frappe/public/scss/desk/global.scss | 1 - frappe/public/scss/desk/mobile.scss | 5 ----- frappe/public/scss/website/footer.scss | 11 +++++++++++ frappe/public/scss/website/web_form.scss | 1 + .../includes/footer/footer_logo_extension.html | 4 ++-- frappe/www/login.html | 6 +++--- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/frappe/public/scss/common/global.scss b/frappe/public/scss/common/global.scss index 024e0cd2a4..44b6e9ce34 100644 --- a/frappe/public/scss/common/global.scss +++ b/frappe/public/scss/common/global.scss @@ -1,3 +1,7 @@ +html, body { + height: 100%; +} + /* checkbox */ .checkbox { label { diff --git a/frappe/public/scss/desk/global.scss b/frappe/public/scss/desk/global.scss index 333ee30e4d..8c646395e9 100644 --- a/frappe/public/scss/desk/global.scss +++ b/frappe/public/scss/desk/global.scss @@ -1,5 +1,4 @@ html { - height: 100%; background-color: var(--bg-color); } diff --git a/frappe/public/scss/desk/mobile.scss b/frappe/public/scss/desk/mobile.scss index 839fca9bd2..14fa25e50f 100644 --- a/frappe/public/scss/desk/mobile.scss +++ b/frappe/public/scss/desk/mobile.scss @@ -1,9 +1,4 @@ -html { - min-height: 100%; -} - body { - height: 100%; // The html and body elements cannot have any padding or margin. margin: 0px; padding: 0px !important; diff --git a/frappe/public/scss/website/footer.scss b/frappe/public/scss/website/footer.scss index 5208afaa11..dc73fd180e 100644 --- a/frappe/public/scss/website/footer.scss +++ b/frappe/public/scss/website/footer.scss @@ -85,4 +85,15 @@ .form-control { border: none; font-size: var(--text-md); +} + +.footer-logo-extension { + .input-group { + justify-content: flex-end; + #footer-subscribe-email, #footer-subscribe-button { + max-width: 300px; + border: 1px solid var(--dark-border-color); + box-shadow: none; + } + } } \ No newline at end of file diff --git a/frappe/public/scss/website/web_form.scss b/frappe/public/scss/website/web_form.scss index 32b1c46f84..6a6547d79e 100644 --- a/frappe/public/scss/website/web_form.scss +++ b/frappe/public/scss/website/web_form.scss @@ -3,6 +3,7 @@ .web-form-wrapper { .form-control { color: var(--text-color); + background-color: var(--control-bg); } .form-section { diff --git a/frappe/templates/includes/footer/footer_logo_extension.html b/frappe/templates/includes/footer/footer_logo_extension.html index 17f3218c45..87bb4d14af 100644 --- a/frappe/templates/includes/footer/footer_logo_extension.html +++ b/frappe/templates/includes/footer/footer_logo_extension.html @@ -1,13 +1,13 @@