(WIP) Add a button to send edit link by email in anonymous mode
This commit is contained in:
parent
7713281f8c
commit
69bf6593ac
4 changed files with 53 additions and 5 deletions
|
@ -25,6 +25,10 @@ class FlatErrorList(ErrorList):
|
|||
return u' — '.join([e for e in self])
|
||||
|
||||
|
||||
class SendLinkForm(forms.Form):
|
||||
email = forms.EmailField()
|
||||
|
||||
|
||||
class UpdateMapPermissionsForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -1336,11 +1336,23 @@ L.U.Map.include({
|
|||
data: formData,
|
||||
context: this,
|
||||
callback: function (data) {
|
||||
let duration = 3000
|
||||
let duration = 3000,
|
||||
alert = { content: L._('Map has been saved!'), level: 'info' }
|
||||
if (!this.options.umap_id) {
|
||||
duration = 100000 // we want a longer message at map creation (TODO UGLY)
|
||||
alert.duration = 100000 // we want a longer message at map creation (TODO UGLY)
|
||||
this.options.umap_id = data.id
|
||||
this.permissions.setOptions(data.permissions)
|
||||
if (data.permissions && data.permissions.anonymous_edit_url) {
|
||||
alert.actions = [
|
||||
{
|
||||
label: L._('Send me edit link by email'),
|
||||
callback: function () {
|
||||
this.sendEditLink()
|
||||
},
|
||||
callbackContext: this,
|
||||
},
|
||||
]
|
||||
}
|
||||
} else if (!this.permissions.isDirty) {
|
||||
// Do not override local changes to permissions,
|
||||
// but update in case some other editors changed them in the meantime.
|
||||
|
@ -1350,11 +1362,10 @@ L.U.Map.include({
|
|||
if (history && history.pushState)
|
||||
history.pushState({}, this.options.name, data.url)
|
||||
else window.location = data.url
|
||||
if (data.info) msg = data.info
|
||||
else msg = L._('Map has been saved!')
|
||||
alert.content = data.info || alert.content
|
||||
this.once('saved', function () {
|
||||
this.isDirty = false
|
||||
this.ui.alert({ content: msg, level: 'info', duration: duration })
|
||||
this.ui.alert(alert)
|
||||
})
|
||||
this.ui.closePanel()
|
||||
this.permissions.save()
|
||||
|
@ -1362,6 +1373,12 @@ L.U.Map.include({
|
|||
})
|
||||
},
|
||||
|
||||
sendEditLink: function () {
|
||||
var url = L.Util.template(this.options.urls.map_send_edit_link, {
|
||||
map_id: this.options.umap_id,
|
||||
})
|
||||
},
|
||||
|
||||
getEditUrl: function () {
|
||||
return L.Util.template(this.options.urls.map_update, {
|
||||
map_id: this.options.umap_id,
|
||||
|
|
|
@ -111,6 +111,11 @@ i18n_urls += decorated_patterns(
|
|||
views.UpdateMapPermissions.as_view(),
|
||||
name="map_update_permissions",
|
||||
),
|
||||
re_path(
|
||||
r"^map/(?P<map_id>[\d]+)/send-edit-link/$",
|
||||
views.SendEditLink.as_view(),
|
||||
name="map_send_edit_link",
|
||||
),
|
||||
re_path(
|
||||
r"^map/(?P<map_id>[\d]+)/update/owner/$",
|
||||
views.AttachAnonymousMap.as_view(),
|
||||
|
|
|
@ -622,6 +622,28 @@ class AttachAnonymousMap(View):
|
|||
return simple_json_response()
|
||||
|
||||
|
||||
class SendEditLink(FormLessEditMixin, PermissionsMixin, UpdateView):
|
||||
model = Map
|
||||
pk_url_kwarg = 'map_id'
|
||||
|
||||
def form_valid(self, form):
|
||||
if (self.object.owner
|
||||
or not self.object.is_anonymous_owner(self.request)
|
||||
or not self.object.can_edit(self.request.user, self.request)):
|
||||
return HttpResponseForbidden()
|
||||
email = form.cleaned_data["email"]
|
||||
from django.core.mail import send_mail
|
||||
|
||||
send_mail(
|
||||
_('Your secret edit link'),
|
||||
_('Here is your secret edit link: %(link)s' % {"link": link}),
|
||||
settings.FROM_EMAIL,
|
||||
[email],
|
||||
fail_silently=False,
|
||||
)
|
||||
return simple_json_response(info=_("Email sent to %(email)s" % {"email": email}))
|
||||
|
||||
|
||||
class MapDelete(DeleteView):
|
||||
model = Map
|
||||
pk_url_kwarg = "map_id"
|
||||
|
|
Loading…
Reference in a new issue