#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:
+63
-2
@@ -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