Skip to content

Commit

Permalink
Merge pull request #2734 from carpentries/feature/2260-allow-admins-t…
Browse files Browse the repository at this point in the history
…o-see-upcoming-teaching-opportunities

Allow admins to see upcoming teaching opportunities
  • Loading branch information
pbanaszkiewicz authored Jan 8, 2025
2 parents 95640d2 + 2539273 commit f5198fc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
39 changes: 39 additions & 0 deletions amy/dashboard/tests/test_instructor_recruitment_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ def test_view_enabled__community_role_active(self):
self.assertEqual(role.is_active(), True)
self.assertEqual(view.get_view_enabled(request), True)

@override_settings(FLAGS={"INSTRUCTOR_RECRUITMENT": [("boolean", True)]})
def test_view_enabled__admin(self):
# Arrange
request = RequestFactory().get("/")
person = Person.objects.create(
personal="Test", family="User", email="[email protected]", is_superuser=True
)
request.user = person
# Act
view = UpcomingTeachingOpportunitiesList(request=request)
# Assert
self.assertEqual(view.get_view_enabled(request), True)

def test_get_queryset(self):
# Arrange
host = Organization.objects.create(domain="test.com", fullname="Test")
Expand Down Expand Up @@ -265,6 +278,19 @@ def test_view_enabled__community_role_active(self):
self.assertEqual(role.is_active(), True)
self.assertEqual(view.get_view_enabled(request), True)

@override_settings(FLAGS={"INSTRUCTOR_RECRUITMENT": [("boolean", True)]})
def test_view_enabled__admin(self):
# Arrange
request = RequestFactory().get("/")
person = Person.objects.create(
personal="Test", family="User", email="[email protected]", is_superuser=True
)
request.user = person
# Act
view = SignupForRecruitment(request=request)
# Assert
self.assertEqual(view.get_view_enabled(request), True)

def test_get_context_data(self):
# Arrange
host = Organization.objects.create(domain="test.com", fullname="Test")
Expand Down Expand Up @@ -581,6 +607,19 @@ def test_view_enabled__community_role_active(self):
self.assertEqual(role.is_active(), True)
self.assertEqual(view.get_view_enabled(request), True)

@override_settings(FLAGS={"INSTRUCTOR_RECRUITMENT": [("boolean", True)]})
def test_view_enabled__admin(self):
# Arrange
request = RequestFactory().get("/")
person = Person.objects.create(
personal="Test", family="User", email="[email protected]", is_superuser=True
)
request.user = person
# Act
view = ResignFromRecruitment(request=request)
# Assert
self.assertEqual(view.get_view_enabled(request), True)

def test_get_queryset(self):
# Arrange
host = Organization.objects.create(domain="test.com", fullname="Test")
Expand Down
9 changes: 9 additions & 0 deletions amy/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ def get_queryset(self):
return super().get_queryset()

def get_view_enabled(self, request) -> bool:
if request.user.is_admin:
return True

try:
role = CommunityRole.objects.get(
person=self.request.user, config__name="instructor"
Expand Down Expand Up @@ -438,6 +441,9 @@ class SignupForRecruitment(
template_name = "dashboard/signup_for_recruitment.html"

def get_view_enabled(self, request) -> bool:
if request.user.is_admin:
return True

try:
role = CommunityRole.objects.get(
person=self.request.user, config__name="instructor"
Expand Down Expand Up @@ -563,6 +569,9 @@ def post(self, request, *args, **kwargs):
return redirect(redirect_url)

def get_view_enabled(self, request) -> bool:
if request.user.is_admin:
return True

try:
role = CommunityRole.objects.get(
person=self.request.user, config__name="instructor"
Expand Down
6 changes: 4 additions & 2 deletions amy/templates/dashboard/instructor_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

{% flag_enabled 'INSTRUCTOR_RECRUITMENT' as INSTRUCTOR_RECRUITMENT_ENABLED %}
{% get_community_role user role_name="instructor" as INSTRUCTOR_COMMUNITY_ROLE %}
{% if INSTRUCTOR_RECRUITMENT_ENABLED and INSTRUCTOR_COMMUNITY_ROLE.is_active %}
<a href="{% url 'upcoming-teaching-opportunities' %}" class="btn btn-primary btn-lg my-3">View upcoming teaching opportunities with The Carpentries</a>
{% if INSTRUCTOR_RECRUITMENT_ENABLED %}
{% if INSTRUCTOR_COMMUNITY_ROLE.is_active or user.is_admin %}
<a href="{% url 'upcoming-teaching-opportunities' %}" class="btn btn-primary btn-lg my-3">View upcoming teaching opportunities with The Carpentries</a>
{% endif %}
{% endif %}

<div>
Expand Down
1 change: 1 addition & 0 deletions amy/templates/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<div class="dropdown-divider"></div>
{% if user.is_superuser %}
<a class="dropdown-item" href="{% url 'admin:index' %}">Django Admin</a>
<a class="dropdown-item" href="{% url 'instructor-dashboard' %}">Instructor dashboard</a>
{% endif %}
<a class="dropdown-item" href="{% url 'feature_flags' %}">Feature flags</a>
<div class="dropdown-divider"></div>
Expand Down
6 changes: 4 additions & 2 deletions amy/templates/navigation_instructor_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

{% flag_enabled 'INSTRUCTOR_RECRUITMENT' as INSTRUCTOR_RECRUITMENT_ENABLED %}
{% get_community_role user role_name="instructor" as INSTRUCTOR_COMMUNITY_ROLE %}
{% if INSTRUCTOR_RECRUITMENT_ENABLED and INSTRUCTOR_COMMUNITY_ROLE.is_active %}
{% navbar_element "Upcoming Teaching Opportunities" "upcoming-teaching-opportunities" %}
{% if INSTRUCTOR_RECRUITMENT_ENABLED %}
{% if INSTRUCTOR_COMMUNITY_ROLE.is_active or user.is_admin %}
{% navbar_element "Upcoming Teaching Opportunities" "upcoming-teaching-opportunities" %}
{% endif %}
{% endif %}
</ul>

Expand Down

0 comments on commit f5198fc

Please sign in to comment.