Skip to content

Commit

Permalink
Merge pull request #140 from gaiaresources/master
Browse files Browse the repository at this point in the history
!932: User action Audit Trail
  • Loading branch information
dbca-asi committed Oct 20, 2016
2 parents 63d6312 + 9817968 commit cb37761
Show file tree
Hide file tree
Showing 35 changed files with 1,956 additions and 218 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<div class="top-buffer bottom-buffer">
<h4>{{label}}</h4>
<h4 class="inline">{{label}}</h4>
{{#unless isRemovable}}
{{#if help_text}}
<p id="description_{{name}}" >{{{help_text}}}</p>
{{/if}}
{{/unless}}
<div class="panel panel-default">
<div class="panel-body">
<div class="children-anchor-point" style="padding-left: 0px">
<a class="collapse-link-top pull-right"><span class="glyphicon glyphicon-chevron-down"></a>
<div class="children-anchor-point collapse in" style="padding-left: 0px">
</div>
{{#unless isPreviewMode }}
{{#if isRepeatable }}
<a id="copy_{{name}}">Copy {{label}}</a>
{{/if}}
<div class="pull-right">
<a id="remove_{{name}}" class="{{#unless isRemovable}}hidden{{/unless}}">Remove</a>
</div>
<span class="{{#unless isRemovable}}hidden{{/unless}}">
<span class="margin-left margin-right">|</span>
<a id="remove_{{name}}" ">Remove {{label}}</a>
</span>
{{/unless}}
<a class="collapse-link-bottom pull-right"><span class="glyphicon glyphicon-chevron-up"></a>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<h3 id="{{name}}" class="section">{{label}}</h3>
<hr>
<h3 id="{{name}}" class="section inline">{{label}}</h3><a class="collapse-link-top top-buffer-s pull-right"><span class="glyphicon glyphicon-chevron-down"></span></a>
<hr>
<div class="children-anchor-point collapse in">
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.10 on 2016-10-12 02:42
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('wl_applications', '0010_auto_20160901_1436'),
]

operations = [
migrations.CreateModel(
name='ApplicationUserAction',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('when', models.DateTimeField(auto_now_add=True)),
('what', models.TextField()),
('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='wl_applications.Application')),
('who', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]
40 changes: 39 additions & 1 deletion wildlifelicensing/apps/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ledger.accounts.models import EmailUser, Profile, Document, RevisionedMixin
from wildlifelicensing.apps.main.models import WildlifeLicence, WildlifeLicenceType, Condition, \
CommunicationsLogEntry, AssessorGroup, Variant
CommunicationsLogEntry, AssessorGroup, Variant, UserAction


@python_2_unicode_compatible
Expand Down Expand Up @@ -130,6 +130,9 @@ def is_senior_offer_applicable(self):
self.applicant.is_senior and \
bool(self.applicant.senior_card)

def log_user_action(self, action, request):
return ApplicationUserAction.log_action(self, action, request.user)


class ApplicationVariantLink(models.Model):
application = models.ForeignKey(Application)
Expand Down Expand Up @@ -210,6 +213,41 @@ class Meta:
unique_together = ('condition', 'assessment', 'order')


class ApplicationUserAction(UserAction):
ACTION_CREATE_CUSTOMER_ = "Create customer {}"
ACTION_CREATE_PROFILE_ = "Create profile {}"
ACTION_LODGE_APPLICATION = "Lodge application {}"
ACTION_ASSIGN_TO_ = "Assign to {}"
ACTION_UNASSIGN = "Unassign"
ACTION_ACCEPT_ID = "Accept ID"
ACTION_RESET_ID = "Reset ID"
ACTION_ID_REQUEST_UPDATE = 'Request ID update'
ACTION_ACCEPT_CHARACTER = 'Accept character'
ACTION_RESET_CHARACTER = "Reset character"
ACTION_ACCEPT_REVIEW = 'Accept review'
ACTION_RESET_REVIEW = "Reset review"
ACTION_ID_REQUEST_AMENDMENTS = "Request amendments"
ACTION_SEND_FOR_ASSESSMENT_TO_ = "Send for assessment to {}"
ACTION_SEND_ASSESSMENT_REMINDER_TO_ = "Send assessment reminder to {}"
ACTION_DECLINE_APPLICATION = "Decline application"
ACTION_ENTER_CONDITIONS = "Enter Conditions"
ACTION_CREATE_CONDITION_ = "Create condition {}"
ACTION_ISSUE_LICENCE_ = "Issue Licence {}"
# Assessors
ACTION_SAVE_ASSESSMENT_ = "Save assessment {}"
ACTION_CONCLUDE_ASSESSMENT_ = "Conclude assessment {}"

@classmethod
def log_action(cls, application, action, user):
return cls.objects.create(
application=application,
who=user,
what=str(action)
)

application = models.ForeignKey(Application)


@receiver(pre_delete, sender=Application)
def delete_documents(sender, instance, *args, **kwargs):
for document in instance.documents.all():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ define(['jQuery', 'handlebars.runtime', 'parsley', 'bootstrap', 'bootstrap-datet

_initInputField(item, $itemContainer);

if(item.type === 'section' || item.type === 'group') {
_initCollapsible($itemContainer);
}

// unset item name and value if they were set otherwise there may be unintended consequences if extra form fields are created dynamically
item.name = item.name.slice(0, item.name.indexOf(suffix));
item.value = undefined;
Expand Down Expand Up @@ -190,6 +194,44 @@ define(['jQuery', 'handlebars.runtime', 'parsley', 'bootstrap', 'bootstrap-datet
}
}

function _initCollapsible($itemContainer, removeExistingEvents) {
var $collapsible = $itemContainer.find('.children-anchor-point').first(),
$topLink = $collapsible.siblings('.collapse-link-top'),
$topLinkSpan = $topLink.find('span'),
$bottomLink = $collapsible.siblings('.collapse-link-bottom').first();

if(removeExistingEvents) {
$collapsible.off('hide.bs.collapse').off('show.bs.collapse').off('shown.bs.collapse');
$topLink.off('click');
if($bottomLink.length) {
$bottomLink.off('click');
}
}

$collapsible.on('hide.bs.collapse', function () {
$topLinkSpan.removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
if($bottomLink.length) {
$bottomLink.hide();
}
}).on('show.bs.collapse', function() {
$topLinkSpan.removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
}).on('shown.bs.collapse', function() {
if($bottomLink.length) {
$bottomLink.show();
};
});

$topLink.click(function() {
$collapsible.collapse('toggle');
});

if($bottomLink.length) {
$bottomLink.click(function() {
$collapsible.collapse('toggle');
});
}
}

function _setupCopyRemoveEvents(item, itemSelector, suffix) {
itemSelector.find('[id^="copy_' + item.name + '"]').first().click(function(e) {
var itemCopy = itemSelector.clone(true, true),
Expand Down Expand Up @@ -241,9 +283,14 @@ define(['jQuery', 'handlebars.runtime', 'parsley', 'bootstrap', 'bootstrap-datet
$(this).replaceWith(speciesClone);
});

itemCopy.find('[id^="remove_' + item.name + '"]').removeClass('hidden');
itemCopy.find('[id^="copy_' + item.name + '"]').off('click');
itemCopy.find('[id^="remove_' + item.name + '"]').parent().removeClass('hidden');
itemCopy.find('[id^="description_' + item.name + '"]').addClass('hidden');

itemSelector.after(itemCopy);

_initCollapsible(itemCopy, true);

groupInput.val(groupCount + 1);
_setupCopyRemoveEvents(item, itemCopy, suffix);
});
Expand Down Expand Up @@ -308,4 +355,4 @@ define(['jQuery', 'handlebars.runtime', 'parsley', 'bootstrap', 'bootstrap-datet
sectionList.affix({ offset: { top: sectionList.offset().top }});
}
};
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'j
if(item.type === 'section' || item.type === 'group') {
item.isPreviewMode = true;
itemContainer.append(Handlebars.templates[item.type](item));
_initCollapsible(itemContainer);
} else if (item.type === 'radiobuttons' || item.type === 'select') {
var isSpecified = false;
itemContainer.append($('<label>').text(item.label));
Expand Down Expand Up @@ -65,7 +66,6 @@ define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'j
childrenAnchorPoint = _getCreateChildrenAnchorPoint(itemContainer);

if(item.conditions !== undefined) {

if(item.conditions !== undefined) {
$.each(item.conditions, function(condition, children) {
if(condition === itemData[item.name]) {
Expand Down Expand Up @@ -122,6 +122,36 @@ define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'j
return $childrenAnchorPoint;
}

function _initCollapsible($itemContainer) {
var $collapsible = $itemContainer.find('.children-anchor-point').first(),
$topLink = $collapsible.siblings('.collapse-link-top'),
$topLinkSpan = $topLink.find('span'),
$bottomLink = $collapsible.siblings('.collapse-link-bottom').first();

$collapsible.on('hide.bs.collapse', function () {
$topLinkSpan.removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
if($bottomLink.length) {
$bottomLink.hide();
}
}).on('show.bs.collapse', function() {
$topLinkSpan.removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
}).on('shown.bs.collapse', function() {
if($bottomLink.length) {
$bottomLink.show();
};
});

$topLink.click(function() {
$collapsible.collapse('toggle');
});

if($bottomLink.length) {
$bottomLink.click(function() {
$collapsible.collapse('toggle');
});
}
}

return {
layoutPreviewItems: function(containerSelector, formStructure, data, tempFilesUrl) {
var container = $(containerSelector);
Expand Down Expand Up @@ -157,4 +187,4 @@ define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'j
});
}
};
});
});
2 changes: 1 addition & 1 deletion wildlifelicensing/apps/applications/static/wl/js/entry/select_licence_type.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['jQuery', 'bootstrap.treeView'], function ($) {
define(['jQuery', 'js/wl.bootstrap-treeview'], function ($) {
"use strict";

function _convertToSlug(text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'j
}

itemContainer.append($template);

_initCollapsible(itemContainer);
} else if (item.type === 'radiobuttons' || item.type === 'select') {
itemContainer.append($('<label>').text(item.label));
if(item.valueCurrent === item.valuePrevious || (item.valuePrevious === undefined && isRepeat)) {
Expand Down Expand Up @@ -219,6 +221,36 @@ define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'j
return $childrenAnchorPoint;
}

function _initCollapsible($itemContainer) {
var $collapsible = $itemContainer.find('.children-anchor-point').first(),
$topLink = $collapsible.siblings('.collapse-link-top'),
$topLinkSpan = $topLink.find('span'),
$bottomLink = $collapsible.siblings('.collapse-link-bottom').first();

$collapsible.on('hide.bs.collapse', function () {
$topLinkSpan.removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
if($bottomLink.length) {
$bottomLink.hide();
}
}).on('show.bs.collapse', function() {
$topLinkSpan.removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
}).on('shown.bs.collapse', function() {
if($bottomLink.length) {
$bottomLink.show();
};
});

$topLink.click(function() {
$collapsible.collapse('toggle');
});

if($bottomLink.length) {
$bottomLink.click(function() {
$collapsible.collapse('toggle');
});
}
}

return {
layoutPreviewItems: function(containerSelector, formStructure, currentData, previousData) {
var container = $(containerSelector);
Expand All @@ -240,4 +272,4 @@ define(['jQuery', 'handlebars.runtime', 'bootstrap', 'js/handlebars_helpers', 'j
}
}
};
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@
{% endblock %}

{% block requirements %}
require(['js/conditions/assessor_enter_conditions', 'js/communications_log'], function (enter_conditions, commsLog) {
require([
'js/conditions/assessor_enter_conditions',
'js/logs'
], function (enter_conditions, logs) {
$(function () {
enter_conditions.init({{ assessment|jsonify }}, {{ application|jsonify }},
{{ form_structure|jsonify }}, {{ other_assessments|jsonify }});

commsLog.initCommunicationLog({
showLogPopoverSelector: '#showLog',
showLogEntryModalSelector: '#addLogEntry',
logEntryModalSelector: '#logEntryModal',
logEntryFormSelector: '#addLogEntryForm',
logs.initCommunicationLog({
logListURL: "{% url 'wl_applications:log_list' application.id %}",
addLogEntryURL: "{% url 'wl_applications:add_log_entry' application.id %}"
});
logs.initActionLog({
logListURL: "{% url 'wl_applications:action_list' application.id %}",
});

});
});
{% endblock %}
Expand Down Expand Up @@ -103,9 +106,7 @@ <h3>{{ application.licence_type.name }}</h3>
</div>
</div>
</div>
{% with disable_collapse=True add_text='Add application log entry' %}
{% include 'wl/communications_panel.html' %}
{% endwith %}
{% include 'wl/logs_panel.html' %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
Expand Down Expand Up @@ -176,5 +177,5 @@ <h3>Current Conditions</h3>
{% endblock %}

{% block modals %}
{% include 'wl/communications_modal.html' %}
{% include 'wl/logs_comm_entry_modal.html' %}
{% endblock %}
Loading

0 comments on commit cb37761

Please sign in to comment.