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

Require rejection reason when rejecting a new user #1443

Merged
merged 1 commit into from
Jan 23, 2023
Merged
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
20 changes: 17 additions & 3 deletions dandiapi/api/templates/dashboard/user_approval.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ <h5>Last changed: {{ user.metadata.modified }}</h5>
{% csrf_token %}
<input type="hidden" name="status" value="REJECTED">
<button
{% if user.metadata.status == 'REJECTED' %}
disabled
{% endif %}
disabled
id="rejection_btn"
class="waves-effect waves-light btn-large red accent-5 mb-5" type="submit">
<span>REJECT</span>
</button>
<br /><br /><br />
<label for="rejection_reason">Rejection reason (optional)</label>
<input
id="rejection_reason"
type="text"
name="rejection_reason"
value="{% if user.metadata.rejection_reason != None %}{{ user.metadata.rejection_reason }}{% endif %}"
Expand All @@ -100,4 +100,18 @@ <h5>Last changed: {{ user.metadata.modified }}</h5>
</div>
</div>
</div>

<script>
// Event listener that disables the Reject button when no rejection reason is provided
var rejectionReason = document.getElementById('rejection_reason');
rejectionReason.addEventListener('keyup', function (event) {
var rejection_btn = document.getElementById('rejection_btn');
if (event.target.value) {
rejection_btn.removeAttribute('disabled');
}
else {
rejection_btn.setAttribute('disabled', true);
}
});
</script>
{% endblock %}
9 changes: 7 additions & 2 deletions dandiapi/api/views/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from allauth.socialaccount.models import SocialAccount
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.core.exceptions import PermissionDenied, ValidationError
from django.db.models import Exists, OuterRef
from django.shortcuts import get_object_or_404, render
from django.views.decorators.http import require_http_methods
Expand Down Expand Up @@ -84,7 +84,12 @@ def user_approval_view(request, username: str):

if request.method == 'POST':
req_body = request.POST.dict()
user.metadata.status = req_body.get('status')
status = req_body.get('status')

if status == UserMetadata.Status.REJECTED and not req_body.get('rejection_reason'):
raise ValidationError('A rejection reason must be provided to reject a user.')

user.metadata.status = status
if req_body.get('rejection_reason') is not None:
user.metadata.rejection_reason = req_body.get('rejection_reason')
user.metadata.save()
Expand Down