From 3951202d074204a865e95018ebe0e55391a6962a Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:43:11 +0530 Subject: [PATCH 01/14] chore(site): remove database access related fields and add field for connection limit - default connection limit for a site will be 16 --- press/press/doctype/site/site.json | 44 ++++++------------------------ press/press/doctype/site/site.py | 7 ++--- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/press/press/doctype/site/site.json b/press/press/doctype/site/site.json index a39feb3908..4026cf299c 100644 --- a/press/press/doctype/site/site.json +++ b/press/press/doctype/site/site.json @@ -72,11 +72,7 @@ "setup_wizard_status_check_retries", "setup_wizard_status_check_next_retry_on", "database_section", - "is_database_access_enabled", - "database_access_mode", - "column_break_lfuz", - "database_access_user", - "database_access_password", + "database_access_connection_limit", "saas_section", "is_standby", "standby_for", @@ -452,13 +448,6 @@ "fieldtype": "Section Break", "label": "Database Access" }, - { - "default": "0", - "fieldname": "is_database_access_enabled", - "fieldtype": "Check", - "label": "Is Database Access Enabled", - "read_only": 1 - }, { "fieldname": "standby_for", "fieldtype": "Link", @@ -528,29 +517,6 @@ "fieldtype": "Check", "label": "Hide Config" }, - { - "fieldname": "database_access_password", - "fieldtype": "Password", - "label": "Database Access Password", - "read_only": 1 - }, - { - "fieldname": "database_access_mode", - "fieldtype": "Select", - "label": "Database Access Mode", - "options": "\nread_only\nread_write", - "read_only": 1 - }, - { - "fieldname": "column_break_lfuz", - "fieldtype": "Column Break" - }, - { - "fieldname": "database_access_user", - "fieldtype": "Data", - "label": "Database Access User", - "read_only": 1 - }, { "collapsible": 1, "fieldname": "backups_section", @@ -628,6 +594,12 @@ "fieldname": "setup_wizard_status_check_next_retry_on", "fieldtype": "Datetime", "label": "Next Retry On" + }, + { + "default": "16", + "fieldname": "database_access_connection_limit", + "fieldtype": "Int", + "label": "Database Access Connection Limit" } ], "links": [ @@ -702,7 +674,7 @@ "link_fieldname": "site" } ], - "modified": "2024-11-04 09:40:44.252728", + "modified": "2024-11-28 15:40:02.431631", "modified_by": "Administrator", "module": "Press", "name": "Site", diff --git a/press/press/doctype/site/site.py b/press/press/doctype/site/site.py index f90675908f..712679fccf 100644 --- a/press/press/doctype/site/site.py +++ b/press/press/doctype/site/site.py @@ -125,9 +125,7 @@ class Site(Document, TagHelpers): current_cpu_usage: DF.Int current_database_usage: DF.Int current_disk_usage: DF.Int - database_access_mode: DF.Literal["", "read_only", "read_write"] - database_access_password: DF.Password | None - database_access_user: DF.Data | None + database_access_connection_limit: DF.Int database_name: DF.Data | None domain: DF.Link | None erpnext_consultant: DF.Link | None @@ -136,7 +134,6 @@ class Site(Document, TagHelpers): hide_config: DF.Check host_name: DF.Data | None hybrid_saas_pool: DF.Link | None - is_database_access_enabled: DF.Check is_erpnext_setup: DF.Check is_standby: DF.Check notify_email: DF.Data | None @@ -189,7 +186,7 @@ class Site(Document, TagHelpers): "cluster", "bench", "group", - "is_database_access_enabled", + "database_access_connection_limit", "trial_end_date", "tags", "server", From 95a6839f4807a8f3f4a2794f12f8c4d5cae93368 Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:43:48 +0530 Subject: [PATCH 02/14] chore(site): remove `Show Database Credentials` button from site actions --- press/press/doctype/site/site.js | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/press/press/doctype/site/site.js b/press/press/doctype/site/site.js index 7ad3c1827e..1b0323615e 100644 --- a/press/press/doctype/site/site.js +++ b/press/press/doctype/site/site.js @@ -185,29 +185,6 @@ frappe.ui.form.on('Site', { }); frm.toggle_enable(['host_name'], frm.doc.status === 'Active'); - if (frm.doc.is_database_access_enabled) { - frm.add_custom_button( - __('Show Database Credentials'), - () => - frm.call('get_database_credentials').then((r) => { - let message = `Host: ${r.message.host} - -Port: ${r.message.port} - -Database: ${r.message.database} - -Username: ${r.message.username} - -Password: ${r.message.password} - -\`\`\`\nmysql -u ${r.message.username} -p${r.message.password} -h ${r.message.host} -P ${r.message.port} --ssl --ssl-verify-server-cert\n\`\`\``; - - frappe.msgprint(frappe.markdown(message), 'Database Credentials'); - }), - __('Actions'), - ); - } - frm.add_custom_button( __('Replicate Site'), () => { From 400935f134b1a03594af7b8350b3801613f8a2f0 Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:13:52 +0530 Subject: [PATCH 03/14] chore(site): remove redundant agent callback for database access --- press/press/doctype/agent_job/agent_job.py | 11 +---------- press/press/doctype/site/site.py | 11 ----------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/press/press/doctype/agent_job/agent_job.py b/press/press/doctype/agent_job/agent_job.py index 3674272f0f..72c538822f 100644 --- a/press/press/doctype/agent_job/agent_job.py +++ b/press/press/doctype/agent_job/agent_job.py @@ -896,7 +896,6 @@ def process_job_updates(job_name: str, response_data: dict | None = None): # no process_setup_erpnext_site_job_update, ) from press.press.doctype.site.site import ( - process_add_proxysql_user_job_update, process_archive_site_job_update, process_complete_setup_wizard_job_update, process_create_user_job_update, @@ -905,7 +904,6 @@ def process_job_updates(job_name: str, response_data: dict | None = None): # no process_move_site_to_bench_job_update, process_new_site_job_update, process_reinstall_site_job_update, - process_remove_proxysql_user_job_update, process_rename_site_job_update, process_restore_job_update, process_restore_tables_job_update, @@ -979,16 +977,9 @@ def process_job_updates(job_name: str, response_data: dict | None = None): # no process_add_ssh_user_job_update(job) elif job.job_type == "Remove User from Proxy": process_remove_ssh_user_job_update(job) - elif job.job_type == "Add User to ProxySQL": + elif job.job_type == "Add User to ProxySQL" or job.job_type == "Remove User from ProxySQL": if job.reference_doctype == "Site Database User": SiteDatabaseUser.process_job_update(job) - else: - process_add_proxysql_user_job_update(job) - elif job.job_type == "Remove User from ProxySQL": - if job.reference_doctype == "Site Database User": - SiteDatabaseUser.process_job_update(job) - else: - process_remove_proxysql_user_job_update(job) elif job.job_type == "Reload NGINX": process_update_nginx_job_update(job) elif job.job_type == "Move Site to Bench": diff --git a/press/press/doctype/site/site.py b/press/press/doctype/site/site.py index 712679fccf..8f248ba5b2 100644 --- a/press/press/doctype/site/site.py +++ b/press/press/doctype/site/site.py @@ -3032,17 +3032,6 @@ def process_rename_site_job_update(job): # noqa: C901 create_site_status_update_webhook_event(job.site) -# TODO -def process_add_proxysql_user_job_update(job): - if job.status == "Success": - frappe.db.set_value("Site", job.site, "is_database_access_enabled", True) - - -def process_remove_proxysql_user_job_update(job): - if job.status == "Success": - frappe.db.set_value("Site", job.site, "is_database_access_enabled", False) - - def process_move_site_to_bench_job_update(job): updated_status = { "Pending": "Pending", From e3d8cc7e33a298fc79ce52fe57d86c0607f031f1 Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:18:09 +0530 Subject: [PATCH 04/14] chore(site-database-user): add field for max database connection --- .../doctype/site_database_user/site_database_user.json | 9 ++++++++- .../doctype/site_database_user/site_database_user.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/press/press/doctype/site_database_user/site_database_user.json b/press/press/doctype/site_database_user/site_database_user.json index 6ef23f3e82..7953216e9a 100644 --- a/press/press/doctype/site_database_user/site_database_user.json +++ b/press/press/doctype/site_database_user/site_database_user.json @@ -10,6 +10,7 @@ "site", "team", "column_break_udtx", + "max_database_connections", "username", "password", "user_created_in_database", @@ -125,6 +126,12 @@ "options": "Team", "reqd": 1, "search_index": 1 + }, + { + "default": "4", + "fieldname": "max_database_connections", + "fieldtype": "Int", + "label": "Max Database Connections" } ], "index_web_pages_for_search": 1, @@ -135,7 +142,7 @@ "link_fieldname": "reference_name" } ], - "modified": "2024-11-07 13:03:27.265288", + "modified": "2024-11-28 17:17:57.639463", "modified_by": "Administrator", "module": "Press", "name": "Site Database User", diff --git a/press/press/doctype/site_database_user/site_database_user.py b/press/press/doctype/site_database_user/site_database_user.py index 30d5f0a85c..6cad5f3a06 100644 --- a/press/press/doctype/site_database_user/site_database_user.py +++ b/press/press/doctype/site_database_user/site_database_user.py @@ -28,6 +28,7 @@ class SiteDatabaseUser(Document): failed_agent_job: DF.Link | None failure_reason: DF.SmallText + max_database_connections: DF.Int mode: DF.Literal["read_only", "read_write", "granular"] password: DF.Password permissions: DF.Table[SiteDatabaseTablePermission] From 2427dedb5279440e47c47a3dfecf58d3e1afc20b Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:27:02 +0530 Subject: [PATCH 05/14] chore(site-database-user): validation added for max database connection --- .../site_database_user/site_database_user.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/press/press/doctype/site_database_user/site_database_user.py b/press/press/doctype/site_database_user/site_database_user.py index 6cad5f3a06..fce84a648e 100644 --- a/press/press/doctype/site_database_user/site_database_user.py +++ b/press/press/doctype/site_database_user/site_database_user.py @@ -49,6 +49,7 @@ class SiteDatabaseUser(Document): "failed_agent_job", "failure_reason", "permissions", + "max_database_connections", ) def validate(self): @@ -64,6 +65,20 @@ def before_insert(self): frappe.throw("You don't have permission to create database user") if not frappe.db.get_value("Site Plan", site.plan, "database_access"): frappe.throw(f"Database Access is not available on {site.plan} plan") + + # validate connection limit + exists_db_users_connection_limit = frappe.db.get_all( + "Site Database User", + {"site": self.site, "status": ("!=", "Archived")}, + pluck="max_database_connections", + ) + total_used_connections = sum(exists_db_users_connection_limit) + allowed_max_connections_for_site = site.max_database_connections - total_used_connections + if self.max_database_connections > allowed_max_connections_for_site: + frappe.throw( + f"Your site has quota of {site.max_database_connections} connections. You can't allocate more than {allowed_max_connections_for_site} connections. You can drop other database users to allocate more connections." + ) + self.status = "Pending" if not self.username: self.username = frappe.generate_hash(length=15) From 953586aed9ce600ffb88d9e2b0e5381f64a2352a Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:29:39 +0530 Subject: [PATCH 06/14] chore(site-database-user): while calling agent apis pass max database connections limit --- press/agent.py | 11 ++++++++++- .../site_database_user/site_database_user.json | 5 +++-- .../doctype/site_database_user/site_database_user.py | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/press/agent.py b/press/agent.py index 4e5f1044f8..837c85fd2b 100644 --- a/press/agent.py +++ b/press/agent.py @@ -620,12 +620,21 @@ def remove_ssh_user(self, bench): ) def add_proxysql_user( - self, site, database, username, password, database_server, reference_doctype=None, reference_name=None + self, + site, + database: str, + username: str, + password: str, + max_connections: int, + database_server, + reference_doctype=None, + reference_name=None, ): data = { "username": username, "password": password, "database": database, + "max_connections": max_connections, "backend": {"ip": database_server.private_ip, "id": database_server.server_id}, } return self.create_agent_job( diff --git a/press/press/doctype/site_database_user/site_database_user.json b/press/press/doctype/site_database_user/site_database_user.json index 7953216e9a..99f526d20e 100644 --- a/press/press/doctype/site_database_user/site_database_user.json +++ b/press/press/doctype/site_database_user/site_database_user.json @@ -131,7 +131,8 @@ "default": "4", "fieldname": "max_database_connections", "fieldtype": "Int", - "label": "Max Database Connections" + "label": "Max Database Connections", + "set_only_once": 1 } ], "index_web_pages_for_search": 1, @@ -142,7 +143,7 @@ "link_fieldname": "reference_name" } ], - "modified": "2024-11-28 17:17:57.639463", + "modified": "2024-11-29 12:25:19.446170", "modified_by": "Administrator", "module": "Press", "name": "Site Database User", diff --git a/press/press/doctype/site_database_user/site_database_user.py b/press/press/doctype/site_database_user/site_database_user.py index fce84a648e..e4249ac3cd 100644 --- a/press/press/doctype/site_database_user/site_database_user.py +++ b/press/press/doctype/site_database_user/site_database_user.py @@ -59,6 +59,9 @@ def validate(self): if self.mode != "granular": self.permissions.clear() + if not self.is_new() and self.has_value_changed("max_database_connections"): + frappe.throw("You can't update the max database connections. Archive it and create a new one.") + def before_insert(self): site = frappe.get_doc("Site", self.site) if not site.has_permission(): @@ -186,6 +189,7 @@ def add_user_to_proxysql(self): database, self.username, self.get_password("password"), + self.max_database_connections, database_server, reference_doctype="Site Database User", reference_name=self.name, From a8cdb1f1d7b144de2468d5234024267ace7cc11c Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:42:51 +0530 Subject: [PATCH 07/14] chore(site-database-user): set default max database connections to 16 --- .../press/doctype/site_database_user/site_database_user.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/press/press/doctype/site_database_user/site_database_user.json b/press/press/doctype/site_database_user/site_database_user.json index 99f526d20e..2b1d8b89f2 100644 --- a/press/press/doctype/site_database_user/site_database_user.json +++ b/press/press/doctype/site_database_user/site_database_user.json @@ -128,7 +128,7 @@ "search_index": 1 }, { - "default": "4", + "default": "16", "fieldname": "max_database_connections", "fieldtype": "Int", "label": "Max Database Connections", @@ -143,7 +143,7 @@ "link_fieldname": "reference_name" } ], - "modified": "2024-11-29 12:25:19.446170", + "modified": "2024-11-29 12:42:22.786821", "modified_by": "Administrator", "module": "Press", "name": "Site Database User", From 62a126992695131fce89402c46e2deb42fb845e2 Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:50:34 +0530 Subject: [PATCH 08/14] chore(site-database-user): rename max_database_connections to max_connections --- .../site_database_user/site_database_user.json | 8 ++++---- .../site_database_user/site_database_user.py | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/press/press/doctype/site_database_user/site_database_user.json b/press/press/doctype/site_database_user/site_database_user.json index 2b1d8b89f2..16c73eecfd 100644 --- a/press/press/doctype/site_database_user/site_database_user.json +++ b/press/press/doctype/site_database_user/site_database_user.json @@ -10,7 +10,7 @@ "site", "team", "column_break_udtx", - "max_database_connections", + "max_connections", "username", "password", "user_created_in_database", @@ -129,9 +129,9 @@ }, { "default": "16", - "fieldname": "max_database_connections", + "fieldname": "max_connections", "fieldtype": "Int", - "label": "Max Database Connections", + "label": "Max Connections", "set_only_once": 1 } ], @@ -143,7 +143,7 @@ "link_fieldname": "reference_name" } ], - "modified": "2024-11-29 12:42:22.786821", + "modified": "2024-11-29 13:49:11.220888", "modified_by": "Administrator", "module": "Press", "name": "Site Database User", diff --git a/press/press/doctype/site_database_user/site_database_user.py b/press/press/doctype/site_database_user/site_database_user.py index e4249ac3cd..356c20cbd0 100644 --- a/press/press/doctype/site_database_user/site_database_user.py +++ b/press/press/doctype/site_database_user/site_database_user.py @@ -28,7 +28,7 @@ class SiteDatabaseUser(Document): failed_agent_job: DF.Link | None failure_reason: DF.SmallText - max_database_connections: DF.Int + max_connections: DF.Int mode: DF.Literal["read_only", "read_write", "granular"] password: DF.Password permissions: DF.Table[SiteDatabaseTablePermission] @@ -49,7 +49,7 @@ class SiteDatabaseUser(Document): "failed_agent_job", "failure_reason", "permissions", - "max_database_connections", + "max_connections", ) def validate(self): @@ -59,7 +59,7 @@ def validate(self): if self.mode != "granular": self.permissions.clear() - if not self.is_new() and self.has_value_changed("max_database_connections"): + if not self.is_new() and self.has_value_changed("max_connections"): frappe.throw("You can't update the max database connections. Archive it and create a new one.") def before_insert(self): @@ -73,13 +73,13 @@ def before_insert(self): exists_db_users_connection_limit = frappe.db.get_all( "Site Database User", {"site": self.site, "status": ("!=", "Archived")}, - pluck="max_database_connections", + pluck="max_connections", ) total_used_connections = sum(exists_db_users_connection_limit) - allowed_max_connections_for_site = site.max_database_connections - total_used_connections - if self.max_database_connections > allowed_max_connections_for_site: + allowed_max_connections_for_site = site.max_connections - total_used_connections + if self.max_connections > allowed_max_connections_for_site: frappe.throw( - f"Your site has quota of {site.max_database_connections} connections. You can't allocate more than {allowed_max_connections_for_site} connections. You can drop other database users to allocate more connections." + f"Your site has quota of {site.max_connections} connections. You can't allocate more than {allowed_max_connections_for_site} connections. You can drop other database users to allocate more connections." ) self.status = "Pending" @@ -189,7 +189,7 @@ def add_user_to_proxysql(self): database, self.username, self.get_password("password"), - self.max_database_connections, + self.max_connections, database_server, reference_doctype="Site Database User", reference_name=self.name, @@ -249,6 +249,7 @@ def get_credential(self): "username": self.username, "password": self.get_password("password"), "mode": self.mode, + "max_connections": self.max_connections, } @dashboard_whitelist() From a6419e0e693fa687ce06bbbb57ec2dcab7a53b79 Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:04:17 +0530 Subject: [PATCH 09/14] feat(site-database-user): ui updated to allow setting up database user connection limit --- .../src2/components/SiteDatabaseAccessDialog.vue | 13 ++++++++++--- .../SiteDatabaseAddEditUserDialog.vue | 13 ++++++++++++- .../SiteDatabaseUserCredentialDialog.vue | 5 +++++ .../site_database_user/site_database_user.py | 9 +++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/dashboard/src2/components/SiteDatabaseAccessDialog.vue b/dashboard/src2/components/SiteDatabaseAccessDialog.vue index 53b18c6296..444db05827 100644 --- a/dashboard/src2/components/SiteDatabaseAccessDialog.vue +++ b/dashboard/src2/components/SiteDatabaseAccessDialog.vue @@ -2,7 +2,7 @@ @@ -137,7 +137,7 @@ export default { { label: 'Username', fieldname: 'username', - width: 1 + width: 0.5 }, { label: 'Status', @@ -146,6 +146,13 @@ export default { align: 'center', type: 'Badge' }, + { + label: 'DB Connections', + fieldname: 'max_connections', + width: 0.5, + align: 'center', + format: value => `${value} Connection` + (value > 1 ? 's' : '') + }, { label: 'Mode', fieldname: 'mode', @@ -168,7 +175,7 @@ export default { } ], rowActions: ({ row, listResource, documentResource }) => { - if (row.status === 'Archived') { + if (row.status === 'Archived' || row.status === 'Pending') { return []; } return [ diff --git a/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue b/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue index 5a6e4022ef..c6f0d7aca7 100644 --- a/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue +++ b/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue @@ -40,6 +40,14 @@ label="Access Mode" v-model="mode" /> +

Use SSL: Yes

+

+ Max Database Connection{{ + databaseCredential?.max_connections > 1 ? 's' : '' + }}: {{ databaseCredential?.max_connections }} +

diff --git a/press/press/doctype/site_database_user/site_database_user.py b/press/press/doctype/site_database_user/site_database_user.py index 356c20cbd0..d0e7e8212b 100644 --- a/press/press/doctype/site_database_user/site_database_user.py +++ b/press/press/doctype/site_database_user/site_database_user.py @@ -62,6 +62,11 @@ def validate(self): if not self.is_new() and self.has_value_changed("max_connections"): frappe.throw("You can't update the max database connections. Archive it and create a new one.") + if not self.max_connections: + frappe.throw( + "Max database connections can't be zero. You need to opt for at least one connection." + ) + def before_insert(self): site = frappe.get_doc("Site", self.site) if not site.has_permission(): @@ -76,10 +81,10 @@ def before_insert(self): pluck="max_connections", ) total_used_connections = sum(exists_db_users_connection_limit) - allowed_max_connections_for_site = site.max_connections - total_used_connections + allowed_max_connections_for_site = site.database_access_connection_limit - total_used_connections if self.max_connections > allowed_max_connections_for_site: frappe.throw( - f"Your site has quota of {site.max_connections} connections. You can't allocate more than {allowed_max_connections_for_site} connections. You can drop other database users to allocate more connections." + f"Your site has quota of {site.database_access_connection_limit} database connections.\nYou can't allocate more than {allowed_max_connections_for_site} connections for new user. You can drop other database users to allocate more connections." ) self.status = "Pending" From 36918e183d6d175a87997c33d612dc60b845b73a Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:27:36 +0530 Subject: [PATCH 10/14] feat(site-database-user): added field for label of db user cred --- .../doctype/site_database_user/site_database_user.json | 9 ++++++++- .../doctype/site_database_user/site_database_user.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/press/press/doctype/site_database_user/site_database_user.json b/press/press/doctype/site_database_user/site_database_user.json index 16c73eecfd..235160d883 100644 --- a/press/press/doctype/site_database_user/site_database_user.json +++ b/press/press/doctype/site_database_user/site_database_user.json @@ -6,6 +6,7 @@ "engine": "InnoDB", "field_order": [ "status", + "label", "mode", "site", "team", @@ -133,6 +134,12 @@ "fieldtype": "Int", "label": "Max Connections", "set_only_once": 1 + }, + { + "fieldname": "label", + "fieldtype": "Data", + "label": "Label", + "reqd": 1 } ], "index_web_pages_for_search": 1, @@ -143,7 +150,7 @@ "link_fieldname": "reference_name" } ], - "modified": "2024-11-29 13:49:11.220888", + "modified": "2024-11-29 15:25:08.468806", "modified_by": "Administrator", "module": "Press", "name": "Site Database User", diff --git a/press/press/doctype/site_database_user/site_database_user.py b/press/press/doctype/site_database_user/site_database_user.py index d0e7e8212b..01d0dec5bf 100644 --- a/press/press/doctype/site_database_user/site_database_user.py +++ b/press/press/doctype/site_database_user/site_database_user.py @@ -28,6 +28,7 @@ class SiteDatabaseUser(Document): failed_agent_job: DF.Link | None failure_reason: DF.SmallText + label: DF.Data max_connections: DF.Int mode: DF.Literal["read_only", "read_write", "granular"] password: DF.Password @@ -41,6 +42,7 @@ class SiteDatabaseUser(Document): # end: auto-generated types dashboard_fields = ( + "label", "status", "site", "username", From ad5f60f99f1933c2c9ebbecfe5d2c3e13926e46e Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:29:43 +0530 Subject: [PATCH 11/14] feat(site-database-user): label for site database user added --- .../src2/components/SiteDatabaseAccessDialog.vue | 8 ++++---- .../SiteDatabaseAddEditUserDialog.vue | 11 +++++++++++ .../site_database_user/site_database_user.json | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/dashboard/src2/components/SiteDatabaseAccessDialog.vue b/dashboard/src2/components/SiteDatabaseAccessDialog.vue index 444db05827..55f3297f64 100644 --- a/dashboard/src2/components/SiteDatabaseAccessDialog.vue +++ b/dashboard/src2/components/SiteDatabaseAccessDialog.vue @@ -122,7 +122,7 @@ export default { site: this.site, status: ['!=', 'Archived'] }, - searchField: 'username', + searchField: 'label', filterControls() { return [ { @@ -135,9 +135,9 @@ export default { }, columns: [ { - label: 'Username', - fieldname: 'username', - width: 0.5 + label: 'Label', + fieldname: 'label', + width: '150px' }, { label: 'Status', diff --git a/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue b/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue index c6f0d7aca7..257aa905db 100644 --- a/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue +++ b/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue @@ -18,6 +18,14 @@ type="error" > + Date: Fri, 29 Nov 2024 16:30:31 +0530 Subject: [PATCH 12/14] feat(site-database-user): show database user label in list view --- press/press/doctype/site_database_user/site_database_user.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/press/press/doctype/site_database_user/site_database_user.json b/press/press/doctype/site_database_user/site_database_user.json index 88fbdaa551..dbb5757219 100644 --- a/press/press/doctype/site_database_user/site_database_user.json +++ b/press/press/doctype/site_database_user/site_database_user.json @@ -138,6 +138,7 @@ { "fieldname": "label", "fieldtype": "Data", + "in_list_view": 1, "label": "Label", "reqd": 1 } @@ -150,7 +151,7 @@ "link_fieldname": "reference_name" } ], - "modified": "2024-11-29 15:54:25.951266", + "modified": "2024-11-29 16:29:57.632579", "modified_by": "Administrator", "module": "Press", "name": "Site Database User", From 0e82652f95f12dd8d9bdd3e157c1495488b98d4c Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Fri, 29 Nov 2024 17:10:35 +0530 Subject: [PATCH 13/14] feat(site-database-user): write patch to fill label for existing db users --- press/patches.txt | 1 + .../v0_7_0/set_label_for_site_database_user.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 press/patches/v0_7_0/set_label_for_site_database_user.py diff --git a/press/patches.txt b/press/patches.txt index d6e837399b..79d1a06292 100644 --- a/press/patches.txt +++ b/press/patches.txt @@ -134,3 +134,4 @@ press.patches.v0_7_0.update_enable_performance_tuning press.press.doctype.server.patches.set_plan_and_subscription press.patches.v0_7_0.move_site_db_access_users_to_site_db_perm_manager press.press.doctype.drip_email.patches.set_correct_field_for_html +press.patches.v0_7_0.set_label_for_site_database_user diff --git a/press/patches/v0_7_0/set_label_for_site_database_user.py b/press/patches/v0_7_0/set_label_for_site_database_user.py new file mode 100644 index 0000000000..40e20661aa --- /dev/null +++ b/press/patches/v0_7_0/set_label_for_site_database_user.py @@ -0,0 +1,12 @@ +import frappe + + +def execute(): + db_users = frappe.get_all( + "Site Database User", + filters={"status": ("!=", "Archived")}, + fields=["name", "username"], + ) + + for db_user in db_users: + frappe.db.set_value("Site Database User", db_user.name, "label", f"User {db_user.username}") From af22760a4414cda237f61bfb225941cb3d874a9c Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:59:04 +0530 Subject: [PATCH 14/14] chore(site-database-user): allow support to configure only label of user --- .../SiteDatabaseAddEditUserDialog.vue | 2 + .../site_database_user/site_database_user.py | 58 +++++++++++++------ 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue b/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue index 257aa905db..2b0139de58 100644 --- a/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue +++ b/dashboard/src2/components/site_database_user/SiteDatabaseAddEditUserDialog.vue @@ -49,6 +49,7 @@ v-model="mode" />