[gtranslator] Disable redirection on DL requests



commit 21115425362ac8a32b5a4c95cda8de757d6282fc
Author: Daniel GarcĂ­a Moreno <dani danigm net>
Date:   Mon Mar 15 09:18:17 2021 +0100

    Disable redirection on DL requests
    
    This patch disables the redirecction management in the soup message sent
    to the damned lies server to receive the real response 302 status code
    when the authentication code is not correct.
    
    This will fix the problem of not having configured the token and trying
    to reserve a module with a better error message.
    
    Fix https://gitlab.gnome.org/GNOME/gtranslator/-/issues/129

 src/gtr-actions-file.c | 19 +++++++++++++------
 src/gtr-dl-teams.c     | 25 ++++++++++++++++---------
 2 files changed, 29 insertions(+), 15 deletions(-)
---
diff --git a/src/gtr-actions-file.c b/src/gtr-actions-file.c
index d76c9ed7..2f8d6fd4 100644
--- a/src/gtr-actions-file.c
+++ b/src/gtr-actions-file.c
@@ -430,6 +430,7 @@ gtr_upload_file_dialog (GtkAction * action, GtrWindow * window)
 
   /* Get the associated message */
   msg = soup_form_request_new_from_multipart (upload_endpoint, mpart);
+  soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
 
   /* Append the authentication header*/
   soup_message_headers_append (msg->request_headers, "Authentication", auth);
@@ -452,12 +453,18 @@ gtr_upload_file_dialog (GtkAction * action, GtrWindow * window)
           return;
         }
 
-      dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                       flags,
-                                       GTK_MESSAGE_WARNING,
-                                       GTK_BUTTONS_CLOSE,
-                                       _("An error occurred while uploading the file: %s"),
-                                       soup_status_get_phrase (msg->status_code));
+      dialog = gtk_message_dialog_new_with_markup (
+        GTK_WINDOW (window),
+        flags,
+        GTK_MESSAGE_WARNING,
+        GTK_BUTTONS_CLOSE,
+        _(
+          "An error occurred while uploading the file: %s\n"
+          "Maybe you've not configured your <i>l10n.gnome.org</i> "
+          "<b>token</b> correctly in your profile or you don't have "
+          "permissions to upload this module."
+        ),
+        soup_status_get_phrase (msg->status_code));
       gtk_dialog_run (GTK_DIALOG (dialog));
       gtk_widget_destroy (dialog);
       return;
diff --git a/src/gtr-dl-teams.c b/src/gtr-dl-teams.c
index 9337cf2e..cfe6fa42 100644
--- a/src/gtr-dl-teams.c
+++ b/src/gtr-dl-teams.c
@@ -630,20 +630,27 @@ gtr_dl_teams_reserve_for_translation (GtkWidget *button, GtrDlTeams *self)
                                   "/reserve", NULL);
 
   msg = soup_message_new ("POST", reserve_endpoint);
+  soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
   soup_message_headers_append (msg->request_headers, "Authentication", auth);
   session = soup_session_new ();
   soup_session_send_message (session, msg);
 
-  if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code))
+  if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
   {
-    dialog = gtk_message_dialog_new(GTK_WINDOW(priv->main_window),
-                                    GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                    GTK_MESSAGE_WARNING,
-                                    GTK_BUTTONS_CLOSE,
-                                    _("An error occurred while reserving this module: %s"),
-                                    soup_status_get_phrase(msg->status_code));
-    gtk_dialog_run(GTK_DIALOG(dialog));
-    gtk_widget_destroy(dialog);
+    dialog = gtk_message_dialog_new_with_markup (
+      GTK_WINDOW (priv->main_window),
+      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+      GTK_MESSAGE_WARNING,
+      GTK_BUTTONS_CLOSE,
+      _(
+        "An error occurred while reserving this module: %s\n"
+        "Maybe you've not configured your <i>l10n.gnome.org</i> "
+        "<b>token</b> correctly in your profile or you don't have "
+        "permissions to reserve this module."
+      ),
+      soup_status_get_phrase (msg->status_code));
+    gtk_dialog_run (GTK_DIALOG (dialog));
+    gtk_widget_destroy (dialog);
     return FALSE;
   }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]