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

[ENG-2111] Unregistered Contributor Claim on Registration also claims on Project #9472

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/test_webtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,44 @@ def test_claim_user_registered_with_correct_password(self):
# unclaimed record for the project has been deleted
assert_not_in(self.project, self.user.unclaimed_records)

def test_claim_user_registered_registration_with_correct_password(self):
registration = RegistrationFactory(project=self.project)
self.user.reload()

name, email = fake.name(), fake_email()

assert_in(self.user, registration.contributors)

reg_user = AuthUserFactory() # NOTE: AuthUserFactory sets password as 'queenfan86'
self.user.reload()
url = self.user.get_claim_url(registration._id)
# Follow to password re-enter page
res = self.app.get(url, auth=reg_user.auth).follow(auth=reg_user.auth)

# verify that the "Claim Account" form is returned
assert_in('Claim Contributor', res.body.decode())

form = res.forms['claimContributorForm']
form['password'] = 'queenfan86'
res = form.submit(auth=reg_user.auth)

registration.reload()
self.project.reload()
self.user.reload()

# user is now a contributor to the registration and project
assert_in(reg_user, registration.contributors)
assert_in(reg_user, self.project.contributors)

# the unregistered user (unreg_user) is removed as a contributor to the registration and project
assert_not_in(self.user, registration.contributors)
assert_not_in(self.user, self.project.contributors)

# unclaimed record for the registration and project has been deleted
assert_not_in(registration, self.user.unclaimed_records)
assert_not_in(self.project, self.user.unclaimed_records)


def test_claim_user_registered_preprint_with_correct_password(self):
preprint = PreprintFactory(creator=self.referrer)
name, email = fake.name(), fake_email()
Expand Down
5 changes: 4 additions & 1 deletion website/project/views/contributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from framework.utils import get_timestamp, throttle_period_expired
from osf.models import Tag
from osf.exceptions import NodeStateError
from osf.models import AbstractNode, DraftRegistration, OSFGroup, OSFUser, Preprint, PreprintProvider, RecentlyAddedContributor
from osf.models import AbstractNode, DraftRegistration, OSFGroup, OSFUser, Preprint, PreprintProvider, RecentlyAddedContributor, Registration
from osf.utils import sanitize
from osf.utils.permissions import ADMIN
from website import mails, language, settings
Expand Down Expand Up @@ -733,6 +733,9 @@ def claim_user_registered(auth, node, **kwargs):
if should_claim:
node.replace_contributor(old=unreg_user, new=current_user)
node.save()
if isinstance(node, Registration):
project = node.registered_from
project.replace_contributor(old=unreg_user, new=current_user)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if the user is removed from the project before they have a chance to claim on the registration?

if isinstance(node, OSFGroup):
status.push_status_message(
'You are now a member of this OSFGroup.',
Expand Down