Skip to content

Commit

Permalink
cleanup invite process view, add todos (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jul 3, 2024
1 parent 05f1257 commit d329fe7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions projectroles/templates/projectroles/user_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h2>
</div>

<div class="container-fluid sodar-page-container">
{# TODO: Add link to OIDC login if new user and OIDC enabled #}
<form method="post">
{% csrf_token %}
{{ form | crispy }}
Expand Down
23 changes: 10 additions & 13 deletions projectroles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,6 +2757,8 @@ def get(self, *args, **kwargs):
return redirect(reverse('home'))


# TODO: Refactor this into a "logged-in-process-view", redirect from local user
# handling and OIDC login?
class ProjectInviteProcessLDAPView(
LoginRequiredMixin, ProjectInviteProcessMixin, View
):
Expand Down Expand Up @@ -2799,8 +2801,8 @@ def get(self, *args, **kwargs):
)


# TODO: Handle OIDC invite together with local
# TODO: OIDC user should not get form to edit details
# TODO: Handle OIDC invite together with local, forward to logged-in view once
# logged in
class ProjectInviteProcessLocalView(ProjectInviteProcessMixin, FormView):
"""View to handle accepting a project local invite"""

Expand All @@ -2813,6 +2815,7 @@ def get(self, *args, **kwargs):
return redirect(reverse('home'))
timeline = get_backend_api('timeline_backend')
# Check if local users are enabled
# TODO: Also allow OIDC
if not settings.PROJECTROLES_ALLOW_LOCAL_USERS:
messages.error(self.request, INVITE_LOCAL_NOT_ALLOWED_MSG)
return redirect(reverse('home'))
Expand Down Expand Up @@ -2843,30 +2846,24 @@ def get(self, *args, **kwargs):
kwargs={'secret': invite.secret},
)
)
# Show form if user doesn't exists and no user is logged in
# Show form if user doesn't exist and no user is logged in
return super().get(*args, **kwargs)
# Logged in but the invited user does not exist yet
if not user:
messages.error(
self.request,
INVITE_LOGGED_IN_ACCEPT_MSG,
)
messages.error(self.request, INVITE_LOGGED_IN_ACCEPT_MSG)
return redirect(reverse('home'))
# Logged in user is not invited user
if not self.request.user == user:
messages.error(
self.request,
INVITE_USER_NOT_EQUAL_MSG,
)
if self.request.user != user:
messages.error(self.request, INVITE_USER_NOT_EQUAL_MSG)
return redirect(reverse('home'))
# User exists but is not local
# TODO: This should instead check if LDAP user
if not user.is_local():
messages.error(self.request, 'User exists, but is not local.')
return redirect(reverse('home'))
# Create role if user exists
if not self.create_assignment(invite, user, timeline=timeline):
return redirect(reverse('home'))

return redirect(
reverse(
'projectroles:detail',
Expand Down

0 comments on commit d329fe7

Please sign in to comment.