#19 Tests
* refactors CheckableMixin and RecordableMixin into CheckableObject and RecordableObject * adds ShareableObject for wrapping share related fields and functionality * adds share functionality to EcoAccount and EMA, just like Intervention
This commit is contained in:
@@ -7,12 +7,11 @@ from django.db.models import QuerySet
|
||||
from compensation.models import AbstractCompensation
|
||||
from ema.managers import EmaManager
|
||||
from ema.utils.quality import EmaQualityChecker
|
||||
from konova.models import AbstractDocument, generate_document_file_upload_path, RecordableMixin
|
||||
from konova.models import AbstractDocument, generate_document_file_upload_path, RecordableObject, ShareableObject
|
||||
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
class Ema(AbstractCompensation, RecordableMixin):
|
||||
class Ema(AbstractCompensation, ShareableObject, RecordableObject):
|
||||
"""
|
||||
EMA = Ersatzzahlungsmaßnahme
|
||||
(compensation actions from payments)
|
||||
@@ -28,23 +27,6 @@ class Ema(AbstractCompensation, RecordableMixin):
|
||||
EMA therefore holds data like a compensation: actions, before-/after-states, deadlines, ...
|
||||
|
||||
"""
|
||||
# Users having access on this object
|
||||
# Not needed in regular Compensation since their access is defined by the linked intervention's access
|
||||
users = models.ManyToManyField(
|
||||
User,
|
||||
help_text="Users having access (shared with)"
|
||||
)
|
||||
|
||||
# Refers to "verzeichnen"
|
||||
recorded = models.OneToOneField(
|
||||
UserActionLogEntry,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Holds data on user and timestamp of this action",
|
||||
related_name="+"
|
||||
)
|
||||
|
||||
objects = EmaManager()
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
</button>
|
||||
</a>
|
||||
{% if has_access %}
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Share' %}" data-form-url="{% url 'ema:share-create' obj.id %}">
|
||||
{% fa5_icon 'share-alt' %}
|
||||
</button>
|
||||
{% if is_ets_member %}
|
||||
{% if obj.recorded %}
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Unrecord' %}" data-form-url="{% url 'ema:record' obj.id %}">
|
||||
|
||||
@@ -22,6 +22,8 @@ urlpatterns = [
|
||||
path('<id>/state/new', state_new_view, name='new-state'),
|
||||
path('<id>/action/new', action_new_view, name='new-action'),
|
||||
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||
path('<id>/share/<token>', share_view, name='share'),
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
|
||||
# Documents
|
||||
# Document remove route can be found in konova/urls.py
|
||||
|
||||
65
ema/views.py
65
ema/views.py
@@ -10,8 +10,9 @@ import compensation
|
||||
from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm
|
||||
from ema.forms import NewEmaForm, EditEmaForm
|
||||
from ema.tables import EmaTable
|
||||
from intervention.forms.modalForms import ShareInterventionModalForm
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import conservation_office_group_required
|
||||
from konova.decorators import conservation_office_group_required, default_group_required
|
||||
from ema.models import Ema, EmaDocument
|
||||
from konova.forms import RemoveModalForm, NewDocumentForm, SimpleGeomForm, RecordModalForm
|
||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||
@@ -460,4 +461,64 @@ def report_view(request:HttpRequest, id: str):
|
||||
"actions": actions,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
def share_view(request: HttpRequest, id: str, token: str):
|
||||
""" Performs sharing of an ema
|
||||
|
||||
If token given in url is not valid, the user will be redirected to the dashboard
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): EMA's id
|
||||
token (str): Access token for EMA
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
user = request.user
|
||||
obj = get_object_or_404(Ema, id=id)
|
||||
# Check tokens
|
||||
if obj.access_token == token:
|
||||
# Send different messages in case user has already been added to list of sharing users
|
||||
if obj.is_shared_with(user):
|
||||
messages.info(
|
||||
request,
|
||||
_("{} has already been shared with you").format(obj.identifier)
|
||||
)
|
||||
else:
|
||||
messages.success(
|
||||
request,
|
||||
_("{} has been shared with you").format(obj.identifier)
|
||||
)
|
||||
obj.users.add(user)
|
||||
return redirect("ema:detail", id=id)
|
||||
else:
|
||||
messages.error(
|
||||
request,
|
||||
_("Share link invalid"),
|
||||
extra_tags="danger",
|
||||
)
|
||||
return redirect("home")
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def create_share_view(request: HttpRequest, id: str):
|
||||
""" Renders sharing form for an Ema
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): Ema's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
obj = get_object_or_404(Ema, id=id)
|
||||
form = ShareInterventionModalForm(request.POST or None, instance=obj, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Share settings updated")
|
||||
)
|
||||
Reference in New Issue
Block a user