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

[7941]disable new projects #2675

Merged
merged 2 commits into from
Jan 16, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ coverage.xml
venv/
/pyvenv.cfg
/pip-selfcheck.json
.python-version

# Node
node_modules/
Expand Down
4 changes: 4 additions & 0 deletions euth/dashboard/templates/euth_dashboard/dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
<ul class="dropdown-menu" aria-labelledby="dLabel">
{% for organisation in orgs %}
<li>
{% if user.is_superuser %}
<a href="{% url 'a4dashboard:project-list' organisation_slug=organisation.slug %}" class="dropdown-item">{{ organisation.name }}</a>
{% else %}
<a href="{% url 'a4dashboard:organisation-edit' organisation_slug=organisation.slug %}" class="dropdown-item">{{ organisation.name }}</a>
{% endif %}
</li>
{% endfor %}
</ul>
Expand Down
24 changes: 23 additions & 1 deletion euth/dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
from django.urls import re_path

from adhocracy4.dashboard.urls import urlpatterns as a4dashboard_urlpatterns
from euth.dashboard import views
from euth.organisations.views import DashboardOrganisationUpdateView

app_name = 'a4dashboard'

urlpatterns = [
re_path(r'^organisations/(?P<organisation_slug>[-\w_]+)/settings/$',
DashboardOrganisationUpdateView.as_view(),
name='organisation-edit')
name='organisation-edit'),
re_path(
r"^organisations/(?P<organisation_slug>[-\w_]+)/blueprints/$",
views.BlueprintAdminListView.as_view(),
name="blueprint-list",
),
re_path(
r"^organisations/(?P<organisation_slug>[-\w_]+)/projects/$",
views.ProjectAdminListView.as_view(),
name="project-list",
),
re_path(
r"^organisations/(?P<organisation_slug>[-\w_]+)/blueprints/"
r"(?P<blueprint_slug>[-\w_]+)/$",
views.ProjectAdminCreateView.as_view(),
name="project-create",
),
re_path(
r"^publish/project/(?P<project_slug>[-\w_]+)/$",
views.ProjectAdminPublishView.as_view(),
name="project-publish",
),
] + a4dashboard_urlpatterns
28 changes: 28 additions & 0 deletions euth/dashboard/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from adhocracy4.dashboard.views import BlueprintListView
from adhocracy4.dashboard.views import ProjectCreateView
from adhocracy4.dashboard.views import ProjectListView
from adhocracy4.dashboard.views import ProjectPublishView


class ProjectAdminListView(ProjectListView):
"""Only admins can view dashboard"""

permission_required = "euth_projects.add_project"


class ProjectAdminCreateView(ProjectCreateView):
"""Only admins can create new projects"""

permission_required = "euth_projects.add_project"


class ProjectAdminPublishView(ProjectPublishView):
"""Only admins can publish new projects"""

permission_required = "euth_projects.change_project"


class BlueprintAdminListView(BlueprintListView):
"""Only admins can view list of blueprints"""

permission_required = "euth_projects.add_project"
6 changes: 6 additions & 0 deletions euth/projects/rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import rules
from rules.predicates import is_superuser

rules.add_perm("euth_projects.add_project", is_superuser)

rules.add_perm("euth_projects.change_project", is_superuser)
4 changes: 4 additions & 0 deletions euth/users/templates/euth_users/indicator_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

{% for organisation in request.user.organisations %}
<li>
{% if request.user.is_superuser %}
<a href="{% url 'a4dashboard:project-list' organisation_slug=organisation.slug %}" class="dropdown-item">
{% else %}
<a href="{% url 'a4dashboard:organisation-edit' organisation_slug=organisation.slug %}" class="dropdown-item">
{% endif %}
<img src="{{ organisation.logo|thumbnail_url:'org_avatar_small' }}" alt="" width="20"><span class="dropdown-text">{{ organisation.name }}</span>
</a>
</li>
Expand Down
2 changes: 2 additions & 0 deletions euth_wagtail/templates/a4dashboard/base_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<ul class="dashboard-header-tabs nav nav-tabs float-end" role="tablist">
{% url 'a4dashboard:organisation-edit' organisation_slug=view.organisation.slug as organisation_edit_url %}
<li role="presentation" class="dashboard-header-tab {% if not request.get_full_path == organisation_edit_url %} active {% endif %}">
{% if request.user.is_superuser %}
<a href="{% url 'a4dashboard:project-list' organisation_slug=view.organisation.slug %}" class="nav-link dashboard-header-link" aria-controls="projects" role="presentation" >{% trans 'Projects' %}</a>
{% endif %}
</li>
<li role="presentation" class="dashboard-header-tab {% if request.get_full_path == organisation_edit_url %} active {% endif %}">
<a href="{{ organisation_edit_url }}" class="nav-link dashboard-header-link" aria-controls="organisation" role="presentation" >{% trans 'Organisation' %}</a>
Expand Down
18 changes: 10 additions & 8 deletions euth_wagtail/templates/a4dashboard/blueprint_list.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
{% extends "a4dashboard/base_dashboard.html" %}
{% load i18n static %}

{% block title %}{% trans "New Project" %} &mdash; {{ block.super }}{% endblock%}
{% if user.is_superuser %}
{% block title %}{% translate "New Project" %} &mdash; {{ block.super }}{% endblock%}
{% endif %}

{% block dashboard_content %}
<div class="container dashboard-content row">
<div class="col-md-10 offset-md-1">
<h1 class="dashboard-content-heading">
{% trans "What kind of project would you like to create?" %}
{% translate "What kind of project would you like to create?" %}
</h1>

<div class="blueprint-list">

<div class="dst-tile">
<img src="{% static 'images/placeholder_transparent.png' %}" alt="Decision support tool">
<h2 class="sans-serif h4">{% trans 'Not sure which template?' %}</h2>
<h2 class="sans-serif h4">{% translate 'Not sure which template?' %}</h2>
<div class="dst-description">
<h3 class="h5">{% trans "Try the Decision Support Tool (DST)!" %}</h3>
{% trans "In just three minutes you'll find out which process suits your needs. It's easy." %}
<h3 class="h5">{% translate "Try the Decision Support Tool (DST)!" %}</h3>
{% translate "In just three minutes you'll find out which process suits your needs. It's easy." %}
</div>

<div class="dst-footer">
<a href="{% url 'blueprints-form' organisation_slug=view.organisation.slug %}"
class="btn btn-primary">
{% trans 'Choose template'%}
{% translate 'Choose template'%}
</a>
</div>
</div>
Expand All @@ -46,10 +48,10 @@ <h2 class="sans-serif h4">{{ blueprint.title }}</h2>
<div class="blueprint-footer">
<a href="{% url 'a4dashboard:project-create' organisation_slug=view.organisation.slug blueprint_slug=blueprint_slug %}"
class="btn btn-primary">
{% trans 'use this template' %}
{% translate 'use this template' %}
</a>

<button class="btn-link" type="button" data-bs-toggle="modal" data-bs-target="#dst-infopage-{{ blueprint_slug }}">{% trans 'Learn More' %}</button>
<button class="btn-link" type="button" data-bs-toggle="modal" data-bs-target="#dst-infopage-{{ blueprint_slug }}">{% translate 'Learn More' %}</button>
</div>

{% include 'euth_blueprints/includes/infopage.html'%}
Expand Down
2 changes: 2 additions & 0 deletions euth_wagtail/templates/a4dashboard/project_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
{% block project_list %}
<div class="dashboard-content-header">
<h1 class="dashboard-content-left dashboard-content-heading">{% trans 'Projects' %}</h1>
{% if user.is_superuser %}
<div class="dashboard-content-right">
<a href="{% url 'a4dashboard:blueprint-list' organisation_slug=view.organisation.slug %}" class="btn btn-primary">
{% trans 'New Project' %}
</a>
</div>
{% endif %}
</div>

{% if project_list|length > 0 %}
Expand Down
29 changes: 6 additions & 23 deletions tests/dashboard/test_dashboard_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def test_initiator_list_projects(client, project):
'organisation_slug': project.organisation.slug,
})
response = client.get(url)
assert response.status_code == 200
assert project in list(response.context_data['project_list']) == [project]
assert response.status_code == 403


@pytest.mark.django_db
Expand All @@ -57,17 +56,8 @@ def test_initiator_create_project(client, organisation):
'blueprint_slug': 'brainstorming'
})
response = client.get(url)
assert response.status_code == 200

response = client.post(url, {
'name': 'Project name',
'description': 'Project info'
})
assert response.status_code == 302
assert redirect_target(response) == 'project-edit'
project = organisation.project_set.first()
assert project.is_draft
assert project.name == 'Project name'
# only admins can create new projects
assert response.status_code == 403


@pytest.mark.django_db
Expand Down Expand Up @@ -317,22 +307,15 @@ def test_dashboard_organisation_delete_language(client, organisation):
organisation.save()


'''
@pytest.mark.django_db
def test_dashboard_blueprint(client, organisation):
from euth.blueprints.blueprints import blueprints
user = organisation.initiators.first()
client.login(username=user.email, password='password')
url = reverse('a4dashboard:blueprint-list', kwargs={
'organisation_slug': organisation.slug
})
user = organisation.initiators.first()
response = client.get(url)
assert response.status_code == 302
assert redirect_target(response) == 'account_login'
client.login(username=user.email, password='password')
response = client.get(url)
assert response.status_code == 200
assert response.context_data['view'].blueprints == blueprints
'''
assert response.status_code == 403


@pytest.mark.django_db
Expand Down
Loading