start developing the control module
This commit is contained in:
parent
2a00e9ba0a
commit
b26a3548fc
16 changed files with 160 additions and 53 deletions
|
@ -1,5 +0,0 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ControlConfig(AppConfig):
|
||||
name = 'control'
|
11
src/c3nav/control/static/control/css/c3nav-control.css
Normal file
11
src/c3nav/control/static/control/css/c3nav-control.css
Normal file
|
@ -0,0 +1,11 @@
|
|||
body {
|
||||
font-size:16px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom:20px;
|
||||
}
|
||||
|
||||
.login .container {
|
||||
max-width:420px;
|
||||
}
|
|
@ -6,51 +6,24 @@
|
|||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>c3nav Administration</title>
|
||||
<title>c3nav control panel</title>
|
||||
{% compress css %}
|
||||
<link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'leaflet/leaflet.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'control/css/c3nav-control.css' %}" rel="stylesheet">
|
||||
{% endcompress %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body class="{% block bodyclass %}{% endblock %}">
|
||||
|
||||
<nav class="navbar navbar-default">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">c3nav Administration</a>
|
||||
</div>
|
||||
<div id="navbar" class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="{% url 'control.dashboard' %}">Dashboard</a></li>
|
||||
<li><a href="{% url 'control.editor' %}">Editor</a></li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li><a href="{% url 'admin:index' %}">Django Admin</a></li>
|
||||
<li><a href="{% url 'admin:logout' %}">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
<div class="container" id="main">
|
||||
<h1>c3nav control panel</h1>
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
{% compress js %}
|
||||
<script type="text/javascript" src="{% static 'jquery/jquery.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'leaflet/leaflet.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'leaflet/leaflet.editable.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'jquery/jquery.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'bootstrap/js/bootstrap.js' %}"></script>
|
||||
{% endcompress %}
|
||||
{% block addbottom %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
{% extends 'control/base.html' %}
|
||||
{% block content %}
|
||||
<h1>Dashboard</h1>
|
||||
{% endblock %}
|
24
src/c3nav/control/templates/control/login.html
Normal file
24
src/c3nav/control/templates/control/login.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% extends 'control/base.html' %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block bodyclass %}login{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<legend>{% trans 'Log in' %}</legend>
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary btn-block btn-lg">{% trans 'Log in' %}</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
<p>{% blocktrans %}This is the non-public backend for creation of auth tokens.{% endblocktrans %}</p>
|
||||
|
||||
<p><a class="btn btn-sm btn-default btn-block" href="{% url 'control.prove' %}">
|
||||
{% blocktrans %}Prove that you should have access{% endblocktrans %}
|
||||
</a></p>
|
||||
</form>
|
||||
{% endblock %}
|
41
src/c3nav/control/templates/control/prove.html
Normal file
41
src/c3nav/control/templates/control/prove.html
Normal file
|
@ -0,0 +1,41 @@
|
|||
{% extends 'control/base.html' %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block bodyclass %}login{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<legend>{% trans 'Prove access rights' %}</legend>
|
||||
<p>{% blocktrans %}Please enter a valid authentication code for the hosters of the following non-public map packages:{% endblocktrans %}</p>
|
||||
{% if success %}
|
||||
<div class="alert alert-success">
|
||||
<strong>{% trans 'Thanks – you get full access to the map!' %}</strong>
|
||||
</div>
|
||||
{% elif hosters %}
|
||||
{% if error %}
|
||||
<div class="alert alert-dismissible alert-danger">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<strong>{% trans 'Sorry.' %}</strong> {% trans 'One or more access tokens were not correct.' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for package in hosters %}
|
||||
<div class="form-group">
|
||||
<label for="hoster{{ forloop.counter0 }}">{{ package.name }}</label>
|
||||
<input type="password" class="form-control" id="hoster{{ forloop.counter0 }}" name="{{ package.name }}" placeholder="{% trans 'Access Token' %}">
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary btn-block btn-lg">{% trans 'Submit' %}</button>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-info">
|
||||
<strong>{% trans 'Sorry, this service is currently not available.' %}</strong>
|
||||
</div>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -1,7 +1,11 @@
|
|||
from django.conf.urls import url
|
||||
from django.contrib.auth import views as auth_views
|
||||
|
||||
from c3nav.control.views import dashboard
|
||||
from c3nav.control.views import dashboard, prove
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', dashboard, name='control.dashboard'),
|
||||
url(r'^prove/$', prove, name='control.prove'),
|
||||
url(r'^login/$', auth_views.login, {'template_name': 'control/login.html'}, name='site.login'),
|
||||
url(r'^logout/$', auth_views.logout, name='site.logout'),
|
||||
]
|
||||
|
|
|
@ -1,7 +1,40 @@
|
|||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import render
|
||||
|
||||
from c3nav.editor.hosters import get_hoster_for_package
|
||||
from c3nav.mapdata.permissions import get_nonpublic_packages
|
||||
|
||||
@staff_member_required
|
||||
|
||||
@login_required(login_url='/control/login/')
|
||||
def dashboard(request):
|
||||
return render(request, 'control/dashboard.html')
|
||||
|
||||
|
||||
def prove(request):
|
||||
hosters = OrderedDict((package, get_hoster_for_package(package)) for package in get_nonpublic_packages())
|
||||
|
||||
if None in hosters.values():
|
||||
return render(request, 'control/prove.html', context={'hosters': None})
|
||||
|
||||
error = False
|
||||
success = False
|
||||
if request.method == 'POST':
|
||||
user_ids = {}
|
||||
for package, hoster in hosters.items():
|
||||
access_token = request.POST.get(package.name)
|
||||
user_id = hoster.get_user_id_with_access_token(access_token)
|
||||
if user_id is None:
|
||||
error = True
|
||||
break
|
||||
user_ids[hoster] = user_id
|
||||
|
||||
if not error:
|
||||
success = True
|
||||
|
||||
return render(request, 'control/prove.html', context={
|
||||
'hosters': hosters,
|
||||
'error': error,
|
||||
'success': success,
|
||||
})
|
||||
|
|
|
@ -157,3 +157,10 @@ class Hoster(ABC):
|
|||
message and an optional 'url' key containing an URL to the created pull request.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_id_with_access_token(self, access_token) -> str:
|
||||
"""
|
||||
Get User ID of the User with this access token or None if the access token does not work.
|
||||
"""
|
||||
pass
|
||||
|
|
|
@ -192,3 +192,7 @@ class GithubHoster(Hoster):
|
|||
'success': True,
|
||||
'url': merge_request['html_url']
|
||||
}
|
||||
|
||||
def get_user_id_with_access_token(self, access_token):
|
||||
# Todo: Implement this
|
||||
return None
|
||||
|
|
|
@ -139,3 +139,12 @@ class GitlabHoster(Hoster):
|
|||
'success': True,
|
||||
'url': merge_request['web_url']
|
||||
}
|
||||
|
||||
def get_user_id_with_access_token(self, access_token):
|
||||
if not access_token.strip():
|
||||
return None
|
||||
|
||||
response = requests.get(self.base_url + 'api/v3/user?private_token=' + access_token)
|
||||
if response.status_code != 200:
|
||||
return None
|
||||
return str(response.json()['id'])
|
||||
|
|
|
@ -16,6 +16,11 @@ def get_public_packages():
|
|||
return [packages_cached[name] for name in settings.PUBLIC_PACKAGES]
|
||||
|
||||
|
||||
def get_nonpublic_packages():
|
||||
packages_cached = get_packages_cached()
|
||||
return [package for name, package in packages_cached.items() if name not in settings.PUBLIC_PACKAGES]
|
||||
|
||||
|
||||
def get_unlocked_packages_names(request, packages_cached=None):
|
||||
if packages_cached is None:
|
||||
packages_cached = get_packages_cached()
|
||||
|
|
|
@ -183,3 +183,8 @@ circle.pos {
|
|||
vertical-align:middle;
|
||||
line-height: 1.42857143;
|
||||
}
|
||||
|
||||
|
||||
.login .container {
|
||||
max-width:420px;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
c3nav = {
|
||||
init: function() {
|
||||
if (!$('#c3nav-main').length) return;
|
||||
|
||||
c3nav._typeahead_locations = new Bloodhound({
|
||||
datumTokenizer: function(data) {
|
||||
var result = [data.id]
|
||||
|
@ -100,5 +102,3 @@ c3nav = {
|
|||
}
|
||||
};
|
||||
$(document).ready(c3nav.init);
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
{% endcompress %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body class="{% block bodyclass %}{% endblock %}">
|
||||
|
||||
<div class="container" id="main">
|
||||
<h1>c3nav</h1>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
<form method="post" id="main_view">
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
{% trans "Origin" as heading %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue