-
Notifications
You must be signed in to change notification settings - Fork 0
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
SS-643 Users can edit their account details #235
Merged
anondo1969
merged 30 commits into
develop
from
SS-643-Make-an-option-to-edit-account-details
Oct 22, 2024
Merged
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d321a3f
Updated info about using Serve for teaching (#194)
akochari 2b5cadc
Revert "Updated info about using Serve for teaching (#194)"
akochari 2d769be
Merge branch 'staging' into main
sandstromviktor ab7d54f
Merge branch 'staging'
churnikov 46f589c
Merge branch 'staging'
churnikov c958069
SS-643-Make-an-option-to-edit-account-details
anondo1969 7c8099b
SS-643-Make-an-option-to-edit-account-details
anondo1969 4e3de76
SS-643 extending ProfileForm
anondo1969 d38f4ce
SS-643 Updated edit HTML form
anondo1969 d86a443
SS-643 Updated edit HTML form
anondo1969 32b49eb
SS-643 pre-commit check fixed
anondo1969 bba6f8b
SS-643 pre-commit with black check
anondo1969 0048d66
SS-643 pre-commit with black check 2
anondo1969 cf33450
Merge branch 'develop' into SS-643-Make-an-option-to-edit-account-det…
anondo1969 cded668
fix failing e2e test
akochari 8194013
change the edit profile icon
akochari a05bf15
uncomment the line I accidentally commented out
akochari ee23c4e
Update common/views.py
anondo1969 b3481fd
Update common/forms.py
anondo1969 6bb12aa
Update common/forms.py
anondo1969 41b2862
fix super class init.
anondo1969 491b6f8
changes in view
anondo1969 da00974
ensure login required in form post method
anondo1969 f78edf6
Merge branch 'develop' into SS-643-Make-an-option-to-edit-account-det…
anondo1969 7f13f1e
ensuring curl injection does not work
anondo1969 a96fdfd
fixing the profile-edit bug in superuser mode
anondo1969 5a7fa52
Merge branch 'develop' into SS-643-Make-an-option-to-edit-account-det…
anondo1969 0d50532
Merge branch 'develop' into SS-643-Make-an-option-to-edit-account-det…
anondo1969 2d11a65
differentiate admin user and common user with or without Staff/Superu…
anondo1969 ce5e4a8
differentiate admin user and common user with or without Staff/Superu…
anondo1969 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
from django.conf import settings | ||
from django.contrib import messages | ||
from django.contrib.auth import authenticate, login, logout | ||
|
||
# from django.contrib.auth.decorators import login_required | ||
from django.contrib.auth.decorators import login_required | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.core.mail import send_mail | ||
from django.db import transaction | ||
|
@@ -146,7 +145,7 @@ def post(self, request, *args, **kwargs): | |
return render(request, self.template_name, {"form": form}) | ||
|
||
|
||
# @method_decorator(login_required, name="post") | ||
@method_decorator(login_required, name="dispatch") | ||
class EditProfileView(TemplateView): | ||
template_name = "user/profile_edit_form.html" | ||
|
||
|
@@ -170,72 +169,48 @@ def get_user_profile_info(self, request): | |
|
||
def get(self, request, *args, **kwargs): | ||
user_profile_data = self.get_user_profile_info(request) | ||
common_user = True if not request.user.is_superuser else False | ||
|
||
profile_edit_form = self.profile_edit_form_class( | ||
initial={"affiliation": user_profile_data.affiliation, "department": user_profile_data.department} | ||
initial={ | ||
"affiliation": user_profile_data.affiliation if common_user else "uu", | ||
"department": user_profile_data.department if common_user else "", | ||
} | ||
) | ||
|
||
user_edit_form = self.user_edit_form_class( | ||
initial={ | ||
"email": user_profile_data.user.email, | ||
"first_name": user_profile_data.user.first_name, | ||
"last_name": user_profile_data.user.last_name, | ||
"email": user_profile_data.user.email if common_user else "[email protected]", | ||
"first_name": user_profile_data.user.first_name if common_user else "admin_first_name", | ||
"last_name": user_profile_data.user.last_name if common_user else "admin_last_name", | ||
} | ||
) | ||
|
||
return render(request, self.template_name, {"form": user_edit_form, "profile_form": profile_edit_form}) | ||
|
||
def post(self, request, *args, **kwargs): | ||
user_profile_data = self.get_user_profile_info(request) | ||
common_user = True if not request.user.is_superuser else False | ||
|
||
user_form_details = self.user_edit_form_class( | ||
request.POST, | ||
instance=request.user, | ||
initial={ | ||
"email": user_profile_data.user.email, | ||
"email": user_profile_data.user.email if common_user else "[email protected]", | ||
}, | ||
) | ||
|
||
profile_form_details = self.profile_edit_form_class( | ||
request.POST, | ||
instance=user_profile_data, | ||
initial={ | ||
"affiliation": user_profile_data.affiliation, | ||
"affiliation": user_profile_data.affiliation if common_user else "uu", | ||
}, | ||
) | ||
|
||
if user_form_details.is_valid() and profile_form_details.is_valid(): | ||
try: | ||
with transaction.atomic(): | ||
""" | ||
# If we only want to save the new information, | ||
#rather overriding existing one in the database | ||
user_form_retrived_data = user_form_details.save(commit=False) | ||
|
||
# Only saving the new values, overwriting other existing values | ||
if ( | ||
user_form_retrived_data.first_name != user_profile_data.user.first_name | ||
or user_form_retrived_data.last_name != user_profile_data.user.last_name | ||
): | ||
user_form_retrived_data.username = user_profile_data.user.username | ||
user_form_retrived_data.email = user_profile_data.user.email | ||
user_form_retrived_data.password1 = user_profile_data.user.password | ||
user_form_retrived_data.password2 = user_profile_data.user.password | ||
user_form_retrived_data.save() | ||
|
||
else: | ||
logger.info("Not saving user form info as nothing has changed", exc_info=True) | ||
|
||
profile_form_retrived_data = profile_form_details.save(commit=False) | ||
|
||
# Only saving the new values, overwriting other existing values | ||
profile_form_retrived_data.affiliation = user_profile_data.affiliation | ||
profile_form_retrived_data.deleted_on = user_profile_data.deleted_on | ||
profile_form_retrived_data.why_account_needed = user_profile_data.why_account_needed | ||
profile_form_retrived_data.save() | ||
|
||
# profile_form_details.save_m2m() | ||
""" | ||
user_form_details.save() | ||
profile_form_details.save() | ||
|
||
|
@@ -244,7 +219,9 @@ def post(self, request, *args, **kwargs): | |
logger.info("Updated Department: " + str(self.get_user_profile_info(request).department)) | ||
|
||
except Exception as e: | ||
return HttpResponse("Error updating records: " + str(e)) | ||
# For the superuser it is expected to not to be able to update records | ||
# as it does not have a user profile object. | ||
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. That's what I'm talking about as well, may be we should actually generate this data for the super user as well. Let's discuss this with the team. |
||
return HttpResponse("Superuser: " + str(not common_user) + ", Error updating records: " + str(e)) | ||
|
||
return render(request, "user/profile.html", {"user_profile": self.get_user_profile_info(request)}) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
And superuser can be a regular promoted user, so this would be misleading.
What I suggest us doing is keeping it a broken page for now, but add a jira issue to populate default super user with this data. We should bring it to the broad group.