Skip to content

Commit

Permalink
Merge pull request #585 from rdmorganiser/dev-1.9.2/572-import-parent…
Browse files Browse the repository at this point in the history
…-permissions

Fix #572 Import parent permissions
  • Loading branch information
jochenklar authored Feb 23, 2023
2 parents 28809d6 + a01ecfd commit 77b1f79
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load rules %}
{% load projects_tags %}

{% if can_change_project %}
Expand All @@ -13,13 +14,19 @@
{% for node in project_tree %}
<li>
{% projects_indent node.level %}
<a href="{% url 'project' node.id %}">
{% if node.id == project.id %}
<strong>{{ node.title }}</strong>
{% else %}
{{ node.title }}
{% endif %}
</a>

{% has_perm 'projects.view_project_object' request.user node as can_view_parent_project %}
{% if can_view_parent_project %}
<a href="{% url 'project' node.id %}">
{% if node.id == project.id %}
<strong>{{ node.title }}</strong>
{% else %}
{{ node.title }}
{% endif %}
</a>
{% else %}
{{ node.title }}
{% endif %}
</li>
{% endfor %}
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ <h2 id="import-project">{% trans 'Import values' %}</h2>
{% url 'project_update_import' project.id as upload_url %}
{% include 'core/upload_form.html' with upload_url=upload_url label=True %}
</li>
{% if settings.NESTED_PROJECTS and project.get_ancestors %}
{% if settings.NESTED_PROJECTS and ancestors_import %}
<li>
<p>
<strong>{% trans 'Import from parent project' %}</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<input type="hidden" name="method" value="import_project">

<select class="form-control" name="source">
{% for project in project.get_ancestors %}
{% for project in ancestors_import %}
<option value="{{ project.id }}">{{ project.title }}</option>
{% endfor %}
</select>
Expand Down
6 changes: 5 additions & 1 deletion rdmo/projects/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@ def get_context_data(self, **kwargs):
.filter_catalog(self.object.catalog) \
.filter_group(self.request.user) \
.filter_availability(self.request.user).exists()
ancestors_import = []
for instance in ancestors.exclude(id=project.id):
if self.request.user.has_perm('projects.view_project_object', instance):
ancestors_import.append(instance)
context['ancestors_import'] = ancestors_import
context['memberships'] = memberships.order_by('user__last_name', '-project__level')
context['integrations'] = integrations.order_by('provider_key', '-project__level')
context['providers'] = get_plugins('PROJECT_ISSUE_PROVIDERS')
context['issues'] = [issue for issue in project.issues.all() if issue.resolve(values)]
context['snapshots'] = project.snapshots.all()
context['invites'] = project.invites.all()
context['membership'] = Membership.objects.filter(project=project, user=self.request.user).first()

return context


Expand Down

0 comments on commit 77b1f79

Please sign in to comment.