Skip to content

Commit

Permalink
Devel (#43)
Browse files Browse the repository at this point in the history
* Add hostname field validation

* Add management of managed services

* Add configurable upload path

* Move high-level css and js files

* Set max service description length

* Change default upload folder
  • Loading branch information
maricaantonacci authored Dec 11, 2022
1 parent e1d39c9 commit 8482164
Show file tree
Hide file tree
Showing 19 changed files with 897 additions and 292 deletions.
8 changes: 7 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def inject_settings():
'FEATURE_PORTS_REQUEST') else "no",
enable_s3creds=app.config.get('FEATURE_S3CREDS_MENU') if app.config.get(
'FEATURE_S3CREDS_MENU') else "no",
s3_allowed_groups=app.config.get("S3_IAM_GROUPS") if app.config.get("S3_IAM_GROUPS") else []
s3_allowed_groups=app.config.get("S3_IAM_GROUPS") if app.config.get("S3_IAM_GROUPS") else [],
enable_access_request=app.config.get("FEATURE_ACCESS_REQUEST") if app.config.get(
'FEATURE_ACCESS_REQUEST') else "no",
access_request_tag=app.config.get("ACCESS_REQUEST_TAG")
)


Expand Down Expand Up @@ -134,6 +137,9 @@ def inject_settings():
from app.swift.routes import swift_bp
app.register_blueprint(swift_bp, url_prefix="/swift")

from app.services.routes import services_bp
app.register_blueprint(services_bp, url_prefix="/services")

if app.config.get("FEATURE_VAULT_INTEGRATION") == "yes":
from app.vault.routes import vault_bp
app.register_blueprint(vault_bp, url_prefix="/vault")
Expand Down
14 changes: 13 additions & 1 deletion app/deployments/templates/createdep.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ <h4 class="font-weight-bold text-primary">
//console.log("ok");
port.removeClass("is-invalid");
}

}

function validateCidr(input){
Expand All @@ -235,7 +234,20 @@ <h4 class="font-weight-bold text-primary">
//console.log("ok");
cidr.removeClass("is-invalid");
}
}

function validateHostname(input){
var hostname = $(input)
//console.log("val: \"" + hostname.val() + "\"");
let val = hostname.val();
let re = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
if (!re.test(val)){
hostname.addClass("is-invalid");
}
else {
//console.log("ok");
hostname.removeClass("is-invalid");
}
}

function __attachValidationHandler(input) {
Expand Down
6 changes: 6 additions & 0 deletions app/deployments/templates/input_types.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
<input type="hidden" class="form-control" data-type="{{value.type}}" id="{{key}}" name="{{key}}" value="{{value.default}}" >
<!-- end hidden types -->

<!-- hostname type -->
{% elif value.type == "hostname" %}
<input type="text" class="form-control" onblur="validateHostname(this)" data-type="{{value.type}}" id="{{key}}" name="{{key}}" value="{{value.default}}" aria-describedby="help{{key}}" placeholder="{{value.placeholder}}" {% if value.required %}required{%endif%} {{mode}} />
<div class="invalid-feedback">Please provide a valid hostname</div>
<!-- end hostname type -->

<!-- email type -->
{% elif value.type == "email" %}
<input type="email" class="form-control" data-type="{{value.type}}" id="{{key}}" name="{{key}}" value="{{ session['useremail'] }}" {% if value.required %}required{%endif%} {{mode}} >
Expand Down
14 changes: 3 additions & 11 deletions app/home/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,11 @@ def home():

session['userrole'] = user.role # role

# templates_info = {}
# tg = False
#
# if tosca.tosca_gmetadata:
# templates_info = {k: v for (k, v) in tosca.tosca_gmetadata.items() if
# check_template_access(v.get("metadata").get("allowed_groups"), user_groups)}
# tg = True
# else:
# templates_info = {k: v for (k, v) in toscaInfo.items() if
# check_template_access(v.get("metadata").get("allowed_groups"), user_groups)}
services = dbhelpers.get_services(visibility='public')
services.extend(dbhelpers.get_services(visibility='private', groups=[session['active_usergroup']]))
templates_info, enable_template_groups = check_template_access(user_groups, session['active_usergroup'])

return render_template(app.config.get('PORTFOLIO_TEMPLATE'), templates_info=templates_info,
return render_template(app.config.get('PORTFOLIO_TEMPLATE'), services=services, templates_info=templates_info,
enable_template_groups=enable_template_groups)


Expand Down
15 changes: 12 additions & 3 deletions app/home/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<!-- Toggle -->
<link href="https://cdn.jsdelivr.net/gh/gitbrent/[email protected]/css/bootstrap4-toggle.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/gh/gitbrent/[email protected]/js/bootstrap4-toggle.min.js"></script>
<!-- include summernote css/js -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote-bs4.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote-bs4.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://unpkg.com/[email protected]/dist/bootstrap-show-password.min.js"></script>
<!-- FontAwesome-->
Expand Down Expand Up @@ -95,7 +98,7 @@
<ul class="navbar-nav mr-auto">
{% if session['username'] %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Deployments</a>
<a id="depMenuItem" class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Deployments</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="{{ url_for("deployments_bp.showdeploymentsoverview") }}">Overview</a>
<a class="dropdown-item" href="{{ url_for("deployments_bp.showdeployments") }}">List</a>
Expand Down Expand Up @@ -124,14 +127,20 @@
</li>
{% endif %}
{% if session['userrole'] == 'admin' %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('users_bp.show_users') }}">Users</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Admin</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="{{ url_for('users_bp.show_users') }}">Users</a>
<a class="dropdown-item" href="{{ url_for('services_bp.list_as_admin') }}">Services</a>
</div>
</li>
{% endif %}
{% endif %}
</ul>
{% if session['username'] %}
<ul class="navbar-nav ml-auto">
{% if session['active_usergroup'] != None and 'gets3creds' not in request.path and 'overview' not in request.path %}
<li class="nav-item dropdown">
<li id="groupMenuItem" class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">
{{ session['active_usergroup'] }}<span class="caret"></span>
</a>
Expand Down
57 changes: 57 additions & 0 deletions app/home/templates/managed_services.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<p class="font-weight-bold" style="font-size:20px;font-variant:small-caps">Centralised Services: </p>
{% for service in services %}
{% if loop.index % 3 == 1 %}
<!-- open card deck -->
<div id="card-deck" class="card-deck">
{% endif %}
<div class="card mb-4" style="max-width: 20rem; max-height: 25rem;">
<div class="card-body">
<h5 class="card-title text-center">
<strong>{{ service.name }}</strong>
</h5>
</div>
<div class="wrapper">
{% if service.icon != "" %}
<img class="card-img-bottom img-fluid" src="{{ url_for('services_bp.showimg', filename=service.icon) }}" alt="Card image cap">
{% else %}
<img class="card-img-bottom img-fluid" src="{{ url_for('services_bp.static', filename='images/default_service.png') }}" alt="Card image cap">
{% endif %}
</div>
<div class="card-img-overlay text-center" style="z-index: 1;">
<h5>
<strong>{{ service.name }}</strong>
</h5>
<div id="toscaDescription" class="card-text service-descr">
<small>{{ service.description | safe}}</small>
</div>
<div class="row justify-content-center mt-4">
<div class="col">
<a class="badge badge-pill badge-info text-left read_more" tabindex="0" data-toggle="popover" title="Full description" data-trigger="focus" data-html="true" data-content="{{ service.description }}">Read More</a>
</div>
{% if session['userrole'] == 'admin' and 'admin' in request.path %}
<div class="col">
<a href="{{ url_for('services_bp.edit', id=service.id) }}" class="badge badge-pill badge-warning">Edit</a>
</div>
<div class="col">
<form action="{{ url_for('services_bp.delete', id=service.id) }}" method="post">
<button type="submit" class="badge badge-pill badge-danger" style="border-width:0 !important;">Delete</button>
</form>
</div>
{% endif %}
<div class="col">
<a href="{{ service.url }}" target="_blank" class="badge badge-pill badge-primary">Go to service</a>
</div>
</div>
</div>
{% if service.visibility | enum2str == 'private' %}
<div class="card-footer" style="height: 40px;">
<small class="text-muted">Scope: {{ service.get_groups_list() | join(', ') }}</small>
</div> {% endif %}
</div>
{% if loop.index % 3 == 0 %} <!-- close card deck if it contains 3 cards -->
</div>
{% endif %}
{% endfor %}
{% if services|count % 3 != 0 %} <!-- close card deck if last row contains less then 3 cards -->
</div>
{% endif %}
Loading

0 comments on commit 8482164

Please sign in to comment.