Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #121 from scaleoutsystems/feature/STACKN-51
Browse files Browse the repository at this point in the history
Added possibility to change model's access level after creation.
  • Loading branch information
stefanhellander authored Aug 6, 2020
2 parents 34d0c3d + 13527e8 commit a99cf66
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
34 changes: 34 additions & 0 deletions components/studio/models/templates/models_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@ <h2>{{ model.name }}</h2>
{% endif %}
</div>
</div>
<form method="POST" action="{% url 'models:change_access' request.user model.project.slug model.id %}">
{% csrf_token %}

<div class="d-flex bd-highlight mb-3 col-md-6">
<label for="id_access" class="p-2 bd-highlight" style="font-weight: bold;">
Visibility
</label>
<select id="id_access" type="text" name="access" maxlength="2" required
class="ml-auto form-control form-control-sm" style="width: 20%;">
<option selected>
{% if model.access == 'PR' %}
Private
{% elif model.access == 'PU' %}
Public
{% else %}
Limited
{% endif %}
</option>
{% for choice in model_access_choices %}
{% if choice == 'PR' %}
<option value="PR">Private</option>
{% elif choice == 'PU' %}
<option value="PU">Public</option>
{% else %}
<option value="LI">Limited</option>
{% endif %}
{% endfor%}
</select>
</div>
<div class="d-flex bd-highlight mb-3 col-md-6"
style="border-top: 1px solid #dee2e6; padding-top: 20px;">
<button type="submit" class="ml-auto btn btn-primary">Save</button>
</div>
</form>
</div>
<div class="tab-pane fade" id="deployments" role="tabpanel" aria-labelledby="profile-tab">
{% if deployments %}
Expand Down
1 change: 1 addition & 0 deletions components/studio/models/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
path('<user>/<project>/models/<int:id>', views.details, name='details'),
path('models/<int:id>', views.details_public, name='details_public'),
path('<user>/<project>/models/<int:id>/delete', views.delete, name='delete'),
path('<user>/<project>/models/<int:id>/access', views.change_access, name='change_access'),
]
16 changes: 16 additions & 0 deletions components/studio/models/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,26 @@ def create(request, user, project):
return render(request, template, locals())


@login_required(login_url='/accounts/login')
def change_access(request, user, project, id):
model = Model.objects.filter(pk=id).first()

if request.method == 'POST':
visibility = request.POST.get('access', '')
if visibility != model.access:
model.access = visibility
model.save()

return HttpResponseRedirect(
reverse('models:details', kwargs={'user': user, 'project': project, 'id': id}))


@login_required(login_url='/accounts/login')
def details(request, user, project, id):
project = Project.objects.filter(slug=project).first()
model = Model.objects.filter(id=id).first()
model_access_choices = ['PU', 'PR', 'LI']
model_access_choices.remove(model.access)
deployments = DeploymentInstance.objects.filter(model=model)

report_generators = ReportGenerator.objects.filter(project=project)
Expand Down

0 comments on commit a99cf66

Please sign in to comment.