internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: learningequality/kolibri

Issue:
improve handling of video transcripts with RTL languages
### Observed behavior

observed during the beta 1 bug bash by @jeepurs:

> Arabic video transcript looks left to right
> 
> http://kolibribeta.learningequality.org/en/learn/#/topics/c/ac962cea9c185057baec90ec6c46814c is an example video of the TED ones in Arabic
> 
> ![image](https://user-images.githubusercontent.com/2367265/69928118-79772c00-146f-11ea-9382-1f3387d60c8e.png)


### Expected behavior

This is rather subtle, especially when the app language and transcript language might be different from each other.

* The overall user interface layout should conform to the current language set at the application level. In this case, if Kolibri is set to Arabic then UI elements that are typically on the right should be on the left, and vice-versa. For example, the overall transcript viewer and the specific location of timestamps should be mirrored. See #4686 for an example of making the epub content renderer RTL-compatible
* The individual text transcript lines should be aligned based on their actual content. If Kolibri is set to English but the transcript is in Arabic, the text should be right-aligned. If Kolibri is in Arabic but the text is in English, the text should be left-aligned. In general this can be achieved by simply setting `dir="auto"`. See #3781 for more info

### User-facing consequences

users of RTL languages have a less-optimal experience


### Steps to reproduce

* view RTL-language transcripts with the app set to an LRT language
* view LTR-language transcripts with the app set to an RTL language
* view RTL-language transcripts with the app set to an RTL language

### Context

0.13.0 beta 3


Discussion:
migrated part of issue to https://github.com/learningequality/kolibri/issues/6239
This probably needs confirmation that it can be reproduced, but I think this could be done within the scope of the issue and doesn't necessarily need QA re-review

Resolving patch:
diff --git a/kolibri/core/kolibri_plugin.py b/kolibri/core/kolibri_plugin.py
--- a/kolibri/core/kolibri_plugin.py
+++ b/kolibri/core/kolibri_plugin.py
@@ -147,7 +147,7 @@ def language_globals(self):
                 "english_name": lang_info["english_name"]
                 if lang_info
                 else get_language_info(code)["name"],
-                "lang_direction": get_language_info(code)["bidi"],
+                "lang_direction": "rtl" if get_language_info(code)["bidi"] else "ltr",
             }
         return {
             "coreLanguageMessages": self.frontend_messages(),


Test patch:
Repository: learningequality/kolibri

Issue:
SetupWizard | Syncing: Investigate cancleable tasks during user import
## Observed behavior
<!--
Description of the behavior that was observed, including screenshots or other references when applicable
-->

**Possibly an issue outside of the Setup Wizard:** 

Peter reported that the "Cancel" button was not working on the task after going through **LOD -> Create new user**. Investigate if this is due to a failure to properly handle the "Cancel" button in the Setup Wizard or if the "Cancel" button is not working in other contexts (content import?).


Discussion:

Resolving patch:
diff --git a/kolibri/core/auth/tasks.py b/kolibri/core/auth/tasks.py
--- a/kolibri/core/auth/tasks.py
+++ b/kolibri/core/auth/tasks.py
@@ -835,7 +835,7 @@ def validate(self, data):
 
 @register_task(
     validator=PeerImportSingleSyncJobValidator,
-    cancellable=True,
+    cancellable=False,
     track_progress=True,
     queue=soud_sync_queue,
     permission_classes=[IsSuperAdmin() | NotProvisioned()],


Test patch:
Repository: learningequality/kolibri

Issue:
AttributeError: 'NoneType' object has no attribute 'getpeername'
<!--
Instructions:
 * Fill out the sections below, replace …'s with information about your issue
 * Use the 'preview' function above this text box to verify formatting before submitting
-->

## Observed behavior
<!--
Description of the behavior that was observed, including screenshots or other references when applicable
-->
Observed during the bug bash, in logs from @AllanOXDi's device. The error occurred during a request for a device's facilities within new code that's meant to obtain the remote IP address of the device.

## Errors and logs
```
ERROR 2023-03-30 22:57:42,880 django.request Internal Server Error: /api/discovery/networklocation_facilities/3360a0e95197f8effe006caed955f118/
Traceback (most recent call last):
  File "django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "rest_framework/viewsets.py", line 116, in view
  File "rest_framework/views.py", line 495, in dispatch
  File "rest_framework/views.py", line 455, in handle_exception
  File "rest_framework/views.py", line 492, in dispatch
  File "kolibri/core/discovery/api.py", line 65, in retrieve
  File "kolibri/core/discovery/utils/network/client.py", line 104, in get
  File "kolibri/core/discovery/utils/network/client.py", line 119, in request
AttributeError: 'NoneType' object has no attribute 'getpeername'
```

## Expected behavior
<!--
Description of what behavior was expected but did not occur
-->
The code is defensive against this being `None`


## Context
<!--
Tell us about your environment, including:
 * Kolibri version
 * Operating system
 * Browser
-->
Kolibri 0.16.0a11



Discussion:

Resolving patch:
diff --git a/kolibri/core/discovery/utils/network/client.py b/kolibri/core/discovery/utils/network/client.py
--- a/kolibri/core/discovery/utils/network/client.py
+++ b/kolibri/core/discovery/utils/network/client.py
@@ -115,6 +115,9 @@ def request(self, method, path, **kwargs):
             with super(NetworkClient, self).request(
                 method, url, stream=True, **kwargs
             ) as response:
+                if response.raw._connection.sock is None:
+                    raise requests.exceptions.ConnectionError("No socket available")
+
                 # capture the remote IP address, which requires `stream=True` and before consumed
                 self.remote_ip = response.raw._connection.sock.getpeername()[0]
                 # now consume content, see how `Session.send` does this when `stream=False`


Test patch:
Repository: learningequality/kolibri

Issue:
Finalize Studio remote browsing integration
## Observed behavior
https://github.com/learningequality/kolibri/pull/10227 was merged with some fairly involved special case logic for Studio that uses the existing RemoteChannelsEndpoint.

Now that the implementation of the public APIs on Studio have been finalized and merged to unstable, we can now do further testing of this flow using unstable as our upstream Studio, and remove most of th

## Expected behavior
With the new API endpoints in place, we should be able to check Studio's info endpoint, and confirm that it is indeed upgraded to a version equivalent to Kolibri 0.16.0 (using the minVersion composable logic), and then display it if so.

We should then be able to browse the device exactly like any other, with current device info that sets the `baseurl` to the set Studio URL in Kolibri configuration.

To test with unstable we can override this configuration by setting this environment variable:
```
KOLIBRI_CENTRAL_CONTENT_BASE_URL=https://unstable.studio.learningequality.org/
```


Discussion:
Added https://github.com/learningequality/kolibri/issues/10431

Resolving patch:
diff --git a/kolibri/core/content/api.py b/kolibri/core/content/api.py
--- a/kolibri/core/content/api.py
+++ b/kolibri/core/content/api.py
@@ -121,7 +121,8 @@ def _should_proxy_request(self, request):
     def _get_request_headers(self, request):
         return {
             "Accept": request.META.get("HTTP_ACCEPT"),
-            "Accept-Encoding": request.META.get("HTTP_ACCEPT_ENCODING"),
+            # Don't proxy client's accept headers as it may include br for brotli
+            # that we cannot rely on having decompression for available on the server.
             "Accept-Language": request.META.get("HTTP_ACCEPT_LANGUAGE"),
             "Content-Type": request.META.get("CONTENT_TYPE"),
             "If-None-Match": request.META.get("HTTP_IF_NONE_MATCH", ""),
@@ -154,6 +155,9 @@ def _hande_proxied_request(self, request):
             response = requests.get(
                 remote_url, params=qs, headers=self._get_request_headers(request)
             )
+            if response.status_code == 404:
+                raise Http404("Remote resource not found")
+            response.raise_for_status()
             # If Etag is set on the response we have returned here, any further Etag will not be modified
             # by the django etag decorator, so this should allow us to transparently proxy the remote etag.
             try:
@@ -1721,6 +1725,9 @@ def kolibri_studio_status(self, request, **kwargs):
             if resp.status_code == 404:
                 raise requests.ConnectionError("Kolibri Studio URL is incorrect!")
             else:
-                return Response({"status": "online"})
+                data = resp.json()
+                data["available"] = True
+                data["status"] = "online"
+                return Response(data)
         except requests.ConnectionError:
-            return Response({"status": "offline"})
+            return Response({"status": "offline", "available": False})


Test patch:
Repository: learningequality/kolibri

Issue:
Removing last user from "on my own facility" does not remove the facility from the device

## Observed behavior
Reported by @rtibbles in the alpha9 bug bash 

When the last user is migrated out of an on my own facility, that facility is not removed from the device

## Expected behavior
The facility should be removed from the device



Discussion:

Resolving patch:
diff --git a/kolibri/plugins/user_profile/tasks.py b/kolibri/plugins/user_profile/tasks.py
--- a/kolibri/plugins/user_profile/tasks.py
+++ b/kolibri/plugins/user_profile/tasks.py
@@ -9,6 +9,7 @@
 from kolibri.core.auth.constants import role_kinds
 from kolibri.core.auth.models import FacilityUser
 from kolibri.core.auth.tasks import PeerImportSingleSyncJobValidator
+from kolibri.core.auth.utils.delete import delete_facility
 from kolibri.core.auth.utils.migrate import merge_users
 from kolibri.core.device.models import DevicePermissions
 from kolibri.core.device.utils import set_device_settings
@@ -32,6 +33,7 @@ class MergeUserValidator(PeerImportSingleSyncJobValidator):
         queryset=FacilityUser.objects.all(), required=False
     )
     facility_name = serializers.CharField(default="")
+    set_as_super_user = serializers.BooleanField(required=False)
 
     def validate(self, data):
         try:
@@ -44,6 +46,8 @@ def validate(self, data):
         job_data["extra_metadata"].update(user_fullname=data["local_user_id"].full_name)
         if data.get("new_superuser_id"):
             job_data["kwargs"]["new_superuser_id"] = data["new_superuser_id"].id
+        if data.get("set_as_super_user"):
+            job_data["kwargs"]["set_as_super_user"] = data["set_as_super_user"]
 
         return job_data
 
@@ -152,4 +156,14 @@ def mergeuser(command, **kwargs):
     job.extra_metadata["remote_user_pk"] = remote_user_pk
     job.save_meta()
     job.update_progress(1.0, 1.0)
-    local_user.delete()
+
+    # check if current user should be set as superuser:
+    set_as_super_user = kwargs.get("set_as_super_user")
+    if set_as_super_user:
+        DevicePermissions.objects.create(
+            user=remote_user, is_superuser=True, can_manage_content=True
+        )
+        delete_facility(local_user.facility)
+        set_device_settings(default_facility=remote_user.facility)
+    else:
+        local_user.delete()


Test patch:
Repository: learningequality/kolibri

Issue:
Modal for adding a storage location doesn't resolve some special characters
## Observed behavior
Noted by @jamalex in the alpha12 bug bash:

Modal for adding content storage location doesn’t resolve things like “~”. Maybe we want to use os.path.realpath() when resolving these paths?


## Steps to reproduce
Add a path in the Device Settings page that uses "~"

## Context
0.16.0-alpha12


Discussion:

Resolving patch:
diff --git a/kolibri/core/device/api.py b/kolibri/core/device/api.py
--- a/kolibri/core/device/api.py
+++ b/kolibri/core/device/api.py
@@ -63,6 +63,7 @@
 from kolibri.utils.conf import OPTIONS
 from kolibri.utils.filesystem import check_is_directory
 from kolibri.utils.filesystem import get_path_permission
+from kolibri.utils.filesystem import resolve_path
 from kolibri.utils.server import get_status_from_pid_file
 from kolibri.utils.server import get_urls
 from kolibri.utils.server import installation_type
@@ -434,5 +435,6 @@ def get(self, request):
             {
                 "writable": get_path_permission(pathname),
                 "directory": check_is_directory(pathname),
+                "path": resolve_path(pathname),
             }
         )
diff --git a/kolibri/utils/filesystem.py b/kolibri/utils/filesystem.py
--- a/kolibri/utils/filesystem.py
+++ b/kolibri/utils/filesystem.py
@@ -13,7 +13,7 @@ def get_path_permission(path):
     :return: True if the path is writable, False otherwise.
     """
     try:
-        return os.access(path, os.W_OK)
+        return os.access(resolve_path(path), os.W_OK)
     except (IOError, OSError):
         return False
 
@@ -25,6 +25,18 @@ def check_is_directory(path):
     :return: True if the path is a directory.
     """
     try:
-        return os.path.exists(path)
+        return os.path.exists(resolve_path(path))
     except (IOError, OSError):
         return False
+
+
+def resolve_path(path):
+    """
+    Expand and resolve the path.
+    :param path: Path to expand and resolve
+    :return: The resolved path.
+    """
+    try:
+        return os.path.realpath(os.path.expanduser(path))
+    except (IOError, OSError):
+        return None


Test patch:
Repository: learningequality/kolibri

Issue:
Cannot update DeviceSettings
## Observed behavior
Reported by @nucleogenesis [in the alpha13 bug bash ](https://www.notion.so/learningequality/Cannot-update-DeviceSettings-24859b98d15b411a8c55b83cddebc6d6?pvs=4)

> I tried to change a device setting, but it failed due to (it seems) a bad or unexpected value for secondary_storage_... 


## Context
0.16.0-a13



Discussion:

Resolving patch:
diff --git a/kolibri/utils/filesystem.py b/kolibri/utils/filesystem.py
--- a/kolibri/utils/filesystem.py
+++ b/kolibri/utils/filesystem.py
@@ -36,6 +36,9 @@ def resolve_path(path):
     :param path: Path to expand and resolve
     :return: The resolved path.
     """
+    if not path:  # Check if the path is empty
+        return path
+
     try:
         return os.path.realpath(os.path.expanduser(path))
     except (IOError, OSError):


Test patch:
Repository: learningequality/kolibri

Issue:
Update device provisioning so that first user is given superadmin permissions
## Observed behavior
Currently, our device provisioning grants the first of a provisioned device 'content management' permissions. Because this user is not granted 'super admin' permissions, the device never has a superadmin. 

## Desired behavior
The provisioning should be updated so that the first user has 'device superuser permissions'. 

## User-facing consequences
This update will allow for much better management of provisioned devices. Related problems have been reported by S2S regarding the difficulty of re-provisioning devices, or otherwise managing provisioned devices. This update will be a first step to alleviating some of these concerns, and by creating the superuser, it will allow for more work to build on top of this, to further improve the workflows around device provisioning.

In 0.15, we avoided doing this, as there was concern about granting full superuser permissions to the learner imported onto the device. However, in 0.16, we are mitigating against this with the PIN functionality, to allow some restrictions on access. This means that the downsides of not having a super admin outweight these risks.


Discussion:
@akolson do you recall if the PIN prompt checks the user type (ie, if the user is a SuperAdmin, don't show the PIN prompt)?
Yes, we do check for the user type. More precisely we check for
```
if (get(isLearnerOnlyImport) && !isFacilityAdmin && (isSuperuser || userCanManageContent)) {...}
```

Resolving patch:
diff --git a/kolibri/core/device/serializers.py b/kolibri/core/device/serializers.py
--- a/kolibri/core/device/serializers.py
+++ b/kolibri/core/device/serializers.py
@@ -197,7 +197,7 @@ def create(self, validated_data):  # noqa C901
                 if DevicePermissions.objects.count() == 0:
                     DevicePermissions.objects.create(
                         user=superuser,
-                        is_superuser=not is_soud,
+                        is_superuser=True,
                         can_manage_content=True,
                     )
 


Test patch:
Repository: learningequality/kolibri

Issue:
Remote browsing - Search and filters are not working
## Observed behavior
Both search and filters are not working while remote browsing.

## Expected behavior
Fully functional search and fitlers.

## Steps to reproduce the issue
1. Install the latest develop build
2. Navigate to Library > Explore libraries > Browse channel > Folder 
3. Attempt to search by a keyword or apply a filter

## Video

https://github.com/learningequality/kolibri/assets/79847249/93e5d096-4b98-4748-93c5-015009b3b368

## Usage Details
Kolibri 0.16alfa17
Windows 10, Ubuntu - Chrome


Discussion:
@radinamatic 
Confirming that the search and filtering is not getting any results on both remote browsing the Kolibri Library on Studio, as well when browsing other peer libraries.


https://github.com/learningequality/kolibri/assets/1457929/da1f489a-285d-49c0-a2d3-1698d1a23bd7


Thanks @radinamatic - at least that means it's an issue on the Kolibri side, and we don't have to fix anything on Studio! I'll take it from here.
Some additional testing confirms that not only the keyword search, but also none of the filters work during remote browsing, both on Kolibri Library (Studio), or on peer libraries. Basically, none of them are active/actionable... 


https://github.com/learningequality/kolibri/assets/1457929/b8bb3575-cd0c-436f-97b1-582f2753205d


Recording is from browsing Studio, but it's absolutely the same on peer library

Resolving patch:
diff --git a/kolibri/utils/kolibri_whitenoise.py b/kolibri/utils/kolibri_whitenoise.py
--- a/kolibri/utils/kolibri_whitenoise.py
+++ b/kolibri/utils/kolibri_whitenoise.py
@@ -141,7 +141,7 @@ class StreamingStaticFile(EndRangeStaticFile):
     def __init__(self, path, headers, remote_url, encodings=None, stat_cache=None):
         self.path = path
         self.remote_url = remote_url
-        super().__init__(path, headers, encodings, stat_cache)
+        super(StreamingStaticFile, self).__init__(path, headers, encodings, stat_cache)
 
     @staticmethod
     def get_file_stats(path, encodings, stat_cache):


Test patch:
Repository: learningequality/kolibri

Issue:
Mac app - Cannot save the changes made at Device > Settings
## Observed behavior
Nothing happens when I click the 'Save changes' button at Device > Settings

## Expected behavior
All changes made should be saved.

## Steps to reproduce the issue
1. Install the [v0.16.0-beta1](https://github.com/learningequality/kolibri/releases/tag/v0.16.0-beta1) 
2. Go to Device > Settings
3. Click the 'Save changes' button

## Video

https://github.com/learningequality/kolibri/assets/79847249/4c695726-8a5a-4250-b9ca-25583e5762ac

## Logs

[logs.zip](https://github.com/learningequality/kolibri/files/12309862/logs.zip)

## Usage Details
Kolibri 0.16.0b1
MacOS Catalina version 10.15.7


Discussion:
@radinamatic 
@pcenov can you attach the log files for this?
@rtibbles - yes, I've attached them now.

Resolving patch:
diff --git a/kolibri/plugins/utils/__init__.py b/kolibri/plugins/utils/__init__.py
--- a/kolibri/plugins/utils/__init__.py
+++ b/kolibri/plugins/utils/__init__.py
@@ -474,7 +474,7 @@ def check_plugin_config_file_location(version):
 def iterate_plugins():
     # Use to dedupe plugins
     plugin_ids = set()
-    for entry_point in entry_points()["kolibri.plugins"]:
+    for entry_point in entry_points().get("kolibri.plugins", []):
         name = entry_point.name
         if name not in plugin_ids:
             plugin_ids.add(name)


Test patch:
Repository: learningequality/kolibri

Issue:
Learn-only device - The 'Full name' value entered in the setup wizard is missing
## Observed behavior
If I create a new learner user through the 'LOD>Create a new user account for an existing facility' user flow then the 'Full name' value is missing from both the learner's profile page and the user details in Facility > Users

![2023-09-01_15-24-40](https://github.com/learningequality/kolibri/assets/79847249/23ba6915-2ab3-45a4-a62b-4665115a8c9f)

## Expected behavior
The 'Full name' value should be stored and displayed correctly as it is a required field.

## Steps to reproduce the issue
1. Install the latest [Beta 4 build](https://github.com/learningequality/kolibri/releases/tag/v0.16.0-beta4).
2. On one VM create a Full facility
3. On another VM go through the 'LOD>Create a new user account for an existing facility' user flow

## More information

https://github.com/learningequality/kolibri/assets/79847249/0a5e978b-ee99-481b-8ce3-d5c4d166eef2

## Usage Details
Kolibri 0.16beta4
Windows 10, Ubuntu - Chrome, Firefox


Discussion:
@radinamatic 
hey @radinamatic i would like to give a try to resolve the above mentioned issue , can you assign it to me .
Hi @GarvitSinghal47, we think it'd be best to leave this issue for one of the core team members. I recently assigned you another issue which is a pretty big one, so it'd suggest we focus on that for now.

Resolving patch:
diff --git a/kolibri/plugins/setup_wizard/api.py b/kolibri/plugins/setup_wizard/api.py
--- a/kolibri/plugins/setup_wizard/api.py
+++ b/kolibri/plugins/setup_wizard/api.py
@@ -42,6 +42,7 @@ def createuseronremote(self, request):
         facility_id = request.data.get("facility_id", None)
         username = request.data.get("username", None)
         password = request.data.get("password", None)
+        full_name = request.data.get("full_name", "")
         baseurl = request.data.get("baseurl", None)
 
         api_url = reverse("kolibri:core:publicsignup-list")
@@ -52,6 +53,7 @@ def createuseronremote(self, request):
             "facility_id": facility_id,
             "username": username,
             "password": password,
+            "full_name": full_name,
         }
 
         r = requests.post(url, data=payload)


Test patch: