SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 9ae2fb90 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

fix permissions and layout in nominations

parent caf145a0
No related branches found
No related tags found
1 merge request!58[Fellowship Nominations] Rework the fellowship nomination system and UI
...@@ -24,6 +24,8 @@ from submissions.models import Submission ...@@ -24,6 +24,8 @@ from submissions.models import Submission
from scipost.forms import RequestFormMixin from scipost.forms import RequestFormMixin
from scipost.models import Contributor from scipost.models import Contributor
from colleges.permissions import is_edadmin
from .models import ( from .models import (
College, College,
Fellowship, Fellowship,
...@@ -417,7 +419,10 @@ class FellowshipNominationForm(forms.ModelForm): ...@@ -417,7 +419,10 @@ class FellowshipNominationForm(forms.ModelForm):
self.profile = kwargs.pop("profile") self.profile = kwargs.pop("profile")
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields["college"].queryset = College.objects.filter( self.fields["college"].queryset = College.objects.filter(
acad_field=self.profile.acad_field acad_field=self.profile.acad_field,
# id__in=Fellowship.objects.active()
# .filter(contributor=self.fields["nominated_by"].initial)
# .values_list("college", flat=True),
) )
self.fields["college"].empty_label = None self.fields["college"].empty_label = None
self.fields["nominator_comments"].label = False self.fields["nominator_comments"].label = False
...@@ -456,6 +461,16 @@ class FellowshipNominationForm(forms.ModelForm): ...@@ -456,6 +461,16 @@ class FellowshipNominationForm(forms.ModelForm):
self.add_error( self.add_error(
"college", "Mismatch between college.acad_field and profile.acad_field." "college", "Mismatch between college.acad_field and profile.acad_field."
) )
if (not is_edadmin(data["nominated_by"].user)) and (
data["college"].id
not in Fellowship.objects.active()
.filter(contributor=data["nominated_by"])
.values_list("college", flat=True)
):
self.add_error(
"college",
"You do not have an active Fellowship in the selected College.",
)
return data return data
def save(self): def save(self):
...@@ -515,10 +530,15 @@ class FellowshipNominationForm(forms.ModelForm): ...@@ -515,10 +530,15 @@ class FellowshipNominationForm(forms.ModelForm):
class FellowshipNominationSearchForm(forms.Form): class FellowshipNominationSearchForm(forms.Form):
all_nominations = FellowshipNomination.objects.all()
nomination_colleges = all_nominations.values_list("college", flat=True).distinct()
nominee = forms.CharField(max_length=100, required=False, label="Nominee") nominee = forms.CharField(max_length=100, required=False, label="Nominee")
college = forms.MultipleChoiceField( college = forms.MultipleChoiceField(
choices=College.objects.all().order_by("name").values_list("id", "name"), choices=College.objects.filter(id__in=nomination_colleges)
.order_by("name")
.values_list("id", "name"),
required=False, required=False,
) )
...@@ -551,6 +571,7 @@ class FellowshipNominationSearchForm(forms.Form): ...@@ -551,6 +571,7 @@ class FellowshipNominationSearchForm(forms.Form):
("latest_round_open", "Voting start"), ("latest_round_open", "Voting start"),
("latest_round_decision_outcome", "Decision"), ("latest_round_decision_outcome", "Decision"),
("profile__last_name", "Nominee"), ("profile__last_name", "Nominee"),
("nominated_on", "Nominated date"),
), ),
required=False, required=False,
) )
...@@ -653,9 +674,8 @@ class FellowshipNominationSearchForm(forms.Form): ...@@ -653,9 +674,8 @@ class FellowshipNominationSearchForm(forms.Form):
.distinct() .distinct()
) )
if self.cleaned_data.get("can_vote") or not self.user.has_perm( if self.cleaned_data.get("can_vote"):
"scipost.can_view_all_nomination_voting_rounds" # or not self.user.has_perm("scipost.can_view_all_nomination_voting_rounds"):
):
# Restrict rounds to those the user can vote on # Restrict rounds to those the user can vote on
nominations = nominations.with_user_votable_rounds(self.user).distinct() nominations = nominations.with_user_votable_rounds(self.user).distinct()
...@@ -889,9 +909,8 @@ class FellowshipNominationVotingRoundSearchForm(forms.Form): ...@@ -889,9 +909,8 @@ class FellowshipNominationVotingRoundSearchForm(forms.Form):
rounds = FellowshipNominationVotingRound.objects.all() rounds = FellowshipNominationVotingRound.objects.all()
if self.cleaned_data.get("can_vote") or not self.user.has_perm( if self.cleaned_data.get("can_vote"):
"scipost.can_view_all_nomination_voting_rounds" # or not self.user.has_perm("scipost.can_view_all_nomination_voting_rounds"):
):
# Restrict rounds to those the user can vote on # Restrict rounds to those the user can vote on
rounds = rounds.where_user_can_vote(self.user) rounds = rounds.where_user_can_vote(self.user)
......
{% load user_groups %}
{% is_ed_admin request.user as is_ed_admin %}
<div class="p-2"> <div class="p-2">
<div class="row mb-0"> <div class="row mb-0">
...@@ -88,7 +91,7 @@ ...@@ -88,7 +91,7 @@
{% comment %} or "active_senior_fellow" in user_roles {% endcomment %} {% comment %} or "active_senior_fellow" in user_roles {% endcomment %}
{% if "edadmin" in user_roles %} {% if is_ed_admin %}
<div class="col-12 col-md mb-3"> <div class="col-12 col-md mb-3">
<details class="card"> <details class="card">
<summary class="card-header d-flex flex-row justify-content-between list-triangle"> <summary class="card-header d-flex flex-row justify-content-between list-triangle">
...@@ -129,16 +132,22 @@ ...@@ -129,16 +132,22 @@
</div> </div>
</div> </div>
<details {% if not nomination.invitation %}open{% endif %} class="card mb-3"> {% if nomination.voting_rounds.exists or perms.scipost.can_manage_college_composition %}
<summary class="card-header list-triangle">Voting Rounds</summary> <details
<div class="card-body"> {% if not nomination.invitation or 'edadmin' not in user_roles %}open{% endif %}
<div hx-get="{% url 'colleges:_hx_nomination_voting_rounds_tab' nomination_id=nomination.id round_id=nomination.latest_voting_round.id|default:0 %}" class="card mb-3">
hx-trigger="intersect once"></div> <summary class="card-header list-triangle">Voting Rounds</summary>
</div> <div class="card-body">
</details> <div hx-get="{% url 'colleges:_hx_nomination_voting_rounds_tab' nomination_id=nomination.id round_id=nomination.latest_voting_round.id|default:0 %}"
hx-trigger="intersect once"></div>
</div>
</details>
{% endif %}
{% if "edadmin" in user_roles and nomination.decision.outcome == 'elected' %} {% if is_ed_admin and nomination.decision.outcome == 'elected' %}
<details {% if nomination.invitation %}open{% endif %} class="card"> <details
{% if nomination.invitation %}open{% endif %}
class="card">
<summary class="card-header d-flex flex-row justify-content-between list-triangle"> <summary class="card-header d-flex flex-row justify-content-between list-triangle">
<div>Invitation</div> <div>Invitation</div>
<div>{{ nomination.invitation.get_response_display }}</div> <div>{{ nomination.invitation.get_response_display }}</div>
......
<div class="row"> <h3>Cast your vote:</h3>
<div class="col-12 col-md">
<h3>Cast your vote:</h3>
{% for vote_option, color in vote_options %} {% for vote_option, color in vote_options %}
<form hx-post="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" <form hx-post="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}"
hx-target="#nomination-{{ voting_round.nomination.id }}-vote"> hx-target="#nomination-{{ voting_round.nomination.id }}-vote">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="vote" value="{{ vote_option }}" /> <input type="hidden" name="vote" value="{{ vote_option }}" />
<button class="btn d-flex justify-content-between align-items-center w-100 mb-2 bg-{{ color }} text-white"> <button class="btn d-flex justify-content-between align-items-center w-100 mb-2 bg-{{ color }} text-white">
<div>{{ vote_option|title }}</div> <div>{{ vote_option|title }}</div>
{% if vote_object.vote == vote_option %} {% if vote_object.vote == vote_option %}
{% include 'bi/check-square-fill.html' %} {% include 'bi/check-square-fill.html' %}
{% endif %} {% endif %}
</button> </button>
</form> </form>
{% endfor %} {% endfor %}
</div>
</div>
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
hx-trigger="intersect once"></div> hx-trigger="intersect once"></div>
</div> </div>
<div class="col-auto d-flex flex-column justify-content-between"> <div class="col-12 col-md-auto d-flex flex-column justify-content-between">
{% if not voting_round.is_closed %} {% if not voting_round.is_closed %}
...@@ -42,10 +42,9 @@ ...@@ -42,10 +42,9 @@
</button> </button>
</div> </div>
{% elif session_fellowship and session_fellowship in voting_round.eligible_to_vote.all %} {% elif session_fellowship and session_fellowship in voting_round.eligible_to_vote.all and voting_round.is_open %}
<div id="nomination-{{ voting_round.nomination.id }}-vote" <div id="nomination-{{ voting_round.nomination.id }}-vote"
class="col-12 col-md-4"
hx-get="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}" hx-get="{% url 'colleges:_hx_nomination_vote' voting_round_id=voting_round.id %}"
hx-trigger="intersect once"></div> hx-trigger="intersect once"></div>
......
...@@ -1060,6 +1060,14 @@ def _hx_nomination_vote(request, voting_round_id): ...@@ -1060,6 +1060,14 @@ def _hx_nomination_vote(request, voting_round_id):
pk=voting_round_id, pk=voting_round_id,
eligible_to_vote=fellowship, eligible_to_vote=fellowship,
) )
# Check if the voting round is still open
if not voting_round.is_open:
return HTMXResponse(
"""You cannot vote in non-open rounds.""",
tag="danger",
)
vote_options_with_color = [ vote_options_with_color = [
(FellowshipNominationVote.VOTE_AGREE, "success"), (FellowshipNominationVote.VOTE_AGREE, "success"),
(FellowshipNominationVote.VOTE_ABSTAIN, "warning"), (FellowshipNominationVote.VOTE_ABSTAIN, "warning"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment