Skip to content

Commit

Permalink
updated fullname
Browse files Browse the repository at this point in the history
  • Loading branch information
annapurna-gupta committed Dec 13, 2024
1 parent 2716bd3 commit cee3269
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 251 deletions.
38 changes: 12 additions & 26 deletions mslib/mscolab/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,50 +219,36 @@ def auth_type(self, u_id, op_id):
return False
return perm.access_level

def modify_user(self, user, attribute=None, value=None, action=None):
def modify_user_fullname(self, user, value=None, action=None):
if action == "create":
user_query = User.query.filter_by(emailid=str(user.emailid)).first()
if user_query is None:
if not user.full_name or not user.nickname:
raise ValueError("Full name and nickname must be provided.")
if not user.fullname:
raise ValueError("Full name must be provided.")
db.session.add(user)
db.session.commit()
else:
return False
elif action == "delete":
user_query = User.query.filter_by(id=user.id).first()
if user_query is not None:
# Delete profile image if it exists
if user.profile_image_path:
self.delete_user_profile_image(user.profile_image_path)
db.session.delete(user)
db.session.commit()
user_query = User.query.filter_by(id=user.id).first()
# on delete we return successful deleted
if user_query is None:
return True
elif action == "update_idp_user":
user_query = User.query.filter_by(emailid=str(user.emailid)).first()
if user_query is not None:
db.session.add(user)
db.session.commit()
else:
elif action == "update_fullname":
user_query = User.query.filter_by(id=user.id).first()
if user_query is None:
return False
user_query = User.query.filter_by(id=user.id).first()
if user_query is None:
return False
if None not in (attribute, value):
if attribute == "emailid":
user_query = User.query.filter_by(emailid=str(value)).first()
if user_query is not None:
return False
if attribute in ["full_name", "nickname"]:
if not value.strip():
raise ValueError(f"{attribute} cannot be empty.")
setattr(user, attribute, value)
db.session.commit()
if value is not None:
if not value.strip():
raise ValueError("Full name cannot be empty.")
setattr(user, "fullname", value)
db.session.commit()
return True


def delete_user_profile_image(self, image_to_be_deleted):
'''
This function is called when deleting account or updating the profile picture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ def downgrade():
batch_op.drop_column('profile_image_path')

# ### end Alembic commands ###


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.add_column(sa.Column('fullname', sa.String(length=255), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_column('fullname')
# ### end Alembic commands ###

This file was deleted.

8 changes: 2 additions & 6 deletions mslib/mscolab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ class User(db.Model):
confirmed_on = db.Column(AwareDateTime, nullable=True)
permissions = db.relationship('Permission', cascade='all,delete,delete-orphan', backref='user')
authentication_backend = db.Column(db.String(255), nullable=False, default='local')

fullname = db.Column(db.String(255), nullable=True)
nickname = db.Column(db.String(255), nullable=True)

def __init__(self, emailid, username, password, profile_image_path=None, confirmed=False,
confirmed_on=None, authentication_backend='local', fullname="", nickname=""):
confirmed_on=None, authentication_backend='local', fullname=""):
self.username = str(username)
self.emailid = str(emailid)
self.hash_password(password)
Expand All @@ -78,9 +76,7 @@ def __init__(self, emailid, username, password, profile_image_path=None, confirm
self.confirmed = bool(confirmed)
self.confirmed_on = confirmed_on
self.authentication_backend = str(authentication_backend)

self.fullname = str(fullname) if fullname else None
self.nickname = str(nickname) if nickname else None
self.fullname = str(fullname)

def __repr__(self):
return f'<User {self.username}>'
Expand Down
21 changes: 9 additions & 12 deletions mslib/mscolab/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,32 +620,29 @@ def set_version_name():
def edit_user_info():
user = g.user
fullname = request.form.get("fullname")
nickname = request.form.get("nickname")

try:
# Update the user's full name and nickname in the database
# Update the user's full name in the database
user_record = User.query.filter_by(id=int(user.id)).first()
if user_record is None:
return jsonify({"success": False, "error": "User not found."}), 404

# Update fields
# Update the full name
user_record.fullname = fullname # Update full name
user_record.nickname = nickname # Update nickname

# Commit changes to the database
db.session.commit()
_handle_db_upgrade().session.commit()
return jsonify({
"success": True,
"fullname": user_record.fullname,
"nickname": user_record.nickname
"fullname": user_record.fullname # Return the updated full name
}), 200

except Exception as e:
logging.debug(f"Error updating user info: {str(e)}")
return jsonify({
"success": False,
"error": "Failed to update user info"
}), 500
logging.debug(f"Error updating user info: {str(e)}")
return jsonify({
"success": False,
"error": "Failed to update user info"
}), 500



Expand Down
17 changes: 8 additions & 9 deletions mslib/msui/mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,23 +966,22 @@ def delete_account(self, _=None):
if r.status_code == 200 and json.loads(r.text)["success"] is True:
self.logout()

@verify_token_required
@verify_user_token
def editfull_name(self):
fullname, ok = QtWidgets.QInputDialog.getText(
self.ui,
self.ui.tr("Edit Full Name"),
self.ui.tr(
f"You're about to change the full name - '{self.active_operation_name}' "
f"Enter new full name: "
),
self.ui,
self.ui.tr("Edit Full Name"),
self.ui.tr("Enter new full name:")
)

if ok:
data = {
"token": self.token,
"fullname": str(fullname)
"fullname": str(fullname)
}
url = url_join(self.mscolab_server_url, 'edit_full_name')
url = urljoin(self.mscolab_server_url, 'edit_full_name')
r = requests.post(url, data=data)

if r.text == "true":
self.error_dialog = QtWidgets.QErrorMessage()
self.error_dialog.showMessage("Fullname is updated successfully.")
Expand Down
1 change: 1 addition & 0 deletions mslib/msui/qt5/ui_add_user_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ def retranslateUi(self, addUserDialog):
self.password.setPlaceholderText(_translate("addUserDialog", "Your password"))
self.confirmPasswordLabel.setText(_translate("addUserDialog", "Confirm Password:"))
self.rePassword.setPlaceholderText(_translate("addUserDialog", "Confirm your password"))

58 changes: 25 additions & 33 deletions mslib/msui/qt5/ui_mscolab_connect_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Ui_MSColabConnectDialog(object):
def setupUi(self, MSColabConnectDialog):
MSColabConnectDialog.setObjectName("MSColabConnectDialog")
MSColabConnectDialog.resize(446, 305)
MSColabConnectDialog.resize(446, 332)
self.gridLayout_4 = QtWidgets.QGridLayout(MSColabConnectDialog)
self.gridLayout_4.setObjectName("gridLayout_4")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
Expand Down Expand Up @@ -90,46 +90,40 @@ def setupUi(self, MSColabConnectDialog):
self.newUserTopicLabel.setFont(font)
self.newUserTopicLabel.setObjectName("newUserTopicLabel")
self.gridLayout_2.addWidget(self.newUserTopicLabel, 0, 1, 1, 1)
self.newPasswordLe = QtWidgets.QLineEdit(self.newuserPage)
self.newPasswordLe.setEchoMode(QtWidgets.QLineEdit.Password)
self.newPasswordLe.setObjectName("newPasswordLe")
self.gridLayout_2.addWidget(self.newPasswordLe, 10, 1, 1, 1)
self.newConfirmPasswordLe = QtWidgets.QLineEdit(self.newuserPage)
self.newConfirmPasswordLe.setEchoMode(QtWidgets.QLineEdit.Password)
self.newConfirmPasswordLe.setObjectName("newConfirmPasswordLe")
self.gridLayout_2.addWidget(self.newConfirmPasswordLe, 11, 1, 1, 1)
self.newEmailLe = QtWidgets.QLineEdit(self.newuserPage)
self.newEmailLe.setObjectName("newEmailLe")
self.gridLayout_2.addWidget(self.newEmailLe, 8, 1, 1, 1)
self.newUserBb = QtWidgets.QDialogButtonBox(self.newuserPage)
self.newUserBb.setLayoutDirection(QtCore.Qt.LeftToRight)
self.newUserBb.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.newUserBb.setObjectName("newUserBb")
self.gridLayout_2.addWidget(self.newUserBb, 12, 1, 1, 1, QtCore.Qt.AlignLeft)
self.newEmailLe = QtWidgets.QLineEdit(self.newuserPage)
self.newEmailLe.setObjectName("newEmailLe")
self.gridLayout_2.addWidget(self.newEmailLe, 9, 1, 1, 1)
self.gridLayout_2.addWidget(self.newUserBb, 11, 1, 1, 1, QtCore.Qt.AlignLeft)
self.newPasswordLe = QtWidgets.QLineEdit(self.newuserPage)
self.newPasswordLe.setEchoMode(QtWidgets.QLineEdit.Password)
self.newPasswordLe.setObjectName("newPasswordLe")
self.gridLayout_2.addWidget(self.newPasswordLe, 9, 1, 1, 1)
self.newEmailLabel = QtWidgets.QLabel(self.newuserPage)
self.newEmailLabel.setObjectName("newEmailLabel")
self.gridLayout_2.addWidget(self.newEmailLabel, 9, 0, 1, 1, QtCore.Qt.AlignRight)
self.gridLayout_2.addWidget(self.newEmailLabel, 8, 0, 1, 1, QtCore.Qt.AlignRight)
self.newConfirmPasswordLe = QtWidgets.QLineEdit(self.newuserPage)
self.newConfirmPasswordLe.setEchoMode(QtWidgets.QLineEdit.Password)
self.newConfirmPasswordLe.setObjectName("newConfirmPasswordLe")
self.gridLayout_2.addWidget(self.newConfirmPasswordLe, 10, 1, 1, 1)
self.fullname = QtWidgets.QLineEdit(self.newuserPage)
self.fullname.setObjectName("fullname")
self.gridLayout_2.addWidget(self.fullname, 2, 1, 1, 1)
self.newPasswordLabel = QtWidgets.QLabel(self.newuserPage)
self.newPasswordLabel.setObjectName("newPasswordLabel")
self.gridLayout_2.addWidget(self.newPasswordLabel, 10, 0, 1, 1, QtCore.Qt.AlignRight)
self.newConfirmPasswordLabel = QtWidgets.QLabel(self.newuserPage)
self.newConfirmPasswordLabel.setObjectName("newConfirmPasswordLabel")
self.gridLayout_2.addWidget(self.newConfirmPasswordLabel, 11, 0, 1, 1, QtCore.Qt.AlignRight)
self.nickname = QtWidgets.QLineEdit(self.newuserPage)
self.nickname.setObjectName("nickname")
self.gridLayout_2.addWidget(self.nickname, 3, 1, 1, 1)
self.newUsernameLabel = QtWidgets.QLabel(self.newuserPage)
self.newUsernameLabel.setObjectName("newUsernameLabel")
self.gridLayout_2.addWidget(self.newUsernameLabel, 1, 0, 1, 1)
self.gridLayout_2.addWidget(self.newConfirmPasswordLabel, 10, 0, 1, 1, QtCore.Qt.AlignRight)
self.newPasswordLabel = QtWidgets.QLabel(self.newuserPage)
self.newPasswordLabel.setObjectName("newPasswordLabel")
self.gridLayout_2.addWidget(self.newPasswordLabel, 9, 0, 1, 1, QtCore.Qt.AlignRight)
self.fullnameLabel = QtWidgets.QLabel(self.newuserPage)
self.fullnameLabel.setObjectName("fullnameLabel")
self.gridLayout_2.addWidget(self.fullnameLabel, 2, 0, 1, 1)
self.nicknameLabel = QtWidgets.QLabel(self.newuserPage)
self.nicknameLabel.setObjectName("nicknameLabel")
self.gridLayout_2.addWidget(self.nicknameLabel, 3, 0, 1, 1)
self.newUsernameLabel = QtWidgets.QLabel(self.newuserPage)
self.newUsernameLabel.setObjectName("newUsernameLabel")
self.gridLayout_2.addWidget(self.newUsernameLabel, 1, 0, 1, 1)
self.stackedWidget.addWidget(self.newuserPage)
self.httpAuthPage = QtWidgets.QWidget()
self.httpAuthPage.setObjectName("httpAuthPage")
Expand Down Expand Up @@ -244,17 +238,15 @@ def retranslateUi(self, MSColabConnectDialog):
self.loginPasswordLe.setPlaceholderText(_translate("MSColabConnectDialog", "Password"))
self.newUsernameLe.setPlaceholderText(_translate("MSColabConnectDialog", "John Doe"))
self.newUserTopicLabel.setText(_translate("MSColabConnectDialog", "New User Details"))
self.newPasswordLe.setPlaceholderText(_translate("MSColabConnectDialog", "New Password"))
self.newConfirmPasswordLe.setPlaceholderText(_translate("MSColabConnectDialog", "Confirm New Password"))
self.newEmailLe.setPlaceholderText(_translate("MSColabConnectDialog", "[email protected]"))
self.newPasswordLe.setPlaceholderText(_translate("MSColabConnectDialog", "New Password"))
self.newEmailLabel.setText(_translate("MSColabConnectDialog", "Email:"))
self.newConfirmPasswordLe.setPlaceholderText(_translate("MSColabConnectDialog", "Confirm New Password"))
self.fullname.setPlaceholderText(_translate("MSColabConnectDialog", "John Michael Doe"))
self.newPasswordLabel.setText(_translate("MSColabConnectDialog", "Password:"))
self.newConfirmPasswordLabel.setText(_translate("MSColabConnectDialog", "Confirm Password:"))
self.nickname.setPlaceholderText(_translate("MSColabConnectDialog", "Johnny"))
self.newUsernameLabel.setText(_translate("MSColabConnectDialog", " Username:"))
self.newPasswordLabel.setText(_translate("MSColabConnectDialog", "Password:"))
self.fullnameLabel.setText(_translate("MSColabConnectDialog", " Fullname:"))
self.nicknameLabel.setText(_translate("MSColabConnectDialog", " Nickname:"))
self.newUsernameLabel.setText(_translate("MSColabConnectDialog", " Username:"))
self.httpTopicLabel.setText(_translate("MSColabConnectDialog", "HTTP Server Authentication"))
self.httpPasswordLe.setPlaceholderText(_translate("MSColabConnectDialog", "Server Auth Password"))
self.httpPasswordLabel.setText(_translate("MSColabConnectDialog", "Password:"))
Expand Down
Loading

0 comments on commit cee3269

Please sign in to comment.