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

Remove Labels func #195

Merged
merged 4 commits into from
Feb 29, 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
3 changes: 2 additions & 1 deletion embark/dashboard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
path('dashboard/log/<uuid:analysis_id>', views.show_log, name='embark-show-log'),
path('dashboard/logviewer/<uuid:analysis_id>', views.show_logviewer, name='embark-show-logviewer'),
path('dashboard/report/createlabel/', views.create_label, name='embark-dashboard-create-label'),
path('dashboard/report/addlabel/<uuid:analysis_id>', views.add_label, name='embark-dashboard-add-label')
path('dashboard/report/addlabel/<uuid:analysis_id>', views.add_label, name='embark-dashboard-add-label'),
path('dashboard/report/rmlabel/<uuid:analysis_id><str:label_name>', views.rm_label, name='embark-dashboard-remove-label'),
]
19 changes: 18 additions & 1 deletion embark/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from uploader.boundedexecutor import BoundedExecutor
from uploader.forms import LabelForm

from uploader.models import FirmwareAnalysis
from uploader.models import FirmwareAnalysis, Label
from dashboard.models import Result
from dashboard.forms import LabelSelectForm, StopAnalysisForm
from porter.views import make_zip
Expand Down Expand Up @@ -283,3 +283,20 @@ def add_label(request, analysis_id):
logger.error("label form invalid %s ", request.POST)
messages.error(request, 'Adding Label failed')
return redirect('..')


@csrf_protect
@require_http_methods(["POST"])
@login_required(login_url='/' + settings.LOGIN_URL)
def rm_label(request, analysis_id, label_name):
req_logger.info("User %s called rm label", request.user.username)

logger.info("User %s tryied to rm label %s", request.user.username, label_name)
# get analysis obj
analysis = FirmwareAnalysis.objects.get(id=analysis_id)
# get lobel obj
label_obj = Label.objects.get(label_name=label_name)
analysis.label.remove(label_obj)
analysis.save()
messages.info(request, 'removing successful of ' + str(label_name))
return redirect('..')
10 changes: 9 additions & 1 deletion embark/static/content/css/reportDashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ table.dataTable td, table.dataTable th {

.buttonRowElem {
margin: 2px;
}
}

.hidden {
display: none;
}

.label:hover form button, .label:focus form button {
display: block;
}
11 changes: 10 additions & 1 deletion embark/templates/dashboard/label.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{% load django_bootstrap5 %}

<form action="{% url 'embark-dashboard-add-label' firmware.id %}" method="post" id="form">
{% csrf_token %}
<div class="innerBlock">
{% load filters %}
{% bootstrap_form label_select_form %}
{% bootstrap_button "Add" button_type="submit" button_class="btn-primary" %}
</div>
</form>
<hr>
<form action="{% url 'embark-dashboard-create-label' %}" method="post" id="form">
{% csrf_token %}
<div class="innerBlock">
{% load filters %}
{% bootstrap_form label_form layout='grid' %}
{% bootstrap_button "Create" button_type="submit" button_class="btn-primary" %}
</div>
</form>
</form>
17 changes: 7 additions & 10 deletions embark/templates/dashboard/reportDashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@
{% if firmware.label.all is not None %}
{% for label in firmware.label.all %}
<div class="col-sm">
<button onclick="onclick_label('label={{ label.label_name }}');" class="label badge rounded-pill bg-info">{{ label.label_name }}</button>
<a onclick="onclick_label('label={{ label.label_name }}');" class="badge label bg-info position-relative" role="button">
{{ label.label_name }}
<form action={% url 'embark-dashboard-remove-label' firmware.id label.label_name %} method="post" id="remove-label-{{ label.label_name }}-{{ firmware.id }}">
{% csrf_token %}
<button type="submit" class="hidden position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">x</button>
</form>
</a>
</div>
{% endfor %}
{% endif %}
Expand Down Expand Up @@ -194,15 +200,6 @@ <h5 class="modal-title" id="AddLabelModal-{{ firmware.id }}-Label">Add Label to
</button>
</div>
<div class="modal-body">
<!-- TODO click select with all options-->
<form action="{% url 'embark-dashboard-add-label' firmware.id %}" method="post" id="form">
{% csrf_token %}
<div class="innerBlock">
{% load filters %}
{% bootstrap_form label_select_form %}
{% bootstrap_button "Add" button_type="submit" button_class="btn-primary" %}
</div>
</form>
{% block label %}{% include "dashboard/label.html" %}{% endblock label %}
</div>
<div class="modal-footer">
Expand Down
2 changes: 1 addition & 1 deletion embark/uploader/boundedexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
semaphore = BoundedSemaphore(MAX_QUEUE)

# emba directories
EMBA_SCRIPT_LOCATION = f"cd {settings.EMBA_ROOT} && sudo ./emba"
EMBA_SCRIPT_LOCATION = f"cd {settings.EMBA_ROOT} && sudo -E ./emba"


class BoundedException(Exception):
Expand Down
4 changes: 3 additions & 1 deletion installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,14 @@ install_embark_dev(){
# install pipenv
pip3 install pipenv

#Add user nosudo
# Add user nosudo
echo "${SUDO_USER:-${USER}}"" ALL=(ALL) NOPASSWD: ""${PWD}""/emba/emba" | EDITOR='tee -a' visudo
echo "${SUDO_USER:-${USER}}"" ALL=(ALL) NOPASSWD: /bin/pkill" | EDITOR='tee -a' visudo
echo "root ALL=(ALL) NOPASSWD: ""${PWD}""/emba/emba" | EDITOR='tee -a' visudo
echo "root ALL=(ALL) NOPASSWD: /bin/pkill" | EDITOR='tee -a' visudo

# Set some globals
echo "NO_UPDATE_CHECK=1" >> /etc/environment

#pipenv
MYSQLCLIENT_LDFLAGS='-L/usr/mysql/lib -lmysqlclient -lssl -lcrypto -lresolv' MYSQLCLIENT_CFLAGS='-I/usr/include/mysql/' PIPENV_VENV_IN_PROJECT=1 pipenv install --dev
Expand Down
Loading