mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 16:56:30 -06:00
Ensure that the user's storage directory is created when the users are created, as well as for those users who have not yet been created. #5824
This commit is contained in:
parent
48f2e2744c
commit
0a543d0e95
@ -35,6 +35,7 @@ Bug fixes
|
||||
| `Issue #4784 <https://github.com/pgadmin-org/pgadmin4/issues/4784>`_ - Handle errors occurring during decoding UTF-8 encoded query result data which contains ascii characters.
|
||||
| `Issue #5735 <https://github.com/pgadmin-org/pgadmin4/issues/5735>`_ - Show appropriate error message when master password is not set instead of 'Crypt key missing'.
|
||||
| `Issue #5775 <https://github.com/pgadmin-org/pgadmin4/issues/5775>`_ - Display the 'No menu available for this object' message if the selected tree node does not have any options.
|
||||
| `Issue #5824 <https://github.com/pgadmin-org/pgadmin4/issues/5824>`_ - Ensure that the user's storage directory is created when the users are created, as well as for those users who have not yet been created.
|
||||
| `Issue #5833 <https://github.com/pgadmin-org/pgadmin4/issues/5833>`_ - Fixed an issue where user MFA entry was not getting delete after deleting a user.
|
||||
| `Issue #5874 <https://github.com/pgadmin-org/pgadmin4/issues/5874>`_ - Make "using" and "with check" fields a textarea in the RLS policy.
|
||||
| `Issue #5901 <https://github.com/pgadmin-org/pgadmin4/issues/5901>`_ - Update SQLAlchemy, Flask, Flask-SQLAlchemy, and other packages to current versions.
|
||||
|
@ -42,17 +42,17 @@ APP_ICON = 'pg-icon'
|
||||
#
|
||||
|
||||
# Application version number components
|
||||
APP_RELEASE = 6
|
||||
APP_REVISION = 21
|
||||
APP_RELEASE = 7
|
||||
APP_REVISION = 0
|
||||
|
||||
# Application version suffix, e.g. 'beta1', 'dev'. Usually an empty string
|
||||
# for GA releases.
|
||||
APP_SUFFIX = ''
|
||||
APP_SUFFIX = 'dev'
|
||||
|
||||
# Numeric application version for upgrade checks. Should be in the format:
|
||||
# [X]XYYZZ, where X is the release version, Y is the revision, with a leading
|
||||
# zero if needed, and Z represents the suffix, with a leading zero if needed
|
||||
APP_VERSION_INT = 62100
|
||||
APP_VERSION_INT = 70000
|
||||
|
||||
# DO NOT CHANGE!
|
||||
# The application version string, constructed from the components
|
||||
|
@ -20,13 +20,14 @@ from werkzeug.exceptions import InternalServerError
|
||||
import config
|
||||
from pgadmin.utils import PgAdminModule
|
||||
from pgadmin.utils.ajax import make_response as ajax_response, \
|
||||
make_json_response, bad_request, internal_server_error, forbidden
|
||||
make_json_response, bad_request, internal_server_error
|
||||
from pgadmin.utils.csrf import pgCSRFProtect
|
||||
from pgadmin.utils.constants import MIMETYPE_APP_JS, INTERNAL,\
|
||||
SUPPORTED_AUTH_SOURCES
|
||||
from pgadmin.utils.validation_utils import validate_email
|
||||
from pgadmin.model import db, Role, User, UserPreference, Server, \
|
||||
ServerGroup, Process, Setting, roles_users, SharedServer
|
||||
from pgadmin.utils.paths import create_users_storage_directory
|
||||
|
||||
# set template path for sql scripts
|
||||
MODULE_NAME = 'user_management'
|
||||
@ -532,6 +533,9 @@ def create_user(data):
|
||||
except Exception as e:
|
||||
return False, str(e)
|
||||
|
||||
# Create users storage directory
|
||||
create_users_storage_directory()
|
||||
|
||||
return True, ''
|
||||
|
||||
|
||||
|
@ -10,15 +10,27 @@
|
||||
"""This file contains functions fetching different utility paths."""
|
||||
|
||||
import os
|
||||
|
||||
import config
|
||||
from flask import current_app, url_for
|
||||
from flask_security import current_user
|
||||
from werkzeug.exceptions import InternalServerError
|
||||
from pgadmin.utils.constants import MY_STORAGE
|
||||
from pgadmin.model import User
|
||||
|
||||
|
||||
def preprocess_username(un):
|
||||
ret_un = un
|
||||
if len(ret_un) == 0 or ret_un[0].isdigit():
|
||||
ret_un = 'pga_user_' + un
|
||||
|
||||
ret_un = ret_un.replace('@', '_') \
|
||||
.replace('/', 'slash') \
|
||||
.replace('\\', 'slash')
|
||||
|
||||
return ret_un
|
||||
|
||||
|
||||
def get_storage_directory(user=current_user, shared_storage=''):
|
||||
import config
|
||||
if config.SERVER_MODE is not True:
|
||||
return None
|
||||
|
||||
@ -44,18 +56,7 @@ def get_storage_directory(user=current_user, shared_storage=''):
|
||||
if storage_dir is None:
|
||||
return None
|
||||
|
||||
def _preprocess_username(un):
|
||||
ret_un = un
|
||||
if len(ret_un) == 0 or ret_un[0].isdigit():
|
||||
ret_un = 'pga_user_' + un
|
||||
|
||||
ret_un = ret_un.replace('@', '_')\
|
||||
.replace('/', 'slash')\
|
||||
.replace('\\', 'slash')
|
||||
|
||||
return ret_un
|
||||
|
||||
username = _preprocess_username(user.username.split('@')[0])
|
||||
username = preprocess_username(user.username.split('@')[0])
|
||||
|
||||
# Figure out the old-style storage directory name
|
||||
old_storage_dir = os.path.join(
|
||||
@ -64,7 +65,7 @@ def get_storage_directory(user=current_user, shared_storage=''):
|
||||
username
|
||||
)
|
||||
|
||||
username = _preprocess_username(user.username)
|
||||
username = preprocess_username(user.username)
|
||||
|
||||
if is_shared_storage:
|
||||
# Figure out the new style storage directory name
|
||||
@ -95,7 +96,6 @@ def get_storage_directory(user=current_user, shared_storage=''):
|
||||
|
||||
|
||||
def init_app():
|
||||
import config
|
||||
if config.SERVER_MODE is not True:
|
||||
return None
|
||||
|
||||
@ -131,3 +131,37 @@ def get_cookie_path():
|
||||
'/browser/', ''
|
||||
)
|
||||
return cookie_root_path
|
||||
|
||||
|
||||
def create_users_storage_directory():
|
||||
"""
|
||||
This function is used to iterate through all the users and
|
||||
create users directory if not already created.
|
||||
"""
|
||||
if not config.SERVER_MODE:
|
||||
return None
|
||||
|
||||
users = User.query.all()
|
||||
|
||||
for usr in users:
|
||||
username = preprocess_username(usr.username)
|
||||
|
||||
storage_dir = getattr(
|
||||
config, 'STORAGE_DIR',
|
||||
os.path.join(
|
||||
os.path.realpath(
|
||||
os.path.expanduser('~/.pgadmin/')
|
||||
), 'storage'
|
||||
)
|
||||
)
|
||||
|
||||
if storage_dir is None:
|
||||
return None
|
||||
|
||||
storage_dir = os.path.join(
|
||||
storage_dir.decode('utf-8') if hasattr(storage_dir, 'decode')
|
||||
else storage_dir, username
|
||||
)
|
||||
|
||||
if not os.path.exists(storage_dir):
|
||||
os.makedirs(storage_dir, int('700', 8))
|
||||
|
Loading…
Reference in New Issue
Block a user