Skip to content

Commit 3b104e4

Browse files
Fix directory owner update & UI issues. #8034
1 parent be534be commit 3b104e4

File tree

7 files changed

+28
-64
lines changed

7 files changed

+28
-64
lines changed

docs/en_US/directory_dialog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
`Directory Dialog`:index:
55
*************************
66

7-
Use the Directory dialog to Create an alias for a file system directory path.
7+
Use the Directory dialog to create an alias for a file system directory path.
88
To create directories, you must have the CREATE ANY DIRECTORY system privilege.
99
When you create a directory, you are automatically granted READ and WRITE privileges
1010
on the directory, and you can grant READ and WRITE privileges to other users and roles.
3.82 KB
Loading
2.68 KB
Loading

web/pgadmin/browser/server_groups/servers/directories/__init__.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def create(self, gid, sid):
303303

304304
# To fetch the oid of newly created directory
305305
SQL = render_template(
306-
"/".join([self.template_path, self._ALTER_SQL]),
306+
"/".join([self.template_path, self._CREATE_SQL]),
307307
directory=data['name'], conn=self.conn
308308
)
309309

@@ -312,31 +312,6 @@ def create(self, gid, sid):
312312
if not status:
313313
return internal_server_error(errormsg=dr_id)
314314

315-
SQL = render_template(
316-
"/".join([self.template_path, self._ALTER_SQL]),
317-
data=data, conn=self.conn
318-
)
319-
320-
# Checking if we are not executing empty query
321-
if SQL and SQL.strip('\n') and SQL.strip(' '):
322-
status, res = self.conn.execute_scalar(SQL)
323-
if not status:
324-
return jsonify(
325-
node=self.blueprint.generate_browser_node(
326-
dr_id,
327-
sid,
328-
data['name'],
329-
icon="icon-directory"
330-
),
331-
success=0,
332-
errormsg=gettext(
333-
'Directory created successfully.'
334-
),
335-
info=gettext(
336-
res
337-
)
338-
)
339-
340315
return jsonify(
341316
node=self.blueprint.generate_browser_node(
342317
dr_id,
@@ -359,7 +334,7 @@ def update(self, gid, sid, dr_id):
359334
)
360335

361336
try:
362-
SQL, name = self.get_sql(gid, sid, data, dr_id)
337+
SQL, diruser = self.get_sql(gid, sid, data, dr_id)
363338
# Most probably this is due to error
364339
if not isinstance(SQL, str):
365340
return SQL
@@ -373,7 +348,7 @@ def update(self, gid, sid, dr_id):
373348
node=self.blueprint.generate_browser_node(
374349
dr_id,
375350
sid,
376-
name,
351+
diruser,
377352
icon="icon-%s" % self.node_type,
378353
)
379354
)
@@ -524,13 +499,9 @@ def get_sql(self, gid, sid, data, dr_id=None):
524499
"/".join([self.template_path, self._CREATE_SQL]),
525500
data=data, conn=self.conn
526501
)
527-
SQL += "\n"
528-
SQL += render_template(
529-
"/".join([self.template_path, self._ALTER_SQL]),
530-
data=data, conn=self.conn
531-
)
532502
SQL = re.sub('\n{2,}', '\n\n', SQL)
533-
return SQL, data['name'] if 'name' in data else old_data['name']
503+
diruser = data['diruser'] if 'diruser' in data else old_data['diruser']
504+
return SQL, diruser
534505

535506
@check_precondition
536507
def sql(self, gid, sid, dr_id):
@@ -565,11 +536,6 @@ def sql(self, gid, sid, dr_id):
565536
"/".join([self.template_path, self._CREATE_SQL]),
566537
data=old_data, conn=self.conn
567538
)
568-
SQL += "\n"
569-
SQL += render_template(
570-
"/".join([self.template_path, self._ALTER_SQL]),
571-
data=old_data, conn=self.conn
572-
)
573539

574540
sql_header = """
575541
-- Directory: {0}

web/pgadmin/browser/server_groups/servers/directories/static/js/directory.ui.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { isEmptyString } from '../../../../../../static/js/validators';
1414
export default class DirectorySchema extends BaseUISchema {
1515
constructor(getPrivilegeRoleSchema, treeNodeInfo, fieldOptions={}, initValues={}) {
1616
super({
17+
diruser: undefined,
1718
name: undefined,
18-
owner: undefined,
1919
path: undefined,
2020
diracl: [],
2121
...initValues,

web/pgadmin/browser/server_groups/servers/directories/templates/directories/sql/default/alter.sql

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
{### SQL to create directory object ###}
22
{% if data %}
3+
34
CREATE DIRECTORY {{ conn|qtIdent(data.name) }} AS {{ data.path|qtLiteral(conn) }};
4-
{% endif %}
5+
6+
{### Owner on directory ###}
7+
{% if data.diruser %}
8+
ALTER DIRECTORY {{ conn|qtIdent(data.name) }}
9+
OWNER TO {{ conn|qtIdent(data.diruser) }};
10+
{% endif %}
11+
12+
{### ACL on directory ###}
13+
{% if data.diracl %}
14+
{% for priv in data.diracl %}
15+
{{ PRIVILEGE.APPLY(conn, 'DIRECTORY', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}
16+
{% endfor %}
17+
{% endif %}
18+
19+
{% endif %}
20+
21+
{# ======== The SQl Below will fetch id for given dataspace ======== #}
22+
{% if directory %}
23+
SELECT dir.oid FROM pg_catalog.edb_dir dir WHERE dirname = {{directory|qtLiteral(conn)}};
24+
{% endif %}

0 commit comments

Comments
 (0)