Skip to content

Commit

Permalink
feat(site-database-user): ui updated to allow setting up database use…
Browse files Browse the repository at this point in the history
…r connection limit
  • Loading branch information
tanmoysrt committed Nov 29, 2024
1 parent 62a1269 commit a6419e0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
13 changes: 10 additions & 3 deletions dashboard/src2/components/SiteDatabaseAccessDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Dialog
:options="{
title: 'Manage Database Users',
size: planSupportsDatabaseAccess ? '2xl' : 'xl'
size: planSupportsDatabaseAccess ? '3xl' : 'xl'
}"
v-model="show"
>
Expand Down Expand Up @@ -137,7 +137,7 @@ export default {
{
label: 'Username',
fieldname: 'username',
width: 1
width: 0.5
},
{
label: 'Status',
Expand All @@ -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',
Expand All @@ -168,7 +175,7 @@ export default {
}
],
rowActions: ({ row, listResource, documentResource }) => {
if (row.status === 'Archived') {
if (row.status === 'Archived' || row.status === 'Pending') {
return [];
}
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
label="Access Mode"
v-model="mode"
/>
<FormControl
class="mt-2"
type="number"
size="sm"
variant="subtle"
label="Database Connections"
v-model="database_connections"
/>
<!-- Permission configuration for Granular Mode -->
<div v-if="mode == 'granular'">
<div
Expand Down Expand Up @@ -131,6 +139,7 @@ export default {
data() {
return {
mode: 'read_only',
database_connections: 1,
permissions: [],
lastGeneratedRowId: 0
};
Expand Down Expand Up @@ -171,6 +180,7 @@ export default {
};
});
this.permissions = fetched_permissions;
this.database_connections = data?.max_connections ?? 1;
}
};
},
Expand All @@ -195,7 +205,8 @@ export default {
team: this.$team.doc.name,
site: this.site,
mode: this.mode,
permissions: permissions
permissions: permissions,
max_connections: parseInt(this.database_connections || 1)
}
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
Password: {{ databaseCredential?.password }}
</p>
<p class="ml-1 font-mono text-sm">Use SSL: Yes</p>
<p class="ml-1 font-mono text-sm">
Max Database Connection{{
databaseCredential?.max_connections > 1 ? 's' : ''
}}: {{ databaseCredential?.max_connections }}
</p>
</div>
<div class="pb-2 pt-5">
<p class="mb-2 text-base font-semibold text-gray-700">
Expand Down
9 changes: 7 additions & 2 deletions press/press/doctype/site_database_user/site_database_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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"
Expand Down

0 comments on commit a6419e0

Please sign in to comment.