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

implementation of delete profile for users without usable passwords (shibboleth, allauth social accounts, ..) #601

Merged
merged 23 commits into from
Apr 14, 2023

Conversation

MyPyDavid
Copy link
Member

@MyPyDavid MyPyDavid commented Mar 14, 2023

Changes for #599:

Added functionalities for when user.has_usable_password() is False, this holds for users from shibboleth or from allauth social accounts. Did not (need?) to use if settings.SHIBBOLETH for this implementation.

  • added optional pop password field in RemoveForm
  • refactored delete_user func
  • refactored a little bit the remove_user View
  • added tests for test coverage

  • discuss about the implementation
    • do LDAP users have a normal password? so that user.has_usable_password() is True for them @m6121

@MyPyDavid MyPyDavid self-assigned this Mar 14, 2023
@MyPyDavid MyPyDavid linked an issue Mar 14, 2023 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Mar 14, 2023

Coverage Status

Coverage: 90.679% (+0.2%) from 90.469% when pulling c4946bb on feature/599-add-shibboleth-delete-profile into 813df5e on dev-1.10.0.

@m6121
Copy link
Member

m6121 commented Mar 14, 2023

Hi @MyPyDavid
Phew, good question! Interestingly the current implementation works for LDAP, too. Need to check this branch with LDAP to answer it.

@MyPyDavid MyPyDavid force-pushed the feature/599-add-shibboleth-delete-profile branch from 86bef01 to c72d0db Compare March 24, 2023 12:06
Copy link
Member

@m6121 m6121 left a comment

Choose a reason for hiding this comment

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

Hi @MyPyDavid, thanks a lot for this contribution. I reviewed your changes and added some minor questions what might be changed. For the LDAP-case this implementation works analogue to the Shibboleth-case, i.e. without prompting for password and only by entering the e-mail address. I am not sure if it is a requirement that we should ask for the password in LDAP-case as it is currently.

username = 'user'
email = 'user@example.com'
db_user = get_user_model().objects.get(username=username, email=email)
assert get_user_from_db_or_none(username, email) == db_user
Copy link
Member

Choose a reason for hiding this comment

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

Probably, we might add tests that if either the username or the e-mail does not correspond to the same user. Because I think the current implementation in get_user_from_db_or_none() allows to have multiple users with the same e-mail if the username is different.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I've added a testcase with a loop here:

def test_get_user_from_db_or_none_returns_none_when_wrong_input_was_given(db):

Copy link
Member

Choose a reason for hiding this comment

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

In this case it is much nicer to use @pytest.mark.parametrize to create seperate tests for the different users automatically, e.g.

@pytest.mark.parametrize('username,password', users)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a bunch of @pytest.mark.parametrize to the tests.

rdmo/accounts/tests/test_views.py Outdated Show resolved Hide resolved
@@ -258,6 +291,36 @@ def test_remove_user_post(db, client):
assert not get_user_model().objects.filter(username='user').exists()


def test_remove_user_post_cancelled_when_update_is_true(db, client, settings):
settings.PROFILE_UPDATE = True
if settings.PROFILE_DELETE:
Copy link
Member

Choose a reason for hiding this comment

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

Same here, should we add tests so that all combinations are tested: Update True/False and Delete True/False? Maybe this is a general question for our tests. I think it would make sense to try to test all combinations in order not to forget something due to the local/default test config.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes think so too. In general, I would like to have the option to loop through these different test configs/combinations as well.. I can look into that but don't know if it will be too much for this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

for now, I will keep it so that the settings are set to True/False at the start of each test case. We can keep in mind to refactor/improve the tests with that in another PR but also that the amount of test cases should be kept maintainable.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added now a True/False option with @pytest.mark.parametrize('test_setting', boolean_toggle) to most of the test cases. Then in each test case, only the relevant part is checked in a conditional eg:

   if settings.PROFILE_UPDATE:
        assertTemplateUsed(response, 'profile/profile_update_form.html')
    else:
        assertTemplateUsed(response, 'profile/profile_update_closed.html')

rdmo/accounts/tests/test_views.py Outdated Show resolved Hide resolved
rdmo/accounts/tests/test_views.py Outdated Show resolved Hide resolved
@jochenklar
Copy link
Member

Hi @MyPyDavid and @m6121 , thanks a lot. Looks ok to me.

@MyPyDavid MyPyDavid force-pushed the feature/599-add-shibboleth-delete-profile branch 2 times, most recently from 9950d75 to c4946bb Compare April 13, 2023 17:05
@MyPyDavid MyPyDavid changed the title implementation for shibboleth user delete profile implementation of delete profile for users without usable passwords (shibboleth, allauth social accounts, ..) Apr 14, 2023
@MyPyDavid MyPyDavid marked this pull request as ready for review April 14, 2023 06:40
@MyPyDavid MyPyDavid requested a review from m6121 April 14, 2023 06:40
Copy link
Member

@m6121 m6121 left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks a lot @MyPyDavid for your work on the tests and the implementation. Looks good to me.

@MyPyDavid
Copy link
Member Author

alright! thanks for the review and discussions @m6121 and @jochenklar !

@jochenklar jochenklar merged commit c9a0e2c into dev-1.10.0 Apr 14, 2023
14 checks passed
assert response.url == reverse('account_reset_password_from_key', args=['4','set-password'])
# get the link from the mail
# urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', mail.outbox[0].body) # complicated regex
urls = [i.strip() for i in mail.outbox[0].body.splitlines() if i.strip().startswith('http')] # simpler alternative
Copy link
Member Author

Choose a reason for hiding this comment

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

should we leave this complicated regex:

urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', mail.outbox[0].body)  # complicated regex

or this in here?

urls = [i.strip() for i in mail.outbox[0].body.splitlines() if i.strip().startswith('http')]  # simpler alternative

Copy link
Member Author

@MyPyDavid MyPyDavid Apr 20, 2023

Choose a reason for hiding this comment

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

  • keep the regex

@MyPyDavid MyPyDavid added this to the 1.10.0 milestone Apr 21, 2023
@MyPyDavid MyPyDavid deleted the feature/599-add-shibboleth-delete-profile branch June 6, 2023 15:04
CalamityC pushed a commit to CalamityC/rdmo that referenced this pull request Nov 23, 2023
…-shibboleth-delete-profile

implementation of delete profile for users without usable passwords (shibboleth, allauth social accounts, ..)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow shibboleth users to delete profile
4 participants