Skip to content

[ENG-8016] Re-adding the same user to preprint providers as moderator/admin creates duplicate records. #11159

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

Open
wants to merge 1 commit into
base: feature/pbs-25-10
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions admin/preprint_providers/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def __init__(self, *args, provider_groups=None, **kwargs):
super().__init__(*args, **kwargs)

provider_groups = provider_groups or Group.objects.none()
self.fields['group_perms'] = forms.ModelMultipleChoiceField(
self.fields['group_perms'] = forms.ModelChoiceField(
queryset=provider_groups,
required=False,
widget=forms.CheckboxSelectMultiple
widget=forms.RadioSelect
)

user_id = forms.CharField(required=True, max_length=5, min_length=5)
8 changes: 6 additions & 2 deletions admin/preprint_providers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,14 @@ def form_valid(self, form):
if not osf_user:
raise Http404(f'OSF user with id "{user_id}" not found. Please double check.')

for group in form.cleaned_data.get('group_perms'):
self.target_provider.add_to_group(osf_user, group)
if osf_user.has_groups(self.target_provider.group_names):
messages.error(self.request, f'User with guid: {user_id} is already a moderator or admin')
return super().form_invalid(form)

group = form.cleaned_data.get('group_perms')
self.target_provider.add_to_group(osf_user, group)
osf_user.save()

messages.success(self.request, f'Permissions update successful for OSF User {osf_user.username}!')
return super().form_valid(form)

Expand Down
3 changes: 1 addition & 2 deletions admin/providers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def post(self, request, *args, **kwargs):
messages.error(request, f'User for guid: {data["add-moderators-form"][0]} could not be found')
return redirect(f'{self.url_namespace}:add_admin_or_moderator', provider_id=provider.id)

groups = [provider.format_group(name) for name in provider.groups.keys()]
if target_user.has_groups(groups):
if target_user.has_groups(provider.group_names):
messages.error(request, f'User with guid: {data["add-moderators-form"][0]} is already a moderator or admin')
return redirect(f'{self.url_namespace}:add_admin_or_moderator', provider_id=provider.id)

Expand Down
Loading