Skip to content

Commit

Permalink
Merge pull request #243 from makinacorpus/improve_logentry
Browse files Browse the repository at this point in the history
Improve logentry
  • Loading branch information
submarcos authored Jun 10, 2022
2 parents cf177b1 + d9a1d3a commit cbdff57
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 105 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ CHANGELOG
8.1.0+dev (XXXX-XX-XX)
-----------------------

**Bug fixes**

- Fix Log Entry GeoJSON with no geometry
- Fix log entry access by creating mapentity.read_logentry permission
- Hide log entry menu for users without permission.
- Hide "Show full history" from object for users without permission.
- Hide admin menu entry for users without permission.
- Fix message in default in 404 view
- Fix exception recursion in default error 500 view


8.1.0 (2022-06-03)
-----------------------
Expand Down
17 changes: 17 additions & 0 deletions mapentity/migrations/0002_alter_logentry_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.13 on 2022-06-09 15:23

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mapentity', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='logentry',
options={'permissions': (('read_logentry', 'Can read log entries'),)},
),
]
15 changes: 14 additions & 1 deletion mapentity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_permission_codename(cls, entity_kind):
appname = opts.app_label.lower()
if opts.proxy:
proxied = opts.proxy_for_model._meta
appname = proxied.app_label.lower()
appname = proxied.app_label.lower() if proxied.app_label.lower() != "admin" else appname
return '%s.%s' % (appname, auth.get_permission_codename(perm, opts))

@classmethod
Expand Down Expand Up @@ -280,6 +280,9 @@ class LogEntry(BaseMapEntityMixin, BaseLogEntry):
class Meta:
proxy = True
app_label = 'mapentity'
permissions = (
('read_logentry', 'Can read log entries'),
)

@property
def action_flag_display(self):
Expand All @@ -306,3 +309,13 @@ def object_display(self):
else:
return '<a data-pk="%s" href="%s" >%s %s</a>' % (
obj.pk, obj_url, model_str, self.object_repr)

def get_date_update(self):
return self.action_time

@classmethod
def latest_updated(cls):
try:
return cls.objects.only('action_time').latest('action_time').get_date_update()
except (cls.DoesNotExist, FieldError):
return None
5 changes: 4 additions & 1 deletion mapentity/templates/404.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% extends "mapentity/base_site.html" %}

{% load i18n %}

{% block container %}
<h1>{% trans "Page not found" %}</h1>
<div id="container" class="container-fluid">
<h1>{% trans "Page not found" %}</h1>
</div>
{% endblock container %}
14 changes: 8 additions & 6 deletions mapentity/templates/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
{% load i18n %}

{% block container %}
<div class="page-header">
<h1>{% trans "Internal error" %} <small>{{ exception }}</small></h1>
</div>
<div class="alert alert-error">
<strong>{% trans "Details" %}</strong>
<pre>{{ stack }}</pre>
<div id="container" class="container-fluid">
<div class="page-header">
<h1>{% trans "Internal error" %} <small>(500)</small></h1>
</div>
</div>
{% endblock container %}

{% block js_setings_view %}
{# disable js settings view to avoid exception in exception #}
{% endblock %}
12 changes: 6 additions & 6 deletions mapentity/templates/mapentity/_base_navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@

{% if request.user.is_staff %}
<li class="dropdown-item"><a href="{% url 'admin:index' %}">{% trans "Admin" %}</a></li>
{% else %}
<li class="dropdown-item" class="disabled"><a href="#">{% trans "Admin" %}</a></li>
{% endif %}

{% if ACTION_HISTORY_ENABLED %}
{% if 'admin.read_logentry' in perms %}
<li class="dropdown-item"><a class="{% block nav-logbook %}{% endblock nav-logbook %}" href="{% url 'mapentity:logentry_list' %}">{% trans "Logbook" %}</a></li>
{% else %}
<li class="dropdown-item" class="disabled"><a href="#">{% trans "Logbook" %}</a></li>
{% if 'mapentity.read_logentry' in perms %}
<li class="dropdown-item">
<a class="{% block nav-logbook %}{% endblock nav-logbook %}" href="{% url 'mapentity:logentry_list' %}">
{% trans "Logbook" %}
</a>
</li>
{% endif %}
{% endif %}

Expand Down
198 changes: 108 additions & 90 deletions mapentity/templates/mapentity/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,116 +2,133 @@
<!DOCTYPE html>
<html>
<head>
<!-- version {{ VERSION }} -->
{% block head %}

<title>{% block title %}{{ TITLE }}{% endblock title %}</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="{% media_static_fallback 'upload/favicon.png' 'images/favicon.png' %}" />

{% compress css %}
{% if DEBUG %}
<link rel="stylesheet" type="text/css" href="{% static 'mapentity/vendor/bootstrap-4.6.0/css/bootstrap.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'mapentity/vendor/bootstrap-datepicker-1.9.0/css/bootstrap-datepicker.css' %}">
{% else %}
<link rel="stylesheet" href="{% static 'mapentity/vendor/bootstrap-4.6.0/css/bootstrap.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'mapentity/vendor/bootstrap-datepicker-1.9.0/css/bootstrap-datepicker.min.css' %}">
{% endif %}
<link rel="stylesheet" type="text/css" href="{% static 'mapentity/vendor/datatables-1.11.5/datatables.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'mapentity/vendor/bootstrap-icons-1.2.2/font/bootstrap-icons.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'mapentity/vendor/chosen-1.8.7/chosen.css' %}">
{% leaflet_css plugins="ALL" %}

<style>
{% for entity in allowed_entities %}
.list-panel.{{ entity.modelname }},
.form-panel.{{ entity.modelname }},
.details-panel.{{ entity.modelname }} {
background-image: url({% static entity.icon_big %});
}
li.history.{{ entity.modelname }} > a,
li.history.{{ entity.modelname }} button:first-child {
background: url({% static entity.icon_small %}) no-repeat;
background-position: left center;
}
.nav-item.{{ entity.modelname }} .btn-list {
background-image: url({% static entity.icon_big %});
}
{% endfor %}
{% if not DEBUG %}
.map-error { border: 0px;}
{% endif %}
</style>
<link rel="stylesheet" href="{% static 'mapentity/style.css' %}" />

{% smart_include "extracss" %}

{% endcompress %}

{% if DEBUG %}
<script type="text/javascript" src="{% static 'mapentity/vendor/jquery/jquery-1.9.1.js' %}"></script>
{% else %}
<script type="text/javascript" src="{% static 'mapentity/vendor/jquery/jquery-1.9.1.min.js' %}"></script>
{% endif %}
{% endblock head %}

{% block extrahead %}
{% endblock extrahead %}
<!-- version {{ VERSION }} -->
{% block head %}

<title>{% block title %}{{ TITLE }}{% endblock title %}</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="{% media_static_fallback 'upload/favicon.png' 'images/favicon.png' %}"/>

{% compress css %}
{% if DEBUG %}
<link rel="stylesheet" type="text/css"
href="{% static 'mapentity/vendor/bootstrap-4.6.0/css/bootstrap.css' %}"/>
<link rel="stylesheet" type="text/css"
href="{% static 'mapentity/vendor/bootstrap-datepicker-1.9.0/css/bootstrap-datepicker.css' %}">
{% else %}
<link rel="stylesheet" href="{% static 'mapentity/vendor/bootstrap-4.6.0/css/bootstrap.min.css' %}"/>
<link rel="stylesheet" type="text/css"
href="{% static 'mapentity/vendor/bootstrap-datepicker-1.9.0/css/bootstrap-datepicker.min.css' %}">
{% endif %}
<link rel="stylesheet" type="text/css"
href="{% static 'mapentity/vendor/datatables-1.11.5/datatables.min.css' %}"/>
<link rel="stylesheet" type="text/css"
href="{% static 'mapentity/vendor/bootstrap-icons-1.2.2/font/bootstrap-icons.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'mapentity/vendor/chosen-1.8.7/chosen.css' %}">
{% leaflet_css plugins="ALL" %}

<style>
{% for entity in allowed_entities %}
.list-panel.{{ entity.modelname }},
.form-panel.{{ entity.modelname }},
.details-panel.{{ entity.modelname }} {
background-image: url({% static entity.icon_big %});
}
li.history.{{ entity.modelname }} > a,
li.history.{{ entity.modelname }} button:first-child {
background: url({% static entity.icon_small %}) no-repeat;
background-position: left center;
}
.nav-item.{{ entity.modelname }} .btn-list {
background-image: url({% static entity.icon_big %});
}
{% endfor %}

{% if not DEBUG %}
.map-error {
border: 0px;
}
{% endif %}
</style>
<link rel="stylesheet" href="{% static 'mapentity/style.css' %}"/>

{% smart_include "extracss" %}

{% endcompress %}

{% if DEBUG %}
<script type="text/javascript" src="{% static 'mapentity/vendor/jquery/jquery-1.9.1.js' %}"></script>
{% else %}
<script type="text/javascript" src="{% static 'mapentity/vendor/jquery/jquery-1.9.1.min.js' %}"></script>
{% endif %}
{% endblock head %}

{% block extrahead %}
{% endblock extrahead %}
</head>
<body data-viewname="{{ viewname }}"
data-appname="{{ appname }}"
data-modelname="{{ modelname }}"
data-objectsname="{{ objectsname }}"
data-pk="{{ object.pk }}">

{% block content %}
{% block content %}
{% block navbar %}
{% include "mapentity/_base_navbar.html" %}
{% endblock navbar %}

{% block container %}
<div id="container" class="container-fluid {% if MAP_BACKGROUND_FOGGED %}map-fogged{% endif %}">

{% if messages %}
{% for message in messages %}
<div class="alert {{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endfor %}
{% endif %}

<div class="row">
{% block mainpanel %}
{% endblock mainpanel %}
</div><!--/row-->
</div><!--/container-->
<div id="container" class="container-fluid {% if MAP_BACKGROUND_FOGGED %}map-fogged{% endif %}">

{% if messages %}
{% for message in messages %}
<div class="alert {{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endfor %}
{% endif %}

<div class="row">
{% block mainpanel %}
{% endblock mainpanel %}
</div><!--/row-->
</div><!--/container-->
{% endblock container %}
{% endblock content %}
{% endblock content %}


{% block extrabody %}
{% block extrabody %}
{{ block.super }}

{# Global Javascript settings #}
<script src="{% url JS_SETTINGS_VIEW %}?callback=window.SETTINGS%3D"></script>
{% block js_setings_view %}
<script src="{% url JS_SETTINGS_VIEW %}?callback=window.SETTINGS%3D"></script>
{% endblock %}
{% block change_style %}{% endblock change_style %}
{% compress js %}
{% if DEBUG %}
<script type="text/javascript" src="{% static 'mapentity/vendor/bootstrap-4.6.0/js/bootstrap.bundle.js' %}"></script>
<script type="text/javascript" src="{% static 'mapentity/vendor/bootstrap-datepicker-1.9.0/js/bootstrap-datepicker.js' %}"></script>
<script type="text/javascript"
src="{% static 'mapentity/vendor/bootstrap-4.6.0/js/bootstrap.bundle.js' %}"></script>
<script type="text/javascript"
src="{% static 'mapentity/vendor/bootstrap-datepicker-1.9.0/js/bootstrap-datepicker.js' %}"></script>
{% else %}
<script type="text/javascript" src="{% static 'mapentity/vendor/bootstrap-4.6.0/js/bootstrap.bundle.min.js' %}"></script>
<script type="text/javascript" src="{% static 'mapentity/vendor/bootstrap-datepicker-1.9.0/js/bootstrap-datepicker.min.js' %}"></script>
<script type="text/javascript"
src="{% static 'mapentity/vendor/bootstrap-4.6.0/js/bootstrap.bundle.min.js' %}"></script>
<script type="text/javascript"
src="{% static 'mapentity/vendor/bootstrap-datepicker-1.9.0/js/bootstrap-datepicker.min.js' %}"></script>
{% endif %}
<script type="text/javascript" src="{% static 'mapentity/vendor/popper-1.16.1/popper.min.js' %}"></script>
<script src="{% static 'mapentity/jquery.hoverIntent.js' %}"></script>
<script src="{% static 'paperclip/bootstrap-4-confirm.js' %}"></script>
{% for lang in LANGUAGES %}
{% if lang.0 != 'en' %}<script type="text/javascript" src="{% get_static_prefix %}mapentity/vendor/bootstrap-datepicker-1.9.0/locales/bootstrap-datepicker.{{ lang.0 }}.min.js" charset="UTF-8"></script>{% endif %}
{% if lang.0 != 'en' %}
<script type="text/javascript"
src="{% get_static_prefix %}mapentity/vendor/bootstrap-datepicker-1.9.0/locales/bootstrap-datepicker.{{ lang.0 }}.min.js"
charset="UTF-8"></script>{% endif %}
{% endfor %}

{% leaflet_js plugins="ALL" %}
Expand All @@ -132,17 +149,18 @@
L.GeometryField.unsavedText = "{% trans 'Map geometry is unsaved' %}";

MapEntity.i18n = {
'Objects': "{% trans 'Objects' %}",
'Search': "{% trans 'Search' %}",
'results': "{% trans 'results' %}",
'Current criteria': "{% trans 'Current criteria' %}",
'No filter': "{% trans 'No filter' %}",
'Objects': "{% trans 'Objects' %}",
'Search': "{% trans 'Search' %}",
'results': "{% trans 'results' %}",
'Current criteria': "{% trans 'Current criteria' %}",
'No filter': "{% trans 'No filter' %}",
};
</script>

<script type="text/javascript" src="{% static 'mapentity/jquery.deserialize.js' %}"></script>
<script type="text/javascript" src="{% static 'mapentity/vendor/chosen-1.8.7/chosen.jquery.min.js' %}"></script>
<script type="text/javascript" src="{% static 'mapentity/vendor/datatables-1.11.5/datatables.min.js' %}"></script>
<script type="text/javascript"
src="{% static 'mapentity/vendor/datatables-1.11.5/datatables.min.js' %}"></script>
<script type="text/javascript" src="{% static 'mapentity/leaflet-objectslayer.js' %}"></script>
<script type="text/javascript" src="{% static 'mapentity/leaflet-serializers.js' %}"></script>
<script type="text/javascript" src="{% static 'mapentity/leaflet-datatables.js' %}"></script>
Expand All @@ -159,7 +177,7 @@

{% smart_include "extrabody" %}

{% endblock extrabody %}
{% endblock extrabody %}
</body>
</html>

6 changes: 5 additions & 1 deletion mapentity/templates/mapentity/mapentity_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ <h1 class="details-title">{{ object }}</h1>
{% endif %}
</tbody>
</table>
<a href="{% url 'mapentity:logentry_list' %}?content_type={{ object.get_content_type_id }}&object_id={{ object.pk }}" class="btn btn-light">{% trans "Full history" %}</a>
{% if 'mapentity.read_logentry' in perms %}
<a href="{% url 'mapentity:logentry_list' %}?content_type={{ object.get_content_type_id }}&object_id={{ object.pk }}" class="btn btn-light">
{% trans "Full history" %}
</a>
{% endif %}
</div>
{% endif %}
</div>
Expand Down
Loading

0 comments on commit cbdff57

Please sign in to comment.