Skip to content
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

Bugfix: pgAdmin imports servers to the wrong accounts in the server version with webserver auth enabled #6818

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions web/pgadmin/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,16 @@ def _does_user_exist(user, from_setup):
This function will check user is exist or not. If exist then return
"""
if isinstance(user, User):
user = user.email

new_user = User.query.filter_by(email=user).first()
if user.email:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pgAdmin supports multiple authentication at a time, so it is possible to have same email ids and usernames for multiple users.
So you have to check for username + Authentication source combination to get the valid user.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khushboovashi I have made changes :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just didn't know what to do with email because the function accepts text or a user object. So for an object I check auth_source+username, but for text I check email.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am proposing to introduce auth_source as a user input while importing the server itself. So, you need change in setup.py itself. The fix you did does not resolve the issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't know pgadmin code at all. I tried to solve the problem, but I don't know if I can help more. Can you explain in more detail what we want to achieve? What should be changed in the file https://github.com/pgadmin-org/pgadmin4/blob/master/web/setup.py? What do you mean by user input?

user = user.email
new_user = User.query.filter_by(email=user).first()
elif user.username:
user = user.username
new_user = User.query.filter_by(username=user).first()
else:
new_user = None
else:
new_user = User.query.filter_by(email=user).first()

if new_user is None:
print(USER_NOT_FOUND % user)
Expand Down