Share intervention settings
* extends share link form to share settings form * adds list of users with access to the intervention * adds logic for removing these users * enhances translations
This commit is contained in:
		
							parent
							
								
									394ce15c3f
								
							
						
					
					
						commit
						221f7dfb79
					
				@ -238,6 +238,7 @@ class ShareInterventionForm(BaseModalForm):
 | 
			
		||||
    url = forms.CharField(
 | 
			
		||||
        label=_("Share link"),
 | 
			
		||||
        label_suffix="",
 | 
			
		||||
        help_text=_("Send this link to users who you want to have writing access on the data"),
 | 
			
		||||
        required=False,
 | 
			
		||||
        widget=TextToClipboardInput(
 | 
			
		||||
            attrs={
 | 
			
		||||
@ -245,18 +246,38 @@ class ShareInterventionForm(BaseModalForm):
 | 
			
		||||
            }
 | 
			
		||||
        )
 | 
			
		||||
    )
 | 
			
		||||
    users = forms.MultipleChoiceField(
 | 
			
		||||
        label=_("Shared with"),
 | 
			
		||||
        label_suffix="",
 | 
			
		||||
        required=True,
 | 
			
		||||
        help_text=_("Remove check to remove access for this user"),
 | 
			
		||||
        widget=forms.CheckboxSelectMultiple(
 | 
			
		||||
            attrs={
 | 
			
		||||
                "class": "list-unstyled",
 | 
			
		||||
            }
 | 
			
		||||
        ),
 | 
			
		||||
        choices=[]
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.form_title = _("Share")
 | 
			
		||||
        self.form_caption = _("Send this link to users who you want to have writing access on the data.")
 | 
			
		||||
        self.form_caption = _("Share settings for {}").format(self.instance.identifier)
 | 
			
		||||
        self.template = "modal/modal_form.html"
 | 
			
		||||
        self.render_submit = False
 | 
			
		||||
 | 
			
		||||
        # Make sure an access_token is set
 | 
			
		||||
        if self.instance.access_token is None:
 | 
			
		||||
            self.instance.generate_access_token()
 | 
			
		||||
 | 
			
		||||
        self._init_fields()
 | 
			
		||||
 | 
			
		||||
    def _init_fields(self):
 | 
			
		||||
        """ Wraps initializing of fields
 | 
			
		||||
 | 
			
		||||
        Returns:
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        # Initialize share_link field
 | 
			
		||||
        self.share_link = self.request.build_absolute_uri(
 | 
			
		||||
            reverse("intervention:share", args=(self.instance.id, self.instance.access_token,))
 | 
			
		||||
        )
 | 
			
		||||
@ -264,3 +285,23 @@ class ShareInterventionForm(BaseModalForm):
 | 
			
		||||
            "url",
 | 
			
		||||
            self.share_link
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        # Initialize users field
 | 
			
		||||
        users = self.instance.users.all()
 | 
			
		||||
        choices = []
 | 
			
		||||
        for n in users:
 | 
			
		||||
            choices.append(
 | 
			
		||||
                (n.id, n.username)
 | 
			
		||||
            )
 | 
			
		||||
        self.fields["users"].choices = choices
 | 
			
		||||
        u_ids = list(users.values_list("id", flat=True))
 | 
			
		||||
        self.initialize_form_field(
 | 
			
		||||
            "users",
 | 
			
		||||
            u_ids
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def save(self):
 | 
			
		||||
        accessing_users = User.objects.filter(
 | 
			
		||||
            id__in=self.cleaned_data["users"]
 | 
			
		||||
        )
 | 
			
		||||
        self.instance.users.set(accessing_users)
 | 
			
		||||
 | 
			
		||||
@ -254,12 +254,21 @@ def create_share_view(request: HttpRequest, id: str):
 | 
			
		||||
    user = request.user
 | 
			
		||||
    intervention = get_object_or_404(Intervention, id=id)
 | 
			
		||||
    form = ShareInterventionForm(request.POST or None, instance=intervention, request=request)
 | 
			
		||||
    if request.method != "GET":
 | 
			
		||||
    if request.method == "POST":
 | 
			
		||||
        if form.is_valid():
 | 
			
		||||
            form.save()
 | 
			
		||||
            messages.info(
 | 
			
		||||
                request,
 | 
			
		||||
                _("Share settings updated")
 | 
			
		||||
            )
 | 
			
		||||
            return redirect(request.META.get("HTTP_REFERER", "home"))
 | 
			
		||||
    elif request.method == "GET":
 | 
			
		||||
        context = {
 | 
			
		||||
            "form": form,
 | 
			
		||||
        }
 | 
			
		||||
        context = BaseContext(request, context).context
 | 
			
		||||
        return render(request, form.template, context)
 | 
			
		||||
    else:
 | 
			
		||||
        raise NotImplementedError
 | 
			
		||||
    context = {
 | 
			
		||||
        "form": form,
 | 
			
		||||
    }
 | 
			
		||||
    context = BaseContext(request, context).context
 | 
			
		||||
    return render(request, form.template, context)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@ -13,7 +13,7 @@ msgid ""
 | 
			
		||||
msgstr ""
 | 
			
		||||
"Project-Id-Version: PACKAGE VERSION\n"
 | 
			
		||||
"Report-Msgid-Bugs-To: \n"
 | 
			
		||||
"POT-Creation-Date: 2021-07-30 14:26+0200\n"
 | 
			
		||||
"POT-Creation-Date: 2021-07-30 15:00+0200\n"
 | 
			
		||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 | 
			
		||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 | 
			
		||||
"Language-Team: LANGUAGE <LL@li.org>\n"
 | 
			
		||||
@ -251,16 +251,27 @@ msgstr "Eingriff bearbeiten"
 | 
			
		||||
msgid "Share link"
 | 
			
		||||
msgstr "Freigabelink"
 | 
			
		||||
 | 
			
		||||
#: intervention/forms.py:251
 | 
			
		||||
#: intervention/forms.py:241
 | 
			
		||||
msgid "Send this link to users who you want to have writing access on the data"
 | 
			
		||||
msgstr ""
 | 
			
		||||
"Andere Nutzer erhalten über diesen Link Zugriff auf die Daten"
 | 
			
		||||
 | 
			
		||||
#: intervention/forms.py:250
 | 
			
		||||
msgid "Shared with"
 | 
			
		||||
msgstr "Freigegeben für"
 | 
			
		||||
 | 
			
		||||
#: intervention/forms.py:253
 | 
			
		||||
msgid "Remove check to remove access for this user"
 | 
			
		||||
msgstr "Wählen Sie die Nutzer ab, die keinen Zugriff mehr haben sollen"
 | 
			
		||||
 | 
			
		||||
#: intervention/forms.py:264
 | 
			
		||||
#: intervention/templates/intervention/detail/view.html:27
 | 
			
		||||
msgid "Share"
 | 
			
		||||
msgstr "Freigabe"
 | 
			
		||||
 | 
			
		||||
#: intervention/forms.py:252
 | 
			
		||||
msgid ""
 | 
			
		||||
"Send this link to users who you want to have writing access on the data."
 | 
			
		||||
msgstr ""
 | 
			
		||||
"Senden Sie diesen Link an andere KSP Nutzer, damit sie Schreibrechte auf diese Daten erhalten."
 | 
			
		||||
#: intervention/forms.py:265
 | 
			
		||||
msgid "Share settings for {}"
 | 
			
		||||
msgstr "Freigabe Einstellungen für {}"
 | 
			
		||||
 | 
			
		||||
#: intervention/tables.py:70
 | 
			
		||||
msgid "Interventions"
 | 
			
		||||
@ -390,14 +401,6 @@ msgstr "Zuletzt bearbeitet"
 | 
			
		||||
msgid "No geometry added, yet."
 | 
			
		||||
msgstr "Keine Geometrie vorhanden"
 | 
			
		||||
 | 
			
		||||
#: intervention/templates/intervention/text-to-clipboard-input.html:6
 | 
			
		||||
msgid "Copy to clipboard"
 | 
			
		||||
msgstr "In Zwischenablage kopieren"
 | 
			
		||||
 | 
			
		||||
#: intervention/templates/intervention/text-to-clipboard-input.html:16
 | 
			
		||||
msgid "Copied to clipboard"
 | 
			
		||||
msgstr "In Zwischenablage kopiert"
 | 
			
		||||
 | 
			
		||||
#: intervention/views.py:62
 | 
			
		||||
msgid "Intervention {} added"
 | 
			
		||||
msgstr "Eingriff {} hinzugefügt"
 | 
			
		||||
@ -436,6 +439,10 @@ msgstr "{} ist nun für Sie freigegeben"
 | 
			
		||||
msgid "Share link invalid"
 | 
			
		||||
msgstr "Freigabelink ungültig"
 | 
			
		||||
 | 
			
		||||
#: intervention/views.py:262
 | 
			
		||||
msgid "Share settings updated"
 | 
			
		||||
msgstr "Freigabe Einstellungen aktualisiert"
 | 
			
		||||
 | 
			
		||||
#: konova/decorators.py:29
 | 
			
		||||
msgid "You need to be staff to perform this action!"
 | 
			
		||||
msgstr "Hierfür müssen Sie Mitarbeiter sein!"
 | 
			
		||||
@ -509,6 +516,14 @@ msgstr "Wenn meine freigegebenen Daten gelöscht wurden"
 | 
			
		||||
msgid "On registered data edited"
 | 
			
		||||
msgstr "Wenn meine freigegebenen Daten bearbeitet wurden"
 | 
			
		||||
 | 
			
		||||
#: konova/templates/konova/custom_widgets/text-to-clipboard-input.html:6
 | 
			
		||||
msgid "Copy to clipboard"
 | 
			
		||||
msgstr "In Zwischenablage kopieren"
 | 
			
		||||
 | 
			
		||||
#: konova/templates/konova/custom_widgets/text-to-clipboard-input.html:16
 | 
			
		||||
msgid "Copied to clipboard"
 | 
			
		||||
msgstr "In Zwischenablage kopiert"
 | 
			
		||||
 | 
			
		||||
#: konova/templates/konova/home.html:23 konova/templates/konova/home.html:61
 | 
			
		||||
#: konova/templates/konova/home.html:100
 | 
			
		||||
msgid "Total"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user