Skip to content

Commit

Permalink
Merge branch 'main' into feature/passwordless-login-signup
Browse files Browse the repository at this point in the history
* main:
  Instruct prettier to ignore Sublime Text files. (#3569)
  Make it possible to control who, none/staff/staff admins, can export submissions (#3561)
  Add colour to review outcome displays and do not show "Avg. Score" if it is zero (0) (#3548)
  Add code-style checks to Github CI Actions (#3564)
  • Loading branch information
theskumar committed Sep 15, 2023
2 parents c8a7ecc + 425d5ee commit 6819898
Show file tree
Hide file tree
Showing 24 changed files with 942 additions and 829 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/hypha-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install python dependencies
run: pip install `grep "ruff" requirements-dev.txt`
- name: Run python linting
run: pip install `grep -E "ruff|djhtml|black" requirements-dev.txt`
- name: Run ruff
run: ruff --format github .
- name: Run black
run: black . --check
- name: Run djhtml
run: djhtml hypha/ --check

test-be:
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@ media/**
.venv/**
venv/**

# Ignore node files
node_modules/**

# Ignore htmlcov files
htmlcov/**

# Ignore Sublime Text files.
*.sublime-project
*.sublime-workspace
1,620 changes: 830 additions & 790 deletions .test_durations

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fmt:
python -m ruff --fix .
python -m black .
npx prettier . --write
djhtml hypha/

.PHONY: cov-html
cov-html:
Expand All @@ -52,9 +53,10 @@ lint:
@echo "Checking python code style with ruff"
ruff .
black . --check
@echo "Checking html file indendation."
djhtml hypha/ --check
@echo "Checking js and css code style."
npm run lint
npx prettier . --check


.PHONY: lint-fix
Expand Down
12 changes: 12 additions & 0 deletions docs/setup/administrators/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ Good for testing, might not be a good idea in production.

SUBMISSIONS_DRAFT_ACCESS_STAFF = env.bool('SUBMISSIONS_DRAFT_ACCESS_STAFF', False)

### Should staff admins be able to access/see draft submissions.

SUBMISSIONS_DRAFT_ACCESS_STAFF_ADMIN = env.bool('SUBMISSIONS_DRAFT_ACCESS_STAFF_ADMIN', False)

### Should staff be able to export submissions.

SUBMISSIONS_EXPORT_ACCESS_STAFF = env.bool('SUBMISSIONS_EXPORT_ACCESS_STAFF', True)

### Should staff admins be able to export submissions.

SUBMISSIONS_EXPORT_ACCESS_STAFF_ADMIN = env.bool('SUBMISSIONS_EXPORT_ACCESS_STAFF_ADMIN', True)

### Columns to exclude from the submission tables.

Possible values are: fund, round, status, lead, reviewers, screening_statuses, category_options, meta_terms, organization_name
Expand Down
2 changes: 1 addition & 1 deletion hypha/apply/dashboard/templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{% endif %}

{% if rounds.closed or rounds.open %}
{% include "funds/includes/round-block.html" with closed_rounds=rounds.closed open_rounds=rounds.open title="Your rounds and labs" page_type='dashboard' %}
{% include "funds/includes/round-block.html" with can_export=can_export closed_rounds=rounds.closed open_rounds=rounds.open title="Your rounds and labs" page_type='dashboard' %}
{% endif %}

{% if paf_waiting_for_approval.count %}
Expand Down
2 changes: 2 additions & 0 deletions hypha/apply/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ReviewerSettings,
RoundsAndLabs,
)
from hypha.apply.funds.permissions import can_export_submissions
from hypha.apply.funds.tables import (
ReviewerSubmissionsTable,
SubmissionFilterAndSearch,
Expand Down Expand Up @@ -87,6 +88,7 @@ def get_context_data(self, **kwargs):
{
"active_invoices": self.active_invoices(),
"awaiting_reviews": self.awaiting_reviews(submissions),
"can_export": can_export_submissions(self.request.user),
"my_reviewed": self.my_reviewed(submissions),
"projects": self.projects(),
"paf_waiting_for_approval": self.paf_waiting_for_approval(),
Expand Down
8 changes: 8 additions & 0 deletions hypha/apply/funds/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def can_access_drafts(user):
return False


def can_export_submissions(user):
if user.is_apply_staff and settings.SUBMISSIONS_EXPORT_ACCESS_STAFF:
return True
if user.is_apply_staff_admin and settings.SUBMISSIONS_EXPORT_ACCESS_STAFF_ADMIN:
return True
return False


def is_user_has_access_to_view_submission(user, submission):
if not user.is_authenticated:
return False, "Login Required"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
<span>
{{ recommendation|traffic_light }}
</span>
<span class="font-medium">
{% trans 'Avg. Score'%}: {{assigned_reviewers|average_review_score|floatformat:'1'}}
</span>
{% with assigned_reviewers|average_review_score as average %}
<span class="font-medium">
{{ assigned_reviewers|average_review_score }}
</span>
{% endwith %}
</div>

<ul class="reviews-sidebar mt-4" x-data='{showHiddenReviewers: false}'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
{% if reviewer.role %}{% image reviewer.role.icon max-12x12 %}{% endif %}
</div>
{% endif %}
<div>{{ reviewer.review.get_recommendation_display }}</div>
<div>{{ reviewer.review.get_score_display }}</div>
{% with reviewer.review.get_recommendation_display as recommendation and reviewer.review.get_score_display as score %}
<div class="{{ recommendation|slugify }}">{{ recommendation }}</div>
<div class="{{ recommendation|slugify }}">{{ score }}</div>
{% endwith %}
{% endif %}
</li>

Expand All @@ -45,7 +47,7 @@
{% endwith %}
</div>
<div></div>
<div class="reviews-sidebar__outcome {{ opinion.get_opinion_display|lower }}">{{ opinion.get_opinion_display}}</div>
<div class="reviews-sidebar__outcome {{ opinion.get_opinion_display|slugify }}">{{ opinion.get_opinion_display}}</div>
</li>
{% if forloop.last %}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
{% endif %}
</p>
<a class="round-block__view" href="{% url 'apply:rounds:detail' pk=round.pk %}">{% trans 'View' %}</a>
<a class="round-block__view" href="{% url 'apply:rounds:export' pk=round.pk %}">{% trans 'Export' %}</a>
{% if can_export %}
<a class="round-block__view" href="{% url 'apply:rounds:export' pk=round.pk %}">{% trans 'Export' %}</a>
{% endif %}
</li>
{% else %}
<li class="round-block__item round-block__item--more">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h4 class="heading heading--normal heading--no-margin">{{ title }}</a></h4>
{% if page_type == 'dashboard' %}
{% include "funds/includes/no_round_block_dashboard.html" with rounds=open_rounds display_text="Open until" query=open_query type="Open" %}
{% else %}
{% include "funds/includes/round-block-listing.html" with rounds=open_rounds display_text="Open until" query=open_query type="Open" %}
{% include "funds/includes/round-block-listing.html" with can_export=can_export rounds=open_rounds display_text="Open until" query=open_query type="Open" %}
{% endif %}
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{% include "funds/includes/status-block.html" with type="Applications" %}

{% if closed_rounds or open_rounds %}
{% include "funds/includes/round-block.html" with closed_rounds=closed_rounds open_rounds=open_rounds title=rounds_title page_type='submission' %}
{% include "funds/includes/round-block.html" with can_export=can_export closed_rounds=closed_rounds open_rounds=open_rounds title=rounds_title page_type='submission' %}
{% endif %}

{% block table %}
Expand Down
10 changes: 8 additions & 2 deletions hypha/apply/funds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
from .permissions import (
can_access_archived_submissions,
can_access_drafts,
can_export_submissions,
has_permission,
)
from .tables import (
Expand Down Expand Up @@ -432,6 +433,7 @@ def get_context_data(self, **kwargs):
base_query = (
RoundsAndLabs.objects.with_progress().active().order_by("-end_date")
)
can_export = can_export_submissions(self.request.user)
open_rounds = base_query.open()[:limit]
open_query = "?round_state=open"
closed_rounds = base_query.closed()[:limit]
Expand Down Expand Up @@ -465,6 +467,7 @@ def get_context_data(self, **kwargs):
return super().get_context_data(
open_rounds=open_rounds,
open_query=open_query,
can_export=can_export,
closed_rounds=closed_rounds,
closed_query=closed_query,
rounds_title=rounds_title,
Expand Down Expand Up @@ -582,8 +585,8 @@ def test_func(self):
return self.request.user.is_apply_staff or self.request.user.is_reviewer


@method_decorator(staff_required, name="dispatch")
class ExportSubmissionsByRound(BaseAdminSubmissionsTable):
@method_decorator(login_required, name="dispatch")
class ExportSubmissionsByRound(UserPassesTestMixin, BaseAdminSubmissionsTable):
def export_submissions(self, round_id):
csv_stream = StringIO()
writer = csv.writer(csv_stream)
Expand Down Expand Up @@ -632,6 +635,9 @@ def get(self, request, pk):
response["Content-Disposition"] = "inline; filename=" + str(self.obj) + ".csv"
return response

def test_func(self):
return can_export_submissions(self.request.user)


@method_decorator(staff_required, name="dispatch")
class SubmissionsByRound(BaseAdminSubmissionsTable, DelegateableListView):
Expand Down
2 changes: 1 addition & 1 deletion hypha/apply/review/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def get_comments_display(self, include_question=True):

@property
def get_score_display(self):
return "{:.1f}".format(self.score) if self.score != NA else "NA"
return "{:.1f}".format(self.score) if self.score != NA else "-"

def get_absolute_url(self):
return reverse(
Expand Down
10 changes: 5 additions & 5 deletions hypha/apply/review/templatetags/review_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django import template
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _

from ..models import MAYBE, NO, YES
from ..options import NA
Expand Down Expand Up @@ -54,8 +55,7 @@ def average_review_score(reviewers):
and not reviewer.review.score == NA
]
if len(scores) > 0:
return sum(scores) / len(scores)
else:
return 0
else:
return reviewers
return _("Avg. score: {average}").format(
average=round(sum(scores) / len(scores), 1)
)
return ""
9 changes: 7 additions & 2 deletions hypha/apply/templates/forms/includes/multi_input_field.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{% load heroicons %}
<div class="form__item{% if field.help_text %} form__group--wrap{% endif %}{% if field.errors %} form__error{% endif %}{% if not field.initial %} multi-input-field-hidden{% endif %}{% if is_application and field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}"{% if is_application and field.field.group_number > 1 %} data-hidden="{% if not show_all_group_fields %}true{% else %}false{% endif %}"{% endif %}" data-multi-field-for="{{ field.field.multi_input_id }}">
<div
class="form__item{% if field.help_text %} form__group--wrap{% endif %}{% if field.errors %} form__error{% endif %}{% if not field.initial %} multi-input-field-hidden{% endif %}{% if is_application and field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}"
{% if is_application and field.field.group_number > 1 %} data-hidden="{% if not show_all_group_fields %}true{% else %}false{% endif %}"{% endif %}
data-multi-field-for="{{ field.field.multi_input_id }}"
>
{{ field }}

{% if field.errors %}<h6 class="form__error-text">{{ field.errors.as_text|linebreaksbr }}</h6>{% endif %}
</div>

{% if field.field.multi_input_add_button %}
<button class="link link--button link--button--narrow multi-input-add-btn mt-2{% if is_application and field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}"
<button
class="link link--button link--button--narrow multi-input-add-btn mt-2{% if is_application and field.field.group_number > 1 %} field-group field-group-{{ field.field.group_number }}{% endif %}"
type="button" data-multi-field-id="{{ field.field.multi_input_id }}"
data-multi-visibility-index="{{ field.field.visibility_index }}"
data-multi-max-index="{{ field.field.max_index }}"
Expand Down
8 changes: 8 additions & 0 deletions hypha/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@
"SUBMISSIONS_DRAFT_ACCESS_STAFF_ADMIN", False
)

# Should staff be able to export submissions.
SUBMISSIONS_EXPORT_ACCESS_STAFF = env.bool("SUBMISSIONS_EXPORT_ACCESS_STAFF", True)

# Should staff admins be able to export submissions.
SUBMISSIONS_EXPORT_ACCESS_STAFF_ADMIN = env.bool(
"SUBMISSIONS_EXPORT_ACCESS_STAFF_ADMIN", True
)

# Columns to exclude from the submission tables.
# Possible values are: fund, round, status, lead, reviewers, screening_statuses, category_options, meta_terms, organization_name
SUBMISSIONS_TABLE_EXCLUDED_FIELDS = env.list(
Expand Down
2 changes: 1 addition & 1 deletion hypha/static_src/src/sass/apply/components/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
@supports (display: grid) {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 5px;
gap: 5px;
}
}

Expand Down
8 changes: 4 additions & 4 deletions hypha/static_src/src/sass/apply/components/_grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
.grid {
display: grid;
margin-bottom: 1rem;
grid-gap: 10px;
gap: 10px;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));

> * {
Expand All @@ -39,7 +39,7 @@

&--two {
grid-template-columns: 100%;
grid-gap: 0.25rem;
gap: 0.25rem;

@include media-query(tablet-portrait) {
grid-template-columns: 1fr 1fr;
Expand All @@ -51,7 +51,7 @@

.form--comments & {
margin: 20px 0 0;
grid-gap: 10px;
gap: 10px;
grid-template-columns: 100px 100px;
}

Expand All @@ -70,7 +70,7 @@

&--proposal-info {
grid-template-columns: 100%;
grid-gap: 10px;
gap: 10px;
margin: 0 0 1rem;

@include media-query(mob-landscape) {
Expand Down
14 changes: 13 additions & 1 deletion hypha/static_src/src/sass/apply/components/_reviews-sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@supports (display: grid) {
display: grid;
grid-template-columns: 45% 25% 15% 15%;
grid-gap: 5px;
gap: 5px;
}

&--decision {
Expand Down Expand Up @@ -57,6 +57,18 @@
&.no-response {
color: $color--black-20;
}

.yes {
color: $color--green;
}

.maybe {
color: $color--mustard;
}

.no {
color: $color--tomato;
}
}

&__date {
Expand Down
2 changes: 1 addition & 1 deletion hypha/static_src/src/sass/public/components/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
@supports (display: grid) {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 5px;
gap: 5px;
}
}

Expand Down
Loading

0 comments on commit 6819898

Please sign in to comment.