Skip to content

Commit db5943b

Browse files
Add a new permission to allow disabling "Change Password" feature for a pgAdmin role. #1926
1 parent b6f64c4 commit db5943b

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

docs/en_US/images/permissions.png

37.3 KB
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
"""empty message
3+
4+
Revision ID: c62bcc14c3d6
5+
Revises: 1f0eddc8fc79
6+
Create Date: 2025-06-02 21:45:20.653669
7+
8+
"""
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'c62bcc14c3d6'
14+
down_revision = '1f0eddc8fc79'
15+
branch_labels = None
16+
depends_on = None
17+
18+
def upgrade():
19+
# Add 'change_password' permission to all roles except 'Administrator'.
20+
meta = sa.MetaData()
21+
meta.reflect(op.get_bind(), only=('role',))
22+
role_table = sa.Table('role', meta)
23+
24+
perm = role_table.c.permissions
25+
op.execute(role_table.update().where(
26+
(role_table.c.name != 'Administrator')
27+
).values(
28+
permissions=sa.case(
29+
(perm == None, 'change_password'),
30+
(perm == '', 'change_password'),
31+
else_=perm + ',change_password'
32+
))
33+
)
34+
35+
def downgrade():
36+
# pgAdmin only upgrades, downgrade not implemented.
37+
pass

web/pgadmin/model/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#
3434
##########################################################################
3535

36-
SCHEMA_VERSION = 44
36+
SCHEMA_VERSION = 45
3737

3838
##########################################################################
3939
#

web/pgadmin/tools/user_management/PgAdminPermissions.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class AllPermissionTypes:
2626
tools_grant_wizard = 'tools_grant_wizard'
2727
storage_add_folder = 'storage_add_folder'
2828
storage_remove_folder = 'storage_remove_folder'
29+
change_password = 'change_password'
2930

3031
@staticmethod
3132
def list():
@@ -34,9 +35,10 @@ def list():
3435

3536

3637
class AllPermissionCategories:
37-
object_explorer = 'Object Explorer'
38-
tools = 'Tools'
39-
storage_manager = 'Storage Manager'
38+
object_explorer = gettext('Object Explorer')
39+
tools = gettext('Tools')
40+
storage_manager = gettext('Storage Manager')
41+
miscellaneous = gettext('Miscellaneous')
4042

4143

4244
class PgAdminPermissions:
@@ -118,6 +120,11 @@ def __init__(self):
118120
AllPermissionTypes.storage_remove_folder,
119121
gettext("Delete file/folder")
120122
)
123+
self.add_permission(
124+
AllPermissionCategories.miscellaneous,
125+
AllPermissionTypes.change_password,
126+
gettext("Change password")
127+
)
121128

122129
def add_permission(self, category: str, permission: str, label: str):
123130
self._all_permissions.append({

web/pgadmin/tools/user_management/static/js/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import gettext from 'sources/gettext';
1313
import { showChangeUserPassword, showUrlDialog } from '../../../../static/js/Dialogs/index';
1414
import { BROWSER_PANELS } from '../../../../browser/static/js/constants';
1515
import Component from './Component';
16+
import withCheckPermission from '../../../../browser/static/js/withCheckPermission';
1617

1718
class UserManagement {
1819
static instance;
@@ -30,9 +31,11 @@ class UserManagement {
3031
this.initialized = true;
3132
}
3233

33-
// This is a callback function to show change user dialog.
34+
// This is a callback function to show change user dialog based on permission.
3435
change_password(url) {
35-
showChangeUserPassword(url);
36+
withCheckPermission({ permission: 'change_password' }, () => {
37+
showChangeUserPassword(url);
38+
})();
3639
}
3740

3841
// This is a callback function to show 2FA dialog.

0 commit comments

Comments
 (0)