-
Notifications
You must be signed in to change notification settings - Fork 879
Fix inherited-column read-only state and Definition-tab type restriction in the Table dialog #10332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bd252ca
1f8a075
4173ddf
0713356
be8985e
8fec246
77f7464
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -619,6 +619,7 @@ def _check_action(action, kwargs): | |
| return fetch_name, check_permission, forbidden_msg | ||
|
|
||
| def _check_permission(self, check_permission, action, kwargs): | ||
| self.membership_only_update = False | ||
| if check_permission: | ||
| user = self.manager.user_info | ||
|
|
||
|
|
@@ -627,6 +628,15 @@ def _check_permission(self, check_permission, action, kwargs): | |
| (action != 'update' or 'rid' in kwargs) and \ | ||
| kwargs['rid'] != -1 and \ | ||
| user['id'] != kwargs['rid']: | ||
| # A role that only has ADMIN OPTION on this specific role | ||
| # (rather than being a superuser or having CREATEROLE) may | ||
| # still manage that role's membership, so don't forbid the | ||
| # request outright; the update handler restricts what such | ||
| # a request is allowed to change to membership only. | ||
| if action == 'update' and getattr( | ||
| self, 'has_admin_option', False): | ||
| self.membership_only_update = True | ||
| return False | ||
| return True | ||
| return False | ||
|
|
||
|
|
@@ -658,6 +668,7 @@ def _check_and_fetch_name(self, fetch_name, kwargs): | |
| self.role = row['rolname'] | ||
| self.rolCanLogin = row['rolcanlogin'] | ||
| self.rolSuper = row['rolsuper'] | ||
| self.has_admin_option = row.get('has_admin_option', False) | ||
|
|
||
| return False, '' | ||
|
|
||
|
|
@@ -713,16 +724,20 @@ def wrapped(self, **kwargs): | |
| fetch_name, check_permission, \ | ||
| forbidden_msg = RoleView._check_action(action, kwargs) | ||
|
|
||
| is_permission_error = self._check_permission(check_permission, | ||
| action, kwargs) | ||
| if is_permission_error: | ||
| return forbidden(forbidden_msg) | ||
|
|
||
| # Fetched first: the permission check needs to know | ||
| # whether the current user holds ADMIN OPTION on this | ||
| # role before it can decide whether to forbid the | ||
| # request. | ||
| is_error, errmsg = self._check_and_fetch_name(fetch_name, | ||
| kwargs) | ||
| if is_error: | ||
| return errmsg | ||
|
|
||
| is_permission_error = self._check_permission(check_permission, | ||
| action, kwargs) | ||
| if is_permission_error: | ||
| return forbidden(forbidden_msg) | ||
|
|
||
| return f(self, **kwargs) | ||
|
|
||
| return wrapped | ||
|
|
@@ -1023,6 +1038,13 @@ def create(self, gid, sid): | |
| @check_precondition(action='update') | ||
| @validate_request | ||
| def update(self, gid, sid, rid): | ||
| if getattr(self, 'membership_only_update', False) and \ | ||
| not set(self.request) <= {'rolmembers'}: | ||
| return forbidden( | ||
| _("The current user does not have permission to update " | ||
| "the role. Users with ADMIN OPTION on this role may " | ||
| "only manage its membership.") | ||
| ) | ||
|
Comment on lines
+1041
to
+1047
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Authorize against the original request keys.
Store the client-supplied keys before validation mutates Proposed fix def wrap(self, **kwargs):
# Parse data...
+ requested_fields = set(data)
invalid_msg_arr = [
...
]
self.request = data
+ self.requested_fields = requested_fields
def update(self, gid, sid, rid):
if getattr(self, 'membership_only_update', False) and \
- not set(self.request) <= {'rolmembers'}:
+ not self.requested_fields <= {'rolmembers'}:🤖 Prompt for AI Agents |
||
|
|
||
| sql = render_template( | ||
| self.sql_path + self._UPDATE_SQL, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| SELECT | ||
| rolname, rolcanlogin, rolsuper | ||
| rolname, rolcanlogin, rolsuper, | ||
| EXISTS ( | ||
| SELECT 1 FROM pg_catalog.pg_auth_members am | ||
| WHERE am.roleid = {{ rid }}::OID | ||
| AND am.member = ( | ||
| SELECT oid FROM pg_catalog.pg_roles | ||
| WHERE rolname = current_user | ||
| ) | ||
| AND am.admin_option | ||
| ) AS has_admin_option | ||
| FROM | ||
| pg_catalog.pg_roles | ||
| WHERE oid = {{ rid }}::OID |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| ########################################################################## | ||
| # | ||
| # pgAdmin 4 - PostgreSQL Tools | ||
| # | ||
| # Copyright (C) 2013 - 2026, The pgAdmin Development Team | ||
| # This software is released under the PostgreSQL Licence | ||
| # | ||
| ########################################################################## | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| from pgadmin.utils.route import BaseTestGenerator | ||
| from pgadmin.browser.server_groups.servers.roles import RoleView | ||
|
|
||
|
|
||
| class RoleCheckPermissionTest(BaseTestGenerator): | ||
| """Unit tests for RoleView._check_permission's ADMIN OPTION carve-out. | ||
|
|
||
| A role holder who is neither a superuser nor a CREATEROLE holder, but | ||
| who has been granted ADMIN OPTION on the specific role being updated, | ||
| should be allowed through the permission gate so they can manage that | ||
| role's membership - but only for 'update', never for 'drop', and the | ||
| view should record that the request must be restricted to membership | ||
| changes only. | ||
| """ | ||
| scenarios = [ | ||
| ('Check Role Node', dict(url='/browser/role/obj/')) | ||
| ] | ||
|
|
||
| def setUp(self): | ||
| pass | ||
|
|
||
| def runTest(self): | ||
| view = RoleView(cmd=None) | ||
| view.manager = MagicMock() | ||
|
|
||
| # Plain user, no admin option: update is forbidden. | ||
| view.manager.user_info = { | ||
| 'is_superuser': False, 'can_create_role': False, 'id': 5 | ||
| } | ||
| view.has_admin_option = False | ||
| self.assertTrue(view._check_permission(True, 'update', {'rid': 10})) | ||
| self.assertFalse(view.membership_only_update) | ||
|
|
||
| # Same user, but with ADMIN OPTION on the target role: allowed | ||
| # through, flagged as membership-only. | ||
| view.has_admin_option = True | ||
| self.assertFalse(view._check_permission(True, 'update', {'rid': 10})) | ||
| self.assertTrue(view.membership_only_update) | ||
|
|
||
| # ADMIN OPTION does not extend to dropping the role. | ||
| self.assertTrue(view._check_permission(True, 'drop', {'rid': 10})) | ||
|
|
||
| # Superusers are unaffected by the ADMIN OPTION check. | ||
| view.manager.user_info = { | ||
| 'is_superuser': True, 'can_create_role': False, 'id': 5 | ||
| } | ||
| view.has_admin_option = False | ||
| self.assertFalse(view._check_permission(True, 'update', {'rid': 10})) | ||
|
|
||
| def tearDown(self): | ||
| pass |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -649,9 +649,11 @@ def check_is_integer(value): | |
| "found for server '%s'" % server | ||
| ) | ||
| else: | ||
| errmsg = check_attrib("Username") | ||
| if errmsg: | ||
| return errmsg | ||
| if not obj.get("Username"): | ||
| return gettext( | ||
| "'Username' attribute not found for server '%s'" % | ||
| server | ||
| ) | ||
|
Comment on lines
+652
to
+656
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Honor this validation error in every import path.
🤖 Prompt for AI Agents |
||
|
|
||
| errmsg = check_attrib("MaintenanceDB") | ||
| if errmsg: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Protect length and scale controls for loaded inherited columns.
attlenat Lines 389-395 andattprecisionat Lines 421-427 still reject onlyinheritedfrom. When a loaded row has onlyinheritedfromtable, both callbacks can mark the controls editable. Reuse the combined inherited-column check in both callbacks and add regression coverage.🤖 Prompt for AI Agents